#include "task.h"
#include "adc_random.h"
-#if 0
#define AUTO_OFF_COUNT 549316UL /* 5 hrs in 32.768 ms units */
#define AUTO_ON_COUNT 2087402UL /* 19 hrs in 32.768 ms units */
-#else
-#define AUTO_OFF_COUNT 1831 /* 1 minute in 32.768 ms units */
-#define AUTO_ON_COUNT 3662 /* 2 minutes in 32.768 ms units */
-#endif
#define rand_u8() (rand() & 0xff)
#define rand_u16() ((rand() << 8) + rand_u8())
#define rand_incolor_steps(s) (min_incolor_steps[s & 3] + \
} led_t;
/* The index of all step arrays is the speed variable */
-#if 1
const static unsigned min_incolor_steps[4] = { 320, 32, 32, 1 };
const static unsigned range_incolor_steps[4] = { 32768, 128, 32, 8 };
const static int min_fade_steps[4] = { 64, 32, 32, 1 };
const static int range_fade_steps[4] = { 416, 128, 32, 8 };
-#else /* for debugging */
-const static unsigned min_incolor_steps[4] = { 64, 32, 16, 8 };
-const static unsigned range_incolor_steps[4] = { 1, 1, 1, 1 };
-const static int min_fade_steps[4] = { 64, 32, 16, 8 };
-const static int range_fade_steps[4] = { 1, 1, 1, 1 };
-#endif
led_t red;
led_t grn;
wht.remainder = neww - (wht.value + wht.increment * fade_steps);
/* Start the fade timer */
+ tmr_stop(TMR_INCOLOR);
tmr_startPeriodic(TMR_FADE, 1); /* 32.768 msec */
}
{
dbgpin_high();
on = 1;
- rgb_on();
red.value = 0;
grn.value = 0;
blu.value = 0;
wht.value = 0;
+ leds_set(red, grn, blu, wht);
+ rgb_on();
start_fade();
+ btn_pben();
}
void turnOff()
void pb_task()
{
- if (btn_pb() == BTN_PB_UP) {
- speed = (speed + 1) & ~4;
- fade_steps = 0;
+ /* Is this task running nearly continuously? */
+ if (on) {
+ if (btn_pb() == BTN_PB_UP) {
+ speed = (speed + 1) & 3;
+ start_fade();
+ }
+ btn_pben();
}
- btn_pben();
}
void rs_task()
leds_set(red, grn, blu, wht);
}
-void auto_onoff_task()
+void auto_offon_task()
{
if (on) {
turnOff();
if (btn_rs() == BTN_RS_RIGHT)
- tmr_start(TMR_AUTO_OFFON, AUTO_OFF_COUNT);
+ tmr_start(TMR_AUTO_OFFON, AUTO_ON_COUNT);
} else /* off */ {
turnOn();
if (btn_rs() == BTN_RS_RIGHT)
- tmr_start(TMR_AUTO_OFFON, AUTO_ON_COUNT);
+ tmr_start(TMR_AUTO_OFFON, AUTO_OFF_COUNT);
}
}
{
dbgpin_high();
srand((adc_random() << 8) + adc_random());
- pb_task();
rs_task();
}
start_fade();
break;
case TASK_AUTO_OFFON: /* auto on/off timer has fired */
- auto_onoff_task();
+ auto_offon_task();
break;
}
}