added ButtonCombo to activate WiFi AP
This commit is contained in:
parent
4faa0a997b
commit
31b5353158
@ -11,8 +11,11 @@
|
|||||||
#define DIO_FAC_3_7SEG 13
|
#define DIO_FAC_3_7SEG 13
|
||||||
|
|
||||||
#define DIO_FAC_1_TRG 0
|
#define DIO_FAC_1_TRG 0
|
||||||
|
#define FAC_1_TRG_PRESSED LOW
|
||||||
#define DIO_FAC_2_TRG 2
|
#define DIO_FAC_2_TRG 2
|
||||||
|
#define FAC_2_TRG_PRESSED LOW
|
||||||
#define DIO_FAC_3_TRG 15
|
#define DIO_FAC_3_TRG 15
|
||||||
|
#define FAC_3_TRG_PRESSED HIGH
|
||||||
|
|
||||||
#ifndef HOST_NAME
|
#ifndef HOST_NAME
|
||||||
#define HOST_NAME "DE_Timer_%06X" // Use printf-Formatting - Chip-ID (uin32_t) will be added
|
#define HOST_NAME "DE_Timer_%06X" // Use printf-Formatting - Chip-ID (uin32_t) will be added
|
||||||
|
111
src/main.cpp
111
src/main.cpp
@ -45,6 +45,8 @@ void EEPROMCyclicPDS_callback();
|
|||||||
void toggleWiFiAP(boolean shutdown = false);
|
void toggleWiFiAP(boolean shutdown = false);
|
||||||
void SystemShutdown();
|
void SystemShutdown();
|
||||||
void SetBatteryType(batteryType_t type);
|
void SetBatteryType(batteryType_t type);
|
||||||
|
void ProcessKeyCombos();
|
||||||
|
void OverrideDisplay(const uint8_t *message, uint32_t time);
|
||||||
|
|
||||||
#ifdef REMOTE_DEBUG
|
#ifdef REMOTE_DEBUG
|
||||||
RemoteDebug Debug;
|
RemoteDebug Debug;
|
||||||
@ -85,10 +87,17 @@ uint8_t Faction_1_dot = 0;
|
|||||||
uint8_t Faction_2_dot = 0;
|
uint8_t Faction_2_dot = 0;
|
||||||
uint8_t Faction_3_dot = 0;
|
uint8_t Faction_3_dot = 0;
|
||||||
|
|
||||||
|
uint32_t DisplayOverrideFlag = 0;
|
||||||
|
uint8_t *DisplayOverrideValue = 0;
|
||||||
|
|
||||||
Globals_t globals;
|
Globals_t globals;
|
||||||
|
|
||||||
const uint8_t sevenSeg_bat[] = {0x00, 0b01111100, 0b01110111, 0b01111000};
|
const uint8_t sevenSeg_bat[] = {0x00, 0b01111100, 0b01110111, 0b01111000};
|
||||||
const uint8_t sevenSeg_low[] = {0b00111000, 0b01011100, 0x00, 0x00};
|
const uint8_t sevenSeg_low[] = {0b00111000, 0b01011100, 0x00, 0x00};
|
||||||
|
const uint8_t sevenSeg_net[] = {0b01010100, 0b01111001, 0b01111000, 0x00};
|
||||||
|
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 setup()
|
void setup()
|
||||||
{
|
{
|
||||||
@ -149,23 +158,19 @@ void setup()
|
|||||||
|
|
||||||
ArduinoOTA.onStart([]()
|
ArduinoOTA.onStart([]()
|
||||||
{
|
{
|
||||||
const uint8_t seg_ota[] = {0x3F, 0x78, 0x77, 0x00};
|
|
||||||
const uint8_t seg_flsh[] = {0x71, 0x38, 0x6D, 0x76};
|
|
||||||
const uint8_t seg_file[] = {0x71, 0x30, 0x38, 0x79};
|
|
||||||
|
|
||||||
disp_FAC_1.setBrightness(7);
|
disp_FAC_1.setBrightness(7);
|
||||||
disp_FAC_2.setBrightness(7);
|
disp_FAC_2.setBrightness(7);
|
||||||
disp_FAC_3.setBrightness(7);
|
disp_FAC_3.setBrightness(7);
|
||||||
disp_FAC_1.setSegments(seg_ota);
|
disp_FAC_1.setSegments(sevenSeg_ota);
|
||||||
disp_FAC_3.clear();
|
disp_FAC_3.clear();
|
||||||
|
|
||||||
if (ArduinoOTA.getCommand() == U_FLASH)
|
if (ArduinoOTA.getCommand() == U_FLASH)
|
||||||
{
|
{
|
||||||
disp_FAC_2.setSegments(seg_flsh);
|
disp_FAC_2.setSegments(sevenSeg_flsh);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
disp_FAC_2.setSegments(seg_file);
|
disp_FAC_2.setSegments(sevenSeg_file);
|
||||||
LittleFS.end();
|
LittleFS.end();
|
||||||
} });
|
} });
|
||||||
|
|
||||||
@ -239,6 +244,17 @@ String macToString(const unsigned char *mac)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SevenSeg_Output()
|
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)
|
if (globals.battery_level < BAT_LOW_PERCENT && millis() % 10000 > 7000)
|
||||||
{
|
{
|
||||||
@ -264,6 +280,7 @@ void SevenSeg_Output()
|
|||||||
disp_FAC_3.showNumberDecEx(PersistenceData.faction_3_timer / 60, Faction_3_dot, true, 4, 0);
|
disp_FAC_3.showNumberDecEx(PersistenceData.faction_3_timer / 60, Faction_3_dot, true, 4, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FactionTicker_callback()
|
void FactionTicker_callback()
|
||||||
{
|
{
|
||||||
@ -297,20 +314,28 @@ void FactionTicker_callback()
|
|||||||
|
|
||||||
void inputGetterTicker_callback()
|
void inputGetterTicker_callback()
|
||||||
{
|
{
|
||||||
if (digitalRead(DIO_FAC_1_TRG) + digitalRead(DIO_FAC_2_TRG) + !digitalRead(DIO_FAC_3_TRG) < 2)
|
ProcessKeyCombos();
|
||||||
|
|
||||||
|
uint8_t keysPressed = 0;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
if (keysPressed > 1)
|
||||||
{
|
{
|
||||||
Serial.println("ERROR: More than one Flag active - setting no Faction active");
|
Serial.println("ERROR: More than one Flag active - setting no Faction active");
|
||||||
PersistenceData.activeFaction = NONE;
|
PersistenceData.activeFaction = NONE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (digitalRead(DIO_FAC_1_TRG) == LOW)
|
if (digitalRead(DIO_FAC_1_TRG) == FAC_1_TRG_PRESSED)
|
||||||
PersistenceData.activeFaction = FACTION_1;
|
PersistenceData.activeFaction = FACTION_1;
|
||||||
|
|
||||||
if (digitalRead(DIO_FAC_2_TRG) == LOW)
|
if (digitalRead(DIO_FAC_2_TRG) == FAC_2_TRG_PRESSED)
|
||||||
PersistenceData.activeFaction = FACTION_2;
|
PersistenceData.activeFaction = FACTION_2;
|
||||||
|
|
||||||
if (digitalRead(DIO_FAC_3_TRG) == HIGH)
|
if (digitalRead(DIO_FAC_3_TRG) == FAC_3_TRG_PRESSED)
|
||||||
PersistenceData.activeFaction = FACTION_3;
|
PersistenceData.activeFaction = FACTION_3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -568,3 +593,67 @@ void SetBatteryType(batteryType_t type)
|
|||||||
debugV("Set Batterytype to %s", type == BATTERY_LIPO_2S ? "2s Lipo" : "3s LiPo");
|
debugV("Set Batterytype to %s", type == BATTERY_LIPO_2S ? "2s Lipo" : "3s LiPo");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProcessKeyCombos()
|
||||||
|
{
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
KEY_PRESSED,
|
||||||
|
KEY_RELEASED
|
||||||
|
} 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;
|
||||||
|
|
||||||
|
if (digitalRead(DIO_FAC_3_TRG) == 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)
|
||||||
|
{
|
||||||
|
keyStatus_Fac1 = KEY_PRESSED;
|
||||||
|
keyCount_Fac1++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (digitalRead(DIO_FAC_1_TRG) != 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)
|
||||||
|
{
|
||||||
|
keyStatus_Fac2 = KEY_PRESSED;
|
||||||
|
keyCount_Fac2++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (digitalRead(DIO_FAC_2_TRG) != FAC_2_TRG_PRESSED)
|
||||||
|
keyStatus_Fac2 = KEY_RELEASED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (digitalRead(DIO_FAC_3_TRG) != FAC_3_TRG_PRESSED && keyStatus_Fac3 == KEY_PRESSED)
|
||||||
|
{
|
||||||
|
debugV("KeyCombo 1: %d | 2: %d", keyCount_Fac1, keyCount_Fac2);
|
||||||
|
|
||||||
|
if (keyCount_Fac1 == 2 && keyCount_Fac2 == 2)
|
||||||
|
{
|
||||||
|
Serial.println("KeyCombo: WiFi AP ON");
|
||||||
|
OverrideDisplay(sevenSeg_net, 5000);
|
||||||
|
toggleWiFiAP(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
keyCount_Fac1 = 0;
|
||||||
|
keyCount_Fac2 = 0;
|
||||||
|
keyStatus_Fac1 = KEY_RELEASED;
|
||||||
|
keyStatus_Fac2 = KEY_RELEASED;
|
||||||
|
keyStatus_Fac3 = KEY_RELEASED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OverrideDisplay(const uint8_t *message, uint32_t time)
|
||||||
|
{
|
||||||
|
DisplayOverrideFlag = millis() + time;
|
||||||
|
DisplayOverrideValue = (uint8_t *)message;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user