Some improvements.
This commit is contained in:
+105
@@ -0,0 +1,105 @@
|
||||
#ifndef SCENEFOLLOW_H_
|
||||
#define SCENEFOLLOW_H_
|
||||
|
||||
#include <nodemanager_config.h>
|
||||
#include <MySensors.h>
|
||||
#include <NodeManager.h>
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include "NotificationLEDs.h"
|
||||
|
||||
|
||||
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>
|
||||
::follow1_config() noexcept {
|
||||
auto token = strtok(NULL, _configDelims);
|
||||
if (token && token[0] != ' ') {
|
||||
auto color = strtoul(token, NULL, 16);
|
||||
sceneData.follow1.color.color = color;
|
||||
}
|
||||
token = strtok(NULL, _configDelims);
|
||||
if (token && token[0] != ' ') {
|
||||
auto maxCycles = atoi(token);
|
||||
sceneData.follow1.maxCycles = maxCycles;
|
||||
}
|
||||
token = strtok(NULL, _configDelims);
|
||||
if (token && token[0] != ' ') {
|
||||
auto followDir = atoi(token);
|
||||
sceneData.follow1.followDir = followDir;
|
||||
}
|
||||
token = strtok(NULL, _configDelims);
|
||||
if (token && token[0] != ' ') {
|
||||
auto waitTime = atoi(token);
|
||||
sceneData.follow1.waitTime = waitTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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>
|
||||
::follow1_init() noexcept {
|
||||
for (uint8_t i = 0; i < _tpixelCount; i++) {
|
||||
pixels.setPixelColor(i, 0);
|
||||
}
|
||||
pixels.show();
|
||||
if (sceneData.follow1.followDir > 0) {
|
||||
sceneData.follow1.followPos = 0;
|
||||
} else {
|
||||
sceneData.follow1.followPos = 11;
|
||||
}
|
||||
sceneData.follow1.finishing = false;
|
||||
sceneData.follow1.currentCycles = 0;
|
||||
sceneData.follow1.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>
|
||||
::follow1_loop(unsigned long currentUnixTime, unsigned long currentMillis) noexcept {
|
||||
if (currentMillis - sceneData.follow1.lastMillis >= sceneData.follow1.waitTime) {
|
||||
if (sceneData.follow1.finishing) {
|
||||
auto delPos = MOD(sceneData.follow1.followPos-sceneData.follow1.followDir*4, 12);
|
||||
pixels.setPixelColor(delPos, 0);
|
||||
pixels.show();
|
||||
sceneData.follow1.followPos += sceneData.follow1.followDir;
|
||||
if (sceneData.follow1.followPos > 4 && sceneData.follow1.followPos < 7) {
|
||||
returnToLastMode();
|
||||
}
|
||||
} else {
|
||||
pixels.setPixelColor(sceneData.follow1.followPos, sceneData.follow1.color.color);
|
||||
auto delPos = MOD(sceneData.follow1.followPos-sceneData.follow1.followDir*4, 12);
|
||||
pixels.setPixelColor(delPos, 0);
|
||||
pixels.show();
|
||||
sceneData.follow1.followPos += sceneData.follow1.followDir;
|
||||
if (sceneData.follow1.followPos < 0 || sceneData.follow1.followPos > 11) {
|
||||
sceneData.follow1.followPos = MOD(sceneData.follow1.followPos, 12);
|
||||
if (sceneData.follow1.maxCycles > 0 && sceneData.follow1.currentCycles > sceneData.follow1.maxCycles) {
|
||||
sceneData.follow1.finishing = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
sceneData.follow1.lastMillis = currentMillis;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SCENEFOLLOW_H_ */
|
||||
Reference in New Issue
Block a user