Alarm Clock
Revision 4:864d5c5f98ee, committed 2015-11-22
- Comitter:
- takashikojo
- Date:
- Sun Nov 22 08:44:38 2015 +0000
- Parent:
- 3:08b49402846d
- Commit message:
- Cleaned debug messages
Changed in this revision
AlarmClock.cpp | Show annotated file Show diff for this revision Revisions of this file |
AlarmClock.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 08b49402846d -r 864d5c5f98ee AlarmClock.cpp --- a/AlarmClock.cpp Sun Jul 05 11:34:29 2015 +0000 +++ b/AlarmClock.cpp Sun Nov 22 08:44:38 2015 +0000 @@ -3,6 +3,19 @@ #include "DigitalClock.h" #include "AlarmClock.h" +#if 0 +//Enable debug +#define DBG(x, ...) std::printf("[tokyoMetro : DBG]"x"\r\n", ##__VA_ARGS__); +#define WARN(x, ...) std::printf("[tokyoMetro : WARN]"x"\r\n", ##__VA_ARGS__); +#else +//Disable debug +#define DBG(x, ...) +#define WARN(x, ...) +#endif + +#define ERR(x, ...) std::printf("[tokyoMetro : ERR]"x"\r\n", ##__VA_ARGS__); + + AlarmClock::AlarmClock (PinName seg0, PinName seg1, PinName seg2, PinName seg3, PinName seg4, PinName seg5, PinName seg6, PinName dot, PinName digit0, PinName digit1, PinName digit2, PinName digit3, @@ -17,6 +30,7 @@ alarmActive = false ; newAlarmTime= false ; optionActive= true ; + AlarmAhead = 0 ; setDot(0, optionActive) ; alarmButton = new DigitalIn(alarmB) ; @@ -39,10 +53,11 @@ ctTime = time(NULL) + JST ; struct tm ct ; struct tm at ; - //printf("alarmActive=%d, timeMatched=%d, ctTime=%d, alarmTime=%d\n", alarmActive, timeMatched, ctTime, alarmTime) ; + DBG("alarmActive=%d, timeMatched=%d, ctTime=%d, alarmTime=%d\n", alarmActive, timeMatched, ctTime, alarmTime) ; + ctTime += AlarmAhead ; ct = *localtime(&ctTime) ; at = *localtime(&alarmTime) ; - if((ct.tm_hour == at.tm_hour) && (ct.tm_min == at.tm_min)) + if((ct.tm_hour <= at.tm_hour) || ((ct.tm_hour == at.tm_hour) && (ct.tm_min <= at.tm_min))) timeMatched = true ; else timeMatched = false ; if(alarmActive && timeMatched) @@ -64,15 +79,19 @@ } } +void AlarmClock::alarmAhead(int sec) { + AlarmAhead = sec ; +} + void AlarmClock::checkAlarmButton() { struct tm * alarmT ; - //printf("alarmB_stat=%d, alarmButton=%d", alarmB_stat, *alarmButton) ; + DBG("alarmB_stat=%d, alarmButton=%d", alarmB_stat, *alarmButton) ; if(!alarmB_stat && !*alarmButton) { stop() ; /* stop updating LED */ alarmT = localtime(&alarmTime); - //printf("Alarm Time = %d:%d\n", alarmT->tm_hour, alarmT->tm_min) ; + DBG("Alarm Time = %d:%d\n", alarmT->tm_hour, alarmT->tm_min) ; setLED(alarmT->tm_hour, alarmT->tm_min) ; alarmB_stat = true ; newAlarmTime = false ; @@ -82,7 +101,7 @@ alarmB_stat = false ; if(!newAlarmTime)rotateOptions(&alarmActive, &optionActive, &optionCount) ; else alarmActive = true ; - //printf("alarmActive=%d\n", alarmActive) ; + DBG("alarmActive=%d\n", alarmActive) ; setDot(1, alarmActive) ; setDot(0, optionActive) ; flashLED() ; @@ -94,7 +113,7 @@ { struct tm * alarmT ; - //printf(" hourB_stat=%d, hourButton=%d", hourB_stat, hourButton->read()) ; + DBG(" hourB_stat=%d, hourButton=%d", hourB_stat, hourButton->read()) ; if((!hourB_stat && !*hourButton) && !*alarmButton) { alarmTime += HOUR ; alarmT = localtime(&alarmTime); @@ -108,7 +127,7 @@ { struct tm * alarmT ; - //printf(" minB_stat=%d, minButton=%d\n", minB_stat, minButton->read()) ; + DBG(" minB_stat=%d, minButton=%d\n", minB_stat, minButton->read()) ; if((!minB_stat && !*minButton) && !*alarmButton) { alarmTime += MIN ; alarmT = localtime(&alarmTime);
diff -r 08b49402846d -r 864d5c5f98ee AlarmClock.h --- a/AlarmClock.h Sun Jul 05 11:34:29 2015 +0000 +++ b/AlarmClock.h Sun Nov 22 08:44:38 2015 +0000 @@ -14,6 +14,7 @@ ~AlarmClock(); bool getAlarm(int *h, int *min, int *sec) ; bool setAlarm(int h, int min, int sec) ; + void alarmAhead(int sec) ; void alarmTone(bool) ; void poll(void) ; @@ -36,6 +37,7 @@ bool minB_stat ; bool newAlarmTime ; bool timeMatched ; + int AlarmAhead ; } ; #endif