Added a usermod for interacting with BLE Pixels Dice.

This commit is contained in:
jdiamond
2024-08-08 03:13:33 +00:00
parent 7d7b7c1e25
commit 96c7716d3e
21 changed files with 2115 additions and 4 deletions

View File

@@ -7899,18 +7899,21 @@ static const char _data_RESERVED[] PROGMEM = "RSVD";
// add (or replace reserved) effect mode and data into vector
// use id==255 to find unallocated gaps (with "Reserved" data string)
// if vector size() is smaller than id (single) data is appended at the end (regardless of id)
void WS2812FX::addEffect(uint8_t id, mode_ptr mode_fn, const char *mode_name) {
// return the actual id used for the effect or 255 if the add failed.
uint8_t WS2812FX::addEffect(uint8_t id, mode_ptr mode_fn, const char *mode_name) {
if (id == 255) { // find empty slot
for (size_t i=1; i<_mode.size(); i++) if (_modeData[i] == _data_RESERVED) { id = i; break; }
}
if (id < _mode.size()) {
if (_modeData[id] != _data_RESERVED) return; // do not overwrite alerady added effect
if (_modeData[id] != _data_RESERVED) return 255; // do not overwrite an already added effect
_mode[id] = mode_fn;
_modeData[id] = mode_name;
return id;
} else {
_mode.push_back(mode_fn);
_modeData.push_back(mode_name);
if (_modeCount < _mode.size()) _modeCount++;
return (_mode.size() <= 255) ? _mode.size() - 1 : 255;
}
}