Things/things/DeviceRgb.h

37 lines
940 B
C++

#pragma once
#include "Device.h"
#include <Homie.h>
class DeviceRgb : public Device {
public:
inline DeviceRgb(byte rgbRed, byte rgbGreen, byte rgbBlue) {
pinRed = rgbRed;
pinGreen = rgbGreen;
pinBlue = rgbBlue;
}
virtual void deviceSetup();
virtual void deviceRegister();
virtual void deviceLoop();
private:
byte pinRed;
byte pinGreen;
byte pinBlue;
int rgb_red = 0;
int rgb_green = 0;
int rgb_blue = 0;
bool fading = false;
int fade_from_red, fade_to_red;
int fade_from_green, fade_to_green;
int fade_from_blue, fade_to_blue;
unsigned long fade_start = 0;
unsigned long fade_end = 0;
float progress_last = 0;
void setRgb(int red, int green, int blue);
void publishStatus();
bool rgbOnHandler(String value);
bool rgbColorHandler(String message);
bool rgbFadeHandler(String message);
HomieNode rgbNode{"rgb", "rgb"};
};