diff --git a/src/LoRa_APRS_Tracker.cpp b/src/LoRa_APRS_Tracker.cpp index 6de0e85..36a75dd 100644 --- a/src/LoRa_APRS_Tracker.cpp +++ b/src/LoRa_APRS_Tracker.cpp @@ -5,26 +5,24 @@ #include #include #include -#include -#include "BeaconManager.h" #include "configuration.h" #include "display.h" #include "pins.h" #include "power_management.h" -#define VERSION "22.19.0" +#define VERSION "1.0" -logging::Logger logger; - -Configuration Config; -BeaconManager BeaconMan; +// State of State machine +#define HasSynchGPS 1 +#define PrepBeacon 2 +#define Sleep 3 +Configuration mConfig; PowerManagement powerManagement; OneButton userButton = OneButton(BUTTON_PIN, true, true); - -HardwareSerial ss(1); -TinyGPSPlus gps; +HardwareSerial ss(1); +TinyGPSPlus gps; void setup_gps(); void load_config(); @@ -32,215 +30,87 @@ void setup_lora(); String create_lat_aprs(RawDegrees lat); String create_long_aprs(RawDegrees lng); -String create_lat_aprs_dao(RawDegrees lat); -String create_long_aprs_dao(RawDegrees lng); -String create_dao_aprs(RawDegrees lat, RawDegrees lng); String createDateString(time_t t); String createTimeString(time_t t); -String getSmartBeaconState(); String padding(unsigned int number, unsigned int width); -static bool send_update = true; -static bool display_toggle_value = true; - -static void handle_tx_click() { - send_update = true; -} - -static void handle_next_beacon() { - BeaconMan.loadNextBeacon(); - show_display(BeaconMan.getCurrentBeaconConfig()->callsign, BeaconMan.getCurrentBeaconConfig()->message, 2000); -} - -static void toggle_display() { - display_toggle_value = !display_toggle_value; - display_toggle(display_toggle_value); - if (display_toggle_value) { - setup_display(); - } -} - -// cppcheck-suppress unusedFunction void setup() { Serial.begin(115200); - -#ifdef TTGO_T_Beam_V1_0 Wire.begin(SDA, SCL); - if (!powerManagement.begin(Wire)) { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "AXP192", "init done!"); - } else { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "AXP192", "init failed!"); - } + powerManagement.begin(Wire); powerManagement.activateLoRa(); powerManagement.activateOLED(); powerManagement.activateGPS(); powerManagement.activateMeasurement(); -#endif + // make sure wifi and bt is off as we don't need it: + WiFi.mode(WIFI_OFF); + btStop(); - delay(500); - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "LoRa APRS Tracker by OE5BPA (Peter Buchegger)"); - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "Version: " VERSION); setup_display(); - show_display("OE5BPA", "LoRa APRS Tracker", "by Peter Buchegger", "Version: " VERSION, 2000); load_config(); setup_gps(); setup_lora(); - - if (Config.ptt.active) { - pinMode(Config.ptt.io_pin, OUTPUT); - digitalWrite(Config.ptt.io_pin, Config.ptt.reverse ? HIGH : LOW); - } - - // make sure wifi and bt is off as we don't need it: - WiFi.mode(WIFI_OFF); - btStop(); - - if (Config.button.tx) { - // attach TX action to user button (defined by BUTTON_PIN) - userButton.attachClick(handle_tx_click); - } - - if (Config.button.alt_message) { - userButton.attachLongPressStart(handle_next_beacon); - } - userButton.attachDoubleClick(toggle_display); - - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "Smart Beacon is: %s", getSmartBeaconState()); - show_display("INFO", "Smart Beacon is " + getSmartBeaconState(), 1000); - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "setup done..."); - delay(500); + // userButton.attachClick(handle_tx_click); // attach TX action to user button (defined by BUTTON_PIN) + // userButton.attachLongPressStart(handle_next_beacon); + // userButton.attachDoubleClick(toggle_display); + esp_sleep_enable_timer_wakeup(mConfig.beacon.smart_beacon.slow_rate * 1000000); + Serial.println("HI"); + String sM = String("Sleep for : ") + String(mConfig.beacon.smart_beacon.slow_rate, DEC) + String("s"); + Serial.println(sM); + Serial.println("GO..."); + delay(1000); } -// cppcheck-suppress unusedFunction void loop() { + static unsigned int rate_limit_message_text = 0; + static int speed_zero_sent = 0; + static String batteryVoltage = ""; + static String batteryChargeCurrent = ""; + APRSMessage msg; + String lat; + String lng; + String aprsmsg; + static int iState; + userButton.tick(); - if (Config.debug) { - while (Serial.available() > 0) { - char c = Serial.read(); - // Serial.print(c); - gps.encode(c); - } - } else { + switch (iState) { + case HasSynchGPS: { while (ss.available() > 0) { char c = ss.read(); - // Serial.print(c); gps.encode(c); } - } - bool gps_time_update = gps.time.isUpdated(); - bool gps_loc_update = gps.location.isUpdated(); - static bool gps_loc_update_valid = false; - static time_t nextBeaconTimeStamp = -1; + if (gps.time.isValid()) { + setTime(gps.time.hour(), gps.time.minute(), gps.time.second(), gps.date.day(), gps.date.month(), gps.date.year()); + // Serial.println("GPS time ok"); + } - if (gps_loc_update != gps_loc_update_valid) { - gps_loc_update_valid = gps_loc_update; - - if (gps_loc_update) { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Loop", "GPS fix state went to VALID"); + if (gps.location.isValid()) { + Serial.println("GPS pos ok"); + iState = PrepBeacon; + } + if (powerManagement.isCharging()) { + powerManagement.enableChgLed(); } else { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Loop", "GPS fix state went to INVALID"); + powerManagement.disableChgLed(); } + delay(20); + break; } - static double currentHeading = 0; - static double previousHeading = 0; - static unsigned int rate_limit_message_text = 0; - - if (gps.time.isValid()) { - setTime(gps.time.hour(), gps.time.minute(), gps.time.second(), gps.date.day(), gps.date.month(), gps.date.year()); - - if (gps_loc_update && nextBeaconTimeStamp <= now()) { - send_update = true; - if (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active) { - currentHeading = gps.course.deg(); - // enforce message text on slowest Config.smart_beacon.slow_rate - rate_limit_message_text = 0; - } else { - // enforce message text every n's Config.beacon.timeout frame - if (BeaconMan.getCurrentBeaconConfig()->timeout * rate_limit_message_text > 30) { - rate_limit_message_text = 0; - } - } + case PrepBeacon: { + if (powerManagement.isBatteryConnect()) { + batteryVoltage = String(powerManagement.getBatteryVoltage(), 2); + batteryChargeCurrent = String(powerManagement.getBatteryChargeDischargeCurrent(), 0); } - } - - static double lastTxLat = 0.0; - static double lastTxLng = 0.0; - static double lastTxdistance = 0.0; - static uint32_t txInterval = 60000L; // Initial 60 secs internal - static uint32_t lastTxTime = millis(); - static int speed_zero_sent = 0; - - static bool BatteryIsConnected = false; - static String batteryVoltage = ""; - static String batteryChargeCurrent = ""; -#ifdef TTGO_T_Beam_V1_0 - static unsigned int rate_limit_check_battery = 0; - if (!(rate_limit_check_battery++ % 60)) - BatteryIsConnected = powerManagement.isBatteryConnect(); - if (BatteryIsConnected) { - batteryVoltage = String(powerManagement.getBatteryVoltage(), 2); - batteryChargeCurrent = String(powerManagement.getBatteryChargeDischargeCurrent(), 0); - } -#endif - - if (powerManagement.isChargeing()) { - powerManagement.enableChgLed(); - } else { - powerManagement.disableChgLed(); - } - - if (!send_update && gps_loc_update && BeaconMan.getCurrentBeaconConfig()->smart_beacon.active) { - uint32_t lastTx = millis() - lastTxTime; - currentHeading = gps.course.deg(); - lastTxdistance = TinyGPSPlus::distanceBetween(gps.location.lat(), gps.location.lng(), lastTxLat, lastTxLng); - if (lastTx >= txInterval) { - // Trigger Tx Tracker when Tx interval is reach - // Will not Tx if stationary bcos speed < 5 and lastTxDistance < 20 - if (lastTxdistance > 20) { - send_update = true; - } - } - - if (!send_update) { - // Get headings and heading delta - double headingDelta = abs(previousHeading - currentHeading); - - if (lastTx > BeaconMan.getCurrentBeaconConfig()->smart_beacon.min_bcn * 1000) { - // Check for heading more than 25 degrees - if (headingDelta > BeaconMan.getCurrentBeaconConfig()->smart_beacon.turn_min && lastTxdistance > BeaconMan.getCurrentBeaconConfig()->smart_beacon.min_tx_dist) { - send_update = true; - } - } - } - } - - if (send_update && gps_loc_update) { - send_update = false; - - nextBeaconTimeStamp = now() + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? BeaconMan.getCurrentBeaconConfig()->smart_beacon.slow_rate : (BeaconMan.getCurrentBeaconConfig()->timeout * SECS_PER_MIN)); - - APRSMessage msg; - String lat; - String lng; - String dao; - - msg.setSource(BeaconMan.getCurrentBeaconConfig()->callsign); - msg.setPath(BeaconMan.getCurrentBeaconConfig()->path); + msg.setSource(mConfig.beacon.callsign); + msg.setPath(mConfig.beacon.path); msg.setDestination("APLT00"); - - if (!BeaconMan.getCurrentBeaconConfig()->enhance_precision) { - lat = create_lat_aprs(gps.location.rawLat()); - lng = create_long_aprs(gps.location.rawLng()); - } else { - lat = create_lat_aprs_dao(gps.location.rawLat()); - lng = create_long_aprs_dao(gps.location.rawLng()); - dao = create_dao_aprs(gps.location.rawLat(), gps.location.rawLng()); - } + lat = create_lat_aprs(gps.location.rawLat()); + lng = create_long_aprs(gps.location.rawLng()); String alt = ""; int alt_int = max(-99999, min(999999, (int)gps.altitude.feet())); @@ -276,114 +146,65 @@ void loop() { speed_zero_sent = 0; } - String aprsmsg; - aprsmsg = "!" + lat + BeaconMan.getCurrentBeaconConfig()->overlay + lng + BeaconMan.getCurrentBeaconConfig()->symbol + course_and_speed + alt; + aprsmsg = "!" + lat + mConfig.beacon.overlay + lng + mConfig.beacon.symbol + course_and_speed + alt; // message_text every 10's packet (i.e. if we have beacon rate 1min at high // speed -> every 10min). May be enforced above (at expirey of smart beacon // rate (i.e. every 30min), or every third packet on static rate (i.e. // static rate 10 -> every third packet) if (!(rate_limit_message_text++ % 10)) { - aprsmsg += BeaconMan.getCurrentBeaconConfig()->message; - } - if (BatteryIsConnected) { - aprsmsg += " - _Bat.: " + batteryVoltage + "V - Cur.: " + batteryChargeCurrent + "mA"; + aprsmsg += mConfig.beacon.message; } - if (BeaconMan.getCurrentBeaconConfig()->enhance_precision) { - aprsmsg += " " + dao; + if (!powerManagement.isCharging()) { + aprsmsg += "VBat= " + batteryVoltage + "V Cur= " + batteryChargeCurrent + "mA"; } msg.getBody()->setData(aprsmsg); String data = msg.encode(); - logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "Loop", "%s", data.c_str()); - show_display("<< TX >>", data); - - if (Config.ptt.active) { - digitalWrite(Config.ptt.io_pin, Config.ptt.reverse ? LOW : HIGH); - delay(Config.ptt.start_delay); + // show_display("<< TX >>", data); + Serial.println("TX ok"); + // delay(1000); + if (mConfig.ptt.active) { + digitalWrite(mConfig.ptt.io_pin, mConfig.ptt.reverse ? LOW : HIGH); + delay(mConfig.ptt.start_delay); } - LoRa.beginPacket(); - // Header: - LoRa.write('<'); + LoRa.write('<'); // Header LoRa.write(0xFF); LoRa.write(0x01); - // APRS Data: LoRa.write((const uint8_t *)data.c_str(), data.length()); LoRa.endPacket(); - if (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active) { - lastTxLat = gps.location.lat(); - lastTxLng = gps.location.lng(); - previousHeading = currentHeading; - lastTxdistance = 0.0; - lastTxTime = millis(); + show_display(mConfig.beacon.callsign, createDateString(now()) + " " + createTimeString(now()), String("Sats: ") + gps.satellites.value() + " HDOP: " + gps.hdop.hdop(), !powerManagement.isCharging() ? (String("Bat: ") + batteryVoltage + "V, " + batteryChargeCurrent + "mA") : "Powered via USB"); + + if (mConfig.ptt.active) { + delay(mConfig.ptt.end_delay); + digitalWrite(mConfig.ptt.io_pin, mConfig.ptt.reverse ? HIGH : LOW); } - if (Config.ptt.active) { - delay(Config.ptt.end_delay); - digitalWrite(Config.ptt.io_pin, Config.ptt.reverse ? HIGH : LOW); - } + iState = Sleep; + break; + } + case Sleep: { + powerManagement.deactivateGPS(); + Serial.flush(); + esp_light_sleep_start(); + Serial.println("wake up"); + powerManagement.activateGPS(); + iState = HasSynchGPS; + break; } - if (gps_time_update) { - - show_display(BeaconMan.getCurrentBeaconConfig()->callsign, createDateString(now()) + " " + createTimeString(now()), String("Sats: ") + gps.satellites.value() + " HDOP: " + gps.hdop.hdop(), String("Next Bcn: ") + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? "~" : "") + createTimeString(nextBeaconTimeStamp), BatteryIsConnected ? (String("Bat: ") + batteryVoltage + "V, " + batteryChargeCurrent + "mA") : "Powered via USB", String("Smart Beacon: " + getSmartBeaconState())); - - if (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active) { - // Change the Tx internal based on the current speed - int curr_speed = (int)gps.speed.kmph(); - if (curr_speed < BeaconMan.getCurrentBeaconConfig()->smart_beacon.slow_speed) { - txInterval = BeaconMan.getCurrentBeaconConfig()->smart_beacon.slow_rate * 1000; - } else if (curr_speed > BeaconMan.getCurrentBeaconConfig()->smart_beacon.fast_speed) { - txInterval = BeaconMan.getCurrentBeaconConfig()->smart_beacon.fast_rate * 1000; - } else { - /* Interval inbetween low and high speed - min(slow_rate, ..) because: if slow rate is 300s at slow speed <= - 10km/h and fast rate is 60s at fast speed >= 100km/h everything below - current speed 20km/h (100*60/20 = 300) is below slow_rate. - -> In the first check, if curr speed is 5km/h (which is < 10km/h), tx - interval is 300s, but if speed is 6km/h, we are landing in this - section, what leads to interval 100*60/6 = 1000s (16.6min) -> this - would lead to decrease of beacon rate in between 5 to 20 km/h. what - is even below the slow speed rate. - */ - txInterval = min(BeaconMan.getCurrentBeaconConfig()->smart_beacon.slow_rate, BeaconMan.getCurrentBeaconConfig()->smart_beacon.fast_speed * BeaconMan.getCurrentBeaconConfig()->smart_beacon.fast_rate / curr_speed) * 1000; - } - } - } - - if ((Config.debug == false) && (millis() > 5000 && gps.charsProcessed() < 10)) { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "GPS", - "No GPS frames detected! Try to reset the GPS Chip with this " - "firmware: https://github.com/lora-aprs/TTGO-T-Beam_GPS-reset"); - show_display("No GPS frames detected!", "Try to reset the GPS Chip", "https://github.com/lora-aprs/TTGO-T-Beam_GPS-reset", 2000); - } - - // RX - int packetSize = LoRa.parsePacket(); - - if (packetSize) { - String rxdata; - - while (LoRa.available()) { // read packet - rxdata += (char)LoRa.read(); - } - rxdata += "' with RSSI "; - rxdata += (LoRa.packetRssi()); - show_display("<< RX RX >>", rxdata); - delay(4000); + default: + iState = HasSynchGPS; + break; } } void load_config() { ConfigurationManagement confmg("/tracker.json"); - Config = confmg.readConfiguration(); - BeaconMan.loadConfig(Config.beacons); - if (BeaconMan.getCurrentBeaconConfig()->callsign == "NOCALL-10") { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Config", - "You have to change your settings in 'data/tracker.json' and " - "upload it via \"Upload File System image\"!"); + mConfig = confmg.readConfiguration(); + if (mConfig.beacon.callsign == "NOCALL-7") { show_display("ERROR", "You have to change your settings in 'data/tracker.json' and " "upload it via \"Upload File System image\"!"); while (true) { @@ -392,27 +213,18 @@ void load_config() { } void setup_lora() { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "Set SPI pins!"); SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS); - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "Set LoRa pins!"); LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ); - - long freq = Config.lora.frequencyTx; - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "frequency: %d", freq); + long freq = mConfig.lora.frequencyTx; if (!LoRa.begin(freq)) { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "LoRa", "Starting LoRa failed!"); - show_display("ERROR", "Starting LoRa failed!"); while (true) { } } - LoRa.setSpreadingFactor(Config.lora.spreadingFactor); - LoRa.setSignalBandwidth(Config.lora.signalBandwidth); - LoRa.setCodingRate4(Config.lora.codingRate4); + LoRa.setSpreadingFactor(mConfig.lora.spreadingFactor); + LoRa.setSignalBandwidth(mConfig.lora.signalBandwidth); + LoRa.setCodingRate4(mConfig.lora.codingRate4); LoRa.enableCrc(); - - LoRa.setTxPower(Config.lora.power); - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "LoRa init done!"); - show_display("INFO", "LoRa init done!", 2000); + LoRa.setTxPower(mConfig.lora.power); } void setup_gps() { @@ -464,21 +276,6 @@ String create_lat_aprs(RawDegrees lat) { return lat_str; } -String create_lat_aprs_dao(RawDegrees lat) { - // round to 4 digits and cut the last 2 - char str[20]; - char n_s = 'N'; - if (lat.negative) { - n_s = 'S'; - } - // we need sprintf's float up-rounding. Must be the same principle as in - // aprs_dao(). We cut off the string to two decimals afterwards. but sprintf % - // may round to 60.0000 -> 5360.0000 (53° 60min is a wrong notation ;) - sprintf(str, "%02d%s%c", lat.deg, s_min_nn(lat.billionths, 1 /* high precision */), n_s); - String lat_str(str); - return lat_str; -} - String create_long_aprs(RawDegrees lng) { char str[20]; char e_w = 'E'; @@ -490,32 +287,6 @@ String create_long_aprs(RawDegrees lng) { return lng_str; } -String create_long_aprs_dao(RawDegrees lng) { - // round to 4 digits and cut the last 2 - char str[20]; - char e_w = 'E'; - if (lng.negative) { - e_w = 'W'; - } - sprintf(str, "%03d%s%c", lng.deg, s_min_nn(lng.billionths, 1 /* high precision */), e_w); - String lng_str(str); - return lng_str; -} - -String create_dao_aprs(RawDegrees lat, RawDegrees lng) { - // !DAO! extension, use Base91 format for best precision - // /1.1 : scale from 0-99 to 0-90 for base91, int(... + 0.5): round to nearest - // integer https://metacpan.org/dist/Ham-APRS-FAP/source/FAP.pm - // http://www.aprs.org/aprs12/datum.txt - // - - char str[10]; - sprintf(str, "!w%s", s_min_nn(lat.billionths, 2)); - sprintf(str + 3, "%s!", s_min_nn(lng.billionths, 2)); - String dao_str(str); - return dao_str; -} - String createDateString(time_t t) { return String(padding(day(t), 2) + "." + padding(month(t), 2) + "." + padding(year(t), 4)); } @@ -524,13 +295,6 @@ String createTimeString(time_t t) { return String(padding(hour(t), 2) + ":" + padding(minute(t), 2) + ":" + padding(second(t), 2)); } -String getSmartBeaconState() { - if (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active) { - return "On"; - } - return "Off"; -} - String padding(unsigned int number, unsigned int width) { String result; String num(number); diff --git a/src/configuration.cpp b/src/configuration.cpp index dc9f572..8d9e401 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -1,5 +1,4 @@ #include -#include #ifndef CPPCHECK #include @@ -7,15 +6,10 @@ #include "configuration.h" -extern logging::Logger logger; - ConfigurationManagement::ConfigurationManagement(String FilePath) : mFilePath(FilePath) { if (!SPIFFS.begin(true)) { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Configuration", "Mounting SPIFFS was not possible. Trying to format SPIFFS..."); SPIFFS.format(); - if (!SPIFFS.begin()) { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Configuration", "Formatting SPIFFS was not okay!"); - } + SPIFFS.begin(); } } @@ -23,14 +17,12 @@ ConfigurationManagement::ConfigurationManagement(String FilePath) : mFilePath(Fi Configuration ConfigurationManagement::readConfiguration() { File file = SPIFFS.open(mFilePath); if (!file) { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Configuration", "Failed to open file for reading..."); return Configuration(); } DynamicJsonDocument data(2048); DeserializationError error = deserializeJson(data, file); if (error) { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Configuration", "Failed to read file, using default configuration."); } file.close(); @@ -38,35 +30,26 @@ Configuration ConfigurationManagement::readConfiguration() { conf.debug = data["debug"] | false; - JsonArray beacons = data["beacons"].as(); - for (JsonVariant v : beacons) { - Configuration::Beacon beacon; - - if (v.containsKey("callsign")) - beacon.callsign = v["callsign"].as(); - if (v.containsKey("path")) - beacon.path = v["path"].as(); - if (v.containsKey("message")) - beacon.message = v["message"].as(); - beacon.timeout = v["timeout"] | 1; - if (v.containsKey("symbol")) - beacon.symbol = v["symbol"].as(); - if (v.containsKey("overlay")) - beacon.overlay = v["overlay"].as(); - - beacon.smart_beacon.active = v["smart_beacon"]["active"] | false; - beacon.smart_beacon.turn_min = v["smart_beacon"]["turn_min"] | 25; - beacon.smart_beacon.slow_rate = v["smart_beacon"]["slow_rate"] | 300; - beacon.smart_beacon.slow_speed = v["smart_beacon"]["slow_speed"] | 10; - beacon.smart_beacon.fast_rate = v["smart_beacon"]["fast_rate"] | 60; - beacon.smart_beacon.fast_speed = v["smart_beacon"]["fast_speed"] | 100; - beacon.smart_beacon.min_tx_dist = v["smart_beacon"]["min_tx_dist"] | 100; - beacon.smart_beacon.min_bcn = v["smart_beacon"]["min_bcn"] | 5; - - beacon.enhance_precision = v["enhance_precision"] | false; - - conf.beacons.push_back(beacon); - } + // conf.beacon.callsign ="NOCALL-7"; + conf.beacon.callsign = data["beacon"]["callsign"].as(); + // conf.beacon.path ="WIDE1-1"; + conf.beacon.path = data["beacon"]["path"].as(); + // conf.beacon.message="73"; + conf.beacon.message = data["beacon"]["message"].as(); + conf.beacon.timeout = data["beacon"]["timeout"] | 1; + // conf.beacon.symbol = "["; + conf.beacon.symbol = data["beacon"]["symbol"].as(); + // conf.beacon.overlay ="/"; + conf.beacon.overlay = data["beacon"]["overlay"].as(); + conf.beacon.smart_beacon.active = data["beacon"]["smart_beacon"]["active"] | false; + conf.beacon.smart_beacon.turn_min = data["beacon"]["smart_beacon"]["turn_min"] | 25; + conf.beacon.smart_beacon.slow_rate = data["beacon"]["smart_beacon"]["slow_rate"] | 120; + conf.beacon.smart_beacon.slow_speed = data["beacon"]["smart_beacon"]["slow_speed"] | 10; + conf.beacon.smart_beacon.fast_rate = data["beacon"]["smart_beacon"]["fast_rate"] | 10; + conf.beacon.smart_beacon.fast_speed = data["beacon"]["smart_beacon"]["fast_speed"] | 100; + conf.beacon.smart_beacon.min_tx_dist = data["beacon"]["smart_beacon"]["min_tx_dist"] | 100; + conf.beacon.smart_beacon.min_bcn = data["beacon"]["smart_beacon"]["min_bcn"] | 5; + conf.beacon.enhance_precision = data["beacon"]["enhance_precision"] | false; conf.button.tx = data["button"]["tx"] | false; conf.button.alt_message = data["button"]["alt_message"] | false; @@ -87,11 +70,10 @@ Configuration ConfigurationManagement::readConfiguration() { return conf; } -// cppcheck-suppress unusedFunction +/* cppcheck-suppress unusedFunction void ConfigurationManagement::writeConfiguration(Configuration conf) { File file = SPIFFS.open(mFilePath, "w"); if (!file) { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Configuration", "Failed to open file for writing..."); return; } DynamicJsonDocument data(2048); @@ -138,4 +120,4 @@ void ConfigurationManagement::writeConfiguration(Configuration conf) { serializeJson(data, file); file.close(); -} +}*/ diff --git a/src/configuration.h b/src/configuration.h index c7dae47..e41fc29 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -76,7 +76,7 @@ public: } bool debug; - std::list beacons; + Beacon beacon; LoRa lora; PTT ptt; Button button; diff --git a/src/display.cpp b/src/display.cpp index 5c3effa..4e501a6 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -2,13 +2,10 @@ #include #include #include -#include #include "display.h" #include "pins.h" -extern logging::Logger logger; - Adafruit_SSD1306 display(128, 64, &Wire, OLED_RST); // cppcheck-suppress unusedFunction @@ -20,7 +17,6 @@ void setup_display() { Wire.begin(OLED_SDA, OLED_SCL); if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "SSD1306", "allocation failed!"); while (true) { } } diff --git a/src/power_management.cpp b/src/power_management.cpp index d9527a4..f101c28 100644 --- a/src/power_management.cpp +++ b/src/power_management.cpp @@ -81,6 +81,12 @@ bool PowerManagement::isBatteryConnect() { return axp.isBatteryConnect(); } -bool PowerManagement::isChargeing() { +bool PowerManagement::isCharging() { return axp.isChargeing(); } + +// cppcheck-suppress unusedFunction +void PowerManagement::enCharging(bool bChrg) { + axp.enableChargeing(bChrg); +} + diff --git a/src/power_management.h b/src/power_management.h index 73edfbf..ddfe111 100644 --- a/src/power_management.h +++ b/src/power_management.h @@ -28,7 +28,8 @@ public: double getBatteryChargeDischargeCurrent(); bool isBatteryConnect(); - bool isChargeing(); + bool isCharging(); + void enCharging(bool ); private: AXP20X_Class axp;