Some improvements.
This commit is contained in:
+120
-27
@@ -8,6 +8,23 @@
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
|
||||
|
||||
#define EEPROM_POS_STATUSTABLE 1
|
||||
#define EEPROM_POS_HOUROFFSET 2
|
||||
|
||||
union _eeprom_NotificationLEDs_StatusTable {
|
||||
struct {
|
||||
int hourOffset : 1;
|
||||
} status;
|
||||
uint8_t data;
|
||||
};
|
||||
|
||||
|
||||
// mathematically correct modulo
|
||||
#define MOD(a,b) ((((a)%(b))+(b))%(b))
|
||||
|
||||
|
||||
|
||||
template<
|
||||
uint8_t _tpin,
|
||||
uint8_t _trgbwId,
|
||||
@@ -33,6 +50,10 @@ public:
|
||||
void powerOn() noexcept;
|
||||
void returnToLastMode() noexcept;
|
||||
|
||||
void sendRGBWStatus() noexcept;
|
||||
void sendDimmerStatus() noexcept;
|
||||
void sendPowerSwitchStatus() noexcept;
|
||||
|
||||
void defaultScene_config(uint8_t id) noexcept;
|
||||
void defaultScene_init() noexcept;
|
||||
void defaultScene_loop(unsigned long currentUnixTime, unsigned long currentMillis) noexcept;
|
||||
@@ -41,6 +62,7 @@ public:
|
||||
void overrideScene_init() noexcept;
|
||||
void overrideScene_loop(unsigned long currentUnixTime, unsigned long currentMillis) noexcept;
|
||||
|
||||
void analogClock_setup() noexcept;
|
||||
void analogClock_config() noexcept;
|
||||
void analogClock_init() noexcept;
|
||||
void analogClock_loop(unsigned long currentUnixTime, unsigned long currentMillis) noexcept;
|
||||
@@ -57,6 +79,10 @@ public:
|
||||
void pulse1_init() noexcept;
|
||||
void pulse1_loop(unsigned long currentUnixTime, unsigned long currentMillis) noexcept;
|
||||
|
||||
void follow1_config() noexcept;
|
||||
void follow1_init() noexcept;
|
||||
void follow1_loop(unsigned long currentUnixTime, unsigned long currentMillis) noexcept;
|
||||
|
||||
protected:
|
||||
unsigned long lastSendTime = 0;
|
||||
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(_tpixelCount, _tpin, NEO_GRBW + NEO_KHZ800);
|
||||
@@ -110,6 +136,19 @@ protected:
|
||||
uint8_t pulseValue = 0;
|
||||
unsigned long lastMillis = 0;
|
||||
} pulse1;
|
||||
struct {
|
||||
union {
|
||||
uint8_t wrgb[4];
|
||||
uint32_t color = 0x00FF0000;
|
||||
} color;
|
||||
uint8_t maxCycles = 5;
|
||||
int8_t followDir = 1;
|
||||
int8_t followPos = 0;
|
||||
uint8_t waitTime = 50;
|
||||
uint8_t currentCycles = 0;
|
||||
bool finishing = false;
|
||||
unsigned long lastMillis = 0;
|
||||
} follow1;
|
||||
} sceneData;
|
||||
};
|
||||
|
||||
@@ -138,6 +177,7 @@ template<
|
||||
> void NotificationLEDs<_tpin, _trgbwId, _tdimmerId, _tpowerSwitchId, _tcommandId, _tpixelCount, _msgSendInterval>
|
||||
::setup() noexcept {
|
||||
pixels.begin();
|
||||
analogClock_setup();
|
||||
defaultScene_init();
|
||||
}
|
||||
|
||||
@@ -163,6 +203,62 @@ template<
|
||||
}
|
||||
|
||||
|
||||
template<
|
||||
uint8_t _tpin,
|
||||
uint8_t _trgbwId,
|
||||
uint8_t _tdimmerId,
|
||||
uint8_t _tpowerSwitchId,
|
||||
uint8_t _tcommandId,
|
||||
uint16_t _tpixelCount,
|
||||
unsigned long _msgSendInterval
|
||||
> void NotificationLEDs<_tpin, _trgbwId, _tdimmerId, _tpowerSwitchId, _tcommandId, _tpixelCount, _msgSendInterval>
|
||||
::sendRGBWStatus() noexcept {
|
||||
if (mode > 0 && sceneMode == 1) {
|
||||
_sendValue<bool>(true, _trgbwId, V_STATUS);
|
||||
char rgbw[9] = "00000000";
|
||||
// WRGB => RGBW
|
||||
String tmp((staticColor.color & 0xFF000000) >> 24 | ((staticColor.color & 0x00FFFFFF) << 8));
|
||||
memcpy(rgbw+(8-tmp.length()), tmp.c_str(), tmp.length());
|
||||
_sendValue<char*>(rgbw, _trgbwId, V_RGBW);
|
||||
} else {
|
||||
_sendValue<bool>(false, _trgbwId, V_STATUS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<
|
||||
uint8_t _tpin,
|
||||
uint8_t _trgbwId,
|
||||
uint8_t _tdimmerId,
|
||||
uint8_t _tpowerSwitchId,
|
||||
uint8_t _tcommandId,
|
||||
uint16_t _tpixelCount,
|
||||
unsigned long _msgSendInterval
|
||||
> void NotificationLEDs<_tpin, _trgbwId, _tdimmerId, _tpowerSwitchId, _tcommandId, _tpixelCount, _msgSendInterval>
|
||||
::sendDimmerStatus() noexcept {
|
||||
if (sceneMode == 0) {
|
||||
_sendValue<uint8_t>(brightness, _tdimmerId, V_PERCENTAGE);
|
||||
} else {
|
||||
uint16_t cb = max(staticColor.wrgb[0], max(staticColor.wrgb[1], max(staticColor.wrgb[2], staticColor.wrgb[3]))) * 100 / 255;
|
||||
_sendValue<uint8_t>(cb, _tdimmerId, V_PERCENTAGE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<
|
||||
uint8_t _tpin,
|
||||
uint8_t _trgbwId,
|
||||
uint8_t _tdimmerId,
|
||||
uint8_t _tpowerSwitchId,
|
||||
uint8_t _tcommandId,
|
||||
uint16_t _tpixelCount,
|
||||
unsigned long _msgSendInterval
|
||||
> void NotificationLEDs<_tpin, _trgbwId, _tdimmerId, _tpowerSwitchId, _tcommandId, _tpixelCount, _msgSendInterval>
|
||||
::sendPowerSwitchStatus() noexcept {
|
||||
_sendValue<uint8_t>(mode == 0 ? 0 : 1, _tpowerSwitchId, V_STATUS);
|
||||
}
|
||||
|
||||
|
||||
template<
|
||||
uint8_t _tpin,
|
||||
uint8_t _trgbwId,
|
||||
@@ -184,22 +280,11 @@ template<
|
||||
if (lastSendTime == 0 || currentMillis - lastSendTime >= _msgSendInterval) {
|
||||
|
||||
// RGBW Sensor
|
||||
char rgbw[9] = "00000000";
|
||||
// WRGB => RGBW
|
||||
String tmp((staticColor.color & 0xFF000000) >> 24 | ((staticColor.color & 0x00FFFFFF) << 8));
|
||||
memcpy(rgbw+(8-tmp.length()), tmp.c_str(), tmp.length());
|
||||
_sendValue<char*>(rgbw, _trgbwId, V_RGBW);
|
||||
|
||||
sendRGBWStatus();
|
||||
//Dimmer
|
||||
if (sceneMode == 0) {
|
||||
_sendValue<uint8_t>(brightness, _tdimmerId, V_STATUS);
|
||||
} else {
|
||||
uint16_t cb = max(staticColor.wrgb[0], max(staticColor.wrgb[1], max(staticColor.wrgb[2], staticColor.wrgb[3]))) * 100 / 255;
|
||||
_sendValue<uint8_t>(cb, _tdimmerId, V_STATUS);
|
||||
}
|
||||
|
||||
sendDimmerStatus();
|
||||
//Power Switch
|
||||
_sendValue<uint8_t>(mode == 0 ? 0 : 1, _tpowerSwitchId, V_STATUS);
|
||||
sendPowerSwitchStatus();
|
||||
|
||||
lastSendTime = currentMillis;
|
||||
}
|
||||
@@ -223,7 +308,7 @@ template<
|
||||
// Set Message
|
||||
if (msg.getCommand() == C_SET) {
|
||||
if (msg.type == V_STATUS) {
|
||||
auto onOff = msg.getByte();
|
||||
auto onOff = msg.getBool();
|
||||
if (onOff) {
|
||||
enableStaticColor();
|
||||
} else {
|
||||
@@ -248,13 +333,14 @@ template<
|
||||
setStaticColor((color & 0xFFFFFF00) >> 8 | ((color & 0xFF) << 24));
|
||||
retval = true;
|
||||
}
|
||||
if (retval) {
|
||||
sendPowerSwitchStatus();
|
||||
sendRGBWStatus();
|
||||
sendDimmerStatus();
|
||||
}
|
||||
// Request Message
|
||||
} else if (msg.getCommand() == C_REQ) {
|
||||
char rgbw[9] = "00000000";
|
||||
// WRGB => RGBW
|
||||
String tmp((staticColor.color & 0xFF000000) >> 24 | ((staticColor.color & 0x00FFFFFF) << 8));
|
||||
memcpy(rgbw+(8-tmp.length()), tmp.c_str(), tmp.length());
|
||||
_sendValue<char*>(rgbw, _trgbwId, V_RGBW);
|
||||
sendRGBWStatus();
|
||||
retval = true;
|
||||
}
|
||||
}
|
||||
@@ -281,15 +367,11 @@ template<
|
||||
setStaticColor(staticColor.color);
|
||||
}
|
||||
retval = true;
|
||||
sendDimmerStatus();
|
||||
}
|
||||
// Request Message
|
||||
} else if (msg.getCommand() == C_REQ) {
|
||||
if (sceneMode == 0) {
|
||||
_sendValue<uint8_t>(brightness, _tdimmerId, V_STATUS);
|
||||
} else {
|
||||
uint16_t cb = max(staticColor.wrgb[0], max(staticColor.wrgb[1], max(staticColor.wrgb[2], staticColor.wrgb[3]))) * 100 / 255;
|
||||
_sendValue<uint8_t>(cb, _tdimmerId, V_STATUS);
|
||||
}
|
||||
sendDimmerStatus();
|
||||
retval = true;
|
||||
}
|
||||
}
|
||||
@@ -306,10 +388,13 @@ template<
|
||||
powerOn();
|
||||
}
|
||||
retval = true;
|
||||
sendPowerSwitchStatus();
|
||||
sendRGBWStatus();
|
||||
sendDimmerStatus();
|
||||
}
|
||||
// Request Message
|
||||
} else if (msg.getCommand() == C_REQ) {
|
||||
_sendValue<uint8_t>(mode == 0 ? 0 : 1, _tpowerSwitchId, V_STATUS);
|
||||
sendPowerSwitchStatus();
|
||||
retval = true;
|
||||
}
|
||||
}
|
||||
@@ -578,6 +663,9 @@ template<
|
||||
if (id == 0) {
|
||||
overrideScene = id;
|
||||
pulse1_config();
|
||||
} else if (id == 1) {
|
||||
overrideScene = id;
|
||||
follow1_config();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -594,6 +682,8 @@ template<
|
||||
::overrideScene_init() noexcept {
|
||||
if (overrideScene == 0) {
|
||||
pulse1_init();
|
||||
} else if (overrideScene == 1) {
|
||||
follow1_init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -610,12 +700,15 @@ template<
|
||||
::overrideScene_loop(unsigned long currentUnixTime, unsigned long currentMillis) noexcept {
|
||||
if (overrideScene == 0) {
|
||||
pulse1_loop(currentUnixTime, currentMillis);
|
||||
} else if (overrideScene == 1) {
|
||||
follow1_loop(currentUnixTime, currentMillis);
|
||||
}
|
||||
}
|
||||
|
||||
#include "SceneAnalogClock.h"
|
||||
#include "SceneColorWheel.h"
|
||||
#include "ScenePulse.h"
|
||||
#include "SceneFollow.h"
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user