From 30ab66e934c5e0f04e46365769a4bd259e33b599 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Fri, 15 Jun 2012 14:57:08 +1000 Subject: [PATCH] Display an indicator on the LCD if the radio is on --- doc/alarm-clock.dox | 4 ++ .../RTC/examples/AlarmClock/AlarmClock.pde | 3 ++ .../RTC/examples/AlarmClock/FrontScreen.cpp | 50 +++++++++++++++---- .../RTC/examples/AlarmClock/FrontScreen.h | 6 ++- 4 files changed, 52 insertions(+), 11 deletions(-) diff --git a/doc/alarm-clock.dox b/doc/alarm-clock.dox index 1141a9e4..3ec68896 100644 --- a/doc/alarm-clock.dox +++ b/doc/alarm-clock.dox @@ -99,6 +99,10 @@ the radio directly from the Arduino's power supply: \image html relay_control.png +Double-tapping the Alarm Stop button will turn the radio on. Single-tapping +the Alarm Stop button will turn the radio off. A settings field can also +be used to turn the radio on and off. + \section clock_ds3232 Using DS3232 instead of DS1307 For clock modules based on the DS3232 chip, such as the diff --git a/libraries/RTC/examples/AlarmClock/AlarmClock.pde b/libraries/RTC/examples/AlarmClock/AlarmClock.pde index 8e477afa..4d645788 100644 --- a/libraries/RTC/examples/AlarmClock/AlarmClock.pde +++ b/libraries/RTC/examples/AlarmClock/AlarmClock.pde @@ -183,6 +183,7 @@ void loop() { digitalWrite(RADIO, HIGH); else digitalWrite(RADIO, LOW); + frontScreen.setRadioOn(isRadioPlaying); } prevHour = 24; // Force an update of the main screen. findNextAlarm(); // Update the time of the next alarm event. @@ -299,6 +300,7 @@ void turnRadioOn() isRadioPlaying = true; digitalWrite(RADIO, HIGH); radioActive.setValue(true); + frontScreen.setRadioOn(true); } void turnRadioOff() @@ -306,4 +308,5 @@ void turnRadioOff() isRadioPlaying = false; digitalWrite(RADIO, LOW); radioActive.setValue(false); + frontScreen.setRadioOn(false); } diff --git a/libraries/RTC/examples/AlarmClock/FrontScreen.cpp b/libraries/RTC/examples/AlarmClock/FrontScreen.cpp index 3ec2c01e..ea583e4b 100644 --- a/libraries/RTC/examples/AlarmClock/FrontScreen.cpp +++ b/libraries/RTC/examples/AlarmClock/FrontScreen.cpp @@ -29,6 +29,7 @@ // Special characters for indicators. #define IND_RADIO_ON 0 +#define IND_ALARM_SNOOZE 5 #define IND_ALARM_ACTIVE1 6 #define IND_ALARM_ACTIVE2 7 @@ -36,6 +37,7 @@ FrontScreenField::FrontScreenField(Form &form) : Field(form, "") , _alarmMode(FrontScreenField::AlarmOff) , _hourMode(false) + , _radioOn(false) { _date.day = 1; _date.month = 1; @@ -54,7 +56,7 @@ void FrontScreenField::enterField(bool reverse) { updateDate(); updateTime(); - updateAlarm(); + updateIndicators(); } const char *days[] = { @@ -116,17 +118,23 @@ static uint8_t alarmSnooze[8] = { B00000, B00000 }; +static uint8_t radioIndicator[8] = { + B11111, + B10101, + B01110, + B00100, + B00100, + B00100, + B00100, + B00000 +}; void FrontScreenField::setAlarmMode(AlarmMode mode) { if (_alarmMode != mode) { _alarmMode = mode; - if (mode == Snooze) - lcd()->createChar(IND_ALARM_ACTIVE1, alarmSnooze); - else - lcd()->createChar(IND_ALARM_ACTIVE1, alarmActive1); if (isCurrent()) - updateAlarm(); + updateIndicators(); } } @@ -139,6 +147,15 @@ void FrontScreenField::set24HourMode(bool value) } } +void FrontScreenField::setRadioOn(bool value) +{ + if (_radioOn != value) { + _radioOn = value; + if (isCurrent()) + updateIndicators(); + } +} + void FrontScreenField::updateDate() { lcd()->setCursor(0, 0); @@ -186,15 +203,28 @@ void FrontScreenField::updateTime() lcd()->print(pm ? "pm" : "am"); } -void FrontScreenField::updateAlarm() +void FrontScreenField::updateIndicators() { - lcd()->setCursor(14, 1); - lcd()->write(_alarmMode != AlarmOff ? IND_ALARM_ACTIVE1 : ' '); - lcd()->write(_alarmMode != AlarmOff ? IND_ALARM_ACTIVE2 : ' '); + lcd()->setCursor(13, 1); + lcd()->print(" "); + int col = 16; + if (_radioOn) { + --col; + lcd()->setCursor(col, 1); + lcd()->write((uint8_t)IND_RADIO_ON); + } + if (_alarmMode != AlarmOff) { + col -= 2; + lcd()->setCursor(col, 1); + lcd()->write(_alarmMode == Snooze ? IND_ALARM_SNOOZE : IND_ALARM_ACTIVE1); + lcd()->write(IND_ALARM_ACTIVE2); + } } void FrontScreenField::registerIndicators() { + lcd()->createChar(IND_RADIO_ON, radioIndicator); + lcd()->createChar(IND_ALARM_SNOOZE, alarmSnooze); lcd()->createChar(IND_ALARM_ACTIVE1, alarmActive1); lcd()->createChar(IND_ALARM_ACTIVE2, alarmActive2); } diff --git a/libraries/RTC/examples/AlarmClock/FrontScreen.h b/libraries/RTC/examples/AlarmClock/FrontScreen.h index 56859309..12cf5646 100644 --- a/libraries/RTC/examples/AlarmClock/FrontScreen.h +++ b/libraries/RTC/examples/AlarmClock/FrontScreen.h @@ -53,15 +53,19 @@ public: bool is24HourMode() const { return _hourMode; } void set24HourMode(bool value); + bool isRadioOn() const { return _radioOn; } + void setRadioOn(bool value); + private: RTCDate _date; RTCTime _time; AlarmMode _alarmMode; bool _hourMode; + bool _radioOn; void updateDate(); void updateTime(); - void updateAlarm(); + void updateIndicators(); void registerIndicators(); };