From: R. Steve McKown Date: Wed, 7 Dec 2011 02:07:47 +0000 (-0700) Subject: Update buttons_sleep() for auto-off restart case X-Git-Tag: 1.0~48 X-Git-Url: https://oss.titaniummirror.com/gitweb?p=rgblamp.git;a=commitdiff_plain;h=cf3abde4b8055ab1d26116b1f9af47951d1a0395 Update buttons_sleep() for auto-off restart case buttons_sleep() now first sleeps until the rocker switch is turned off before then sleeping until it is turned on. This allows the function to be used for the auto-off case, where the lamp must stay in auto-off when the rocker switch is still in position B. To wake from auto-off manually, one simply turns the rocker off then back to either position A or B. --- diff --git a/buttons.c b/buttons.c index e97f8bf..8ddd7ee 100644 --- a/buttons.c +++ b/buttons.c @@ -7,12 +7,24 @@ #include #include "buttons.h" +#include "timer.h" void buttons_sleep() { + /* If the rocker is on, sleep until it is placed in the off position */ + IOCBN4 = 0; IOCBP4 = 1; + IOCBN5 = 0; IOCBP5 = 1; + while ((buttons_read() & (IN_ROCKERA | IN_ROCKERB))) { + IOCIE = 1; + SLEEP(); + IOCIE = 0; + timer_mwait(50); /* debounce */ + } + + /* Now that the rocker is off, sleep until it is turned on */ + IOCBN4 = 1; IOCBP4 = 0; IOCBF4 = 0; + IOCBN5 = 1; IOCBP5 = 0; IOCBF5 = 0; if ((buttons_read() & (IN_ROCKERA | IN_ROCKERB)) == 0) { - IOCBF4 = 0; - IOCBF5 = 0; IOCIE = 1; SLEEP(); IOCIE = 0; diff --git a/buttons.h b/buttons.h index 39b96e1..63791ac 100644 --- a/buttons.h +++ b/buttons.h @@ -20,8 +20,6 @@ */ #define buttons_init() do { \ nWPUEN = 0; /* enable weak pull-ups on PortB */ \ - IOCBN4 = 1; \ - IOCBN5 = 1; \ TRISB |= IN_MASK; \ ANSELB &= ~IN_MASK; \ } while (0)