Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Led Count #82

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7a49111
dynamic led count take 2
Unreal-Dan Jul 30, 2023
4acfe68
fix
Unreal-Dan Jul 30, 2023
ed8bfbc
fixes
Unreal-Dan Jul 30, 2023
9e32f1f
minor fix
Unreal-Dan Jul 30, 2023
91fadf8
Merge branch 'master' into daniel/core/dynamic_led_count
Unreal-Dan Aug 6, 2023
5bad8c4
Merge branch 'master' into daniel/core/dynamic_led_count
Unreal-Dan Aug 7, 2023
a47913b
dynamic led count take 2
Unreal-Dan Jul 30, 2023
cc160d4
fix
Unreal-Dan Jul 30, 2023
91bca4c
fixes
Unreal-Dan Jul 30, 2023
cebd054
minor fix
Unreal-Dan Jul 30, 2023
87566a0
Merge branch 'daniel/core/dynamic_led_count' of https://github.com/Un…
Unreal-Dan Sep 1, 2023
87b514a
Merge branch 'master' into daniel/core/dynamic_led_count
Unreal-Dan Sep 8, 2023
7e5e865
Merge remote-tracking branch 'origin/master' into daniel/core/dynamic…
Unreal-Dan Sep 10, 2023
bf5ec31
minor fixes
Unreal-Dan Sep 11, 2023
e905c09
fix
Unreal-Dan Sep 11, 2023
dcb77a1
fixed wasm
Unreal-Dan Sep 11, 2023
0a09eed
fix
Unreal-Dan Sep 11, 2023
7fa53ab
fixes
Unreal-Dan Sep 11, 2023
68953f0
added functions
Unreal-Dan Sep 11, 2023
a5e8d87
fixes
Unreal-Dan Sep 11, 2023
9802d7e
Added new wasm api
Unreal-Dan Sep 12, 2023
1e3c305
rapid click
Unreal-Dan Sep 12, 2023
332870c
Lots of new bindings
Unreal-Dan Sep 16, 2023
1238ac9
more fixes and bindings
Unreal-Dan Sep 16, 2023
47c3eb0
registered vector of strings
Unreal-Dan Sep 18, 2023
42917d4
added more bindings
Unreal-Dan Sep 18, 2023
7e81e67
fixes
Unreal-Dan Sep 18, 2023
5d19117
fixes and more bindings
Unreal-Dan Sep 24, 2023
268b786
build flag
Unreal-Dan Sep 24, 2023
0c00c32
adjustment to vortexlib for matching led count
Unreal-Dan Dec 1, 2023
7e9af23
Merge branch 'master' into daniel/core/dynamic_led_count
Unreal-Dan Dec 1, 2023
4d25d6b
recorded tests
Unreal-Dan Dec 1, 2023
e8a1827
Merge branch 'master' into daniel/core/dynamic_led_count
Unreal-Dan Dec 12, 2023
2f7c213
Merge branch 'master' into daniel/core/dynamic_led_count
Unreal-Dan Dec 12, 2023
5434e01
Merge branch 'master' into daniel/core/dynamic_led_count
Unreal-Dan Dec 12, 2023
a16c7e5
Merge branch 'master' into daniel/core/dynamic_led_count
Unreal-Dan Dec 14, 2023
d93c63a
Merge branch 'master' into daniel/core/dynamic_led_count
Unreal-Dan Dec 14, 2023
0ff3d3d
Merge branch 'master' into daniel/core/dynamic_led_count
Unreal-Dan Dec 21, 2023
984cef5
Merge branch 'master' into daniel/core/dynamic_led_count
Unreal-Dan Dec 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions VortexEngine/VortexLib/VortexLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,9 @@ EMSCRIPTEN_BINDINGS(Vortex) {
.class_function("getModes", &Vortex::getModes)
.class_function("setModes", &Vortex::setModes)
.class_function("getCurMode", &Vortex::getCurMode)
.class_function("matchLedCount", &Vortex::matchLedCount)
.class_function("checkLedCount", &Vortex::checkLedCount)
.class_function("setLedCount", &Vortex::setLedCount)
.class_function("curModeIndex", &Vortex::curModeIndex)
.class_function("numModes", &Vortex::numModes)
.class_function("numLedsInMode", &Vortex::numLedsInMode)
Expand Down Expand Up @@ -1046,6 +1049,63 @@ bool Vortex::setModes(ByteStream &stream, bool save)
return !save || doSave();
}

bool Vortex::matchLedCount(ByteStream &stream)
{
#if FIXED_LED_COUNT == 0
if (!stream.decompress()) {
return false;
}
// reset the unserializer index before unserializing anything
stream.resetUnserializer();
uint8_t major = 0;
uint8_t minor = 0;
// unserialize the vortex version
stream.unserialize(&major);
stream.unserialize(&minor);
uint8_t flags;
stream.unserialize(&flags);
// unserialize the global brightness
uint8_t brightness = 0;
stream.unserialize(&brightness);
uint8_t numModes = 0;
stream.unserialize(&numModes);
uint8_t ledCount = 0;
stream.unserialize(&ledCount);
// put the unserializer back where it was for the next thing
stream.resetUnserializer();
return setLedCount(ledCount);
#else
return false;
#endif
}

