1
0
mirror of https://github.com/taigrr/arduinolibs synced 2025-01-18 04:33:12 -08:00

Display an indicator on the LCD if the radio is on

This commit is contained in:
Rhys Weatherley 2012-06-15 14:57:08 +10:00
parent e9a5287b32
commit 30ab66e934
4 changed files with 52 additions and 11 deletions

View File

@ -99,6 +99,10 @@ the radio directly from the Arduino's power supply:
\image html relay_control.png \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 \section clock_ds3232 Using DS3232 instead of DS1307
For clock modules based on the DS3232 chip, such as the For clock modules based on the DS3232 chip, such as the

View File

@ -183,6 +183,7 @@ void loop() {
digitalWrite(RADIO, HIGH); digitalWrite(RADIO, HIGH);
else else
digitalWrite(RADIO, LOW); digitalWrite(RADIO, LOW);
frontScreen.setRadioOn(isRadioPlaying);
} }
prevHour = 24; // Force an update of the main screen. prevHour = 24; // Force an update of the main screen.
findNextAlarm(); // Update the time of the next alarm event. findNextAlarm(); // Update the time of the next alarm event.
@ -299,6 +300,7 @@ void turnRadioOn()
isRadioPlaying = true; isRadioPlaying = true;
digitalWrite(RADIO, HIGH); digitalWrite(RADIO, HIGH);
radioActive.setValue(true); radioActive.setValue(true);
frontScreen.setRadioOn(true);
} }
void turnRadioOff() void turnRadioOff()
@ -306,4 +308,5 @@ void turnRadioOff()
isRadioPlaying = false; isRadioPlaying = false;
digitalWrite(RADIO, LOW); digitalWrite(RADIO, LOW);
radioActive.setValue(false); radioActive.setValue(false);
frontScreen.setRadioOn(false);
} }

View File

@ -29,6 +29,7 @@
// Special characters for indicators. // Special characters for indicators.
#define IND_RADIO_ON 0 #define IND_RADIO_ON 0
#define IND_ALARM_SNOOZE 5
#define IND_ALARM_ACTIVE1 6 #define IND_ALARM_ACTIVE1 6
#define IND_ALARM_ACTIVE2 7 #define IND_ALARM_ACTIVE2 7
@ -36,6 +37,7 @@ FrontScreenField::FrontScreenField(Form &form)
: Field(form, "") : Field(form, "")
, _alarmMode(FrontScreenField::AlarmOff) , _alarmMode(FrontScreenField::AlarmOff)
, _hourMode(false) , _hourMode(false)
, _radioOn(false)
{ {
_date.day = 1; _date.day = 1;
_date.month = 1; _date.month = 1;
@ -54,7 +56,7 @@ void FrontScreenField::enterField(bool reverse)
{ {
updateDate(); updateDate();
updateTime(); updateTime();
updateAlarm(); updateIndicators();
} }
const char *days[] = { const char *days[] = {
@ -116,17 +118,23 @@ static uint8_t alarmSnooze[8] = {
B00000, B00000,
B00000 B00000
}; };
static uint8_t radioIndicator[8] = {
B11111,
B10101,
B01110,
B00100,
B00100,
B00100,
B00100,
B00000
};
void FrontScreenField::setAlarmMode(AlarmMode mode) void FrontScreenField::setAlarmMode(AlarmMode mode)
{ {
if (_alarmMode != mode) { if (_alarmMode != mode) {
_alarmMode = mode; _alarmMode = mode;
if (mode == Snooze)
lcd()->createChar(IND_ALARM_ACTIVE1, alarmSnooze);
else
lcd()->createChar(IND_ALARM_ACTIVE1, alarmActive1);
if (isCurrent()) 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() void FrontScreenField::updateDate()
{ {
lcd()->setCursor(0, 0); lcd()->setCursor(0, 0);
@ -186,15 +203,28 @@ void FrontScreenField::updateTime()
lcd()->print(pm ? "pm" : "am"); lcd()->print(pm ? "pm" : "am");
} }
void FrontScreenField::updateAlarm() void FrontScreenField::updateIndicators()
{ {
lcd()->setCursor(14, 1); lcd()->setCursor(13, 1);
lcd()->write(_alarmMode != AlarmOff ? IND_ALARM_ACTIVE1 : ' '); lcd()->print(" ");
lcd()->write(_alarmMode != AlarmOff ? IND_ALARM_ACTIVE2 : ' '); 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() 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_ACTIVE1, alarmActive1);
lcd()->createChar(IND_ALARM_ACTIVE2, alarmActive2); lcd()->createChar(IND_ALARM_ACTIVE2, alarmActive2);
} }

View File

@ -53,15 +53,19 @@ public:
bool is24HourMode() const { return _hourMode; } bool is24HourMode() const { return _hourMode; }
void set24HourMode(bool value); void set24HourMode(bool value);
bool isRadioOn() const { return _radioOn; }
void setRadioOn(bool value);
private: private:
RTCDate _date; RTCDate _date;
RTCTime _time; RTCTime _time;
AlarmMode _alarmMode; AlarmMode _alarmMode;
bool _hourMode; bool _hourMode;
bool _radioOn;
void updateDate(); void updateDate();
void updateTime(); void updateTime();
void updateAlarm(); void updateIndicators();
void registerIndicators(); void registerIndicators();
}; };