#include "unused.h"
#include "buttons.h"
#include "rgb.h"
-#include "timer.h"
+#include "tmr.h"
#include "adc_random.h"
-#define AUTO_OFF_COUNT 549316UL /* 5 hrs in 32.768 ms units */
+#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 reset_steps() do { incolor_steps = 1; fade_steps = 0; } \
while (0)
#define rand_u8() (rand() & 0xff)
RA2 = 0; \
TRISA2 = 0; \
} while (0)
-#define dbgpin_high() RA2 = 1;
-#define dbgpin_low() RA2 = 0;
+#define dbgpin_high() (RA2 = 1)
+#define dbgpin_low() (RA2 = 0)
+#define dbgpin_toggle() (RA2 = (LATA2 == 0) ? 1 : 0)
typedef struct {
int value;
unused_init();
buttons_init();
rgb_init();
- timer_init();
+ tmr_init();
dbgpin_init();
srand((adc_random() << 8) + adc_random());
rgb_on();
dbgpin_high();
+ tmr_startPeriodic(TMR_FADE, 1); /* 32.768 msec */
while (1) {
unsigned char buttons = buttons_read();
if ((buttons & IN_ROCKERB) && auto_off == 0)
- auto_off = AUTO_OFF_COUNT;
+ tmr_startPeriodic(TMR_AUTO_OFFON, AUTO_OFF_COUNT);
- if (((buttons & IN_ROCKERB) && auto_off && --auto_off == 0) ||
+ if ((buttons & IN_ROCKERB) && tmr_fired(TMR_AUTO_OFFON) ||
(!(buttons & (IN_ROCKERA | IN_ROCKERB)))) {
/* Sleep when auto-off time has expired or if rocker switch is
* turned off.
wht.remainder = neww - (wht.value + wht.increment * fade_steps);
}
dbgpin_low();
- timer_owait(); /* wait 32 ms since last return from last call() */
+ while (!tmr_fired(TMR_FADE));
dbgpin_high();
}
}