Initial Commit.
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
#ifndef SCENECOLORWHEEL_H_
|
||||
#define SCENECOLORWHEEL_H_
|
||||
|
||||
#include <nodemanager_config.h>
|
||||
#include <MySensors.h>
|
||||
#include <NodeManager.h>
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include "NotificationLEDs.h"
|
||||
|
||||
|
||||
void _colorWheel_mapIndex(uint16_t c, uint16_t& r, uint16_t& g, uint16_t& b) {
|
||||
if (c < 255) {
|
||||
r = 255 - c;
|
||||
g = c;
|
||||
b = 0;
|
||||
} else if (c >= 255 && c < 510) {
|
||||
r = 0;
|
||||
g = 510 - c;
|
||||
b = c - 255;
|
||||
} else if (c >= 510 && c < 765) {
|
||||
r = c - 510;
|
||||
g = 0;
|
||||
b = 765 - c;
|
||||
} else {
|
||||
r = g = b = 255;
|
||||
}
|
||||
}
|
||||
|
||||
// mathematically correct modulo
|
||||
#define MOD(a,b) ((((a)%(b))+(b))%(b))
|
||||
|
||||
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>
|
||||
::colorWheel1_config() noexcept {
|
||||
auto token = strtok(NULL, _configDelims);
|
||||
if (token && token[0] != ' ') {
|
||||
auto pixelStep = atoi(token);
|
||||
sceneData.colorWheel1.pixelStep = pixelStep;
|
||||
}
|
||||
token = strtok(NULL, _configDelims);
|
||||
if (token && token[0] != ' ') {
|
||||
auto colorStep = atoi(token);
|
||||
sceneData.colorWheel1.colorStep = colorStep;
|
||||
}
|
||||
token = strtok(NULL, _configDelims);
|
||||
if (token && token[0] != ' ') {
|
||||
auto sleepTime = atoi(token);
|
||||
sceneData.colorWheel1.sleepTime = sleepTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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>
|
||||
::colorWheel1_init() noexcept {
|
||||
for (uint8_t i = 0; i < _tpixelCount; i++) {
|
||||
pixels.setPixelColor(i, 0);
|
||||
}
|
||||
pixels.show();
|
||||
sceneData.colorWheel1.currentColorIndex = 0;
|
||||
sceneData.colorWheel1.currentPixelIndex = 0;
|
||||
sceneData.colorWheel1.lastMillis = 0;
|
||||
}
|
||||
|
||||
|
||||
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>
|
||||
::colorWheel1_loop(unsigned long, unsigned long currentMillis) noexcept {
|
||||
if (currentMillis - sceneData.colorWheel1.lastMillis >= sceneData.colorWheel1.sleepTime) {
|
||||
uint16_t r, g, b;
|
||||
_colorWheel_mapIndex(sceneData.colorWheel1.currentColorIndex, r, g, b);
|
||||
r = r*(uint16_t)brightness/100;
|
||||
g = g*(uint16_t)brightness/100;
|
||||
b = b*(uint16_t)brightness/100;
|
||||
pixels.setPixelColor(sceneData.colorWheel1.currentPixelIndex, r, g, b, 0);
|
||||
pixels.setPixelColor(12, r, g, b, 0);
|
||||
pixels.setPixelColor(13, r, g, b, 0);
|
||||
pixels.setPixelColor(14, r, g, b, 0);
|
||||
pixels.setPixelColor(15, r, g, b, 0);
|
||||
pixels.show();
|
||||
sceneData.colorWheel1.currentColorIndex = MOD(sceneData.colorWheel1.currentColorIndex + sceneData.colorWheel1.colorStep, 765);
|
||||
sceneData.colorWheel1.currentPixelIndex = MOD(sceneData.colorWheel1.currentPixelIndex + sceneData.colorWheel1.pixelStep, 12);
|
||||
sceneData.colorWheel1.lastMillis = currentMillis;
|
||||
}
|
||||
}
|
||||
|
||||
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>
|
||||
::colorWheel2_config() noexcept {
|
||||
auto token = strtok(NULL, _configDelims);
|
||||
if (token && token[0] != ' ') {
|
||||
auto colorStep = atoi(token);
|
||||
sceneData.colorWheel2.colorStep = colorStep;
|
||||
}
|
||||
token = strtok(NULL, _configDelims);
|
||||
if (token && token[0] != ' ') {
|
||||
auto sleepTime = atoi(token);
|
||||
sceneData.colorWheel2.sleepTime = sleepTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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>
|
||||
::colorWheel2_init() noexcept {
|
||||
for (uint8_t i = 0; i < _tpixelCount; i++) {
|
||||
pixels.setPixelColor(i, 0);
|
||||
}
|
||||
pixels.show();
|
||||
sceneData.colorWheel2.currentColorIndex = 0;
|
||||
sceneData.colorWheel2.lastMillis = 0;
|
||||
}
|
||||
|
||||
|
||||
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>
|
||||
::colorWheel2_loop(unsigned long, unsigned long currentMillis) noexcept {
|
||||
if (currentMillis - sceneData.colorWheel2.lastMillis >= sceneData.colorWheel2.sleepTime) {
|
||||
uint16_t r, g, b;
|
||||
_colorWheel_mapIndex(sceneData.colorWheel2.currentColorIndex, r, g, b);
|
||||
r = r*(uint16_t)brightness/100;
|
||||
g = g*(uint16_t)brightness/100;
|
||||
b = b*(uint16_t)brightness/100;
|
||||
for (uint16_t i = 0; i < _tpixelCount; i++) {
|
||||
pixels.setPixelColor(i, r, g, b, 0);
|
||||
}
|
||||
pixels.show();
|
||||
sceneData.colorWheel2.currentColorIndex = MOD(sceneData.colorWheel2.currentColorIndex + sceneData.colorWheel2.colorStep, 765);
|
||||
sceneData.colorWheel2.lastMillis = currentMillis;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* SCENECOLORWHEEL_H_ */
|
||||
Reference in New Issue
Block a user