X-Git-Url: https://oss.titaniummirror.com/gitweb?a=blobdiff_plain;f=main.c;h=0726aafb2942763587a24b3e4a3c8e0f2d907156;hb=bdb1e0ae6aa9374becf3ae012e30d1f806841e88;hp=6d20042721cb8aebf0956e3c62fd80d47f0b1b58;hpb=929d03b37bea1d8763980f447c5f06582cb16bdf;p=rgblamp.git diff --git a/main.c b/main.c index 6d20042..0726aaf 100644 --- a/main.c +++ b/main.c @@ -41,11 +41,17 @@ #include "btn.h" #include "rgb.h" #include "tmr.h" +#include "tmr32.h" #include "task.h" #include "adc_random.h" -#define AUTO_OFF_COUNT 549316UL /* 5 hrs in 32.768 ms units */ -#define AUTO_ON_COUNT 2087402UL /* 19 hrs in 32.768 ms units */ +#if 1 +#define AUTO_OFF_COUNT 1800U /* 1 hr in 2 sec units */ +#define AUTO_ON_COUNT 19800U /* 11 hrs in 2 sec units */ +#else +#define AUTO_OFF_COUNT 9000U /* 5 hrs in 2 sec units */ +#define AUTO_ON_COUNT 34200U /* 19 hrs in 2 sec units */ +#endif #define leds_set(r,g,b,w) rgb_set((r).value >> 7, (g).value >> 7, \ (b).value >> 7, 0) #define dbgpin_init() do { \ @@ -136,6 +142,7 @@ void turnOff() tmr_stop(TMR_FADE); rgb_off(); dbgpin_low(); + SLEEP(); on = 0; } @@ -153,19 +160,19 @@ void pb_task() void rs_task() { + btn_rsen(); switch (btn_rs()) { case BTN_RS_OFF: - tmr_stop(TMR_AUTO_OFFON); + tmr32_set(0); turnOff(); break; case BTN_RS_RIGHT: - tmr_start(TMR_AUTO_OFFON, AUTO_OFF_COUNT); + tmr32_set(AUTO_OFF_COUNT); /* fall through */ case BTN_RS_LEFT: turnOn(); break; } - btn_rsen(); } void fade_task() @@ -194,11 +201,11 @@ void auto_offon_task() if (on) { turnOff(); if (btn_rs() == BTN_RS_RIGHT) - tmr_start(TMR_AUTO_OFFON, AUTO_ON_COUNT); + tmr32_set(AUTO_ON_COUNT); } else /* off */ { turnOn(); if (btn_rs() == BTN_RS_RIGHT) - tmr_start(TMR_AUTO_OFFON, AUTO_OFF_COUNT); + tmr32_set(AUTO_OFF_COUNT); } } @@ -227,7 +234,7 @@ void user_tasks(unsigned char block) case TASK_INCOLOR: /* in-color timer has fired */ start_fade(); break; - case TASK_AUTO_OFFON: /* auto on/off timer has fired */ + case TASK_TMR32: /* auto on/off event */ auto_offon_task(); break; } @@ -242,6 +249,7 @@ int main(void) btn_init(); rgb_init(); tmr_init(); + tmr32_init(); task_init(); dbgpin_init();