#define dbgpin_low() (RA2 = 0)
#define dbgpin_toggle() (RA2 = (LATA2 == 0) ? 1 : 0)
+#define cfg_write(mode, color) do { \
+ eeprom_write(CFG_MODE_ADDR, (mode)); \
+ eeprom_write(CFG_COLOR_ADDR, (color)); \
+ } while (0)
+
+#define cfg_read(mode, color) do { \
+ unsigned char tmp; \
+ tmp = eeprom_read(CFG_MODE_ADDR); \
+ mode = (tmp < MODE_COUNT) ? tmp : MODE_SOLID; \
+ tmp = eeprom_read(CFG_COLOR_ADDR); \
+ color = (tmp < COLOR_COUNT) ? tmp : 0; \
+ } while (0)
+
enum {
/* Operating modes */
MODE_SOLID = 0, /* Cycle through colors[][] before next mode */
BRIGHT_MIN = 1, /* ... by min and max. */
BRIGHT_INIT = 42, /* later, get from eeprom */
STD_FADE = 16, /* Fade time in 32.768 ms units */
- STD_INCOLOR = 29491, /* Time in color when MODE_FADE, in 32.768 ms units */
+ STD_INCOLOR = 29491, /* Time in color when MODE_CYCLE, in 32.768 ms units */
PARTY_MIN = 8, /* Min party fade and incolor units */
PARTY_RANGE = 8, /* Party fade/incolor range mask for rand() */
/* ... see start_fade() */
+ CFG_MODE_ADDR = 0, /* EEPROM address of mode variable */
+ CFG_COLOR_ADDR, /* EEPROM address of color variable */
+ CFG_DELAY = 92, /* 3 seconds in 32.768 msec units */
};
typedef struct {
/* Set the LEDs using both color and brightness values. */
void leds_set()
{
- rgb_set(led_get((red).value),
- led_get((grn).value), led_get((blu).value),
+ rgb_set(led_get((red).value), led_get((grn).value), led_get((blu).value),
led_get((wht).value));
}
void turnOff()
{
/* Event on to off, either by switch or auto-off timer */
+ tmr_stop(TMR_CFG);
tmr_stop(TMR_INCOLOR);
tmr_stop(TMR_FADE);
rgb_off();
void pb_clicked()
{
if (on) {
+ unsigned char omode = mode;
+
if (mode == MODE_SOLID) {
if (++color == COLOR_COUNT) {
color = 0;
mode = 0;
color = 0;
}
+ if (mode != omode || mode == MODE_SOLID)
+ tmr_start(TMR_CFG, CFG_DELAY);
start_fade();
}
}
}
}
-void config_read()
-{
- /* Read configuration fields from eeprom, notably current mode and
- * brightness level.
- */
- /* FIXME: implement this */
-}
-
void user_boot()
{
dbgpin_high();
srand((adc_random() << 8) + adc_random());
- config_read();
+ cfg_read(mode, color);
rs_task();
}
case TASK_TMR32: /* auto on/off event */
auto_offon_task();
break;
+ case TASK_CFG: /* Save config to EEPROM event */
+ cfg_write(mode, color);
+ break;
}
}
}