fix clang (except logger)
This commit is contained in:
parent
5b1be61032
commit
8e262785b7
7 changed files with 731 additions and 830 deletions
|
@ -1,24 +1,24 @@
|
||||||
|
#include <APRS-Decoder.h>
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <LoRa.h>
|
#include <LoRa.h>
|
||||||
#include <APRS-Decoder.h>
|
|
||||||
#include <TinyGPS++.h>
|
|
||||||
#include <TimeLib.h>
|
|
||||||
#include <WiFi.h>
|
|
||||||
#include <OneButton.h>
|
#include <OneButton.h>
|
||||||
|
#include <TimeLib.h>
|
||||||
|
#include <TinyGPS++.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <logger.h>
|
||||||
|
|
||||||
|
#include "configuration.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "pins.h"
|
#include "pins.h"
|
||||||
#include "power_management.h"
|
#include "power_management.h"
|
||||||
#include "configuration.h"
|
|
||||||
Configuration Config;
|
Configuration Config;
|
||||||
|
|
||||||
#include "power_management.h"
|
|
||||||
PowerManagement powerManagement;
|
PowerManagement powerManagement;
|
||||||
OneButton userButton = OneButton(BUTTON_PIN, true, true);
|
OneButton userButton = OneButton(BUTTON_PIN, true, true);
|
||||||
|
|
||||||
#include "logger.h"
|
|
||||||
|
|
||||||
HardwareSerial ss(1);
|
HardwareSerial ss(1);
|
||||||
TinyGPSPlus gps;
|
TinyGPSPlus gps;
|
||||||
|
|
||||||
void load_config();
|
void load_config();
|
||||||
void setup_lora();
|
void setup_lora();
|
||||||
|
@ -35,507 +35,447 @@ String getSmartBeaconState();
|
||||||
String padding(unsigned int number, unsigned int width);
|
String padding(unsigned int number, unsigned int width);
|
||||||
|
|
||||||
static bool send_update = true;
|
static bool send_update = true;
|
||||||
static void handle_tx_click();
|
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
static void handle_tx_click() {
|
||||||
void setup()
|
send_update = true;
|
||||||
{
|
|
||||||
Serial.begin(115200);
|
|
||||||
|
|
||||||
#ifdef TTGO_T_Beam_V1_0
|
|
||||||
Wire.begin(SDA, SCL);
|
|
||||||
if (!powerManagement.begin(Wire))
|
|
||||||
{
|
|
||||||
logPrintlnI("AXP192 init done!");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logPrintlnE("AXP192 init failed!");
|
|
||||||
}
|
|
||||||
powerManagement.activateLoRa();
|
|
||||||
powerManagement.activateOLED();
|
|
||||||
powerManagement.activateGPS();
|
|
||||||
powerManagement.activateMeasurement();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
delay(500);
|
|
||||||
logPrintlnI("LoRa APRS Tracker by OE5BPA (Peter Buchegger)");
|
|
||||||
setup_display();
|
|
||||||
|
|
||||||
show_display("OE5BPA", "LoRa APRS Tracker", "by Peter Buchegger", 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.beacon.button_tx)
|
|
||||||
{
|
|
||||||
// attach TX action to user button (defined by BUTTON_PIN)
|
|
||||||
userButton.attachClick(handle_tx_click);
|
|
||||||
}
|
|
||||||
|
|
||||||
logPrintlnI("Smart Beacon is " + getSmartBeaconState());
|
|
||||||
show_display("INFO", "Smart Beacon is " + getSmartBeaconState(), 1000);
|
|
||||||
logPrintlnI("setup done...");
|
|
||||||
delay(500);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void loop()
|
void setup() {
|
||||||
{
|
Serial.begin(115200);
|
||||||
userButton.tick();
|
|
||||||
|
|
||||||
if(Config.debug)
|
|
||||||
{
|
|
||||||
while(Serial.available() > 0)
|
|
||||||
{
|
|
||||||
char c = Serial.read();
|
|
||||||
//Serial.print(c);
|
|
||||||
gps.encode(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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 time_t nextBeaconTimeStamp = -1;
|
|
||||||
|
|
||||||
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 (Config.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 (Config.beacon.timeout * rate_limit_message_text > 30)
|
|
||||||
{
|
|
||||||
rate_limit_message_text = 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
|
#ifdef TTGO_T_Beam_V1_0
|
||||||
static unsigned int rate_limit_check_battery = 0;
|
Wire.begin(SDA, SCL);
|
||||||
if (!(rate_limit_check_battery++ % 60))
|
if (!powerManagement.begin(Wire)) {
|
||||||
BatteryIsConnected = powerManagement.isBatteryConnect();
|
logPrintlnI("AXP192 init done!");
|
||||||
if (BatteryIsConnected) {
|
} else {
|
||||||
batteryVoltage = String(powerManagement.getBatteryVoltage(), 2);
|
logPrintlnE("AXP192 init failed!");
|
||||||
batteryChargeCurrent = String(powerManagement.getBatteryChargeDischargeCurrent(), 0);
|
}
|
||||||
}
|
powerManagement.activateLoRa();
|
||||||
|
powerManagement.activateOLED();
|
||||||
|
powerManagement.activateGPS();
|
||||||
|
powerManagement.activateMeasurement();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(!send_update && gps_loc_update && Config.smart_beacon.active)
|
delay(500);
|
||||||
{
|
logPrintlnI("LoRa APRS Tracker by OE5BPA (Peter Buchegger)");
|
||||||
uint32_t lastTx = millis() - lastTxTime;
|
setup_display();
|
||||||
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)
|
show_display("OE5BPA", "LoRa APRS Tracker", "by Peter Buchegger", 2000);
|
||||||
{
|
load_config();
|
||||||
// Get headings and heading delta
|
|
||||||
double headingDelta = abs(previousHeading - currentHeading);
|
|
||||||
|
|
||||||
if(lastTx > Config.smart_beacon.min_bcn * 1000)
|
setup_gps();
|
||||||
{
|
setup_lora();
|
||||||
// Check for heading more than 25 degrees
|
|
||||||
if(headingDelta > Config.smart_beacon.turn_min && lastTxdistance > Config.smart_beacon.min_tx_dist)
|
|
||||||
{
|
|
||||||
send_update = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(send_update && gps_loc_update)
|
if (Config.ptt.active) {
|
||||||
{
|
pinMode(Config.ptt.io_pin, OUTPUT);
|
||||||
send_update = false;
|
digitalWrite(Config.ptt.io_pin, Config.ptt.reverse ? HIGH : LOW);
|
||||||
nextBeaconTimeStamp = now() + (Config.smart_beacon.active ? Config.smart_beacon.slow_rate : (Config.beacon.timeout * SECS_PER_MIN));
|
}
|
||||||
|
|
||||||
APRSMessage msg;
|
// make sure wifi and bt is off as we don't need it:
|
||||||
String lat;
|
WiFi.mode(WIFI_OFF);
|
||||||
String lng;
|
btStop();
|
||||||
String dao;
|
|
||||||
|
|
||||||
msg.setSource(Config.callsign);
|
if (Config.beacon.button_tx) {
|
||||||
msg.setDestination("APLT00-1");
|
// attach TX action to user button (defined by BUTTON_PIN)
|
||||||
|
userButton.attachClick(handle_tx_click);
|
||||||
|
}
|
||||||
|
|
||||||
if (!Config.enhance_precision){
|
logPrintlnI("Smart Beacon is " + getSmartBeaconState());
|
||||||
lat = create_lat_aprs(gps.location.rawLat());
|
show_display("INFO", "Smart Beacon is " + getSmartBeaconState(), 1000);
|
||||||
lng = create_long_aprs(gps.location.rawLng());
|
logPrintlnI("setup done...");
|
||||||
} else {
|
delay(500);
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
String alt = "";
|
|
||||||
int alt_int = max(-99999, min(999999, (int)gps.altitude.feet()));
|
|
||||||
if (alt_int < 0)
|
|
||||||
{
|
|
||||||
alt = "/A=-" + padding(alt_int * -1, 5);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
alt = "/A=" + padding(alt_int, 6);
|
|
||||||
}
|
|
||||||
|
|
||||||
String course_and_speed = "";
|
|
||||||
int speed_int = max(0, min(999, (int)gps.speed.knots()));
|
|
||||||
if (speed_zero_sent < 3)
|
|
||||||
{
|
|
||||||
String speed = padding(speed_int, 3);
|
|
||||||
int course_int = max(0, min(360, (int)gps.course.deg()));
|
|
||||||
/* course in between 1..360 due to aprs spec */
|
|
||||||
if (course_int == 0)
|
|
||||||
{
|
|
||||||
course_int = 360;
|
|
||||||
}
|
|
||||||
String course = padding(course_int, 3);
|
|
||||||
course_and_speed = course + "/" + speed;
|
|
||||||
}
|
|
||||||
if (speed_int == 0)
|
|
||||||
{
|
|
||||||
/* speed is 0.
|
|
||||||
we send 3 packets with speed zero (so our friends know we stand still).
|
|
||||||
After that, we save airtime by not sending speed/course 000/000.
|
|
||||||
Btw, even if speed we really do not move, measured course is changeing (-> no useful / even wrong info)
|
|
||||||
*/
|
|
||||||
if (speed_zero_sent < 3)
|
|
||||||
{
|
|
||||||
speed_zero_sent += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
speed_zero_sent = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
String aprsmsg;
|
|
||||||
aprsmsg = "!" + lat + Config.beacon.overlay + lng + Config.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 += Config.beacon.message;
|
|
||||||
}
|
|
||||||
if (BatteryIsConnected)
|
|
||||||
{
|
|
||||||
aprsmsg += " - _Bat.: " + batteryVoltage + "V - Cur.: " + batteryChargeCurrent + "mA";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Config.enhance_precision){
|
|
||||||
aprsmsg += " " + dao;
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.getAPRSBody()->setData(aprsmsg);
|
|
||||||
String data = msg.encode();
|
|
||||||
logPrintlnD(data);
|
|
||||||
show_display("<< TX >>", data);
|
|
||||||
|
|
||||||
if (Config.ptt.active)
|
|
||||||
{
|
|
||||||
digitalWrite(Config.ptt.io_pin, Config.ptt.reverse ? LOW : HIGH);
|
|
||||||
delay(Config.ptt.start_delay);
|
|
||||||
}
|
|
||||||
|
|
||||||
LoRa.beginPacket();
|
|
||||||
// Header:
|
|
||||||
LoRa.write('<');
|
|
||||||
LoRa.write(0xFF);
|
|
||||||
LoRa.write(0x01);
|
|
||||||
// APRS Data:
|
|
||||||
LoRa.write((const uint8_t *)data.c_str(), data.length());
|
|
||||||
LoRa.endPacket();
|
|
||||||
|
|
||||||
if (Config.smart_beacon.active)
|
|
||||||
{
|
|
||||||
lastTxLat = gps.location.lat();
|
|
||||||
lastTxLng = gps.location.lng();
|
|
||||||
previousHeading = currentHeading;
|
|
||||||
lastTxdistance = 0.0;
|
|
||||||
lastTxTime = millis();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Config.ptt.active)
|
|
||||||
{
|
|
||||||
delay(Config.ptt.end_delay);
|
|
||||||
digitalWrite(Config.ptt.io_pin, Config.ptt.reverse ? HIGH : LOW);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(gps_time_update)
|
|
||||||
{
|
|
||||||
show_display(Config.callsign,
|
|
||||||
createDateString(now()) + " " + createTimeString(now()),
|
|
||||||
String("Sats: ") + gps.satellites.value() + " HDOP: " + gps.hdop.hdop(),
|
|
||||||
String("Nxt Bcn: ") + (Config.smart_beacon.active ? "~" : "") + createTimeString(nextBeaconTimeStamp),
|
|
||||||
BatteryIsConnected ? (String("Bat: ") + batteryVoltage + "V, " + batteryChargeCurrent + "mA" ) : "Powered via USB",
|
|
||||||
String("Smart Beacon: " + getSmartBeaconState()) );
|
|
||||||
|
|
||||||
if(Config.smart_beacon.active)
|
|
||||||
{
|
|
||||||
// Change the Tx internal based on the current speed
|
|
||||||
int curr_speed = (int ) gps.speed.kmph();
|
|
||||||
if(curr_speed < Config.smart_beacon.slow_speed)
|
|
||||||
{
|
|
||||||
txInterval = Config.smart_beacon.slow_rate * 1000;
|
|
||||||
}
|
|
||||||
else if(curr_speed > Config.smart_beacon.fast_speed)
|
|
||||||
{
|
|
||||||
txInterval = Config.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(Config.smart_beacon.slow_rate, Config.smart_beacon.fast_speed * Config.smart_beacon.fast_rate / curr_speed) * 1000;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((Config.debug == false) && (millis() > 5000 && gps.charsProcessed() < 10))
|
|
||||||
{
|
|
||||||
logPrintlnE("No GPS frames detected! Try to reset the GPS Chip with this firmware: https://github.com/lora-aprs/TTGO-T-Beam_GPS-reset");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_config()
|
// cppcheck-suppress unusedFunction
|
||||||
{
|
void loop() {
|
||||||
ConfigurationManagement confmg("/tracker.json");
|
userButton.tick();
|
||||||
Config = confmg.readConfiguration();
|
|
||||||
if(Config.callsign == "NOCALL-10")
|
if (Config.debug) {
|
||||||
{
|
while (Serial.available() > 0) {
|
||||||
logPrintlnE("You have to change your settings in 'data/tracker.json' and upload it via \"Upload File System image\"!");
|
char c = Serial.read();
|
||||||
show_display("ERROR", "You have to change your settings in 'data/tracker.json' and upload it via \"Upload File System image\"!");
|
// Serial.print(c);
|
||||||
while(true)
|
gps.encode(c);
|
||||||
{}
|
}
|
||||||
}
|
} else {
|
||||||
|
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 time_t nextBeaconTimeStamp = -1;
|
||||||
|
|
||||||
|
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 (Config.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 (Config.beacon.timeout * rate_limit_message_text > 30) {
|
||||||
|
rate_limit_message_text = 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 (!send_update && gps_loc_update && Config.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 > Config.smart_beacon.min_bcn * 1000) {
|
||||||
|
// Check for heading more than 25 degrees
|
||||||
|
if (headingDelta > Config.smart_beacon.turn_min && lastTxdistance > Config.smart_beacon.min_tx_dist) {
|
||||||
|
send_update = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (send_update && gps_loc_update) {
|
||||||
|
send_update = false;
|
||||||
|
nextBeaconTimeStamp = now() + (Config.smart_beacon.active ? Config.smart_beacon.slow_rate : (Config.beacon.timeout * SECS_PER_MIN));
|
||||||
|
|
||||||
|
APRSMessage msg;
|
||||||
|
String lat;
|
||||||
|
String lng;
|
||||||
|
String dao;
|
||||||
|
|
||||||
|
msg.setSource(Config.callsign);
|
||||||
|
msg.setDestination("APLT00-1");
|
||||||
|
|
||||||
|
if (!Config.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());
|
||||||
|
}
|
||||||
|
|
||||||
|
String alt = "";
|
||||||
|
int alt_int = max(-99999, min(999999, (int)gps.altitude.feet()));
|
||||||
|
if (alt_int < 0) {
|
||||||
|
alt = "/A=-" + padding(alt_int * -1, 5);
|
||||||
|
} else {
|
||||||
|
alt = "/A=" + padding(alt_int, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
String course_and_speed = "";
|
||||||
|
int speed_int = max(0, min(999, (int)gps.speed.knots()));
|
||||||
|
if (speed_zero_sent < 3) {
|
||||||
|
String speed = padding(speed_int, 3);
|
||||||
|
int course_int = max(0, min(360, (int)gps.course.deg()));
|
||||||
|
/* course in between 1..360 due to aprs spec */
|
||||||
|
if (course_int == 0) {
|
||||||
|
course_int = 360;
|
||||||
|
}
|
||||||
|
String course = padding(course_int, 3);
|
||||||
|
course_and_speed = course + "/" + speed;
|
||||||
|
}
|
||||||
|
if (speed_int == 0) {
|
||||||
|
/* speed is 0.
|
||||||
|
we send 3 packets with speed zero (so our friends know we stand still).
|
||||||
|
After that, we save airtime by not sending speed/course 000/000.
|
||||||
|
Btw, even if speed we really do not move, measured course is changeing
|
||||||
|
(-> no useful / even wrong info)
|
||||||
|
*/
|
||||||
|
if (speed_zero_sent < 3) {
|
||||||
|
speed_zero_sent += 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
speed_zero_sent = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
String aprsmsg;
|
||||||
|
aprsmsg = "!" + lat + Config.beacon.overlay + lng + Config.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 += Config.beacon.message;
|
||||||
|
}
|
||||||
|
if (BatteryIsConnected) {
|
||||||
|
aprsmsg += " - _Bat.: " + batteryVoltage + "V - Cur.: " + batteryChargeCurrent + "mA";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Config.enhance_precision) {
|
||||||
|
aprsmsg += " " + dao;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.getAPRSBody()->setData(aprsmsg);
|
||||||
|
String data = msg.encode();
|
||||||
|
logPrintlnD(data);
|
||||||
|
show_display("<< TX >>", data);
|
||||||
|
|
||||||
|
if (Config.ptt.active) {
|
||||||
|
digitalWrite(Config.ptt.io_pin, Config.ptt.reverse ? LOW : HIGH);
|
||||||
|
delay(Config.ptt.start_delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
LoRa.beginPacket();
|
||||||
|
// Header:
|
||||||
|
LoRa.write('<');
|
||||||
|
LoRa.write(0xFF);
|
||||||
|
LoRa.write(0x01);
|
||||||
|
// APRS Data:
|
||||||
|
LoRa.write((const uint8_t *)data.c_str(), data.length());
|
||||||
|
LoRa.endPacket();
|
||||||
|
|
||||||
|
if (Config.smart_beacon.active) {
|
||||||
|
lastTxLat = gps.location.lat();
|
||||||
|
lastTxLng = gps.location.lng();
|
||||||
|
previousHeading = currentHeading;
|
||||||
|
lastTxdistance = 0.0;
|
||||||
|
lastTxTime = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Config.ptt.active) {
|
||||||
|
delay(Config.ptt.end_delay);
|
||||||
|
digitalWrite(Config.ptt.io_pin, Config.ptt.reverse ? HIGH : LOW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gps_time_update) {
|
||||||
|
show_display(Config.callsign, createDateString(now()) + " " + createTimeString(now()), String("Sats: ") + gps.satellites.value() + " HDOP: " + gps.hdop.hdop(), String("Nxt Bcn: ") + (Config.smart_beacon.active ? "~" : "") + createTimeString(nextBeaconTimeStamp), BatteryIsConnected ? (String("Bat: ") + batteryVoltage + "V, " + batteryChargeCurrent + "mA") : "Powered via USB", String("Smart Beacon: " + getSmartBeaconState()));
|
||||||
|
|
||||||
|
if (Config.smart_beacon.active) {
|
||||||
|
// Change the Tx internal based on the current speed
|
||||||
|
int curr_speed = (int)gps.speed.kmph();
|
||||||
|
if (curr_speed < Config.smart_beacon.slow_speed) {
|
||||||
|
txInterval = Config.smart_beacon.slow_rate * 1000;
|
||||||
|
} else if (curr_speed > Config.smart_beacon.fast_speed) {
|
||||||
|
txInterval = Config.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(Config.smart_beacon.slow_rate, Config.smart_beacon.fast_speed * Config.smart_beacon.fast_rate / curr_speed) * 1000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((Config.debug == false) && (millis() > 5000 && gps.charsProcessed() < 10)) {
|
||||||
|
logPrintlnE("No GPS frames detected! Try to reset the GPS Chip with this "
|
||||||
|
"firmware: https://github.com/lora-aprs/TTGO-T-Beam_GPS-reset");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_lora()
|
void load_config() {
|
||||||
{
|
ConfigurationManagement confmg("/tracker.json");
|
||||||
logPrintlnI("Set SPI pins!");
|
Config = confmg.readConfiguration();
|
||||||
SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS);
|
if (Config.callsign == "NOCALL-10") {
|
||||||
logPrintlnI("Set LoRa pins!");
|
logPrintlnE("You have to change your settings in 'data/tracker.json' and "
|
||||||
LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ);
|
"upload it via \"Upload File System image\"!");
|
||||||
|
show_display("ERROR", "You have to change your settings in 'data/tracker.json' and "
|
||||||
long freq = Config.lora.frequencyTx;
|
"upload it via \"Upload File System image\"!");
|
||||||
logPrintI("frequency: ");
|
while (true) {
|
||||||
logPrintlnI(String(freq));
|
}
|
||||||
if (!LoRa.begin(freq)) {
|
}
|
||||||
logPrintlnE("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.enableCrc();
|
|
||||||
|
|
||||||
LoRa.setTxPower(Config.lora.power);
|
|
||||||
logPrintlnI("LoRa init done!");
|
|
||||||
show_display("INFO", "LoRa init done!", 2000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_gps()
|
void setup_lora() {
|
||||||
{
|
logPrintlnI("Set SPI pins!");
|
||||||
ss.begin(9600, SERIAL_8N1, GPS_TX, GPS_RX);
|
SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS);
|
||||||
|
logPrintlnI("Set LoRa pins!");
|
||||||
|
LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ);
|
||||||
|
|
||||||
|
long freq = Config.lora.frequencyTx;
|
||||||
|
logPrintI("frequency: ");
|
||||||
|
logPrintlnI(String(freq));
|
||||||
|
if (!LoRa.begin(freq)) {
|
||||||
|
logPrintlnE("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.enableCrc();
|
||||||
|
|
||||||
|
LoRa.setTxPower(Config.lora.power);
|
||||||
|
logPrintlnI("LoRa init done!");
|
||||||
|
show_display("INFO", "LoRa init done!", 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *s_min_nn(uint32_t min_nnnnn, int high_precision)
|
void setup_gps() {
|
||||||
{
|
ss.begin(9600, SERIAL_8N1, GPS_TX, GPS_RX);
|
||||||
/* min_nnnnn: RawDegrees billionths is uint32_t by definition and is n'telth degree (-> *= 6 -> nn.mmmmmm minutes)
|
|
||||||
* high_precision: 0: round at decimal position 2. 1: round at decimal position 4. 2: return decimal position 3-4 as base91 encoded char
|
|
||||||
*/
|
|
||||||
|
|
||||||
static char buf[6];
|
|
||||||
min_nnnnn = min_nnnnn * 0.006;
|
|
||||||
|
|
||||||
if (high_precision) {
|
|
||||||
if ((min_nnnnn % 10) >= 5 && min_nnnnn < 6000000 - 5) {
|
|
||||||
// round up. Avoid overflow (59.999999 should never become 60.0 or more)
|
|
||||||
min_nnnnn = min_nnnnn + 5;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ((min_nnnnn % 1000) >= 500 && min_nnnnn < (6000000 - 500)) {
|
|
||||||
// round up. Avoid overflow (59.9999 should never become 60.0 or more)
|
|
||||||
min_nnnnn = min_nnnnn + 500;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (high_precision < 2)
|
|
||||||
sprintf(buf, "%02u.%02u", (unsigned int ) ((min_nnnnn / 100000) % 100), (unsigned int ) ((min_nnnnn / 1000) % 100));
|
|
||||||
else
|
|
||||||
sprintf(buf, "%c", (char) ((min_nnnnn % 1000) / 11) + 33);
|
|
||||||
// Like to verify? type in python for i.e. RawDegrees billions 566688333: i = 566688333; "%c" % (int(((i*.0006+0.5) % 100)/1.1) +33)
|
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_tx_click()
|
char *s_min_nn(uint32_t min_nnnnn, int high_precision) {
|
||||||
{
|
/* min_nnnnn: RawDegrees billionths is uint32_t by definition and is n'telth
|
||||||
send_update = true;
|
* degree (-> *= 6 -> nn.mmmmmm minutes) high_precision: 0: round at decimal
|
||||||
|
* position 2. 1: round at decimal position 4. 2: return decimal position 3-4
|
||||||
|
* as base91 encoded char
|
||||||
|
*/
|
||||||
|
|
||||||
|
static char buf[6];
|
||||||
|
min_nnnnn = min_nnnnn * 0.006;
|
||||||
|
|
||||||
|
if (high_precision) {
|
||||||
|
if ((min_nnnnn % 10) >= 5 && min_nnnnn < 6000000 - 5) {
|
||||||
|
// round up. Avoid overflow (59.999999 should never become 60.0 or more)
|
||||||
|
min_nnnnn = min_nnnnn + 5;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((min_nnnnn % 1000) >= 500 && min_nnnnn < (6000000 - 500)) {
|
||||||
|
// round up. Avoid overflow (59.9999 should never become 60.0 or more)
|
||||||
|
min_nnnnn = min_nnnnn + 500;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (high_precision < 2)
|
||||||
|
sprintf(buf, "%02u.%02u", (unsigned int)((min_nnnnn / 100000) % 100), (unsigned int)((min_nnnnn / 1000) % 100));
|
||||||
|
else
|
||||||
|
sprintf(buf, "%c", (char)((min_nnnnn % 1000) / 11) + 33);
|
||||||
|
// Like to verify? type in python for i.e. RawDegrees billions 566688333: i =
|
||||||
|
// 566688333; "%c" % (int(((i*.0006+0.5) % 100)/1.1) +33)
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
String create_lat_aprs(RawDegrees lat)
|
String create_lat_aprs(RawDegrees lat) {
|
||||||
{
|
char str[20];
|
||||||
char str[20];
|
char n_s = 'N';
|
||||||
char n_s = 'N';
|
if (lat.negative) {
|
||||||
if(lat.negative)
|
n_s = 'S';
|
||||||
{
|
}
|
||||||
n_s = 'S';
|
// we like sprintf's float up-rounding.
|
||||||
}
|
// but sprintf % may round to 60.00 -> 5360.00 (53° 60min is a wrong notation
|
||||||
// we like sprintf's float up-rounding.
|
// ;)
|
||||||
// but sprintf % may round to 60.00 -> 5360.00 (53° 60min is a wrong notation ;)
|
sprintf(str, "%02d%s%c", lat.deg, s_min_nn(lat.billionths, 0), n_s);
|
||||||
sprintf(str, "%02d%s%c", lat.deg, s_min_nn(lat.billionths, 0), n_s);
|
String lat_str(str);
|
||||||
String lat_str(str);
|
return lat_str;
|
||||||
return lat_str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String create_lat_aprs_dao(RawDegrees lat)
|
String create_lat_aprs_dao(RawDegrees lat) {
|
||||||
{
|
// round to 4 digits and cut the last 2
|
||||||
//round to 4 digits and cut the last 2
|
char str[20];
|
||||||
char str[20];
|
char n_s = 'N';
|
||||||
char n_s = 'N';
|
if (lat.negative) {
|
||||||
if(lat.negative)
|
n_s = 'S';
|
||||||
{
|
}
|
||||||
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 %
|
||||||
// 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.
|
// may round to 60.0000 -> 5360.0000 (53° 60min is a wrong notation ;)
|
||||||
// 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);
|
||||||
sprintf(str, "%02d%s%c", lat.deg, s_min_nn(lat.billionths, 1 /* high precision */), n_s);
|
String lat_str(str);
|
||||||
String lat_str(str);
|
return lat_str;
|
||||||
return lat_str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String create_long_aprs(RawDegrees lng)
|
String create_long_aprs(RawDegrees lng) {
|
||||||
{
|
char str[20];
|
||||||
char str[20];
|
char e_w = 'E';
|
||||||
char e_w = 'E';
|
if (lng.negative) {
|
||||||
if(lng.negative)
|
e_w = 'W';
|
||||||
{
|
}
|
||||||
e_w = 'W';
|
sprintf(str, "%03d%s%c", lng.deg, s_min_nn(lng.billionths, 0), e_w);
|
||||||
}
|
String lng_str(str);
|
||||||
sprintf(str, "%03d%s%c", lng.deg, s_min_nn(lng.billionths, 0), e_w);
|
return lng_str;
|
||||||
String lng_str(str);
|
|
||||||
return lng_str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String create_long_aprs_dao(RawDegrees lng)
|
String create_long_aprs_dao(RawDegrees lng) {
|
||||||
{
|
// round to 4 digits and cut the last 2
|
||||||
//round to 4 digits and cut the last 2
|
char str[20];
|
||||||
char str[20];
|
char e_w = 'E';
|
||||||
char e_w = 'E';
|
if (lng.negative) {
|
||||||
if(lng.negative)
|
e_w = 'W';
|
||||||
{
|
}
|
||||||
e_w = 'W';
|
sprintf(str, "%03d%s%c", lng.deg, s_min_nn(lng.billionths, 1 /* high precision */), e_w);
|
||||||
}
|
String lng_str(str);
|
||||||
sprintf(str, "%03d%s%c", lng.deg, s_min_nn(lng.billionths, 1 /* high precision */), e_w);
|
return lng_str;
|
||||||
String lng_str(str);
|
|
||||||
return lng_str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String create_dao_aprs(RawDegrees lat, RawDegrees lng)
|
String create_dao_aprs(RawDegrees lat, RawDegrees lng) {
|
||||||
{
|
// !DAO! extension, use Base91 format for best precision
|
||||||
// !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
|
||||||
// /1.1 : scale from 0-99 to 0-90 for base91, int(... + 0.5): round to nearest integer
|
// integer https://metacpan.org/dist/Ham-APRS-FAP/source/FAP.pm
|
||||||
// https://metacpan.org/dist/Ham-APRS-FAP/source/FAP.pm
|
// http://www.aprs.org/aprs12/datum.txt
|
||||||
// http://www.aprs.org/aprs12/datum.txt
|
//
|
||||||
//
|
|
||||||
|
|
||||||
char str[10];
|
char str[10];
|
||||||
sprintf(str, "!w%s", s_min_nn(lat.billionths, 2));
|
sprintf(str, "!w%s", s_min_nn(lat.billionths, 2));
|
||||||
sprintf(str+3, "%s!", s_min_nn(lng.billionths, 2));
|
sprintf(str + 3, "%s!", s_min_nn(lng.billionths, 2));
|
||||||
String dao_str(str);
|
String dao_str(str);
|
||||||
return dao_str;
|
return dao_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
String createDateString(time_t t)
|
String createDateString(time_t t) {
|
||||||
{
|
return String(padding(day(t), 2) + "." + padding(month(t), 2) + "." + padding(year(t), 4));
|
||||||
return String(padding(day(t), 2) + "." + padding(month(t), 2) + "." + padding(year(t), 4));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String createTimeString(time_t t)
|
String createTimeString(time_t t) {
|
||||||
{
|
return String(padding(hour(t), 2) + "." + padding(minute(t), 2) + "." + padding(second(t), 2));
|
||||||
return String(padding(hour(t), 2) + "." + padding(minute(t), 2) + "." + padding(second(t), 2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String getSmartBeaconState()
|
String getSmartBeaconState() {
|
||||||
{
|
if (Config.smart_beacon.active) {
|
||||||
if (Config.smart_beacon.active)
|
return "On";
|
||||||
{
|
}
|
||||||
return "On";
|
return "Off";
|
||||||
}
|
|
||||||
return "Off";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String padding(unsigned int number, unsigned int width)
|
String padding(unsigned int number, unsigned int width) {
|
||||||
{
|
String result;
|
||||||
String result;
|
String num(number);
|
||||||
String num(number);
|
if (num.length() > width) {
|
||||||
if(num.length() > width)
|
width = num.length();
|
||||||
{
|
}
|
||||||
width = num.length();
|
for (unsigned int i = 0; i < width - num.length(); i++) {
|
||||||
}
|
result.concat('0');
|
||||||
for(unsigned int i = 0; i < width - num.length(); i++)
|
}
|
||||||
{
|
result.concat(num);
|
||||||
result.concat('0');
|
return result;
|
||||||
}
|
|
||||||
result.concat(num);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,125 +1,116 @@
|
||||||
#include <SPIFFS.h>
|
#include <SPIFFS.h>
|
||||||
|
#include <logger.h>
|
||||||
|
|
||||||
#ifndef CPPCHECK
|
#ifndef CPPCHECK
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "logger.h"
|
|
||||||
|
|
||||||
ConfigurationManagement::ConfigurationManagement(String FilePath)
|
ConfigurationManagement::ConfigurationManagement(String FilePath) : mFilePath(FilePath) {
|
||||||
: mFilePath(FilePath)
|
if (!SPIFFS.begin(true)) {
|
||||||
{
|
logPrintlnE("Mounting SPIFFS was not possible. Trying to format SPIFFS...");
|
||||||
if(!SPIFFS.begin(true))
|
SPIFFS.format();
|
||||||
{
|
if (!SPIFFS.begin()) {
|
||||||
logPrintlnE("Mounting SPIFFS was not possible. Trying to format SPIFFS...");
|
logPrintlnE("Formating SPIFFS was not okay!");
|
||||||
SPIFFS.format();
|
}
|
||||||
if(!SPIFFS.begin())
|
}
|
||||||
{
|
|
||||||
logPrintlnE("Formating SPIFFS was not okay!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
Configuration ConfigurationManagement::readConfiguration()
|
Configuration ConfigurationManagement::readConfiguration() {
|
||||||
{
|
File file = SPIFFS.open(mFilePath);
|
||||||
File file = SPIFFS.open(mFilePath);
|
if (!file) {
|
||||||
if(!file)
|
logPrintlnE("Failed to open file for reading...");
|
||||||
{
|
return Configuration();
|
||||||
logPrintlnE("Failed to open file for reading...");
|
}
|
||||||
return Configuration();
|
DynamicJsonDocument data(2048);
|
||||||
}
|
DeserializationError error = deserializeJson(data, file);
|
||||||
DynamicJsonDocument data(2048);
|
|
||||||
DeserializationError error = deserializeJson(data, file);
|
|
||||||
|
|
||||||
if(error)
|
if (error) {
|
||||||
{
|
logPrintlnE("Failed to read file, using default configuration.");
|
||||||
logPrintlnE("Failed to read file, using default configuration.");
|
}
|
||||||
}
|
file.close();
|
||||||
file.close();
|
|
||||||
|
|
||||||
Configuration conf;
|
Configuration conf;
|
||||||
if(data.containsKey("callsign"))
|
if (data.containsKey("callsign"))
|
||||||
conf.callsign = data["callsign"].as<String>();
|
conf.callsign = data["callsign"].as<String>();
|
||||||
conf.debug = data["debug"] | false;
|
conf.debug = data["debug"] | false;
|
||||||
conf.enhance_precision = data["enhance_precision"] | false;
|
conf.enhance_precision = data["enhance_precision"] | false;
|
||||||
if(data.containsKey("beacon") && data["beacon"].containsKey("message"))
|
if (data.containsKey("beacon") && data["beacon"].containsKey("message"))
|
||||||
conf.beacon.message = data["beacon"]["message"].as<String>();
|
conf.beacon.message = data["beacon"]["message"].as<String>();
|
||||||
conf.beacon.timeout = data["beacon"]["timeout"] | 1;
|
conf.beacon.timeout = data["beacon"]["timeout"] | 1;
|
||||||
if(data.containsKey("beacon") && data["beacon"].containsKey("symbol"))
|
if (data.containsKey("beacon") && data["beacon"].containsKey("symbol"))
|
||||||
conf.beacon.symbol = data["beacon"]["symbol"].as<String>();
|
conf.beacon.symbol = data["beacon"]["symbol"].as<String>();
|
||||||
if(data.containsKey("beacon") && data["beacon"].containsKey("overlay"))
|
if (data.containsKey("beacon") && data["beacon"].containsKey("overlay"))
|
||||||
conf.beacon.overlay = data["beacon"]["overlay"].as<String>() ;
|
conf.beacon.overlay = data["beacon"]["overlay"].as<String>();
|
||||||
if(data.containsKey("beacon") && data["beacon"].containsKey("button_tx"))
|
if (data.containsKey("beacon") && data["beacon"].containsKey("button_tx"))
|
||||||
conf.beacon.button_tx = data["beacon"]["button_tx"] | false;
|
conf.beacon.button_tx = data["beacon"]["button_tx"] | false;
|
||||||
|
|
||||||
conf.smart_beacon.active = data["smart_beacon"]["active"] | false;
|
conf.smart_beacon.active = data["smart_beacon"]["active"] | false;
|
||||||
conf.smart_beacon.turn_min = data["smart_beacon"]["turn_min"] | 25;
|
conf.smart_beacon.turn_min = data["smart_beacon"]["turn_min"] | 25;
|
||||||
conf.smart_beacon.slow_rate = data["smart_beacon"]["slow_rate"] | 300;
|
conf.smart_beacon.slow_rate = data["smart_beacon"]["slow_rate"] | 300;
|
||||||
conf.smart_beacon.slow_speed = data["smart_beacon"]["slow_speed"] | 10;
|
conf.smart_beacon.slow_speed = data["smart_beacon"]["slow_speed"] | 10;
|
||||||
conf.smart_beacon.fast_rate = data["smart_beacon"]["fast_rate"] | 60;
|
conf.smart_beacon.fast_rate = data["smart_beacon"]["fast_rate"] | 60;
|
||||||
conf.smart_beacon.fast_speed = data["smart_beacon"]["fast_speed"] | 100;
|
conf.smart_beacon.fast_speed = data["smart_beacon"]["fast_speed"] | 100;
|
||||||
conf.smart_beacon.min_tx_dist = data["smart_beacon"]["min_tx_dist"] | 100;
|
conf.smart_beacon.min_tx_dist = data["smart_beacon"]["min_tx_dist"] | 100;
|
||||||
conf.smart_beacon.min_bcn = data["smart_beacon"]["min_bcn"] | 5;
|
conf.smart_beacon.min_bcn = data["smart_beacon"]["min_bcn"] | 5;
|
||||||
|
|
||||||
conf.lora.frequencyRx = data["lora"]["frequency_rx"] | 433775000;
|
|
||||||
conf.lora.frequencyTx = data["lora"]["frequency_tx"] | 433775000;
|
|
||||||
conf.lora.power = data["lora"]["power"] | 20;
|
|
||||||
conf.lora.spreadingFactor = data["lora"]["spreading_factor"] | 12;
|
|
||||||
conf.lora.signalBandwidth = data["lora"]["signal_bandwidth"] | 125000;
|
|
||||||
conf.lora.codingRate4 = data["lora"]["coding_rate4"] | 5;
|
|
||||||
|
|
||||||
conf.ptt.active = data["ptt_output"]["active"] | false;
|
conf.lora.frequencyRx = data["lora"]["frequency_rx"] | 433775000;
|
||||||
conf.ptt.io_pin = data["ptt_output"]["io_pin"] | 4;
|
conf.lora.frequencyTx = data["lora"]["frequency_tx"] | 433775000;
|
||||||
conf.ptt.start_delay = data["ptt_output"]["start_delay"] | 0;
|
conf.lora.power = data["lora"]["power"] | 20;
|
||||||
conf.ptt.end_delay = data["ptt_output"]["end_delay"] | 0;
|
conf.lora.spreadingFactor = data["lora"]["spreading_factor"] | 12;
|
||||||
conf.ptt.reverse = data["ptt_output"]["reverse"] | false;
|
conf.lora.signalBandwidth = data["lora"]["signal_bandwidth"] | 125000;
|
||||||
|
conf.lora.codingRate4 = data["lora"]["coding_rate4"] | 5;
|
||||||
|
|
||||||
return conf;
|
conf.ptt.active = data["ptt_output"]["active"] | false;
|
||||||
|
conf.ptt.io_pin = data["ptt_output"]["io_pin"] | 4;
|
||||||
|
conf.ptt.start_delay = data["ptt_output"]["start_delay"] | 0;
|
||||||
|
conf.ptt.end_delay = data["ptt_output"]["end_delay"] | 0;
|
||||||
|
conf.ptt.reverse = data["ptt_output"]["reverse"] | false;
|
||||||
|
|
||||||
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void ConfigurationManagement::writeConfiguration(Configuration conf)
|
void ConfigurationManagement::writeConfiguration(Configuration conf) {
|
||||||
{
|
File file = SPIFFS.open(mFilePath, "w");
|
||||||
File file = SPIFFS.open(mFilePath, "w");
|
if (!file) {
|
||||||
if(!file)
|
logPrintlnE("Failed to open file for writing...");
|
||||||
{
|
return;
|
||||||
logPrintlnE("Failed to open file for writing...");
|
}
|
||||||
return;
|
DynamicJsonDocument data(2048);
|
||||||
}
|
|
||||||
DynamicJsonDocument data(2048);
|
|
||||||
|
|
||||||
data["callsign"] = conf.callsign;
|
data["callsign"] = conf.callsign;
|
||||||
data["debug"] = conf.debug;
|
data["debug"] = conf.debug;
|
||||||
data["enhance_precision"] = conf.enhance_precision;
|
data["enhance_precision"] = conf.enhance_precision;
|
||||||
data["beacon"]["message"] = conf.beacon.message;
|
data["beacon"]["message"] = conf.beacon.message;
|
||||||
data["beacon"]["timeout"] = conf.beacon.timeout;
|
data["beacon"]["timeout"] = conf.beacon.timeout;
|
||||||
data["beacon"]["symbol"] = conf.beacon.symbol;
|
data["beacon"]["symbol"] = conf.beacon.symbol;
|
||||||
data["beacon"]["overlay"] = conf.beacon.overlay;
|
data["beacon"]["overlay"] = conf.beacon.overlay;
|
||||||
data["beacon"]["button_tx"] = conf.beacon.button_tx;
|
data["beacon"]["button_tx"] = conf.beacon.button_tx;
|
||||||
data["smart_beacon"]["active"] = conf.smart_beacon.active;
|
data["smart_beacon"]["active"] = conf.smart_beacon.active;
|
||||||
data["smart_beacon"]["turn_min"] = conf.smart_beacon.turn_min;
|
data["smart_beacon"]["turn_min"] = conf.smart_beacon.turn_min;
|
||||||
data["smart_beacon"]["slow_rate"] = conf.smart_beacon.slow_rate;
|
data["smart_beacon"]["slow_rate"] = conf.smart_beacon.slow_rate;
|
||||||
data["smart_beacon"]["slow_speed"] = conf.smart_beacon.slow_speed;
|
data["smart_beacon"]["slow_speed"] = conf.smart_beacon.slow_speed;
|
||||||
data["smart_beacon"]["fast_rate"] = conf.smart_beacon.fast_rate;
|
data["smart_beacon"]["fast_rate"] = conf.smart_beacon.fast_rate;
|
||||||
data["smart_beacon"]["fast_speed"] = conf.smart_beacon.fast_speed;
|
data["smart_beacon"]["fast_speed"] = conf.smart_beacon.fast_speed;
|
||||||
data["smart_beacon"]["min_tx_dist"] = conf.smart_beacon.min_tx_dist;
|
data["smart_beacon"]["min_tx_dist"] = conf.smart_beacon.min_tx_dist;
|
||||||
data["smart_beacon"]["min_bcn"] = conf.smart_beacon.min_bcn ;
|
data["smart_beacon"]["min_bcn"] = conf.smart_beacon.min_bcn;
|
||||||
|
|
||||||
data["lora"]["frequency_rx"] = conf.lora.frequencyRx;
|
data["lora"]["frequency_rx"] = conf.lora.frequencyRx;
|
||||||
data["lora"]["frequency_tx"] = conf.lora.frequencyTx;
|
data["lora"]["frequency_tx"] = conf.lora.frequencyTx;
|
||||||
data["lora"]["power"] = conf.lora.power;
|
data["lora"]["power"] = conf.lora.power;
|
||||||
data["lora"]["spreading_factor"] = conf.lora.spreadingFactor;
|
data["lora"]["spreading_factor"] = conf.lora.spreadingFactor;
|
||||||
data["lora"]["signal_bandwidth"] = conf.lora.signalBandwidth;
|
data["lora"]["signal_bandwidth"] = conf.lora.signalBandwidth;
|
||||||
data["lora"]["coding_rate4"] = conf.lora.codingRate4;
|
data["lora"]["coding_rate4"] = conf.lora.codingRate4;
|
||||||
|
|
||||||
data["ptt_out"]["active"] = conf.ptt.active;
|
|
||||||
data["ptt_out"]["io_pin"] = conf.ptt.io_pin;
|
|
||||||
data["ptt_out"]["start_delay"] = conf.ptt.start_delay;
|
|
||||||
data["ptt_out"]["end_delay"] = conf.ptt.end_delay;
|
|
||||||
data["ptt_out"]["reverse"] = conf.ptt.reverse;
|
|
||||||
|
|
||||||
serializeJson(data, file);
|
data["ptt_out"]["active"] = conf.ptt.active;
|
||||||
file.close();
|
data["ptt_out"]["io_pin"] = conf.ptt.io_pin;
|
||||||
|
data["ptt_out"]["start_delay"] = conf.ptt.start_delay;
|
||||||
|
data["ptt_out"]["end_delay"] = conf.ptt.end_delay;
|
||||||
|
data["ptt_out"]["reverse"] = conf.ptt.reverse;
|
||||||
|
|
||||||
|
serializeJson(data, file);
|
||||||
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,82 +5,80 @@
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
class Configuration
|
class Configuration {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
class Beacon
|
class Beacon {
|
||||||
{
|
public:
|
||||||
public:
|
Beacon() : message("LoRa Tracker, Info: github.com/lora-aprs/LoRa_APRS_Tracker"), timeout(1), symbol("["), overlay("/"), button_tx(false) {
|
||||||
Beacon() : message("LoRa Tracker, Info: github.com/lora-aprs/LoRa_APRS_Tracker"), timeout(1), symbol("["), overlay("/"), button_tx(false) {}
|
}
|
||||||
|
|
||||||
String message;
|
String message;
|
||||||
int timeout;
|
int timeout;
|
||||||
String symbol;
|
String symbol;
|
||||||
String overlay;
|
String overlay;
|
||||||
bool button_tx;
|
bool button_tx;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Smart_Beacon
|
class Smart_Beacon {
|
||||||
{
|
public:
|
||||||
public:
|
Smart_Beacon() : active(false), turn_min(25), slow_rate(300), slow_speed(10), fast_rate(60), fast_speed(100), min_tx_dist(100), min_bcn(5) {
|
||||||
Smart_Beacon() : active(false), turn_min(25), slow_rate(300), slow_speed(10), fast_rate(60), fast_speed(100), min_tx_dist(100), min_bcn(5) {}
|
}
|
||||||
|
|
||||||
bool active;
|
bool active;
|
||||||
int turn_min;
|
int turn_min;
|
||||||
int slow_rate;
|
int slow_rate;
|
||||||
int slow_speed;
|
int slow_speed;
|
||||||
int fast_rate;
|
int fast_rate;
|
||||||
int fast_speed;
|
int fast_speed;
|
||||||
int min_tx_dist;
|
int min_tx_dist;
|
||||||
int min_bcn;
|
int min_bcn;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LoRa
|
class LoRa {
|
||||||
{
|
public:
|
||||||
public:
|
LoRa() : frequencyRx(433775000), frequencyTx(433775000), power(20), spreadingFactor(12), signalBandwidth(125000), codingRate4(5) {
|
||||||
LoRa() : frequencyRx(433775000), frequencyTx(433775000), power(20), spreadingFactor(12), signalBandwidth(125000), codingRate4(5) {}
|
}
|
||||||
|
|
||||||
long frequencyRx;
|
long frequencyRx;
|
||||||
long frequencyTx;
|
long frequencyTx;
|
||||||
int power;
|
int power;
|
||||||
int spreadingFactor;
|
int spreadingFactor;
|
||||||
long signalBandwidth;
|
long signalBandwidth;
|
||||||
int codingRate4;
|
int codingRate4;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PTT
|
class PTT {
|
||||||
{
|
public:
|
||||||
public:
|
PTT() : active(false), io_pin(4), start_delay(0), end_delay(0), reverse(false) {
|
||||||
PTT() : active(false), io_pin(4), start_delay(0), end_delay(0), reverse(false) {}
|
}
|
||||||
|
|
||||||
bool active;
|
bool active;
|
||||||
int io_pin;
|
int io_pin;
|
||||||
int start_delay;
|
int start_delay;
|
||||||
int end_delay;
|
int end_delay;
|
||||||
bool reverse;
|
bool reverse;
|
||||||
};
|
};
|
||||||
|
|
||||||
Configuration() : callsign("NOCALL-10"), debug(false), enhance_precision(true) {};
|
Configuration() : callsign("NOCALL-10"), debug(false), enhance_precision(true){};
|
||||||
|
|
||||||
String callsign;
|
String callsign;
|
||||||
bool debug;
|
bool debug;
|
||||||
bool enhance_precision;
|
bool enhance_precision;
|
||||||
Beacon beacon;
|
Beacon beacon;
|
||||||
Smart_Beacon smart_beacon;
|
Smart_Beacon smart_beacon;
|
||||||
LoRa lora;
|
LoRa lora;
|
||||||
PTT ptt;
|
PTT ptt;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConfigurationManagement
|
class ConfigurationManagement {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
explicit ConfigurationManagement(String FilePath);
|
explicit ConfigurationManagement(String FilePath);
|
||||||
|
|
||||||
Configuration readConfiguration();
|
Configuration readConfiguration();
|
||||||
void writeConfiguration(Configuration conf);
|
void writeConfiguration(Configuration conf);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const String mFilePath;
|
const String mFilePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
240
src/display.cpp
240
src/display.cpp
|
@ -1,155 +1,147 @@
|
||||||
|
|
||||||
#include <Wire.h>
|
|
||||||
#include <Adafruit_GFX.h>
|
#include <Adafruit_GFX.h>
|
||||||
#include <Adafruit_SSD1306.h>
|
#include <Adafruit_SSD1306.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <logger.h>
|
||||||
|
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "pins.h"
|
#include "pins.h"
|
||||||
#include "logger.h"
|
|
||||||
|
|
||||||
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RST);
|
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RST);
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void setup_display()
|
void setup_display() {
|
||||||
{
|
pinMode(OLED_RST, OUTPUT);
|
||||||
pinMode(OLED_RST, OUTPUT);
|
digitalWrite(OLED_RST, LOW);
|
||||||
digitalWrite(OLED_RST, LOW);
|
delay(20);
|
||||||
delay(20);
|
digitalWrite(OLED_RST, HIGH);
|
||||||
digitalWrite(OLED_RST, HIGH);
|
|
||||||
|
|
||||||
Wire.begin(OLED_SDA, OLED_SCL);
|
Wire.begin(OLED_SDA, OLED_SCL);
|
||||||
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false))
|
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) {
|
||||||
{
|
logPrintlnE("SSD1306 allocation failed");
|
||||||
logPrintlnE("SSD1306 allocation failed");
|
while (true) {
|
||||||
while(true)
|
}
|
||||||
{}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setTextColor(WHITE);
|
display.setTextColor(WHITE);
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
display.setCursor(0,0);
|
display.setCursor(0, 0);
|
||||||
display.print("LORA SENDER ");
|
display.print("LORA SENDER ");
|
||||||
display.ssd1306_command(SSD1306_SETCONTRAST);
|
display.ssd1306_command(SSD1306_SETCONTRAST);
|
||||||
display.ssd1306_command(1);
|
display.ssd1306_command(1);
|
||||||
display.display();
|
display.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void show_display(String header, int wait)
|
void show_display(String header, int wait) {
|
||||||
{
|
display.clearDisplay();
|
||||||
display.clearDisplay();
|
display.setTextColor(WHITE);
|
||||||
display.setTextColor(WHITE);
|
display.setTextSize(2);
|
||||||
display.setTextSize(2);
|
display.setCursor(0, 0);
|
||||||
display.setCursor(0,0);
|
display.println(header);
|
||||||
display.println(header);
|
display.ssd1306_command(SSD1306_SETCONTRAST);
|
||||||
display.ssd1306_command(SSD1306_SETCONTRAST);
|
display.ssd1306_command(1);
|
||||||
display.ssd1306_command(1);
|
display.display();
|
||||||
display.display();
|
delay(wait);
|
||||||
delay(wait);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void show_display(String header, String line1, int wait)
|
void show_display(String header, String line1, int wait) {
|
||||||
{
|
display.clearDisplay();
|
||||||
display.clearDisplay();
|
display.setTextColor(WHITE);
|
||||||
display.setTextColor(WHITE);
|
display.setTextSize(2);
|
||||||
display.setTextSize(2);
|
display.setCursor(0, 0);
|
||||||
display.setCursor(0,0);
|
display.println(header);
|
||||||
display.println(header);
|
display.setTextSize(1);
|
||||||
display.setTextSize(1);
|
display.setCursor(0, 16);
|
||||||
display.setCursor(0,16);
|
display.println(line1);
|
||||||
display.println(line1);
|
display.ssd1306_command(SSD1306_SETCONTRAST);
|
||||||
display.ssd1306_command(SSD1306_SETCONTRAST);
|
display.ssd1306_command(1);
|
||||||
display.ssd1306_command(1);
|
display.display();
|
||||||
display.display();
|
delay(wait);
|
||||||
delay(wait);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void show_display(String header, String line1, String line2, int wait)
|
void show_display(String header, String line1, String line2, int wait) {
|
||||||
{
|
display.clearDisplay();
|
||||||
display.clearDisplay();
|
display.setTextColor(WHITE);
|
||||||
display.setTextColor(WHITE);
|
display.setTextSize(2);
|
||||||
display.setTextSize(2);
|
display.setCursor(0, 0);
|
||||||
display.setCursor(0,0);
|
display.println(header);
|
||||||
display.println(header);
|
display.setTextSize(1);
|
||||||
display.setTextSize(1);
|
display.setCursor(0, 16);
|
||||||
display.setCursor(0,16);
|
display.println(line1);
|
||||||
display.println(line1);
|
display.setCursor(0, 26);
|
||||||
display.setCursor(0,26);
|
display.println(line2);
|
||||||
display.println(line2);
|
display.ssd1306_command(SSD1306_SETCONTRAST);
|
||||||
display.ssd1306_command(SSD1306_SETCONTRAST);
|
display.ssd1306_command(1);
|
||||||
display.ssd1306_command(1);
|
display.display();
|
||||||
display.display();
|
delay(wait);
|
||||||
delay(wait);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void show_display(String header, String line1, String line2, String line3, int wait)
|
void show_display(String header, String line1, String line2, String line3, int wait) {
|
||||||
{
|
display.clearDisplay();
|
||||||
display.clearDisplay();
|
display.setTextColor(WHITE);
|
||||||
display.setTextColor(WHITE);
|
display.setTextSize(2);
|
||||||
display.setTextSize(2);
|
display.setCursor(0, 0);
|
||||||
display.setCursor(0,0);
|
display.println(header);
|
||||||
display.println(header);
|
display.setTextSize(1);
|
||||||
display.setTextSize(1);
|
display.setCursor(0, 16);
|
||||||
display.setCursor(0,16);
|
display.println(line1);
|
||||||
display.println(line1);
|
display.setCursor(0, 26);
|
||||||
display.setCursor(0,26);
|
display.println(line2);
|
||||||
display.println(line2);
|
display.setCursor(0, 36);
|
||||||
display.setCursor(0,36);
|
display.println(line3);
|
||||||
display.println(line3);
|
display.ssd1306_command(SSD1306_SETCONTRAST);
|
||||||
display.ssd1306_command(SSD1306_SETCONTRAST);
|
display.ssd1306_command(1);
|
||||||
display.ssd1306_command(1);
|
display.display();
|
||||||
display.display();
|
delay(wait);
|
||||||
delay(wait);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void show_display(String header, String line1, String line2, String line3, String line4, int wait)
|
void show_display(String header, String line1, String line2, String line3, String line4, int wait) {
|
||||||
{
|
display.clearDisplay();
|
||||||
display.clearDisplay();
|
display.setTextColor(WHITE);
|
||||||
display.setTextColor(WHITE);
|
display.setTextSize(2);
|
||||||
display.setTextSize(2);
|
display.setCursor(0, 0);
|
||||||
display.setCursor(0,0);
|
display.println(header);
|
||||||
display.println(header);
|
display.setTextSize(1);
|
||||||
display.setTextSize(1);
|
display.setCursor(0, 16);
|
||||||
display.setCursor(0,16);
|
display.println(line1);
|
||||||
display.println(line1);
|
display.setCursor(0, 26);
|
||||||
display.setCursor(0,26);
|
display.println(line2);
|
||||||
display.println(line2);
|
display.setCursor(0, 36);
|
||||||
display.setCursor(0,36);
|
display.println(line3);
|
||||||
display.println(line3);
|
display.setCursor(0, 46);
|
||||||
display.setCursor(0,46);
|
display.println(line4);
|
||||||
display.println(line4);
|
display.ssd1306_command(SSD1306_SETCONTRAST);
|
||||||
display.ssd1306_command(SSD1306_SETCONTRAST);
|
display.ssd1306_command(1);
|
||||||
display.ssd1306_command(1);
|
display.display();
|
||||||
display.display();
|
delay(wait);
|
||||||
delay(wait);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void show_display(String header, String line1, String line2, String line3, String line4, String line5, int wait)
|
void show_display(String header, String line1, String line2, String line3, String line4, String line5, int wait) {
|
||||||
{
|
display.clearDisplay();
|
||||||
display.clearDisplay();
|
display.setTextColor(WHITE);
|
||||||
display.setTextColor(WHITE);
|
display.setTextSize(2);
|
||||||
display.setTextSize(2);
|
display.setCursor(0, 0);
|
||||||
display.setCursor(0,0);
|
display.println(header);
|
||||||
display.println(header);
|
display.setTextSize(1);
|
||||||
display.setTextSize(1);
|
display.setCursor(0, 16);
|
||||||
display.setCursor(0,16);
|
display.println(line1);
|
||||||
display.println(line1);
|
display.setCursor(0, 26);
|
||||||
display.setCursor(0,26);
|
display.println(line2);
|
||||||
display.println(line2);
|
display.setCursor(0, 36);
|
||||||
display.setCursor(0,36);
|
display.println(line3);
|
||||||
display.println(line3);
|
display.setCursor(0, 46);
|
||||||
display.setCursor(0,46);
|
display.println(line4);
|
||||||
display.println(line4);
|
display.setCursor(0, 56);
|
||||||
display.setCursor(0,56);
|
display.println(line5);
|
||||||
display.println(line5);
|
display.ssd1306_command(SSD1306_SETCONTRAST);
|
||||||
display.ssd1306_command(SSD1306_SETCONTRAST);
|
display.ssd1306_command(1);
|
||||||
display.ssd1306_command(1);
|
display.display();
|
||||||
display.display();
|
delay(wait);
|
||||||
delay(wait);
|
|
||||||
}
|
}
|
||||||
|
|
14
src/pins.h
14
src/pins.h
|
@ -5,20 +5,20 @@
|
||||||
#undef OLED_SCL
|
#undef OLED_SCL
|
||||||
#undef OLED_RST
|
#undef OLED_RST
|
||||||
|
|
||||||
#define OLED_SDA 21
|
#define OLED_SDA 21
|
||||||
#define OLED_SCL 22
|
#define OLED_SCL 22
|
||||||
#define OLED_RST 16
|
#define OLED_RST 16
|
||||||
|
|
||||||
#define BUTTON_PIN 38 // The middle button GPIO on the T-Beam
|
#define BUTTON_PIN 38 // The middle button GPIO on the T-Beam
|
||||||
|
|
||||||
#ifdef TTGO_T_Beam_V0_7
|
#ifdef TTGO_T_Beam_V0_7
|
||||||
#define GPS_RX 15
|
#define GPS_RX 15
|
||||||
#define GPS_TX 12
|
#define GPS_TX 12
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TTGO_T_Beam_V1_0
|
#ifdef TTGO_T_Beam_V1_0
|
||||||
#define GPS_RX 12
|
#define GPS_RX 12
|
||||||
#define GPS_TX 34
|
#define GPS_TX 34
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,90 +2,71 @@
|
||||||
#include "power_management.h"
|
#include "power_management.h"
|
||||||
|
|
||||||
// cppcheck-suppress uninitMemberVar
|
// cppcheck-suppress uninitMemberVar
|
||||||
PowerManagement::PowerManagement()
|
PowerManagement::PowerManagement() {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
bool PowerManagement::begin(TwoWire & port)
|
bool PowerManagement::begin(TwoWire &port) {
|
||||||
{
|
bool result = axp.begin(port, AXP192_SLAVE_ADDRESS);
|
||||||
bool result = axp.begin(port, AXP192_SLAVE_ADDRESS);
|
if (!result) {
|
||||||
if(!result)
|
axp.setDCDC1Voltage(3300);
|
||||||
{
|
}
|
||||||
axp.setDCDC1Voltage(3300);
|
return result;
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void PowerManagement::activateLoRa()
|
void PowerManagement::activateLoRa() {
|
||||||
{
|
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON);
|
||||||
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void PowerManagement::deactivateLoRa()
|
void PowerManagement::deactivateLoRa() {
|
||||||
{
|
axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
|
||||||
axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void PowerManagement::activateGPS()
|
void PowerManagement::activateGPS() {
|
||||||
{
|
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON);
|
||||||
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void PowerManagement::deactivateGPS()
|
void PowerManagement::deactivateGPS() {
|
||||||
{
|
axp.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
|
||||||
axp.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void PowerManagement::activateOLED()
|
void PowerManagement::activateOLED() {
|
||||||
{
|
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
|
||||||
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void PowerManagement::decativateOLED()
|
void PowerManagement::decativateOLED() {
|
||||||
{
|
axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
|
||||||
axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void PowerManagement::activateMeasurement()
|
void PowerManagement::activateMeasurement() {
|
||||||
{
|
axp.adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, true);
|
||||||
axp.adc1Enable(AXP202_BATT_CUR_ADC1 |
|
|
||||||
AXP202_BATT_VOL_ADC1,
|
|
||||||
true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void PowerManagement::deactivateMeasurement()
|
void PowerManagement::deactivateMeasurement() {
|
||||||
{
|
axp.adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, false);
|
||||||
axp.adc1Enable(AXP202_BATT_CUR_ADC1 |
|
|
||||||
AXP202_BATT_VOL_ADC1,
|
|
||||||
false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
double PowerManagement::getBatteryVoltage()
|
double PowerManagement::getBatteryVoltage() {
|
||||||
{
|
return axp.getBattVoltage() / 1000.0;
|
||||||
return axp.getBattVoltage() / 1000.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
double PowerManagement::getBatteryChargeDischargeCurrent()
|
double PowerManagement::getBatteryChargeDischargeCurrent() {
|
||||||
{
|
if (axp.isChargeing()) {
|
||||||
if(axp.isChargeing())
|
return axp.getBattChargeCurrent();
|
||||||
{
|
}
|
||||||
return axp.getBattChargeCurrent();
|
return -1.0 * axp.getBattDischargeCurrent();
|
||||||
}
|
|
||||||
return -1.0 * axp.getBattDischargeCurrent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PowerManagement::isBatteryConnect()
|
bool PowerManagement::isBatteryConnect() {
|
||||||
{
|
return axp.isBatteryConnect();
|
||||||
return axp.isBatteryConnect();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,31 +4,30 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <axp20x.h>
|
#include <axp20x.h>
|
||||||
|
|
||||||
class PowerManagement
|
class PowerManagement {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
PowerManagement();
|
PowerManagement();
|
||||||
bool begin(TwoWire & port);
|
bool begin(TwoWire &port);
|
||||||
|
|
||||||
void activateLoRa();
|
void activateLoRa();
|
||||||
void deactivateLoRa();
|
void deactivateLoRa();
|
||||||
|
|
||||||
void activateGPS();
|
void activateGPS();
|
||||||
void deactivateGPS();
|
void deactivateGPS();
|
||||||
|
|
||||||
void activateOLED();
|
void activateOLED();
|
||||||
void decativateOLED();
|
void decativateOLED();
|
||||||
|
|
||||||
void activateMeasurement();
|
void activateMeasurement();
|
||||||
void deactivateMeasurement();
|
void deactivateMeasurement();
|
||||||
|
|
||||||
double getBatteryVoltage();
|
double getBatteryVoltage();
|
||||||
double getBatteryChargeDischargeCurrent();
|
double getBatteryChargeDischargeCurrent();
|
||||||
|
|
||||||
bool isBatteryConnect();
|
bool isBatteryConnect();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AXP20X_Class axp;
|
AXP20X_Class axp;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue