mirror of
https://github.com/taigrr/arduinolibs
synced 2025-01-18 04:33:12 -08:00
Add a 12/24 hour setting to the clock
This commit is contained in:
parent
aee276ed3a
commit
2d031bd2e4
@ -24,6 +24,7 @@
|
|||||||
#include <FreetronicsLCD.h>
|
#include <FreetronicsLCD.h>
|
||||||
#include <Form.h>
|
#include <Form.h>
|
||||||
#include <Field.h>
|
#include <Field.h>
|
||||||
|
#include <BoolField.h>
|
||||||
#include <SoftI2C.h>
|
#include <SoftI2C.h>
|
||||||
#include <DS1307RTC.h>
|
#include <DS1307RTC.h>
|
||||||
#include <Melody.h>
|
#include <Melody.h>
|
||||||
@ -39,6 +40,9 @@
|
|||||||
// Value to adjust for the voltage drop on D2.
|
// Value to adjust for the voltage drop on D2.
|
||||||
#define VOLTAGE_DROP_ADJUST 70 // 0.7 volts
|
#define VOLTAGE_DROP_ADJUST 70 // 0.7 volts
|
||||||
|
|
||||||
|
// Offsets of settings in the realtime clock's NVRAM.
|
||||||
|
#define SETTING_24HOUR 0 // 0: 12 hour, 1: 24 hour
|
||||||
|
|
||||||
// Initialize the LCD
|
// Initialize the LCD
|
||||||
FreetronicsLCD lcd;
|
FreetronicsLCD lcd;
|
||||||
|
|
||||||
@ -56,6 +60,7 @@ uint8_t prevHour = 24;
|
|||||||
// Create the main form and its fields.
|
// Create the main form and its fields.
|
||||||
Form mainForm(lcd);
|
Form mainForm(lcd);
|
||||||
FrontScreenField frontScreen(mainForm);
|
FrontScreenField frontScreen(mainForm);
|
||||||
|
BoolField hourMode(mainForm, "Hour display", "24 hour clock", "12 hour clock", false);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// Enable the screen saver.
|
// Enable the screen saver.
|
||||||
@ -67,6 +72,10 @@ void setup() {
|
|||||||
alarmMelody.setLoopDuration(120000UL);
|
alarmMelody.setLoopDuration(120000UL);
|
||||||
//alarmMelody.play();
|
//alarmMelody.play();
|
||||||
|
|
||||||
|
// Read the clock settings from the realtime clock's NVRAM.
|
||||||
|
hourMode.setValue(rtc.readByte(SETTING_24HOUR) != 0);
|
||||||
|
frontScreen.set24HourMode(hourMode.value());
|
||||||
|
|
||||||
// Show the main form for the first time.
|
// Show the main form for the first time.
|
||||||
mainForm.show();
|
mainForm.show();
|
||||||
}
|
}
|
||||||
@ -97,6 +106,10 @@ void loop() {
|
|||||||
// Dispatch button events to the main form.
|
// Dispatch button events to the main form.
|
||||||
int event = lcd.getButton();
|
int event = lcd.getButton();
|
||||||
if (mainForm.dispatch(event) == FORM_CHANGED) {
|
if (mainForm.dispatch(event) == FORM_CHANGED) {
|
||||||
|
if (hourMode.isCurrent()) {
|
||||||
|
frontScreen.set24HourMode(hourMode.value());
|
||||||
|
rtc.writeByte(SETTING_24HOUR, (byte)hourMode.value());
|
||||||
|
}
|
||||||
prevHour = 24; // Force an update of the main screen.
|
prevHour = 24; // Force an update of the main screen.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ FrontScreenField::FrontScreenField(Form &form)
|
|||||||
, _voltageTrunc(36)
|
, _voltageTrunc(36)
|
||||||
, _batteryBars(IND_BATTERY_FULL)
|
, _batteryBars(IND_BATTERY_FULL)
|
||||||
, _alarmActive(false)
|
, _alarmActive(false)
|
||||||
|
, _hourMode(false)
|
||||||
{
|
{
|
||||||
_date.day = 1;
|
_date.day = 1;
|
||||||
_date.month = 1;
|
_date.month = 1;
|
||||||
@ -123,6 +124,15 @@ void FrontScreenField::setAlarmActive(bool active)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FrontScreenField::set24HourMode(bool value)
|
||||||
|
{
|
||||||
|
if (_hourMode != value) {
|
||||||
|
_hourMode = value;
|
||||||
|
if (isCurrent())
|
||||||
|
updateTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FrontScreenField::updateDate()
|
void FrontScreenField::updateDate()
|
||||||
{
|
{
|
||||||
lcd()->setCursor(0, 0);
|
lcd()->setCursor(0, 0);
|
||||||
@ -141,7 +151,11 @@ void FrontScreenField::updateTime()
|
|||||||
{
|
{
|
||||||
lcd()->setCursor(0, 1);
|
lcd()->setCursor(0, 1);
|
||||||
bool pm;
|
bool pm;
|
||||||
if (_time.hour == 0 || _time.hour == 12) {
|
if (_hourMode) {
|
||||||
|
lcd()->write('0' + _time.hour / 10);
|
||||||
|
lcd()->write('0' + _time.hour % 10);
|
||||||
|
pm = false;
|
||||||
|
} else if (_time.hour == 0 || _time.hour == 12) {
|
||||||
lcd()->write('1');
|
lcd()->write('1');
|
||||||
lcd()->write('2');
|
lcd()->write('2');
|
||||||
pm = (_time.hour == 12);
|
pm = (_time.hour == 12);
|
||||||
@ -161,7 +175,8 @@ void FrontScreenField::updateTime()
|
|||||||
lcd()->write(':');
|
lcd()->write(':');
|
||||||
lcd()->write('0' + _time.second / 10);
|
lcd()->write('0' + _time.second / 10);
|
||||||
lcd()->write('0' + _time.second % 10);
|
lcd()->write('0' + _time.second % 10);
|
||||||
lcd()->print(pm ? "pm" : "am");
|
if (!_hourMode)
|
||||||
|
lcd()->print(pm ? "pm" : "am");
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrontScreenField::updateVoltage()
|
void FrontScreenField::updateVoltage()
|
||||||
|
@ -46,6 +46,9 @@ public:
|
|||||||
bool isAlarmActive() const { return _alarmActive; }
|
bool isAlarmActive() const { return _alarmActive; }
|
||||||
void setAlarmActive(bool active);
|
void setAlarmActive(bool active);
|
||||||
|
|
||||||
|
bool is24HourMode() const { return _hourMode; }
|
||||||
|
void set24HourMode(bool value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RTCDate _date;
|
RTCDate _date;
|
||||||
RTCTime _time;
|
RTCTime _time;
|
||||||
@ -53,6 +56,7 @@ private:
|
|||||||
int _voltageTrunc;
|
int _voltageTrunc;
|
||||||
int _batteryBars;
|
int _batteryBars;
|
||||||
bool _alarmActive;
|
bool _alarmActive;
|
||||||
|
bool _hourMode;
|
||||||
|
|
||||||
void updateDate();
|
void updateDate();
|
||||||
void updateTime();
|
void updateTime();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user