104 lines
3.1 KiB
C++
104 lines
3.1 KiB
C++
#ifndef SCENEPULSE_H_
|
|
#define SCENEPULSE_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>
|
|
::pulse1_config() noexcept {
|
|
auto token = strtok(NULL, _configDelims);
|
|
if (token && token[0] != ' ') {
|
|
auto color = strtoul(token, NULL, 16);
|
|
sceneData.pulse1.color.color = color;
|
|
}
|
|
token = strtok(NULL, _configDelims);
|
|
if (token && token[0] != ' ') {
|
|
auto maxPulses = atoi(token);
|
|
sceneData.pulse1.maxPulses = maxPulses;
|
|
}
|
|
token = strtok(NULL, _configDelims);
|
|
if (token && token[0] != ' ') {
|
|
auto pulseDir = atoi(token);
|
|
sceneData.pulse1.pulseDir = pulseDir;
|
|
}
|
|
}
|
|
|
|
|
|
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>
|
|
::pulse1_init() noexcept {
|
|
for (uint8_t i = 0; i < _tpixelCount; i++) {
|
|
pixels.setPixelColor(i, 0);
|
|
}
|
|
pixels.show();
|
|
sceneData.pulse1.pulseValue = 0;
|
|
sceneData.pulse1.lastMillis = 0;
|
|
sceneData.pulse1.currentPulses = 0;
|
|
}
|
|
|
|
|
|
template<typename T>
|
|
T tmap(T x, T in_min, T in_max, T out_min, T out_max) {
|
|
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
|
}
|
|
|
|
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>
|
|
::pulse1_loop(unsigned long currentUnixTime, unsigned long currentMillis) noexcept {
|
|
if (currentMillis - sceneData.pulse1.lastMillis >= 50) {
|
|
auto color = sceneData.pulse1.color;
|
|
int16_t pulseValue = sceneData.pulse1.pulseValue;
|
|
uint16_t br = 127.5 * (-cos(tmap<float>(pulseValue, 0, 255, 0, 2.0*M_PI))+1.0);
|
|
color.wrgb[0] = (uint16_t)color.wrgb[0]*br/255;
|
|
color.wrgb[1] = (uint16_t)color.wrgb[1]*br/255;
|
|
color.wrgb[2] = (uint16_t)color.wrgb[2]*br/255;
|
|
color.wrgb[3] = (uint16_t)color.wrgb[3]*br/255;
|
|
for (uint16_t i = 0; i < _tpixelCount; i++) {
|
|
pixels.setPixelColor(i, color.color);
|
|
}
|
|
pixels.show();
|
|
pulseValue += sceneData.pulse1.pulseDir;
|
|
if (pulseValue < 0) {
|
|
sceneData.pulse1.pulseDir = -sceneData.pulse1.pulseDir;
|
|
pulseValue = sceneData.pulse1.pulseDir;
|
|
sceneData.pulse1.currentPulses++;
|
|
if (sceneData.pulse1.maxPulses > 0 && sceneData.pulse1.currentPulses > sceneData.pulse1.maxPulses) {
|
|
returnToLastMode();
|
|
}
|
|
} else if (pulseValue > 255) {
|
|
sceneData.pulse1.pulseDir = -sceneData.pulse1.pulseDir;
|
|
pulseValue = 255 + sceneData.pulse1.pulseDir;
|
|
}
|
|
sceneData.pulse1.pulseValue = pulseValue;
|
|
sceneData.pulse1.lastMillis = currentMillis;
|
|
}
|
|
}
|
|
|
|
#endif /* SCENEPULSE_H_ */
|