bool Vortex::checkLedCount()
{
#if FIXED_LED_COUNT == 0
Mode *mode = Modes::curMode();
if (!mode) {
return false;
}
uint8_t numLeds = mode->getLedCount();
if (numLeds != LED_COUNT) {
Leds::setLedCount(numLeds);
}
#endif
return true;
}

bool Vortex::setLedCount(uint8_t count)
{
#if FIXED_LED_COUNT == 0
Mode *cur = Modes::curMode();
if (cur && !cur->setLedCount(count)) {
return false;
}
Leds::setLedCount(count);
#endif
return true;
}

bool Vortex::getCurMode(ByteStream &outStream)
{
Mode *pMode = Modes::curMode();
Expand Down
4 changes: 4 additions & 0 deletions VortexEngine/VortexLib/VortexLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ class Vortex
static bool setModes(ByteStream &stream, bool save = true);
static bool getCurMode(ByteStream &stream);

static bool matchLedCount(ByteStream &stream);
static bool checkLedCount();
static bool setLedCount(uint8_t ledCount);

// functions to operate on the current mode selection
static uint32_t curModeIndex();
static uint32_t numModes();
Expand Down
3 changes: 3 additions & 0 deletions VortexEngine/src/Leds/LedStash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
LedStash::LedStash() :
m_ledColorsStash()
{
#if FIXED_LED_COUNT == 0
m_ledColorsStash.resize(LED_COUNT);
#endif
}

void LedStash::setIndex(LedPos pos, RGBColor col)
Expand Down
8 changes: 8 additions & 0 deletions VortexEngine/src/Leds/LedStash.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include "../Colors/ColorTypes.h"
#include "LedTypes.h"

#if FIXED_LED_COUNT == 0
#include <vector>
#endif

class LedStash
{
friend class Leds;
Expand All @@ -19,7 +23,11 @@ class LedStash
RGBColor &operator[](int index);

private:
#if FIXED_LED_COUNT == 1
RGBColor m_ledColorsStash[LED_COUNT];
#else
std::vector<RGBColor> m_ledColorsStash;
#endif
};

#endif
77 changes: 1 addition & 76 deletions VortexEngine/src/Leds/LedTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,80 +4,9 @@
#include <inttypes.h>
#include <stdarg.h>

#include "../Leds/Leds.h"
#include "../VortexConfig.h"

// Defined the LED positions, their order, and index
enum LedPos : uint8_t
{
// this should always be first
LED_FIRST = 0,

// LED constants for each led
LED_0 = LED_FIRST,
LED_1,
LED_2,
LED_3,
LED_4,
LED_5,
LED_6,
LED_7,
LED_8,
LED_9,

// the number of entries above
LED_COUNT,

// the last LED index
LED_LAST = (LED_COUNT - 1),

// target all leds (multi and single)
// When fetching this the same as LED_ANY
// When setting this will set all of the leds
LED_ALL = LED_COUNT,

// target the multi led slot
//
// When fetching this will return the multi led slot
// When setting this will set the multi led slot
LED_MULTI = (LED_COUNT + 1),

// target all single led slots
//
// When fetching this will return the first single led slot
// When setting this will set all single led slots
LED_ALL_SINGLE = (LED_COUNT + 2),

// Target the 'effective' led slot (any slot)
//
// When fetching this will:
// 1. return the multi led slot if it exists
// 2. otherwise the first single led slot
//
// When setting this will:
// 1. if setting single led pattern will set all
// 2. if setting multi led pattern will set multi
LED_ANY = (LED_COUNT + 3),

// other customs?
// LED_EVENS = (LED_COUNT + 2),
// LED_ODDS = (LED_COUNT + 3),
};

enum Pair : uint8_t
{
PAIR_FIRST = 0,

// one pair for each pair of leds, adjust this to be 2x the LED_COUNT
PAIR_0 = PAIR_FIRST,
PAIR_1,
PAIR_2,
PAIR_3,
PAIR_4,

PAIR_COUNT,
PAIR_LAST = (PAIR_COUNT - 1),
};

// check if an led is even or odd
#define isEven(pos) ((pos % 2) == 0)
#define isOdd(pos) ((pos % 2) != 0)
Expand All @@ -89,10 +18,6 @@ enum Pair : uint8_t
// convert an led position to a pair
#define ledToPair(pos) (Pair)((uint32_t)pos / 2)

// LedMap is a bitmap of leds, used for expressing whether to turn certain leds on
// or off with a single integer
typedef uint64_t LedMap;

// various macros for mapping leds to an LedMap
#define MAP_LED(led) (LedMap)((uint64_t)1 << led)
#define MAP_PAIR_EVEN(pair) MAP_LED(pairEven(pair))
Expand Down
21 changes: 21 additions & 0 deletions VortexEngine/src/Leds/Leds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,28 @@
#include "../../VortexLib/VortexLib.h"
#endif

#if FIXED_LED_COUNT == 0
// led count
uint8_t Leds::m_ledCount = 10;
// array of led color values
std::vector<RGBColor> Leds::m_ledColors;
#else
RGBColor Leds::m_ledColors[LED_COUNT] = { RGB_OFF };
#endif
// global brightness
uint8_t Leds::m_brightness = DEFAULT_BRIGHTNESS;

bool Leds::init()
{
#if FIXED_LED_COUNT == 0
setLedCount(LED_COUNT);
#endif
#ifdef VORTEX_LIB
#if FIXED_LED_COUNT == 0
Vortex::vcallbacks()->ledsInit(m_ledColors.data(), LED_COUNT);
#else
Vortex::vcallbacks()->ledsInit(m_ledColors, LED_COUNT);
#endif
#endif
return true;
}
Expand Down Expand Up @@ -252,3 +265,11 @@ void Leds::update()
Vortex::vcallbacks()->ledsShow();
#endif
}

