diff --git a/libraries/RTC/examples/AlarmClock/AlarmClock.pde b/libraries/RTC/examples/AlarmClock/AlarmClock.pde index 9195e0df..658b5e06 100644 --- a/libraries/RTC/examples/AlarmClock/AlarmClock.pde +++ b/libraries/RTC/examples/AlarmClock/AlarmClock.pde @@ -31,7 +31,7 @@ #include #include #include "FrontScreen.h" -#include "EditTime.h" +#include "SetAlarm.h" #include "SetTime.h" #include "SetDate.h" #include "LowPowerMelody.h" @@ -70,10 +70,10 @@ FrontScreenField frontScreen(mainForm); SetTime setTime(mainForm, "Set current time"); SetDate setDate(mainForm, "Set current date"); BoolField hourMode(mainForm, "Hour display", "24 hour clock", "12 hour clock", false); -EditTime alarm1(mainForm, "Alarm 1"); -EditTime alarm2(mainForm, "Alarm 2"); -EditTime alarm3(mainForm, "Alarm 3"); -EditTime alarm4(mainForm, "Alarm 4"); +SetAlarm alarm1(mainForm, "Alarm 1", 0); +SetAlarm alarm2(mainForm, "Alarm 2", 1); +SetAlarm alarm3(mainForm, "Alarm 3", 2); +SetAlarm alarm4(mainForm, "Alarm 4", 3); void setup() { // Reduce power consumption on I/O pins we don't need. @@ -105,15 +105,6 @@ void setup() { is24HourClock = rtc.readByte(SETTING_24HOUR) != 0; hourMode.setValue(is24HourClock); frontScreen.set24HourMode(is24HourClock); - RTCAlarm alarm; - rtc.readAlarm(0, &alarm); - alarm1.setAlarmValue(alarm); - rtc.readAlarm(1, &alarm); - alarm2.setAlarmValue(alarm); - rtc.readAlarm(2, &alarm); - alarm3.setAlarmValue(alarm); - rtc.readAlarm(3, &alarm); - alarm4.setAlarmValue(alarm); // Show the main form for the first time. mainForm.show(); diff --git a/libraries/RTC/examples/AlarmClock/EditTime.cpp b/libraries/RTC/examples/AlarmClock/EditTime.cpp index 0c0a5580..b32eec88 100644 --- a/libraries/RTC/examples/AlarmClock/EditTime.cpp +++ b/libraries/RTC/examples/AlarmClock/EditTime.cpp @@ -158,6 +158,7 @@ RTCAlarm EditTime::alarmValue() const alarm.hour = _value.hour; alarm.minute = _value.minute; alarm.flags = alarmEnabled ? 1 : 0; + return alarm; } void EditTime::setAlarmValue(const RTCAlarm &value) diff --git a/libraries/RTC/examples/AlarmClock/SetAlarm.cpp b/libraries/RTC/examples/AlarmClock/SetAlarm.cpp new file mode 100644 index 00000000..f003e673 --- /dev/null +++ b/libraries/RTC/examples/AlarmClock/SetAlarm.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2012 Southern Storm Software, Pty Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "SetAlarm.h" +#include + +extern DS1307RTC rtc; + +SetAlarm::SetAlarm(Form &form, const String &label, uint8_t alarmNum) + : EditTime(form, label) + , _alarmNum(alarmNum) +{ + RTCAlarm alarm; + rtc.readAlarm(_alarmNum, &alarm); + setAlarmValue(alarm); +} + +int SetAlarm::dispatch(int event) +{ + int result = EditTime::dispatch(event); + if (result == FORM_CHANGED) { + // Update the alarm details in the realtime clock chip. + RTCAlarm alarm = alarmValue(); + rtc.writeAlarm(_alarmNum, &alarm); + } + return result; +} diff --git a/libraries/RTC/examples/AlarmClock/SetAlarm.h b/libraries/RTC/examples/AlarmClock/SetAlarm.h new file mode 100644 index 00000000..86bd7d00 --- /dev/null +++ b/libraries/RTC/examples/AlarmClock/SetAlarm.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2012 Southern Storm Software, Pty Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef SetAlarm_h +#define SetAlarm_h + +#include "EditTime.h" + +class SetAlarm : public EditTime { +public: + SetAlarm(Form &form, const String &label, uint8_t alarmNum); + + int dispatch(int event); + +private: + uint8_t _alarmNum; +}; + +#endif