ei();
}
+/* Application specific interrupt handler. List the isr functions for all
+ * modules used, plus any additional application specific ISR processing.
+ */
void interrupt isr()
{
tmr_isr();
* This is a small, fast and efficient software implementation of a 16-bit
* Linear Feedback Shift Register (LFSR). It uses the Galois method to perform
* the exclusive OR operations in parallel for improved performance over the
- * standard, or Fibonacci, method. The algorithm also skips the exlusive or
- * operations if it doesn't need to do them, though on this uC the branch may
- * not generate a net performance increase over doing the exclusive or
- * operations every time.
- *
- * After rng returns, RNGLO and RNGHI contain the updated 16-bit random number.
- * RNGLO will contain a value $01-$FF, RNGHI will contain $00-$FF.
+ * standard, or Fibonacci, method.
*
* @author R. Steve McKown <rsmckown@gmail.com>
*/
BRIGHT_BOTTOM = -5, /* ... then down to bottom */
BRIGHT_MAX = 85, /* Bright values are constrained for computations */
BRIGHT_MIN = 1, /* ... by min and max. */
- BRIGHT_INIT = 42, /* later, get from eeprom */
- CBRIGHT_VARIANCE = 20, /* brightness range for candle flicker */
+ BRIGHT_INIT = 42, /* Initial value is replaced by value from eeprom */
+ CBRIGHT_VARIANCE = 20, /* Brightness range for candle flicker */
STD_FADE = 16, /* Fade time 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 */
btn_pben();
}
+/* Event on to off, either by switch or auto-off timer */
void turnOff()
{
- /* Event on to off, either by switch or auto-off timer */
tmr_stop(TMR_CFG);
tmr_stop(TMR_CANDLE);
tmr_stop(TMR_INCOLOR);
}
}
+/* The button is being held. Change the color magnitude. */
void pb_held()
{
- /* The button has been held. Change the color magnitude. */
if (bright_up) {
if (bright == BRIGHT_TOP)
bright_up = 0;
while ((tid = task_get(block)) >= 0) {
switch (tid) {
- case TASK_BTN_PB: /* pushbutton state change */
+ case TASK_BTN_PB:
pb_task();
break;
- case TASK_BTN_RS: /* rocker switch state change */
+ case TASK_BTN_RS:
rs_task();
break;
- case TASK_BTN_PB_HELD: /* pushbutton is being held down */
+ case TASK_BTN_PB_HELD:
pb_held_task();
break;
- case TASK_FADE: /* fade timer has fired */
+ case TASK_FADE:
fade_task();
break;
- case TASK_INCOLOR: /* in-color timer has fired */
+ case TASK_INCOLOR:
start_fade();
break;
- case TASK_CANDLE: /* periodic adjustment for candle flicker */
+ case TASK_CANDLE:
candle_task();
break;
- case TASK_TMR32: /* auto on/off event */
+ case TASK_TMR32:
auto_offon_task();
break;
- case TASK_CFG: /* Save config to EEPROM event */
+ case TASK_CFG:
cfg_write();
break;
}
/*
* File: task.c
*
- * Generic timer module. Currently uses Timer0 to generate ticks every
- * 32 ms. Later will use Timer1, a crystal, and optionally a compare
- * module to be able to generate ticks and wake up from sleep.
+ * Generic task module.
*/
* _task_ids variable in task.c.
*/
enum {
- TASK_BTN_PB = 0,
- TASK_BTN_RS,
- TASK_BTN_PB_HELD,
- TASK_FADE,
- TASK_INCOLOR,
- TASK_TMR32,
- TASK_CANDLE,
- TASK_CFG,
+ TASK_BTN_PB = 0, /* Pushbutton state change */
+ TASK_BTN_RS, /* Rocker switch state change */
+ TASK_BTN_PB_HELD, /* Pushbutton is being held down */
+ TASK_FADE, /* Fade timer has fired */
+ TASK_INCOLOR, /* In-color timer has fired */
+ TASK_TMR32, /* Auto on/off event */
+ TASK_CANDLE, /* Periodic adjustment for candle flicker */
+ TASK_CFG, /* Save config to EEPROM event */
TASK_COUNT
};
* accordingly.
*/
enum {
- TMR_BTN_PB = 0,
- TMR_BTN_RS,
- TMR_BTN_PB_HELD,
- TMR_FADE,
- TMR_INCOLOR,
- TMR_CANDLE,
+ TMR_BTN_PB = 0, /* Pushbutton debounce */
+ TMR_BTN_RS, /* Rocker switch debounce */
+ TMR_BTN_PB_HELD, /* Time elapsed determines clicked vs held */
+ TMR_FADE, /* Time between fade iterations */
+ TMR_INCOLOR, /* Time a given color remains active (no fade) */
+ TMR_CANDLE, /* Time between candle variations */
+
+ /* Time expired before a changed configuration is written. In this way,
+ * several changes to the configuration within TMR_CFG time generate a
+ * single EEPROM write.
+ */
TMR_CFG,
TMR_COUNT