Compare commits
5 Commits
ae29e23812
...
a960e67c7d
Author | SHA1 | Date | |
---|---|---|---|
a960e67c7d | |||
9e1a4d821f | |||
4d0a9918ce | |||
53928a93b0 | |||
6b89ed9a8c |
@ -274,7 +274,7 @@ bool LoRa_E220::begin(){
|
||||
|
||||
this->serialDef.stream->setTimeout(100);
|
||||
Status status = setMode(MODE_0_NORMAL);
|
||||
return status==E220_SUCCESS;
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -26,13 +26,14 @@ upload_speed = 921600
|
||||
|
||||
build_flags=
|
||||
!python git_rev_macro.py
|
||||
;-DSERIAL_DEBUG
|
||||
;-DWIFI_CLIENT
|
||||
-DATOMIC_FS_UPDATE
|
||||
;-DFEATURE_ENABLE_WIFI_CLIENT
|
||||
;-DCAPTIVE
|
||||
-DWIFI_AP_IP_GW=10,0,1,1
|
||||
-DADMIN_PASSWORD=${wifi_cred.admin_password}
|
||||
-DWIFI_SSID=${wifi_cred.wifi_ssid}
|
||||
-DWIFI_PASSWORD=${wifi_cred.wifi_password}
|
||||
-DWIFI_AP_SSID=${wifi_cred.wifi_ap_ssid}
|
||||
-DWIFI_AP_PASSWORD=${wifi_cred.wifi_ap_password}
|
||||
-DDEVICE_NAME='"Dark Emergency Timer"'
|
||||
-DFACTION_1_NAME='"GOF"'
|
||||
|
@ -13,6 +13,7 @@
|
||||
#define HOST_NAME "AirsoftTimer_%08X"
|
||||
|
||||
#define SHUTDOWN_DELAY_MS 5000
|
||||
#define RESETABLE_AFTER_STARTUP_MS 30000
|
||||
|
||||
#define GPIO_LORA_TX D3
|
||||
#define GPIO_LORA_RX D4
|
||||
@ -39,6 +40,9 @@
|
||||
#define I2C_POWER_ADDRESS 0x40
|
||||
#define I2C_EEPROM_ADDRESS 0x50
|
||||
|
||||
#define SW_VERSION 1.0
|
||||
#define FLASH_FS_VERSION 1.0
|
||||
|
||||
#ifndef OTA_DELAY
|
||||
#define OTA_DELAY 50 // ticks -> 10ms / tick
|
||||
#endif
|
||||
@ -52,6 +56,10 @@
|
||||
#ifndef WIFI_SSID
|
||||
#error "You must define an WIFI_SSID for OTA-Update"
|
||||
#endif
|
||||
#ifndef WIFI_AP_SSID
|
||||
#warning "No WIFI_AP_SSID defined. Using DeviceName"
|
||||
#define WIFI_AP_SSID DEVICE_NAME
|
||||
#endif
|
||||
#ifndef WIFI_AP_PASSWORD
|
||||
#error "You must define an WIFI_AP_PASSWORD for Standalone AP-Mode"
|
||||
#endif
|
||||
|
@ -15,6 +15,8 @@ typedef enum DTCNums_e
|
||||
DTC_FLASHFS_ERROR,
|
||||
DTC_FLASHFS_VERSION_ERROR,
|
||||
DTC_EEPROM_CFG_SANITY,
|
||||
DTC_NO_LORA_FOUND,
|
||||
DTC_NO_BATMNON_FOUND,
|
||||
DTC_LAST_DTC
|
||||
} DTCNums_t;
|
||||
|
||||
|
@ -5,11 +5,15 @@ LoRa_E220 e220ttl(GPIO_LORA_TX, GPIO_LORA_RX, GPIO_LORA_AUX, 3, 4); // Arduino R
|
||||
void printParameters(struct Configuration configuration);
|
||||
void printModuleInformation(struct ModuleInformation moduleInformation);
|
||||
|
||||
void InitLoRa(void (*MPinHelper)(int, int))
|
||||
bool InitLoRa(void (*MPinHelper)(int, int))
|
||||
{
|
||||
e220ttl.setMPins = MPinHelper;
|
||||
e220ttl.begin();
|
||||
bool returnval;
|
||||
|
||||
e220ttl.setMPins = MPinHelper;
|
||||
returnval = e220ttl.begin();
|
||||
|
||||
if (returnval == true)
|
||||
{
|
||||
ResponseStructContainer c;
|
||||
c = e220ttl.getConfiguration();
|
||||
// It's important get configuration pointer before all other operation
|
||||
@ -51,6 +55,12 @@ void InitLoRa(void (*MPinHelper)(int, int))
|
||||
c.close();
|
||||
|
||||
printParameters(configuration);
|
||||
}
|
||||
else
|
||||
{
|
||||
MaintainDTC(DTC_NO_LORA_FOUND, DTC_WARN, true);
|
||||
}
|
||||
return returnval;
|
||||
}
|
||||
|
||||
void LoRa_Process()
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
#define FREQUENCY_868
|
||||
|
||||
void InitLoRa(void (*MPinHelper)(int, int));
|
||||
bool InitLoRa(void (*MPinHelper)(int, int));
|
||||
void LoRa_Process();
|
||||
void sendStatus_LoRa();
|
||||
|
||||
|
@ -22,11 +22,14 @@
|
||||
#ifdef WIFI_CLIENT
|
||||
#include <WiFiMulti.h>
|
||||
|
||||
const char *ssid = QUOTE(WIFI_SSID);
|
||||
const char *password = QUOTE(WIFI_PASSWORD);
|
||||
#ifdef FEATURE_ENABLE_WIFI_CLIENT
|
||||
#include <ESP8266WiFiMulti.h>
|
||||
|
||||
const char *ssid = QUOTE(WIFI_SSID_CLIENT);
|
||||
const char *password = QUOTE(WIFI_PASSWORD_CLIENT);
|
||||
const uint32_t connectTimeoutMs = 5000;
|
||||
|
||||
WiFiMulti wifiMulti;
|
||||
ESP8266WiFiMulti wifiMulti;
|
||||
#endif
|
||||
|
||||
PCF8574 i2c_io(I2C_IO_ADDRESS);
|
||||
@ -56,7 +59,7 @@ Ticker tmrInputGetter(tmrCallback_InputGetter, 250, 0, MILLIS);
|
||||
void tmrCallback_EEPROMCyclicPDS();
|
||||
Ticker tmrEEPROMCyclicPDS(tmrCallback_EEPROMCyclicPDS, 60000, 0, MILLIS);
|
||||
|
||||
#ifdef WIFI_CLIENT
|
||||
#ifdef FEATURE_ENABLE_WIFI_CLIENT
|
||||
void tmrCallback_WiFiMaintainConnection();
|
||||
Ticker tmrWiFiMaintainConnection(tmrCallback_WiFiMaintainConnection, 1000, 0, MILLIS);
|
||||
#endif
|
||||
@ -117,17 +120,22 @@ void setup()
|
||||
Serial.print("INA219 not Initialized\n");
|
||||
}
|
||||
|
||||
InitLoRa(&setMPins_Helper);
|
||||
if (InitLoRa(&setMPins_Helper))
|
||||
{
|
||||
Serial.printf("Initialized LoRa_Transceiver");
|
||||
tmrStatusSender.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("LoRa not Initialized\n");
|
||||
}
|
||||
|
||||
#ifdef WIFI_CLIENT
|
||||
#ifdef FEATURE_ENABLE_WIFI_CLIENT
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.setHostname(globals.DeviceName_ID);
|
||||
wifiMulti.addAP(QUOTE(WIFI_SSID), QUOTE(WIFI_PASSWORD));
|
||||
tmrWiFiMaintainConnection.start();
|
||||
WiFi.setHostname(globals.DeviceName);
|
||||
wifiMulti.addAP(QUOTE(WIFI_SSID_CLIENT), QUOTE(WIFI_PASSWORD_CLIENT));
|
||||
WiFiMaintainConnectionTicker.start();
|
||||
#else
|
||||
WiFi.mode(WIFI_AP);
|
||||
WiFi.begin(QUOTE(DEVICE_NAME), QUOTE(WIFI_AP_PASSWORD));
|
||||
WiFi.mode(WIFI_OFF);
|
||||
#endif
|
||||
|
||||
@ -252,13 +260,13 @@ void SevenSeg_Output()
|
||||
if (millis() % 3000 < 1500)
|
||||
snprintf(sevenSegBuff, sizeof(sevenSegBuff), "%4d", globals.battery_level);
|
||||
else
|
||||
snprintf(sevenSegBuff, sizeof(sevenSegBuff), "%2d.%1d", (globals.loadvoltage_mV / 1000), ((globals.loadvoltage_mV % 1000) / 100));
|
||||
snprintf(sevenSegBuff, sizeof(sevenSegBuff), "%3d.%1d", (globals.loadvoltage_mV / 1000), ((globals.loadvoltage_mV % 1000) / 100));
|
||||
|
||||
disp_FAC_1.setBrightness(1);
|
||||
disp_FAC_1.display(" BAT");
|
||||
disp_FAC_1.display(" Bat");
|
||||
|
||||
disp_FAC_2.setBrightness(1);
|
||||
disp_FAC_2.display("LOW ");
|
||||
disp_FAC_2.display("low ");
|
||||
|
||||
disp_FAC_3.setBrightness(1);
|
||||
disp_FAC_3.display(String(sevenSegBuff));
|
||||
@ -420,29 +428,38 @@ void tmrCallback_WiFiMaintainConnection()
|
||||
else
|
||||
{
|
||||
if (WiFiFailCount < WiFiFailMax)
|
||||
{
|
||||
WiFiFailCount++;
|
||||
}
|
||||
else
|
||||
toggleWiFiAP(false);
|
||||
{
|
||||
debugV("WiFi not connected! - Start AP");
|
||||
toggleWiFiAP();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void toggleWiFiAP(boolean shutdown)
|
||||
{
|
||||
if (WiFi.getMode() != WIFI_OFF && shutdown == true)
|
||||
if (WiFi.getMode() != WIFI_OFF)
|
||||
{
|
||||
WiFi.mode(WIFI_OFF);
|
||||
#ifdef WIFI_CLIENT
|
||||
tmrWiFiMaintainConnection.stop();
|
||||
debugV("WiFi turned off");
|
||||
#ifdef FEATURE_ENABLE_WIFI_CLIENT
|
||||
WiFiMaintainConnectionTicker.stop();
|
||||
#endif
|
||||
}
|
||||
else if (shutdown == false)
|
||||
else
|
||||
{
|
||||
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
|
||||
tmrWiFiMaintainConnection.stop();
|
||||
WiFi.softAP(QUOTE(WIFI_AP_SSID), QUOTE(WIFI_AP_PASSWORD));
|
||||
#ifdef FEATURE_ENABLE_WIFI_CLIENT
|
||||
WiFiMaintainConnectionTicker.stop();
|
||||
debugV("WiFi AP started, stopped Maintain-Timer");
|
||||
#else
|
||||
debugV("WiFi AP started");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -489,24 +506,14 @@ void ProcessKeyCombos(bool *btnState)
|
||||
} keyStatus_t;
|
||||
|
||||
static keyStatus_t keyStatus_Fac1 = KEY_RELEASED;
|
||||
static uint8_t keyCount_Fac1 = 0;
|
||||
static keyStatus_t keyStatus_Fac2 = KEY_RELEASED;
|
||||
static uint8_t keyCount_Fac2 = 0;
|
||||
static keyStatus_t keyStatus_Fac3 = KEY_RELEASED;
|
||||
static uint8_t keyCount_Fac3 = 0;
|
||||
|
||||
if (btnState[2] == FAC_3_TRG_PRESSED)
|
||||
{
|
||||
keyStatus_Fac3 = KEY_PRESSED;
|
||||
|
||||
// Process FactionKey 1 ComboCounter
|
||||
if (btnState[0] == FAC_1_TRG_PRESSED && keyStatus_Fac1 == KEY_RELEASED)
|
||||
if (btnState[0] == FAC_1_TRG_PRESSED)
|
||||
{
|
||||
keyStatus_Fac1 = KEY_PRESSED;
|
||||
keyCount_Fac1++;
|
||||
}
|
||||
|
||||
if (btnState[0] != FAC_1_TRG_PRESSED)
|
||||
keyStatus_Fac1 = KEY_RELEASED;
|
||||
|
||||
// Process FactionKey 2 ComboCounter
|
||||
if (btnState[1] == FAC_2_TRG_PRESSED && keyStatus_Fac2 == KEY_RELEASED)
|
||||
@ -517,22 +524,50 @@ void ProcessKeyCombos(bool *btnState)
|
||||
|
||||
if (btnState[1] != FAC_2_TRG_PRESSED)
|
||||
keyStatus_Fac2 = KEY_RELEASED;
|
||||
|
||||
// Process FactionKey 3 ComboCounter
|
||||
if (btnState[2] == FAC_3_TRG_PRESSED && keyStatus_Fac3 == KEY_RELEASED)
|
||||
{
|
||||
keyStatus_Fac3 = KEY_PRESSED;
|
||||
keyCount_Fac3++;
|
||||
}
|
||||
|
||||
if (btnState[2] != FAC_3_TRG_PRESSED && keyStatus_Fac3 == KEY_PRESSED)
|
||||
{
|
||||
if (keyCount_Fac1 > 0 || keyCount_Fac2 > 0)
|
||||
Serial.printf("KeyCombo 1: %d | 2: %d\n", keyCount_Fac1, keyCount_Fac2);
|
||||
if (btnState[2] != FAC_3_TRG_PRESSED)
|
||||
keyStatus_Fac3 = KEY_RELEASED;
|
||||
}
|
||||
|
||||
if (keyCount_Fac1 == 2 && keyCount_Fac2 == 2)
|
||||
if (btnState[0] != FAC_1_TRG_PRESSED && keyStatus_Fac1 == KEY_PRESSED)
|
||||
{
|
||||
if (keyCount_Fac2 > 0 || keyCount_Fac3 > 0)
|
||||
Serial.printf("KeyCombo 2: %d | 3: %d\n", keyCount_Fac2, keyCount_Fac3);
|
||||
|
||||
if (keyCount_Fac2 == 2 && keyCount_Fac3 == 0)
|
||||
{
|
||||
Serial.println("KeyCombo: WiFi AP ON");
|
||||
OverrideDisplay("NET ", 5000);
|
||||
toggleWiFiAP(false);
|
||||
}
|
||||
else if (keyCount_Fac2 == 4 && keyCount_Fac3 == 0)
|
||||
{
|
||||
Serial.printf("KeyCombo: Reset Timer\n");
|
||||
if (millis() < RESETABLE_AFTER_STARTUP_MS)
|
||||
{
|
||||
OverrideDisplay("RST ", 5000);
|
||||
PersistenceData.faction_1_timer = 0;
|
||||
PersistenceData.faction_2_timer = 0;
|
||||
PersistenceData.faction_3_timer = 0;
|
||||
PersistenceData.activeFaction = NONE;
|
||||
globals.requestEEAction = EE_PDS_SAVE;
|
||||
}
|
||||
else
|
||||
{
|
||||
OverrideDisplay("ERR ", 5000);
|
||||
Serial.printf("ERROR: only %d seconds after Startup!\n", RESETABLE_AFTER_STARTUP_MS / 1000);
|
||||
}
|
||||
}
|
||||
|
||||
keyCount_Fac1 = 0;
|
||||
keyCount_Fac2 = 0;
|
||||
keyCount_Fac3 = 0;
|
||||
keyStatus_Fac1 = KEY_RELEASED;
|
||||
keyStatus_Fac2 = KEY_RELEASED;
|
||||
keyStatus_Fac3 = KEY_RELEASED;
|
||||
|
@ -1,4 +1,5 @@
|
||||
[wifi_cred]
|
||||
wifi_ap_ssid = wifi-ap-ssid
|
||||
wifi_ap_password = wifiappass
|
||||
wifi_ssid = wifi-ssid
|
||||
wifi_password = wifi-pass
|
||||
|
Loading…
x
Reference in New Issue
Block a user