diff --git a/lib/MiLight/RgbwPacketFormatter.cpp b/lib/MiLight/RgbwPacketFormatter.cpp index c019913f..9918555a 100644 --- a/lib/MiLight/RgbwPacketFormatter.cpp +++ b/lib/MiLight/RgbwPacketFormatter.cpp @@ -29,7 +29,13 @@ void RgbwPacketFormatter::modeSpeedUp() { } void RgbwPacketFormatter::nextMode() { - command(RGBW_DISCO_MODE, 0); + lastMode = (lastMode + 1) % RGBW_NUM_MODES; + updateMode(lastMode); +} + +void RgbwPacketFormatter::previousMode() { + lastMode = (lastMode - 1) % RGBW_NUM_MODES; + updateMode(lastMode); } void RgbwPacketFormatter::updateMode(uint8_t mode) { diff --git a/lib/MiLight/RgbwPacketFormatter.h b/lib/MiLight/RgbwPacketFormatter.h index 4746050c..735c28bf 100644 --- a/lib/MiLight/RgbwPacketFormatter.h +++ b/lib/MiLight/RgbwPacketFormatter.h @@ -37,11 +37,13 @@ enum MiLightRgbwButton { #define RGBW_COMMAND_INDEX 5 #define RGBW_BRIGHTNESS_GROUP_INDEX 4 #define RGBW_COLOR_INDEX 3 +#define RGBW_NUM_MODES 9 class RgbwPacketFormatter : public PacketFormatter { public: RgbwPacketFormatter() - : PacketFormatter(7) + : PacketFormatter(7), + lastMode(0) { } virtual void updateStatus(MiLightStatus status, uint8_t groupId); @@ -55,10 +57,14 @@ class RgbwPacketFormatter : public PacketFormatter { virtual void modeSpeedDown(); virtual void modeSpeedUp(); virtual void nextMode(); + virtual void previousMode(); virtual void updateMode(uint8_t mode); virtual void enableNightMode(); virtual void initializePacket(uint8_t* packet); + +protected: + uint8_t lastMode; }; #endif