mirror of
https://github.com/taigrr/arduinolibs
synced 2025-01-18 04:33:12 -08:00
Setting alarm values
This commit is contained in:
parent
ad47e33947
commit
849c776a3d
@ -31,7 +31,7 @@
|
|||||||
#include <PowerSave.h>
|
#include <PowerSave.h>
|
||||||
#include <avr/power.h>
|
#include <avr/power.h>
|
||||||
#include "FrontScreen.h"
|
#include "FrontScreen.h"
|
||||||
#include "EditTime.h"
|
#include "SetAlarm.h"
|
||||||
#include "SetTime.h"
|
#include "SetTime.h"
|
||||||
#include "SetDate.h"
|
#include "SetDate.h"
|
||||||
#include "LowPowerMelody.h"
|
#include "LowPowerMelody.h"
|
||||||
@ -70,10 +70,10 @@ FrontScreenField frontScreen(mainForm);
|
|||||||
SetTime setTime(mainForm, "Set current time");
|
SetTime setTime(mainForm, "Set current time");
|
||||||
SetDate setDate(mainForm, "Set current date");
|
SetDate setDate(mainForm, "Set current date");
|
||||||
BoolField hourMode(mainForm, "Hour display", "24 hour clock", "12 hour clock", false);
|
BoolField hourMode(mainForm, "Hour display", "24 hour clock", "12 hour clock", false);
|
||||||
EditTime alarm1(mainForm, "Alarm 1");
|
SetAlarm alarm1(mainForm, "Alarm 1", 0);
|
||||||
EditTime alarm2(mainForm, "Alarm 2");
|
SetAlarm alarm2(mainForm, "Alarm 2", 1);
|
||||||
EditTime alarm3(mainForm, "Alarm 3");
|
SetAlarm alarm3(mainForm, "Alarm 3", 2);
|
||||||
EditTime alarm4(mainForm, "Alarm 4");
|
SetAlarm alarm4(mainForm, "Alarm 4", 3);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// Reduce power consumption on I/O pins we don't need.
|
// Reduce power consumption on I/O pins we don't need.
|
||||||
@ -105,15 +105,6 @@ void setup() {
|
|||||||
is24HourClock = rtc.readByte(SETTING_24HOUR) != 0;
|
is24HourClock = rtc.readByte(SETTING_24HOUR) != 0;
|
||||||
hourMode.setValue(is24HourClock);
|
hourMode.setValue(is24HourClock);
|
||||||
frontScreen.set24HourMode(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.
|
// Show the main form for the first time.
|
||||||
mainForm.show();
|
mainForm.show();
|
||||||
|
@ -158,6 +158,7 @@ RTCAlarm EditTime::alarmValue() const
|
|||||||
alarm.hour = _value.hour;
|
alarm.hour = _value.hour;
|
||||||
alarm.minute = _value.minute;
|
alarm.minute = _value.minute;
|
||||||
alarm.flags = alarmEnabled ? 1 : 0;
|
alarm.flags = alarmEnabled ? 1 : 0;
|
||||||
|
return alarm;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditTime::setAlarmValue(const RTCAlarm &value)
|
void EditTime::setAlarmValue(const RTCAlarm &value)
|
||||||
|
46
libraries/RTC/examples/AlarmClock/SetAlarm.cpp
Normal file
46
libraries/RTC/examples/AlarmClock/SetAlarm.cpp
Normal file
@ -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 <DS1307RTC.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
38
libraries/RTC/examples/AlarmClock/SetAlarm.h
Normal file
38
libraries/RTC/examples/AlarmClock/SetAlarm.h
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user