From 9c60d9490930d5f6a7b6245d6c4abefc4d4103a9 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Wed, 23 May 2012 10:38:29 +1000 Subject: [PATCH] Disable the voltage monitor --- .../RTC/examples/AlarmClock/AlarmClock.pde | 5 +++++ .../RTC/examples/AlarmClock/FrontScreen.cpp | 20 +++++++++++++++++++ .../RTC/examples/AlarmClock/FrontScreen.h | 8 ++++++++ 3 files changed, 33 insertions(+) diff --git a/libraries/RTC/examples/AlarmClock/AlarmClock.pde b/libraries/RTC/examples/AlarmClock/AlarmClock.pde index eb67e787..103c6aab 100644 --- a/libraries/RTC/examples/AlarmClock/AlarmClock.pde +++ b/libraries/RTC/examples/AlarmClock/AlarmClock.pde @@ -81,6 +81,9 @@ IntField alarmTimeout(mainForm, "Alarm timeout", 2, 10, 1, 2, " minutes"); void setup() { // Reduce power consumption on I/O pins we don't need. +#ifndef USE_VOLTAGE_MONITOR + unusedPin(A1); +#endif unusedPin(A2); unusedPin(0); unusedPin(1); @@ -139,6 +142,7 @@ void loop() { prevHour = time.hour; setTime.updateCurrentTime(); +#ifdef USE_VOLTAGE_MONITOR // Update the battery status once a second also. int status = analogRead(SENSE_BATTERY); int voltage = (int)((status * 500L) / 1024L); // e.g. 2.81V = 281 @@ -146,6 +150,7 @@ void loop() { if (voltage > 500) voltage = 500; frontScreen.setVoltage(voltage); +#endif // Trigger an alarm if necessary. if (time.second == 0 && nextAlarm.flags && !alarmMelody.isPlaying()) { diff --git a/libraries/RTC/examples/AlarmClock/FrontScreen.cpp b/libraries/RTC/examples/AlarmClock/FrontScreen.cpp index 15d348d5..d4f7712d 100644 --- a/libraries/RTC/examples/AlarmClock/FrontScreen.cpp +++ b/libraries/RTC/examples/AlarmClock/FrontScreen.cpp @@ -35,9 +35,11 @@ FrontScreenField::FrontScreenField(Form &form) : Field(form, "") +#ifdef USE_VOLTAGE_MONITOR , _voltage(360) , _voltageTrunc(36) , _batteryBars(IND_BATTERY_FULL) +#endif , _alarmActive(false) , _hourMode(false) { @@ -57,7 +59,9 @@ FrontScreenField::~FrontScreenField() void FrontScreenField::enterField(bool reverse) { updateDate(); +#ifdef USE_VOLTAGE_MONITOR updateVoltage(); +#endif updateTime(); updateAlarm(); } @@ -87,6 +91,8 @@ void FrontScreenField::setTime(const RTCTime &time) } } +#ifdef USE_VOLTAGE_MONITOR + void FrontScreenField::setVoltage(int voltage) { // Normal voltage ranges between 2.7 and 3.6. The power supply @@ -116,6 +122,8 @@ void FrontScreenField::setVoltage(int voltage) } } +#endif + void FrontScreenField::setAlarmActive(bool active) { if (_alarmActive != active) { @@ -180,6 +188,8 @@ void FrontScreenField::updateTime() lcd()->print(pm ? "pm" : "am"); } +#ifdef USE_VOLTAGE_MONITOR + void FrontScreenField::updateVoltage() { lcd()->setCursor(15, 0); @@ -192,13 +202,20 @@ void FrontScreenField::updateVoltage() lcd()->write('v'); } +#endif + void FrontScreenField::updateAlarm() { +#ifdef USE_VOLTAGE_MONITOR lcd()->setCursor(13, 0); +#else + lcd()->setCursor(14, 0); +#endif lcd()->write(_alarmActive ? IND_ALARM_ACTIVE1 : ' '); lcd()->write(_alarmActive ? IND_ALARM_ACTIVE2 : ' '); } +#ifdef USE_VOLTAGE_MONITOR static uint8_t batteryEmpty[8] = { B01110, B10001, @@ -259,6 +276,7 @@ static uint8_t batteryFull[8] = { B11111, B00000 }; +#endif static uint8_t alarmActive1[8] = { B00100, B01001, @@ -282,12 +300,14 @@ static uint8_t alarmActive2[8] = { void FrontScreenField::registerIndicators() { +#ifdef USE_VOLTAGE_MONITOR lcd()->createChar(IND_BATTERY_EMPTY, batteryEmpty); lcd()->createChar(IND_BATTERY_20PCT, battery20Pct); lcd()->createChar(IND_BATTERY_40PCT, battery40Pct); lcd()->createChar(IND_BATTERY_60PCT, battery60Pct); lcd()->createChar(IND_BATTERY_80PCT, battery80Pct); lcd()->createChar(IND_BATTERY_FULL, batteryFull); +#endif 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 85e92bad..b6cd4d91 100644 --- a/libraries/RTC/examples/AlarmClock/FrontScreen.h +++ b/libraries/RTC/examples/AlarmClock/FrontScreen.h @@ -26,6 +26,8 @@ #include #include +//#define USE_VOLTAGE_MONITOR 1 + class FrontScreenField : public Field { public: @@ -40,8 +42,10 @@ public: RTCTime time() const { return _time; } void setTime(const RTCTime &time); +#ifdef USE_VOLTAGE_MONITOR int voltage() const { return _voltage; } void setVoltage(int voltage); +#endif bool isAlarmActive() const { return _alarmActive; } void setAlarmActive(bool active); @@ -52,15 +56,19 @@ public: private: RTCDate _date; RTCTime _time; +#ifdef USE_VOLTAGE_MONITOR int _voltage; int _voltageTrunc; int _batteryBars; +#endif bool _alarmActive; bool _hourMode; void updateDate(); void updateTime(); +#ifdef USE_VOLTAGE_MONITOR void updateVoltage(); +#endif void updateAlarm(); void registerIndicators();