#if FIXED_LED_COUNT == 0
void Leds::setLedCount(uint8_t leds)
{
m_ledCount = leds;
m_ledColors.resize(m_ledCount);
}
#endif
106 changes: 105 additions & 1 deletion VortexEngine/src/Leds/Leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,96 @@
#include <inttypes.h>

#include "../Colors/ColorTypes.h"
#include "LedTypes.h"
#include "../VortexConfig.h"

#if FIXED_LED_COUNT == 0
#include <vector>
// drop-in LedPos constant replacements
#define LED_COUNT Leds::ledCount()
#define LED_LAST Leds::ledLast()
#define LED_ALL LED_COUNT
#define LED_MULTI Leds::ledMulti()
#define LED_ALL_SINGLE Leds::ledAllSingle()
#define LED_ANY Leds::ledAny()
#endif

// Defined the LED positions, their order, and index
enum LedPos : uint8_t
{
// this should always be first
LED_FIRST = 0,

// LED constants to supplement pattern code
LED_0 = LED_FIRST,
LED_1,
LED_2,
LED_3,
LED_4,
LED_5,
LED_6,
LED_7,
LED_8,
LED_9,

#if FIXED_LED_COUNT == 1
// the number of entries above
LED_COUNT,

// the last LED index
LED_LAST = (LED_COUNT - 1),

// target all leds (multi and single)
// When fetching this the same as LED_ANY
// When setting this will set all of the leds
LED_ALL = LED_COUNT,

// target the multi led slot
//
// When fetching this will return the multi led slot
// When setting this will set the multi led slot
LED_MULTI = (LED_COUNT + 1),

// target all single led slots
//
// When fetching this will return the first single led slot
// When setting this will set all single led slots
LED_ALL_SINGLE = (LED_COUNT + 2),

// Target the 'effective' led slot (any slot)
//
// When fetching this will:
// 1. return the multi led slot if it exists
// 2. otherwise the first single led slot
//
// When setting this will:
// 1. if setting single led pattern will set all
// 2. if setting multi led pattern will set multi
LED_ANY = (LED_COUNT + 3),

// other customs?
// LED_EVENS = (LED_COUNT + 2),
// LED_ODDS = (LED_COUNT + 3),
#endif
};

enum Pair : uint8_t
{
PAIR_FIRST = 0,

// one pair for each pair of leds, adjust this to be 2x the LED_COUNT
PAIR_0 = PAIR_FIRST,
PAIR_1,
PAIR_2,
PAIR_3,
PAIR_4,

PAIR_COUNT,
PAIR_LAST = (PAIR_COUNT - 1),
};

// LedMap is a bitmap of leds, used for expressing whether to turn certain leds on
// or off with a single integer
typedef uint64_t LedMap;

class LedStash;

Expand Down Expand Up @@ -107,6 +196,15 @@ class Leds
// actually update the LEDs and show the changes
static void update();

#if FIXED_LED_COUNT == 0
static void setLedCount(uint8_t leds);
static LedPos ledCount() { return (LedPos)m_ledCount; }
static LedPos ledLast() { return (LedPos)(m_ledCount - 1); }
static LedPos ledMulti() { return (LedPos)(m_ledCount + 1); }
static LedPos ledAllSingle() { return (LedPos)(m_ledCount + 2); }
static LedPos ledAny() { return (LedPos)(m_ledCount + 3); }
#endif

private:
// accessor for led colors, use this for all access to allow for mapping
static inline RGBColor &led(LedPos pos)
Expand All @@ -120,8 +218,14 @@ class Leds
// the global brightness
static uint8_t m_brightness;

#if FIXED_LED_COUNT == 0
// dynamic led count
static uint8_t m_ledCount;
// array of led color values
static std::vector<RGBColor> m_ledColors;
#else
static RGBColor m_ledColors[LED_COUNT];
#endif
};

#endif
Loading