|
|
|
@@ -1,26 +1,29 @@
|
|
|
|
|
#define FREQUENCY_868
|
|
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
#include <TM1637Display.h>
|
|
|
|
|
#include <Ticker.h>
|
|
|
|
|
#include <DNSServer.h>
|
|
|
|
|
#include <WiFi.h>
|
|
|
|
|
#include <AsyncTCP.h>
|
|
|
|
|
#include <ESPmDNS.h>
|
|
|
|
|
#include <ESP8266WiFi.h>
|
|
|
|
|
#include <ESPAsyncTCP.h>
|
|
|
|
|
#include <ESP8266mDNS.h>
|
|
|
|
|
#include <ArduinoOTA.h>
|
|
|
|
|
#include <ESPAsyncWebServer.h>
|
|
|
|
|
#include <LittleFS.h>
|
|
|
|
|
#include <PCF8574.h>
|
|
|
|
|
#include <Wire.h>
|
|
|
|
|
#include <Adafruit_INA219.h>
|
|
|
|
|
#include <ArduinoJson.h>
|
|
|
|
|
#include <LoRa_E220.h>
|
|
|
|
|
|
|
|
|
|
// local includes
|
|
|
|
|
#include "lora_messages.h"
|
|
|
|
|
#include "defaults.h"
|
|
|
|
|
#include "webui.h"
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "globals.h"
|
|
|
|
|
#include "dtc.h"
|
|
|
|
|
#include "common.h"
|
|
|
|
|
#include "lora_net.h"
|
|
|
|
|
#include "oled_display.h"
|
|
|
|
|
|
|
|
|
|
#ifdef WIFI_CLIENT
|
|
|
|
|
#include <WiFiMulti.h>
|
|
|
|
@@ -32,41 +35,46 @@ const uint32_t connectTimeoutMs = 5000;
|
|
|
|
|
WiFiMulti wifiMulti;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void SevenSeg_Output();
|
|
|
|
|
void FactionTicker_callback();
|
|
|
|
|
void inputGetterTicker_callback();
|
|
|
|
|
void powerMonitorTicker_callback();
|
|
|
|
|
void EEPROMCyclicPDS_callback();
|
|
|
|
|
void toggleWiFiAP(boolean shutdown = false);
|
|
|
|
|
void SystemShutdown();
|
|
|
|
|
void SetBatteryType(batteryType_t type);
|
|
|
|
|
void ProcessKeyCombos();
|
|
|
|
|
void OverrideDisplay(const uint8_t *message, uint32_t time);
|
|
|
|
|
void LoRaPublish_callback();
|
|
|
|
|
|
|
|
|
|
#ifdef WIFI_CLIENT
|
|
|
|
|
void wifiMaintainConnectionTicker_callback();
|
|
|
|
|
Ticker WiFiMaintainConnectionTicker(wifiMaintainConnectionTicker_callback, 1000, 0, MILLIS);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
uint32_t getESPChipID();
|
|
|
|
|
|
|
|
|
|
TM1637Display disp_FAC_1(CLK, DIO_FAC_1_7SEG);
|
|
|
|
|
TM1637Display disp_FAC_2(CLK, DIO_FAC_2_7SEG);
|
|
|
|
|
TM1637Display disp_FAC_3(CLK, DIO_FAC_3_7SEG);
|
|
|
|
|
|
|
|
|
|
PCF8574 i2c_io(I2C_IO_ADDRESS);
|
|
|
|
|
Adafruit_INA219 ina219;
|
|
|
|
|
LoRa_E220 e220ttl(GPIO_LORA_TX, GPIO_LORA_RX, GPIO_LORA_AUX, 3, 4); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
|
|
|
|
|
|
|
|
|
|
TM1637Display disp_FAC_1(GPIO_7SEG_CLK, GPIO_7SEG_EN_FAC1);
|
|
|
|
|
TM1637Display disp_FAC_2(GPIO_7SEG_CLK, GPIO_7SEG_EN_FAC2);
|
|
|
|
|
TM1637Display disp_FAC_3(GPIO_7SEG_CLK, GPIO_7SEG_EN_FAC3);
|
|
|
|
|
|
|
|
|
|
#ifdef CAPTIVE
|
|
|
|
|
DNSServer dnsServer;
|
|
|
|
|
#endif
|
|
|
|
|
AsyncWebServer server(80);
|
|
|
|
|
|
|
|
|
|
Ticker FactionTicker(FactionTicker_callback, 1000, 0, MILLIS);
|
|
|
|
|
Ticker InputGetterTicker(inputGetterTicker_callback, 250, 0, MILLIS);
|
|
|
|
|
Ticker PowerMonitorTicker(powerMonitorTicker_callback, 5000, 0, MILLIS);
|
|
|
|
|
Ticker EEPROMCyclicPDSTicker(EEPROMCyclicPDS_callback, 60000, 0, MILLIS);
|
|
|
|
|
Ticker LoRaPublishTicker(LoRaPublish_callback, 60000, 0, MILLIS);
|
|
|
|
|
void printParameters(struct Configuration configuration);
|
|
|
|
|
void printModuleInformation(struct ModuleInformation moduleInformation);
|
|
|
|
|
void displayInfo();
|
|
|
|
|
void SevenSeg_Output();
|
|
|
|
|
void toggleWiFiAP(boolean shutdown = false);
|
|
|
|
|
void SystemShutdown();
|
|
|
|
|
void SetBatteryType(batteryType_t type);
|
|
|
|
|
void ProcessKeyCombos(bool *btnState);
|
|
|
|
|
void OverrideDisplay(const uint8_t *message, uint32_t time);
|
|
|
|
|
|
|
|
|
|
void tmrCallback_StatusSender();
|
|
|
|
|
Ticker tmrStatusSender(tmrCallback_StatusSender, 30000, 0, MILLIS);
|
|
|
|
|
void tmrCallback_PowerMonitor();
|
|
|
|
|
Ticker tmrPowerMonitor(tmrCallback_PowerMonitor, 10000, 0, MILLIS);
|
|
|
|
|
void tmrCallback_FactionTicker();
|
|
|
|
|
Ticker tmrFactionTicker(tmrCallback_FactionTicker, 1000, 0, MILLIS);
|
|
|
|
|
void tmrCallback_InputGetter();
|
|
|
|
|
Ticker tmrInputGetter(tmrCallback_InputGetter, 250, 0, MILLIS);
|
|
|
|
|
void tmrCallback_EEPROMCyclicPDS();
|
|
|
|
|
Ticker tmrEEPROMCyclicPDS(tmrCallback_EEPROMCyclicPDS, 60000, 0, MILLIS);
|
|
|
|
|
|
|
|
|
|
#ifdef WIFI_CLIENT
|
|
|
|
|
void tmrCallback_WiFiMaintainConnection();
|
|
|
|
|
Ticker tmrWiFiMaintainConnection(tmrCallback_WiFiMaintainConnection, 1000, 0, MILLIS);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
uint32_t getESPChipID();
|
|
|
|
|
|
|
|
|
|
uint8_t Faction_1_dot = 0;
|
|
|
|
|
uint8_t Faction_2_dot = 0;
|
|
|
|
@@ -84,58 +92,117 @@ const uint8_t sevenSeg_ota[] = {0x3F, 0x78, 0x77, 0x00};
|
|
|
|
|
const uint8_t sevenSeg_flsh[] = {0x71, 0x38, 0x6D, 0x76};
|
|
|
|
|
const uint8_t sevenSeg_file[] = {0x71, 0x30, 0x38, 0x79};
|
|
|
|
|
|
|
|
|
|
void setMPins_Helper(int pin, int status)
|
|
|
|
|
{
|
|
|
|
|
i2c_io.write(pin, status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
|
{
|
|
|
|
|
setCpuFrequencyMhz(80);
|
|
|
|
|
WiFi.setAutoReconnect(false);
|
|
|
|
|
WiFi.persistent(false);
|
|
|
|
|
WiFi.disconnect();
|
|
|
|
|
system_update_cpu_freq(SYS_CPU_80MHZ);
|
|
|
|
|
|
|
|
|
|
Serial.begin(115200);
|
|
|
|
|
Serial.print("\n\n\n");
|
|
|
|
|
|
|
|
|
|
strcpy(globals.DeviceName, DEVICE_NAME);
|
|
|
|
|
snprintf(globals.DeviceName_ID, 42, "%s_%08X", globals.DeviceName, getESPChipID());
|
|
|
|
|
|
|
|
|
|
if (LoRa_Init())
|
|
|
|
|
LoRaPublishTicker.start();
|
|
|
|
|
OLED_Init();
|
|
|
|
|
|
|
|
|
|
pinMode(DIO_FAC_1_TRG, INPUT_PULLUP);
|
|
|
|
|
pinMode(DIO_FAC_2_TRG, INPUT_PULLUP);
|
|
|
|
|
pinMode(DIO_FAC_3_TRG, INPUT_PULLUP);
|
|
|
|
|
Serial.begin(115200);
|
|
|
|
|
Serial.print("\n\n\n");
|
|
|
|
|
|
|
|
|
|
#ifdef SERIAL_DEBUG
|
|
|
|
|
Serial.setDebugOutput(true);
|
|
|
|
|
Serial.setDebugOutput(true);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (ina219.begin())
|
|
|
|
|
PowerMonitorTicker.start();
|
|
|
|
|
else
|
|
|
|
|
Serial.println("Failed to find INA219 chip");
|
|
|
|
|
WiFi.persistent(false);
|
|
|
|
|
WiFi.disconnect();
|
|
|
|
|
|
|
|
|
|
LittleFS.begin();
|
|
|
|
|
strcpy(globals.DeviceName, DEVICE_NAME);
|
|
|
|
|
snprintf(globals.DeviceName_ID, 42, "%s_%08X", globals.DeviceName, getESPChipID());
|
|
|
|
|
|
|
|
|
|
if (i2c_io.begin())
|
|
|
|
|
{
|
|
|
|
|
Serial.printf("Initialized PCF8574-GPIO at Address 0x%02X\n", I2C_IO_ADDRESS);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Serial.print("PCF8574-GPIO not Initialized\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ina219.begin())
|
|
|
|
|
{
|
|
|
|
|
Serial.printf("Initialized INA219-Powermonitor at Address 0x%02X\n", I2C_POWER_ADDRESS);
|
|
|
|
|
tmrPowerMonitor.start();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Serial.print("INA219 not Initialized\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e220ttl.setMPins = &setMPins_Helper;
|
|
|
|
|
e220ttl.begin();
|
|
|
|
|
|
|
|
|
|
ResponseStructContainer c;
|
|
|
|
|
c = e220ttl.getConfiguration();
|
|
|
|
|
// It's important get configuration pointer before all other operation
|
|
|
|
|
Configuration configuration = *(Configuration *)c.data;
|
|
|
|
|
Serial.println(c.status.getResponseDescription());
|
|
|
|
|
Serial.println(c.status.code);
|
|
|
|
|
|
|
|
|
|
ResponseStructContainer cMi;
|
|
|
|
|
cMi = e220ttl.getModuleInformation();
|
|
|
|
|
// It's important get information pointer before all other operation
|
|
|
|
|
ModuleInformation mi = *(ModuleInformation *)cMi.data;
|
|
|
|
|
|
|
|
|
|
Serial.println(cMi.status.getResponseDescription());
|
|
|
|
|
Serial.println(cMi.status.code);
|
|
|
|
|
|
|
|
|
|
// ----------------------- DEFAULT TRANSPARENT WITH RSSI -----------------------
|
|
|
|
|
configuration.ADDL = 0x02;
|
|
|
|
|
configuration.ADDH = 0x00;
|
|
|
|
|
|
|
|
|
|
configuration.CHAN = 23;
|
|
|
|
|
|
|
|
|
|
configuration.SPED.uartBaudRate = UART_BPS_9600;
|
|
|
|
|
configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
|
|
|
|
|
configuration.SPED.uartParity = MODE_00_8N1;
|
|
|
|
|
|
|
|
|
|
configuration.OPTION.subPacketSetting = SPS_200_00;
|
|
|
|
|
configuration.OPTION.RSSIAmbientNoise = RSSI_AMBIENT_NOISE_ENABLED;
|
|
|
|
|
configuration.OPTION.transmissionPower = POWER_22;
|
|
|
|
|
|
|
|
|
|
configuration.TRANSMISSION_MODE.enableRSSI = RSSI_ENABLED;
|
|
|
|
|
configuration.TRANSMISSION_MODE.fixedTransmission = FT_FIXED_TRANSMISSION;
|
|
|
|
|
configuration.TRANSMISSION_MODE.enableLBT = LBT_ENABLED;
|
|
|
|
|
configuration.TRANSMISSION_MODE.WORPeriod = WOR_2000_011;
|
|
|
|
|
|
|
|
|
|
// Set configuration changed and set to not hold the configuration
|
|
|
|
|
ResponseStatus rs = e220ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_LOSE);
|
|
|
|
|
Serial.println(rs.getResponseDescription());
|
|
|
|
|
Serial.println(rs.code);
|
|
|
|
|
c.close();
|
|
|
|
|
|
|
|
|
|
printParameters(configuration);
|
|
|
|
|
tmrStatusSender.start();
|
|
|
|
|
|
|
|
|
|
LittleFS.begin();
|
|
|
|
|
|
|
|
|
|
#ifdef WIFI_CLIENT
|
|
|
|
|
WiFi.mode(WIFI_STA);
|
|
|
|
|
WiFi.setHostname(globals.DeviceName_ID);
|
|
|
|
|
wifiMulti.addAP(QUOTE(WIFI_SSID), QUOTE(WIFI_PASSWORD));
|
|
|
|
|
WiFiMaintainConnectionTicker.start();
|
|
|
|
|
WiFi.mode(WIFI_STA);
|
|
|
|
|
WiFi.setHostname(globals.DeviceName_ID);
|
|
|
|
|
wifiMulti.addAP(QUOTE(WIFI_SSID), QUOTE(WIFI_PASSWORD));
|
|
|
|
|
tmrWiFiMaintainConnection.start();
|
|
|
|
|
#else
|
|
|
|
|
WiFi.mode(WIFI_AP);
|
|
|
|
|
WiFi.begin(QUOTE(DEVICE_NAME), QUOTE(WIFI_AP_PASSWORD));
|
|
|
|
|
WiFi.setSleep(true);
|
|
|
|
|
WiFi.mode(WIFI_OFF);
|
|
|
|
|
WiFi.mode(WIFI_AP);
|
|
|
|
|
WiFi.begin(QUOTE(DEVICE_NAME), QUOTE(WIFI_AP_PASSWORD));
|
|
|
|
|
#if defined(ESP32)
|
|
|
|
|
WiFi.sleep(true);
|
|
|
|
|
#endif
|
|
|
|
|
WiFi.mode(WIFI_OFF);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
InitEEPROM();
|
|
|
|
|
InitEEPROM();
|
|
|
|
|
|
|
|
|
|
ArduinoOTA.setPort(8266);
|
|
|
|
|
ArduinoOTA.setHostname(globals.DeviceName_ID);
|
|
|
|
|
ArduinoOTA.setPassword(QUOTE(ADMIN_PASSWORD));
|
|
|
|
|
ArduinoOTA.setPort(8266);
|
|
|
|
|
ArduinoOTA.setHostname(globals.DeviceName_ID);
|
|
|
|
|
ArduinoOTA.setPassword(QUOTE(ADMIN_PASSWORD));
|
|
|
|
|
|
|
|
|
|
ArduinoOTA.onStart([]()
|
|
|
|
|
{
|
|
|
|
|
ArduinoOTA.onStart([]()
|
|
|
|
|
{
|
|
|
|
|
disp_FAC_1.setBrightness(7);
|
|
|
|
|
disp_FAC_2.setBrightness(7);
|
|
|
|
|
disp_FAC_3.setBrightness(7);
|
|
|
|
@@ -152,18 +219,18 @@ void setup()
|
|
|
|
|
LittleFS.end();
|
|
|
|
|
} });
|
|
|
|
|
|
|
|
|
|
ArduinoOTA.onEnd([]()
|
|
|
|
|
{
|
|
|
|
|
ArduinoOTA.onEnd([]()
|
|
|
|
|
{
|
|
|
|
|
const uint8_t seg_done[] = {0x5E, 0x3F, 0x54, 0x79};
|
|
|
|
|
disp_FAC_1.setSegments(seg_done);
|
|
|
|
|
disp_FAC_2.clear();
|
|
|
|
|
disp_FAC_3.clear(); });
|
|
|
|
|
|
|
|
|
|
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total)
|
|
|
|
|
{ disp_FAC_3.showNumberDecEx((progress / (total / 100))); });
|
|
|
|
|
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total)
|
|
|
|
|
{ disp_FAC_3.showNumberDecEx((progress / (total / 100))); });
|
|
|
|
|
|
|
|
|
|
ArduinoOTA.onError([](ota_error_t error)
|
|
|
|
|
{
|
|
|
|
|
ArduinoOTA.onError([](ota_error_t error)
|
|
|
|
|
{
|
|
|
|
|
Serial.printf("Error[%u]: ", error);
|
|
|
|
|
if (error == OTA_AUTH_ERROR)
|
|
|
|
|
Serial.println("Auth Failed");
|
|
|
|
@@ -175,252 +242,392 @@ void setup()
|
|
|
|
|
Serial.println("Receive Failed");
|
|
|
|
|
else if (error == OTA_END_ERROR)
|
|
|
|
|
Serial.println("End Failed"); });
|
|
|
|
|
ArduinoOTA.begin();
|
|
|
|
|
ArduinoOTA.begin();
|
|
|
|
|
|
|
|
|
|
#ifdef CAPTIVE
|
|
|
|
|
dnsServer.start(53, "*", WiFi.softAPIP());
|
|
|
|
|
dnsServer.start(53, "*", WiFi.softAPIP());
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
initWebUI();
|
|
|
|
|
initWebUI();
|
|
|
|
|
|
|
|
|
|
EEPROMCyclicPDSTicker.start();
|
|
|
|
|
FactionTicker.start();
|
|
|
|
|
InputGetterTicker.start();
|
|
|
|
|
Serial.println("Setup Done");
|
|
|
|
|
tmrEEPROMCyclicPDS.start();
|
|
|
|
|
tmrFactionTicker.start();
|
|
|
|
|
tmrInputGetter.start();
|
|
|
|
|
Serial.println("Setup Done");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
|
{
|
|
|
|
|
EEPROMCyclicPDSTicker.update();
|
|
|
|
|
FactionTicker.update();
|
|
|
|
|
InputGetterTicker.update();
|
|
|
|
|
PowerMonitorTicker.update();
|
|
|
|
|
LoRaPublishTicker.update();
|
|
|
|
|
ArduinoOTA.handle();
|
|
|
|
|
SevenSeg_Output();
|
|
|
|
|
EEPROM_Process();
|
|
|
|
|
OLED_Process();
|
|
|
|
|
if (e220ttl.available() > 1)
|
|
|
|
|
{
|
|
|
|
|
ResponseContainer rc = e220ttl.receiveMessageRSSI();
|
|
|
|
|
// Is something goes wrong print error
|
|
|
|
|
if (rc.status.code != 1)
|
|
|
|
|
{
|
|
|
|
|
Serial.println(rc.status.getResponseDescription());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Print the data received
|
|
|
|
|
Serial.println(rc.status.getResponseDescription());
|
|
|
|
|
Serial.println(rc.data);
|
|
|
|
|
Serial.print("RSSI: ");
|
|
|
|
|
Serial.println(rc.rssi, DEC);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tmrEEPROMCyclicPDS.update();
|
|
|
|
|
tmrFactionTicker.update();
|
|
|
|
|
tmrInputGetter.update();
|
|
|
|
|
ArduinoOTA.handle();
|
|
|
|
|
SevenSeg_Output();
|
|
|
|
|
EEPROM_Process();
|
|
|
|
|
|
|
|
|
|
tmrStatusSender.update();
|
|
|
|
|
tmrPowerMonitor.update();
|
|
|
|
|
|
|
|
|
|
#ifdef CAPTIVE
|
|
|
|
|
dnsServer.processNextRequest();
|
|
|
|
|
dnsServer.processNextRequest();
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef WIFI_CLIENT
|
|
|
|
|
WiFiMaintainConnectionTicker.update();
|
|
|
|
|
tmrWiFiMaintainConnection.update();
|
|
|
|
|
#endif
|
|
|
|
|
if (globals.systemStatus == sysStat_Shutdown)
|
|
|
|
|
SystemShutdown();
|
|
|
|
|
yield();
|
|
|
|
|
if (globals.systemStatus == sysStat_Shutdown)
|
|
|
|
|
SystemShutdown();
|
|
|
|
|
yield();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String macToString(const unsigned char *mac)
|
|
|
|
|
{
|
|
|
|
|
char buf[20];
|
|
|
|
|
snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x",
|
|
|
|
|
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
|
|
|
|
return String(buf);
|
|
|
|
|
char buf[20];
|
|
|
|
|
snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x",
|
|
|
|
|
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
|
|
|
|
return String(buf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SevenSeg_Output()
|
|
|
|
|
{
|
|
|
|
|
if (DisplayOverrideFlag > millis())
|
|
|
|
|
{
|
|
|
|
|
disp_FAC_1.setBrightness(7);
|
|
|
|
|
disp_FAC_2.setBrightness(7);
|
|
|
|
|
disp_FAC_3.setBrightness(7);
|
|
|
|
|
disp_FAC_1.setSegments(DisplayOverrideValue);
|
|
|
|
|
disp_FAC_2.clear();
|
|
|
|
|
disp_FAC_3.clear();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (globals.battery_level < BAT_LOW_PERCENT && millis() % 10000 > 7000)
|
|
|
|
|
{
|
|
|
|
|
disp_FAC_1.setBrightness(0);
|
|
|
|
|
disp_FAC_2.setBrightness(0);
|
|
|
|
|
disp_FAC_3.setBrightness(0);
|
|
|
|
|
if (DisplayOverrideFlag > millis())
|
|
|
|
|
{
|
|
|
|
|
disp_FAC_1.setBrightness(7);
|
|
|
|
|
disp_FAC_2.setBrightness(7);
|
|
|
|
|
disp_FAC_3.setBrightness(7);
|
|
|
|
|
disp_FAC_1.setSegments(DisplayOverrideValue);
|
|
|
|
|
disp_FAC_2.clear();
|
|
|
|
|
disp_FAC_3.clear();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (globals.battery_level < BAT_LOW_PERCENT && millis() % 10000 > 7000)
|
|
|
|
|
{
|
|
|
|
|
disp_FAC_1.setBrightness(0);
|
|
|
|
|
disp_FAC_2.setBrightness(0);
|
|
|
|
|
disp_FAC_3.setBrightness(0);
|
|
|
|
|
|
|
|
|
|
disp_FAC_1.setSegments(sevenSeg_bat);
|
|
|
|
|
disp_FAC_2.setSegments(sevenSeg_low);
|
|
|
|
|
if (millis() % 3000 < 1500)
|
|
|
|
|
disp_FAC_3.showNumberDec(globals.battery_level);
|
|
|
|
|
else
|
|
|
|
|
disp_FAC_3.showNumberDecEx(globals.loadvoltage * 100, 0x40);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
disp_FAC_1.setBrightness(PersistenceData.activeFaction == FACTION_1 ? 7 : 0);
|
|
|
|
|
disp_FAC_2.setBrightness(PersistenceData.activeFaction == FACTION_2 ? 7 : 0);
|
|
|
|
|
disp_FAC_3.setBrightness(PersistenceData.activeFaction == FACTION_3 ? 7 : 0);
|
|
|
|
|
disp_FAC_1.setSegments(sevenSeg_bat);
|
|
|
|
|
disp_FAC_2.setSegments(sevenSeg_low);
|
|
|
|
|
if (millis() % 3000 < 1500)
|
|
|
|
|
disp_FAC_3.showNumberDec(globals.battery_level);
|
|
|
|
|
else
|
|
|
|
|
disp_FAC_3.showNumberDecEx(globals.loadvoltage * 100, 0x40);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
disp_FAC_1.setBrightness(PersistenceData.activeFaction == FACTION_1 ? 7 : 0);
|
|
|
|
|
disp_FAC_2.setBrightness(PersistenceData.activeFaction == FACTION_2 ? 7 : 0);
|
|
|
|
|
disp_FAC_3.setBrightness(PersistenceData.activeFaction == FACTION_3 ? 7 : 0);
|
|
|
|
|
|
|
|
|
|
disp_FAC_1.showNumberDecEx(PersistenceData.faction_1_timer / 60, Faction_1_dot, true, 4, 0);
|
|
|
|
|
disp_FAC_2.showNumberDecEx(PersistenceData.faction_2_timer / 60, Faction_2_dot, true, 4, 0);
|
|
|
|
|
disp_FAC_3.showNumberDecEx(PersistenceData.faction_3_timer / 60, Faction_3_dot, true, 4, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
disp_FAC_1.showNumberDecEx(PersistenceData.faction_1_timer / 60, Faction_1_dot, true, 4, 0);
|
|
|
|
|
disp_FAC_2.showNumberDecEx(PersistenceData.faction_2_timer / 60, Faction_2_dot, true, 4, 0);
|
|
|
|
|
disp_FAC_3.showNumberDecEx(PersistenceData.faction_3_timer / 60, Faction_3_dot, true, 4, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FactionTicker_callback()
|
|
|
|
|
void tmrCallback_FactionTicker()
|
|
|
|
|
{
|
|
|
|
|
switch (PersistenceData.activeFaction)
|
|
|
|
|
{
|
|
|
|
|
case FACTION_1:
|
|
|
|
|
PersistenceData.faction_1_timer++;
|
|
|
|
|
Faction_1_dot = Faction_1_dot == 0x80 || Faction_1_dot == 0x00 ? 0x10 : Faction_1_dot << 1;
|
|
|
|
|
Faction_2_dot = 0;
|
|
|
|
|
Faction_3_dot = 0;
|
|
|
|
|
break;
|
|
|
|
|
switch (PersistenceData.activeFaction)
|
|
|
|
|
{
|
|
|
|
|
case FACTION_1:
|
|
|
|
|
PersistenceData.faction_1_timer++;
|
|
|
|
|
Faction_1_dot = Faction_1_dot == 0x80 || Faction_1_dot == 0x00 ? 0x10 : Faction_1_dot << 1;
|
|
|
|
|
Faction_2_dot = 0;
|
|
|
|
|
Faction_3_dot = 0;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case FACTION_2:
|
|
|
|
|
PersistenceData.faction_2_timer++;
|
|
|
|
|
Faction_2_dot = Faction_2_dot == 0x80 || Faction_2_dot == 0x00 ? 0x10 : Faction_2_dot << 1;
|
|
|
|
|
Faction_1_dot = 0;
|
|
|
|
|
Faction_3_dot = 0;
|
|
|
|
|
break;
|
|
|
|
|
case FACTION_2:
|
|
|
|
|
PersistenceData.faction_2_timer++;
|
|
|
|
|
Faction_2_dot = Faction_2_dot == 0x80 || Faction_2_dot == 0x00 ? 0x10 : Faction_2_dot << 1;
|
|
|
|
|
Faction_1_dot = 0;
|
|
|
|
|
Faction_3_dot = 0;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case FACTION_3:
|
|
|
|
|
PersistenceData.faction_3_timer++;
|
|
|
|
|
Faction_3_dot = Faction_3_dot == 0x80 || Faction_3_dot == 0x00 ? 0x10 : Faction_3_dot << 1;
|
|
|
|
|
Faction_1_dot = 0;
|
|
|
|
|
Faction_2_dot = 0;
|
|
|
|
|
break;
|
|
|
|
|
case FACTION_3:
|
|
|
|
|
PersistenceData.faction_3_timer++;
|
|
|
|
|
Faction_3_dot = Faction_3_dot == 0x80 || Faction_3_dot == 0x00 ? 0x10 : Faction_3_dot << 1;
|
|
|
|
|
Faction_1_dot = 0;
|
|
|
|
|
Faction_2_dot = 0;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void inputGetterTicker_callback()
|
|
|
|
|
void tmrCallback_InputGetter()
|
|
|
|
|
{
|
|
|
|
|
ProcessKeyCombos();
|
|
|
|
|
static bool btnState[3];
|
|
|
|
|
static bool btnlastState[3];
|
|
|
|
|
|
|
|
|
|
uint8_t keysPressed = 0;
|
|
|
|
|
btnState[0] = i2c_io.readButton(I2C_IO_BTN_FAC1);
|
|
|
|
|
btnState[1] = i2c_io.readButton(I2C_IO_BTN_FAC2);
|
|
|
|
|
btnState[2] = i2c_io.readButton(I2C_IO_BTN_FAC3);
|
|
|
|
|
|
|
|
|
|
keysPressed = +digitalRead(DIO_FAC_1_TRG) == FAC_1_TRG_PRESSED ? 1 : 0;
|
|
|
|
|
keysPressed = +digitalRead(DIO_FAC_2_TRG) == FAC_2_TRG_PRESSED ? 1 : 0;
|
|
|
|
|
keysPressed = +digitalRead(DIO_FAC_3_TRG) == FAC_3_TRG_PRESSED ? 1 : 0;
|
|
|
|
|
ProcessKeyCombos(btnState);
|
|
|
|
|
|
|
|
|
|
if (keysPressed > 1)
|
|
|
|
|
{
|
|
|
|
|
Serial.println("ERROR: More than one Flag active - setting no Faction active");
|
|
|
|
|
PersistenceData.activeFaction = NONE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < sizeof(btnState); i++)
|
|
|
|
|
{
|
|
|
|
|
if (btnlastState[i] != btnState[i])
|
|
|
|
|
{
|
|
|
|
|
btnlastState[i] = btnState[i];
|
|
|
|
|
Serial.printf("Button %d changed to %d\n", i, btnState[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (digitalRead(DIO_FAC_1_TRG) == FAC_1_TRG_PRESSED)
|
|
|
|
|
PersistenceData.activeFaction = FACTION_1;
|
|
|
|
|
uint8_t keysPressed = 0;
|
|
|
|
|
|
|
|
|
|
if (digitalRead(DIO_FAC_2_TRG) == FAC_2_TRG_PRESSED)
|
|
|
|
|
PersistenceData.activeFaction = FACTION_2;
|
|
|
|
|
keysPressed = +btnState[0] == FAC_1_TRG_PRESSED ? 1 : 0;
|
|
|
|
|
keysPressed = +btnState[1] == FAC_2_TRG_PRESSED ? 1 : 0;
|
|
|
|
|
keysPressed = +btnState[2] == FAC_3_TRG_PRESSED ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
if (digitalRead(DIO_FAC_3_TRG) == FAC_3_TRG_PRESSED)
|
|
|
|
|
PersistenceData.activeFaction = FACTION_3;
|
|
|
|
|
if (keysPressed > 1)
|
|
|
|
|
{
|
|
|
|
|
Serial.println("ERROR: More than one Flag active - setting no Faction active");
|
|
|
|
|
PersistenceData.activeFaction = NONE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (btnState[0] == FAC_1_TRG_PRESSED)
|
|
|
|
|
PersistenceData.activeFaction = FACTION_1;
|
|
|
|
|
|
|
|
|
|
if (btnState[1] == FAC_2_TRG_PRESSED)
|
|
|
|
|
PersistenceData.activeFaction = FACTION_2;
|
|
|
|
|
|
|
|
|
|
if (btnState[2] == FAC_3_TRG_PRESSED)
|
|
|
|
|
PersistenceData.activeFaction = FACTION_3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void powerMonitorTicker_callback()
|
|
|
|
|
void printParameters(struct Configuration configuration)
|
|
|
|
|
{
|
|
|
|
|
// loadvoltage and percentage is global, because of battery Monitoring
|
|
|
|
|
Serial.println("----------------------------------------");
|
|
|
|
|
|
|
|
|
|
const int bat_min_2s = 680;
|
|
|
|
|
const int bat_max_2s = 840;
|
|
|
|
|
const int bat_min_3s = 1020;
|
|
|
|
|
const int bat_max_3s = 1260;
|
|
|
|
|
Serial.print(F("HEAD : "));
|
|
|
|
|
Serial.print(configuration.COMMAND, HEX);
|
|
|
|
|
Serial.print(" ");
|
|
|
|
|
Serial.print(configuration.STARTING_ADDRESS, HEX);
|
|
|
|
|
Serial.print(" ");
|
|
|
|
|
Serial.println(configuration.LENGHT, HEX);
|
|
|
|
|
Serial.println(F(" "));
|
|
|
|
|
Serial.print(F("AddH : "));
|
|
|
|
|
Serial.println(configuration.ADDH, HEX);
|
|
|
|
|
Serial.print(F("AddL : "));
|
|
|
|
|
Serial.println(configuration.ADDL, HEX);
|
|
|
|
|
Serial.println(F(" "));
|
|
|
|
|
Serial.print(F("Chan : "));
|
|
|
|
|
Serial.print(configuration.CHAN, DEC);
|
|
|
|
|
Serial.print(" -> ");
|
|
|
|
|
Serial.println(configuration.getChannelDescription());
|
|
|
|
|
Serial.println(F(" "));
|
|
|
|
|
Serial.print(F("SpeedParityBit : "));
|
|
|
|
|
Serial.print(configuration.SPED.uartParity, BIN);
|
|
|
|
|
Serial.print(" -> ");
|
|
|
|
|
Serial.println(configuration.SPED.getUARTParityDescription());
|
|
|
|
|
Serial.print(F("SpeedUARTDatte : "));
|
|
|
|
|
Serial.print(configuration.SPED.uartBaudRate, BIN);
|
|
|
|
|
Serial.print(" -> ");
|
|
|
|
|
Serial.println(configuration.SPED.getUARTBaudRateDescription());
|
|
|
|
|
Serial.print(F("SpeedAirDataRate : "));
|
|
|
|
|
Serial.print(configuration.SPED.airDataRate, BIN);
|
|
|
|
|
Serial.print(" -> ");
|
|
|
|
|
Serial.println(configuration.SPED.getAirDataRateDescription());
|
|
|
|
|
Serial.println(F(" "));
|
|
|
|
|
Serial.print(F("OptionSubPacketSett: "));
|
|
|
|
|
Serial.print(configuration.OPTION.subPacketSetting, BIN);
|
|
|
|
|
Serial.print(" -> ");
|
|
|
|
|
Serial.println(configuration.OPTION.getSubPacketSetting());
|
|
|
|
|
Serial.print(F("OptionTranPower : "));
|
|
|
|
|
Serial.print(configuration.OPTION.transmissionPower, BIN);
|
|
|
|
|
Serial.print(" -> ");
|
|
|
|
|
Serial.println(configuration.OPTION.getTransmissionPowerDescription());
|
|
|
|
|
Serial.print(F("OptionRSSIAmbientNo: "));
|
|
|
|
|
Serial.print(configuration.OPTION.RSSIAmbientNoise, BIN);
|
|
|
|
|
Serial.print(" -> ");
|
|
|
|
|
Serial.println(configuration.OPTION.getRSSIAmbientNoiseEnable());
|
|
|
|
|
Serial.println(F(" "));
|
|
|
|
|
Serial.print(F("TransModeWORPeriod : "));
|
|
|
|
|
Serial.print(configuration.TRANSMISSION_MODE.WORPeriod, BIN);
|
|
|
|
|
Serial.print(" -> ");
|
|
|
|
|
Serial.println(configuration.TRANSMISSION_MODE.getWORPeriodByParamsDescription());
|
|
|
|
|
Serial.print(F("TransModeEnableLBT : "));
|
|
|
|
|
Serial.print(configuration.TRANSMISSION_MODE.enableLBT, BIN);
|
|
|
|
|
Serial.print(" -> ");
|
|
|
|
|
Serial.println(configuration.TRANSMISSION_MODE.getLBTEnableByteDescription());
|
|
|
|
|
Serial.print(F("TransModeEnableRSSI: "));
|
|
|
|
|
Serial.print(configuration.TRANSMISSION_MODE.enableRSSI, BIN);
|
|
|
|
|
Serial.print(" -> ");
|
|
|
|
|
Serial.println(configuration.TRANSMISSION_MODE.getRSSIEnableByteDescription());
|
|
|
|
|
Serial.print(F("TransModeFixedTrans: "));
|
|
|
|
|
Serial.print(configuration.TRANSMISSION_MODE.fixedTransmission, BIN);
|
|
|
|
|
Serial.print(" -> ");
|
|
|
|
|
Serial.println(configuration.TRANSMISSION_MODE.getFixedTransmissionDescription());
|
|
|
|
|
|
|
|
|
|
float shuntvoltage = 0;
|
|
|
|
|
float current_mA = 0;
|
|
|
|
|
float busvoltage = 0;
|
|
|
|
|
float power_mW = 0;
|
|
|
|
|
int battery_level = 0;
|
|
|
|
|
|
|
|
|
|
shuntvoltage = ina219.getShuntVoltage_mV();
|
|
|
|
|
busvoltage = ina219.getBusVoltage_V();
|
|
|
|
|
current_mA = ina219.getCurrent_mA();
|
|
|
|
|
power_mW = ina219.getPower_mW();
|
|
|
|
|
globals.loadvoltage = busvoltage + (shuntvoltage / 1000);
|
|
|
|
|
switch (ConfigData.batteryType)
|
|
|
|
|
{
|
|
|
|
|
case BATTERY_LIPO_2S:
|
|
|
|
|
battery_level = map(globals.loadvoltage * 100, bat_min_2s, bat_max_2s, 0, 100);
|
|
|
|
|
globals.battery_level = battery_level < 0 ? 0 : battery_level;
|
|
|
|
|
break;
|
|
|
|
|
case BATTERY_LIPO_3S:
|
|
|
|
|
battery_level = map(globals.loadvoltage * 100, bat_min_3s, bat_max_3s, 0, 100);
|
|
|
|
|
globals.battery_level = battery_level < 0 ? 0 : battery_level;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
globals.battery_level = -1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Serial.printf("Battery Level: %d %%\n", globals.battery_level);
|
|
|
|
|
// Serial.printf("Bus Voltage: %f V\n", busvoltage);
|
|
|
|
|
// Serial.printf("Shunt Voltage: %f mV\n", shuntvoltage);
|
|
|
|
|
// Serial.printf("Load Voltage: %f V\n", globals.loadvoltage);
|
|
|
|
|
// Serial.printf("Current: %f mA\n", current_mA);
|
|
|
|
|
// Serial.printf("Power: %f mW\n", power_mW);
|
|
|
|
|
Serial.println("----------------------------------------");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EEPROMCyclicPDS_callback()
|
|
|
|
|
void tmrCallback_StatusSender()
|
|
|
|
|
{
|
|
|
|
|
StorePersistence_EEPROM();
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
MessageType_t type = "STATUS";
|
|
|
|
|
MessageStatus_t status;
|
|
|
|
|
} __attribute__((packed)) sendStatus;
|
|
|
|
|
|
|
|
|
|
sendStatus.status.nodeid = 0x0002;
|
|
|
|
|
sendStatus.status.millis = millis();
|
|
|
|
|
sendStatus.status.faction_active = 1;
|
|
|
|
|
sendStatus.status.faction_1_timer = 0xBBBBBBBB;
|
|
|
|
|
sendStatus.status.faction_2_timer = 0xCCCCCCCC;
|
|
|
|
|
sendStatus.status.faction_3_timer = 0xDDDDDDDD;
|
|
|
|
|
|
|
|
|
|
ResponseStatus rs = e220ttl.sendFixedMessage(0xFF, 0xFF, 23, (byte *)&sendStatus, sizeof(sendStatus));
|
|
|
|
|
Serial.println(rs.getResponseDescription());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tmrCallback_PowerMonitor()
|
|
|
|
|
{
|
|
|
|
|
// loadvoltage and percentage is global, because of battery Monitoring
|
|
|
|
|
|
|
|
|
|
const int bat_min_2s = 680;
|
|
|
|
|
const int bat_max_2s = 840;
|
|
|
|
|
const int bat_min_3s = 1020;
|
|
|
|
|
const int bat_max_3s = 1260;
|
|
|
|
|
|
|
|
|
|
float shuntvoltage = 0;
|
|
|
|
|
//float current_mA = 0;
|
|
|
|
|
float busvoltage = 0;
|
|
|
|
|
//float power_mW = 0;
|
|
|
|
|
int battery_level = 0;
|
|
|
|
|
|
|
|
|
|
shuntvoltage = ina219.getShuntVoltage_mV();
|
|
|
|
|
busvoltage = ina219.getBusVoltage_V();
|
|
|
|
|
//current_mA = ina219.getCurrent_mA();
|
|
|
|
|
//power_mW = ina219.getPower_mW();
|
|
|
|
|
globals.loadvoltage = busvoltage + (shuntvoltage / 1000);
|
|
|
|
|
switch (ConfigData.batteryType)
|
|
|
|
|
{
|
|
|
|
|
case BATTERY_LIPO_2S:
|
|
|
|
|
battery_level = map(globals.loadvoltage * 100, bat_min_2s, bat_max_2s, 0, 100);
|
|
|
|
|
globals.battery_level = battery_level < 0 ? 0 : battery_level;
|
|
|
|
|
break;
|
|
|
|
|
case BATTERY_LIPO_3S:
|
|
|
|
|
battery_level = map(globals.loadvoltage * 100, bat_min_3s, bat_max_3s, 0, 100);
|
|
|
|
|
globals.battery_level = battery_level < 0 ? 0 : battery_level;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
globals.battery_level = -1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Serial.printf("Battery Level: %d %%\n", globals.battery_level);
|
|
|
|
|
// Serial.printf("Bus Voltage: %f V\n", busvoltage);
|
|
|
|
|
// Serial.printf("Shunt Voltage: %f mV\n", shuntvoltage);
|
|
|
|
|
// Serial.printf("Load Voltage: %f V\n", globals.loadvoltage);
|
|
|
|
|
// Serial.printf("Current: %f mA\n", current_mA);
|
|
|
|
|
// Serial.printf("Power: %f mW\n", power_mW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tmrCallback_EEPROMCyclicPDS()
|
|
|
|
|
{
|
|
|
|
|
StorePersistence_EEPROM();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef WIFI_CLIENT
|
|
|
|
|
void wifiMaintainConnectionTicker_callback()
|
|
|
|
|
void tmrCallback_WiFiMaintainConnection()
|
|
|
|
|
{
|
|
|
|
|
static uint32_t WiFiFailCount = 0;
|
|
|
|
|
const uint32_t WiFiFailMax = 20;
|
|
|
|
|
static uint32_t WiFiFailCount = 0;
|
|
|
|
|
const uint32_t WiFiFailMax = 20;
|
|
|
|
|
|
|
|
|
|
if (wifiMulti.run(connectTimeoutMs) == WL_CONNECTED)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (WiFiFailCount < WiFiFailMax)
|
|
|
|
|
WiFiFailCount++;
|
|
|
|
|
else
|
|
|
|
|
toggleWiFiAP(false);
|
|
|
|
|
}
|
|
|
|
|
if (wifiMulti.run(connectTimeoutMs) == WL_CONNECTED)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (WiFiFailCount < WiFiFailMax)
|
|
|
|
|
WiFiFailCount++;
|
|
|
|
|
else
|
|
|
|
|
toggleWiFiAP(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void toggleWiFiAP(boolean shutdown)
|
|
|
|
|
{
|
|
|
|
|
if (WiFi.getMode() != WIFI_OFF && shutdown == true)
|
|
|
|
|
{
|
|
|
|
|
WiFi.mode(WIFI_OFF);
|
|
|
|
|
if (WiFi.getMode() != WIFI_OFF && shutdown == true)
|
|
|
|
|
{
|
|
|
|
|
WiFi.mode(WIFI_OFF);
|
|
|
|
|
#ifdef WIFI_CLIENT
|
|
|
|
|
WiFiMaintainConnectionTicker.stop();
|
|
|
|
|
tmrWiFiMaintainConnection.stop();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
else if (shutdown == false)
|
|
|
|
|
{
|
|
|
|
|
WiFi.mode(WIFI_AP);
|
|
|
|
|
WiFi.softAPConfig(IPAddress(WIFI_AP_IP_GW), IPAddress(WIFI_AP_IP_GW), IPAddress(255, 255, 255, 0));
|
|
|
|
|
WiFi.softAP(globals.DeviceName_ID, QUOTE(WIFI_AP_PASSWORD));
|
|
|
|
|
}
|
|
|
|
|
else if (shutdown == false)
|
|
|
|
|
{
|
|
|
|
|
WiFi.mode(WIFI_AP);
|
|
|
|
|
WiFi.softAPConfig(IPAddress(WIFI_AP_IP_GW), IPAddress(WIFI_AP_IP_GW), IPAddress(255, 255, 255, 0));
|
|
|
|
|
WiFi.softAP(globals.DeviceName_ID, QUOTE(WIFI_AP_PASSWORD));
|
|
|
|
|
#ifdef WIFI_CLIENT
|
|
|
|
|
WiFiMaintainConnectionTicker.stop();
|
|
|
|
|
tmrWiFiMaintainConnection.stop();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SystemShutdown()
|
|
|
|
|
{
|
|
|
|
|
StoreConfig_EEPROM();
|
|
|
|
|
ESP.restart();
|
|
|
|
|
StoreConfig_EEPROM();
|
|
|
|
|
ESP.restart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetBatteryType(batteryType_t type)
|
|
|
|
|
{
|
|
|
|
|
if (ConfigData.batteryType != type)
|
|
|
|
|
{
|
|
|
|
|
ConfigData.batteryType = type;
|
|
|
|
|
globals.requestEEAction = EE_CFG_SAVE;
|
|
|
|
|
Serial.printf("Set Batterytype to %s\n", type == BATTERY_LIPO_2S ? "2s Lipo" : "3s LiPo");
|
|
|
|
|
}
|
|
|
|
|
if (ConfigData.batteryType != type)
|
|
|
|
|
{
|
|
|
|
|
ConfigData.batteryType = type;
|
|
|
|
|
globals.requestEEAction = EE_CFG_SAVE;
|
|
|
|
|
Serial.printf("Set Batterytype to %s\n", type == BATTERY_LIPO_2S ? "2s Lipo" : "3s LiPo");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProcessKeyCombos()
|
|
|
|
|
void OverrideDisplay(const uint8_t *message, uint32_t time)
|
|
|
|
|
{
|
|
|
|
|
DisplayOverrideFlag = millis() + time;
|
|
|
|
|
DisplayOverrideValue = (uint8_t *)message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t getESPChipID()
|
|
|
|
|
{
|
|
|
|
|
#if defined(ESP8266)
|
|
|
|
|
return ESP.getChipId();
|
|
|
|
|
#elif defined(ESP32)
|
|
|
|
|
uint32_t chipId;
|
|
|
|
|
for (int i = 0; i < 17; i = i + 8)
|
|
|
|
|
{
|
|
|
|
|
chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
|
|
|
|
|
}
|
|
|
|
|
return chipId;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProcessKeyCombos(bool *btnState)
|
|
|
|
|
{
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
@@ -434,32 +641,32 @@ void ProcessKeyCombos()
|
|
|
|
|
static uint8_t keyCount_Fac2 = 0;
|
|
|
|
|
static keyStatus_t keyStatus_Fac3 = KEY_RELEASED;
|
|
|
|
|
|
|
|
|
|
if (digitalRead(DIO_FAC_3_TRG) == FAC_3_TRG_PRESSED)
|
|
|
|
|
if (btnState[2] == FAC_3_TRG_PRESSED)
|
|
|
|
|
{
|
|
|
|
|
keyStatus_Fac3 = KEY_PRESSED;
|
|
|
|
|
|
|
|
|
|
// Process FactionKey 1 ComboCounter
|
|
|
|
|
if (digitalRead(DIO_FAC_1_TRG) == FAC_1_TRG_PRESSED && keyStatus_Fac1 == KEY_RELEASED)
|
|
|
|
|
if (btnState[0] == FAC_1_TRG_PRESSED && keyStatus_Fac1 == KEY_RELEASED)
|
|
|
|
|
{
|
|
|
|
|
keyStatus_Fac1 = KEY_PRESSED;
|
|
|
|
|
keyCount_Fac1++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (digitalRead(DIO_FAC_1_TRG) != FAC_1_TRG_PRESSED)
|
|
|
|
|
if (btnState[0] != FAC_1_TRG_PRESSED)
|
|
|
|
|
keyStatus_Fac1 = KEY_RELEASED;
|
|
|
|
|
|
|
|
|
|
// Process FactionKey 2 ComboCounter
|
|
|
|
|
if (digitalRead(DIO_FAC_2_TRG) == FAC_2_TRG_PRESSED && keyStatus_Fac2 == KEY_RELEASED)
|
|
|
|
|
if (btnState[1] == FAC_2_TRG_PRESSED && keyStatus_Fac2 == KEY_RELEASED)
|
|
|
|
|
{
|
|
|
|
|
keyStatus_Fac2 = KEY_PRESSED;
|
|
|
|
|
keyCount_Fac2++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (digitalRead(DIO_FAC_2_TRG) != FAC_2_TRG_PRESSED)
|
|
|
|
|
if (btnState[1] != FAC_2_TRG_PRESSED)
|
|
|
|
|
keyStatus_Fac2 = KEY_RELEASED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (digitalRead(DIO_FAC_3_TRG) != FAC_3_TRG_PRESSED && keyStatus_Fac3 == KEY_PRESSED)
|
|
|
|
|
if (btnState[2] != FAC_3_TRG_PRESSED && keyStatus_Fac3 == KEY_PRESSED)
|
|
|
|
|
{
|
|
|
|
|
Serial.printf("KeyCombo 1: %d | 2: %d\n", keyCount_Fac1, keyCount_Fac2);
|
|
|
|
|
|
|
|
|
@@ -476,38 +683,4 @@ void ProcessKeyCombos()
|
|
|
|
|
keyStatus_Fac2 = KEY_RELEASED;
|
|
|
|
|
keyStatus_Fac3 = KEY_RELEASED;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OverrideDisplay(const uint8_t *message, uint32_t time)
|
|
|
|
|
{
|
|
|
|
|
DisplayOverrideFlag = millis() + time;
|
|
|
|
|
DisplayOverrideValue = (uint8_t *)message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t getESPChipID()
|
|
|
|
|
{
|
|
|
|
|
uint32_t chipId;
|
|
|
|
|
for (int i = 0; i < 17; i = i + 8)
|
|
|
|
|
{
|
|
|
|
|
chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
|
|
|
|
|
}
|
|
|
|
|
return chipId;
|
|
|
|
|
}
|
|
|
|
|
#
|
|
|
|
|
void LoRaPublish_callback()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
StaticJsonDocument<200> doc;
|
|
|
|
|
|
|
|
|
|
doc["lipo"] = globals.battery_level;
|
|
|
|
|
doc["afact"] = PersistenceData.activeFaction;
|
|
|
|
|
doc["fac1"] = PersistenceData.faction_1_timer;
|
|
|
|
|
doc["fac2"] = PersistenceData.faction_2_timer;
|
|
|
|
|
doc["fac3"] = PersistenceData.faction_3_timer;
|
|
|
|
|
|
|
|
|
|
LoRa.beginPacket();
|
|
|
|
|
serializeJson(doc, LoRa);
|
|
|
|
|
LoRa.endPacket();
|
|
|
|
|
|
|
|
|
|
Serial.printf("Sendet LoRa-Status Package\n");
|
|
|
|
|
}
|