From 6f2c8ca1b61e91577c4e5ae9edd8407cd85b4eec Mon Sep 17 00:00:00 2001 From: richonguzman Date: Sat, 23 Sep 2023 10:10:02 -0300 Subject: [PATCH] adding low battery beep --- data/tracker_config.json | 21 +++++++++++---------- src/LoRa_APRS_Tracker.cpp | 3 ++- src/configuration.cpp | 1 + src/configuration.h | 1 + src/display.cpp | 2 +- src/menu_utils.cpp | 29 ++++++++++++++++++++++------- src/notification_utils.cpp | 15 +++++++++++---- src/notification_utils.h | 3 ++- 8 files changed, 51 insertions(+), 24 deletions(-) diff --git a/data/tracker_config.json b/data/tracker_config.json index e6640a6..7f42b0f 100644 --- a/data/tracker_config.json +++ b/data/tracker_config.json @@ -1,7 +1,7 @@ { "beacons": [ { - "callsign": "NOCALL-7", + "callsign": "CD2RXU-7", "symbol": "[", "overlay": "/", "comment": "", @@ -18,7 +18,7 @@ } }, { - "callsign": "NOCALL-7", + "callsign": "CD2RXU-7", "symbol": ">", "overlay": "/", "comment": "", @@ -35,7 +35,7 @@ } }, { - "callsign": "NOCALL-7", + "callsign": "CD2RXU-7", "symbol": "j", "overlay": "/", "comment": "", @@ -86,16 +86,17 @@ "active": false }, "notification": { - "ledTx": false, + "ledTx": true, "ledTxPin": 13, - "ledMessage": false, + "ledMessage": true, "ledMessagePin": 2, - "buzzerActive": false, + "buzzerActive": true, "buzzerPinTone": 33, "buzzerPinVcc": 25, - "bootUpBeep": false, - "txBeep": false, - "messageRxBeep": false, - "stationBeep": false + "bootUpBeep": true, + "txBeep": true, + "messageRxBeep": true, + "stationBeep": true, + "lowBatteryBeep": true } } \ No newline at end of file diff --git a/src/LoRa_APRS_Tracker.cpp b/src/LoRa_APRS_Tracker.cpp index 8ee64eb..fdcae0a 100644 --- a/src/LoRa_APRS_Tracker.cpp +++ b/src/LoRa_APRS_Tracker.cpp @@ -30,7 +30,7 @@ TinyGPSPlus gps; BluetoothSerial SerialBT; OneButton userButton = OneButton(BUTTON_PIN, true, true); -String versionDate = "2023.09.18"; +String versionDate = "2023.09.23"; int myBeaconsIndex = 0; int myBeaconsSize = Config.beacons.size(); @@ -55,6 +55,7 @@ bool bluetoothConnected = false; bool messageLed = false; uint32_t messageLedTime = millis(); +int batteryPercent = 81; uint32_t lastTx = 0.0; uint32_t txInterval = 60000L; diff --git a/src/configuration.cpp b/src/configuration.cpp index 0713539..2163445 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -70,6 +70,7 @@ void Configuration::readFile(fs::FS &fs, const char *fileName) { notification.txBeep = data["notification"]["txBeep"].as(); notification.messageRxBeep = data["notification"]["messageRxBeep"].as(); notification.stationBeep = data["notification"]["stationBeep"].as(); + notification.lowBatteryBeep = data["notification"]["lowBatteryBeep"].as(); simplifiedTrackerMode = data["other"]["simplifiedTrackerMode"].as(); showSymbolOnScreen = data["other"]["showSymbolOnScreen"].as(); diff --git a/src/configuration.h b/src/configuration.h index 1a1f0b9..d261f96 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -58,6 +58,7 @@ public: bool txBeep; bool messageRxBeep; bool stationBeep; + bool lowBatteryBeep; }; diff --git a/src/display.cpp b/src/display.cpp index 700160c..d87503a 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -7,7 +7,7 @@ #include "display.h" #include "TimeLib.h" -//#define ssd1306 //uncomment this line when using SH1106 screen instead of SSD1306 +#define ssd1306 //uncomment this line when using SH1106 screen instead of SSD1306 #ifdef ssd1306 #include diff --git a/src/menu_utils.cpp b/src/menu_utils.cpp index 03f94b2..2863282 100644 --- a/src/menu_utils.cpp +++ b/src/menu_utils.cpp @@ -1,5 +1,6 @@ #include #include +#include "notification_utils.h" #include "custom_characters.h" #include "station_utils.h" #include "configuration.h" @@ -20,6 +21,7 @@ extern std::vector loadedAPRSMessages; extern int messagesIterator; extern uint32_t menuTime; extern bool symbolAvailable; +extern int batteryPercent; namespace MENU_Utils { @@ -132,27 +134,40 @@ namespace MENU_Utils { if (powerManagement.getBatteryInfoIsConnected()) { String batteryVoltage = powerManagement.getBatteryInfoVoltage(); - String batteryChargeCurrent = powerManagement.getBatteryInfoCurrent(); + String batteryCharge = powerManagement.getBatteryInfoCurrent(); #ifdef TTGO_T_Beam_V0_7 sixthRowMainMenu = "Bat: " + batteryVoltage + "V"; #endif #if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_LORA_V2_1) - if (batteryChargeCurrent.toInt() == 0) { + if (batteryCharge.toInt() == 0) { sixthRowMainMenu = "Battery Charged " + batteryVoltage + "V"; - } else if (batteryChargeCurrent.toInt() > 0) { + } else if (batteryCharge.toInt() > 0) { sixthRowMainMenu = "Bat: " + batteryVoltage + "V (charging)"; } else { - sixthRowMainMenu = "Battery " + batteryVoltage + "V " + batteryChargeCurrent + "mA"; + sixthRowMainMenu = "Battery " + batteryVoltage + "V " + batteryCharge + "mA"; } #endif #ifdef TTGO_T_Beam_V1_2 + if (Config.notification.lowBatteryBeep && !powerManagement.isChargeing() && batteryCharge.toInt() < batteryPercent) { + Serial.println(batteryPercent); + Serial.println(batteryCharge.toInt()); + Serial.println("--"); + batteryPercent = batteryCharge.toInt(); + NOTIFICATION_Utils::lowBatteryBeep(); + if (batteryCharge.toInt() < 76) { + NOTIFICATION_Utils::lowBatteryBeep(); + } + } + if (powerManagement.isChargeing()) { + batteryPercent = 81; + } batteryVoltage = batteryVoltage.toFloat()/1000; - if (powerManagement.isChargeing() && batteryChargeCurrent!="100") { + if (powerManagement.isChargeing() && batteryCharge!="100") { sixthRowMainMenu = "Bat: " + String(batteryVoltage) + "V (charging)"; - } else if (!powerManagement.isChargeing() && batteryChargeCurrent=="100") { + } else if (!powerManagement.isChargeing() && batteryCharge=="100") { sixthRowMainMenu = "Battery Charged " + String(batteryVoltage) + "V"; } else { - sixthRowMainMenu = "Battery " + String(batteryVoltage) + "V " + batteryChargeCurrent + "%"; + sixthRowMainMenu = "Battery " + String(batteryVoltage) + "V " + batteryCharge + "%"; } #endif } else { diff --git a/src/notification_utils.cpp b/src/notification_utils.cpp index cb0878b..3525d24 100644 --- a/src/notification_utils.cpp +++ b/src/notification_utils.cpp @@ -8,9 +8,8 @@ int pauseDuration = 20; int startUpSound[] = {440, 880, 440, 1760}; int startUpSoundDuration[] = {100, 100, 100, 200}; -int shutDownSound[] = {1720, 880, 400}; -int shutDownSoundDuration[] = {60, 60, 200}; - +//int shutDownSound[] = {1720, 880, 400}; +//int shutDownSoundDuration[] = {60, 60, 200}; extern Configuration Config; @@ -45,12 +44,20 @@ namespace NOTIFICATION_Utils { digitalWrite(Config.notification.buzzerPinVcc, LOW); } - void shutDownBeep() { + /*void shutDownBeep() { digitalWrite(Config.notification.buzzerPinVcc, HIGH); for (int i = 0; i < sizeof(shutDownSound) / sizeof(shutDownSound[0]); i++) { playTone(shutDownSound[i], shutDownSoundDuration[i]); } digitalWrite(Config.notification.buzzerPinVcc, LOW); + }*/ + + void lowBatteryBeep() { + digitalWrite(Config.notification.buzzerPinVcc, HIGH); + playTone(1600,100); + playTone(1600,100); + playTone(800,100); + digitalWrite(Config.notification.buzzerPinVcc, LOW); } void start() { diff --git a/src/notification_utils.h b/src/notification_utils.h index b52170c..dfe914d 100644 --- a/src/notification_utils.h +++ b/src/notification_utils.h @@ -9,7 +9,8 @@ void playTone(int frequency, int duration); void beaconTxBeep(); void messageBeep(); void stationHeardBeep(); -void shutDownBeep(); +//void shutDownBeep(); +void lowBatteryBeep(); void start(); }