Merge pull request #48 from algernon/f/LED/activate

LEDControl: Add a way to activate a mode by pointer
pull/46/head
Jesse Vincent 8 years ago committed by GitHub
commit 54fb40fd73

@ -1,5 +1,10 @@
#include "LEDControl.h"
void
LEDMode::activate (void) {
LEDControl.activate (this);
}
LEDControl_::LEDControl_(void) {
memset (modes, 0, LED_MAX_MODES * sizeof (modes[0]));
}
@ -54,6 +59,14 @@ LEDControl_::get_mode (void) {
return mode;
}
void
LEDControl_::activate (LEDMode *mode) {
for (uint8_t i = 0; i < LED_MAX_MODES; i++) {
if (modes[i] == mode)
return set_mode(i);
}
}
int8_t
LEDControl_::mode_add (LEDMode *mode) {
for (int i = 0; i < LED_MAX_MODES; i++) {

@ -10,6 +10,7 @@ class LEDMode {
virtual void setup (void) {};
virtual void init (void) {};
virtual void update (void) {};
virtual void activate (void);
};
class LEDControl_ {
@ -26,6 +27,8 @@ class LEDControl_ {
void set_all_leds_to(uint8_t r, uint8_t g, uint8_t b);
void set_all_leds_to(cRGB color);
void activate (LEDMode *mode);
private:
LEDMode *modes[LED_MAX_MODES];
uint8_t previousMode, mode;

Loading…
Cancel
Save