changed Fixed Naming of Factions to defines.

This commit is contained in:
Souko Hiabuto 2021-06-10 14:01:57 +02:00
parent ce7f4ce364
commit dcfec5e759
4 changed files with 151 additions and 99 deletions

View File

@ -20,7 +20,7 @@
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<h3> <h3>
Dark Emergency CTF Timer %TITLE%
</h3> </h3>
<table class="table"> <table class="table">
<thead> <thead>
@ -40,46 +40,46 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr class="table-kgg"> <tr class="table-fac-1">
<td> <td>
1 1
</td> </td>
<td> <td>
KGG %NAME_FAC_1%
</td> </td>
<td> <td>
%POINTS_KGG% %POINTS_FAC_1%
</td> </td>
<td> <td>
%ACTIVE_KGG% %STATUS_FAC_1%
</td> </td>
</tr> </tr>
<tr class="table-miliz"> <tr class="table-fac-2">
<td> <td>
2 2
</td> </td>
<td> <td>
Miliz %NAME_FAC_2%
</td> </td>
<td> <td>
%POINTS_MILIZ% %POINTS_FAC_2%
</td> </td>
<td> <td>
%ACTIVE_MILIZ% %STATUS_FAC_2%
</td> </td>
</tr> </tr>
<tr class="table-gof"> <tr class="table-fac-3">
<td> <td>
3 3
</td> </td>
<td> <td>
GOF %NAME_FAC_3%
</td> </td>
<td> <td>
%POINTS_GOF% %POINTS_FAC_3%
</td> </td>
<td> <td>
%ACTIVE_GOF% %STATUS_FAC_3%
</td> </td>
</tr> </tr>
</tbody> </tbody>

View File

@ -15,6 +15,13 @@ board_build.filesystem = littlefs
board_build.f_flash = 80000000L board_build.f_flash = 80000000L
board_build.ldscript = eagle.flash.4m1m.ld board_build.ldscript = eagle.flash.4m1m.ld
build_flags=
-D WIFI_SSID='"Dark Emergency CTF Timer"'
-D WIFI_PASS='"CaptureTheFlag"'
-D FACTION_1_NAME='"GOF"'
-D FACTION_2_NAME='"MILIZ"'
-D FACTION_3_NAME='"KGG"'
framework = arduino framework = arduino
lib_deps = lib_deps =
smougenot/TM1637@0.0.0-alpha+sha.9486982048 smougenot/TM1637@0.0.0-alpha+sha.9486982048

24
src/defaults.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef _DEFAULTS_H_
#define _DEFAULTS_H_
#ifndef WIFI_SSID
#define WIFI_SSID "3 Factions CTF Timer"
#endif
#ifndef WIFI_PASS
#define WIFI_PASS "CaptureTheFlag"
#endif
#ifndef FACTION_1_NAME
#define FACTION_1_NAME "Team A"
#endif
#ifndef FACTION_2_NAME
#define FACTION_2_NAME "Team B"
#endif
#ifndef FACTION_3_NAME
#define FACTION_3_NAME "Team C"
#endif
#endif

View File

@ -9,73 +9,87 @@
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h> #include <ESPAsyncTCP.h>
#endif #endif
#include "ESPAsyncWebServer.h" #include <ESPAsyncWebServer.h>
#include "LittleFS.h" #include <LittleFS.h>
// local includes
#include "defaults.h"
// Module connection pins (Digital Pins) // Module connection pins (ESP GPIO-Nums)
#define CLK 2 #define CLK 2
#define DIO_GOF_7SEG 0 #define DIO_FAC_1_7SEG 0
#define DIO_MIL_7SEG 5 #define DIO_FAC_2_7SEG 5
#define DIO_KGG_7SEG 4 #define DIO_FAC_3_7SEG 4
#define DIO_GOF_TRG 12 #define DIO_FAC_1_TRG 12
#define DIO_MIL_TRG 13 #define DIO_FAC_2_TRG 13
#define DIO_KGG_TRG 14 #define DIO_FAC_3_TRG 14
enum Parties enum Factions
{ {
NONE, NONE,
GOF, FACTION_1,
MILIZ, FACTION_2,
KGG FACTION_3
}; };
void SevenSeg_Output(); void SevenSeg_Output();
void ticker_callback(); void FactionTicker_callback();
void serialOut_callback(); void serialOutTicker_callback();
void inputGetter_callback(); void inputGetterTicker_callback();
TM1637Display disp_GOF(CLK, DIO_GOF_7SEG); TM1637Display disp_FAC_1(CLK, DIO_FAC_1_7SEG);
TM1637Display disp_MIL(CLK, DIO_MIL_7SEG); TM1637Display disp_FAC_2(CLK, DIO_FAC_2_7SEG);
TM1637Display disp_KGG(CLK, DIO_KGG_7SEG); TM1637Display disp_FAC_3(CLK, DIO_FAC_3_7SEG);
DNSServer dnsServer; DNSServer dnsServer;
AsyncWebServer server(80); AsyncWebServer server(80);
Ticker PartyTicker(ticker_callback, 500, 0, MILLIS); Ticker FactionTicker(FactionTicker_callback, 500, 0, MILLIS);
Ticker SerialOutputTicker(serialOut_callback, 5000, 0, MILLIS); Ticker SerialOutputTicker(serialOutTicker_callback, 5000, 0, MILLIS);
Ticker InputGetterTicker(inputGetter_callback, 500, 0, MILLIS); Ticker InputGetterTicker(inputGetterTicker_callback, 500, 0, MILLIS);
Parties activeParty = NONE; Factions activeFaction = NONE;
uint32_t Count_GOF = 0; uint32_t Count_Faction_1 = 0;
uint32_t Count_MILIZ = 0; uint32_t Count_Faction_2 = 0;
uint32_t Count_KGG = 0; uint32_t Count_Faction_3 = 0;
uint8_t KGG_dot = 0; uint8_t Faction_1_dot = 0;
uint8_t GOF_dot = 0; uint8_t Faction_2_dot = 0;
uint8_t MIL_dot = 0; uint8_t Faction_3_dot = 0;
String processor(const String &var) String processor(const String &var)
{ {
char buffer[16] = {0}; char buffer[16] = {0};
if (var == "POINTS_KGG") if (var == "POINTS_FAC_1")
itoa(Count_KGG, buffer, 10); itoa(Count_Faction_1, buffer, 10);
if (var == "POINTS_GOF") if (var == "POINTS_FAC_2")
itoa(Count_GOF, buffer, 10); itoa(Count_Faction_2, buffer, 10);
if (var == "POINTS_MILIZ") if (var == "POINTS_FAC_3")
itoa(Count_MILIZ, buffer, 10); itoa(Count_Faction_3, buffer, 10);
if (var == "ACTIVE_KGG") if (var == "STATUS_FAC_1")
return activeParty == KGG ? "ACTIVE" : "INACTIVE"; return activeFaction == FACTION_1 ? "ACTIVE" : "INACTIVE";
if (var == "ACTIVE_GOF") if (var == "STATUS_FAC_2")
return activeParty == GOF ? "ACTIVE" : "INACTIVE"; return activeFaction == FACTION_2 ? "ACTIVE" : "INACTIVE";
if (var == "ACTIVE_MILIZ") if (var == "STATUS_FAC_3")
return activeParty == MILIZ ? "ACTIVE" : "INACTIVE"; return activeFaction == FACTION_3 ? "ACTIVE" : "INACTIVE";
if (var == "NAME_FAC_1")
return FACTION_1_NAME;
if (var == "NAME_FAC_2")
return FACTION_2_NAME;
if (var == "NAME_FAC_3")
return FACTION_3_NAME;
if (var == "TITLE")
return WIFI_SSID;
return String(buffer); return String(buffer);
} }
@ -157,38 +171,38 @@ public:
void SevenSeg_Output() void SevenSeg_Output()
{ {
disp_GOF.setBrightness(activeParty == GOF ? 7 : 0); disp_FAC_1.setBrightness(activeFaction == FACTION_1 ? 7 : 0);
disp_MIL.setBrightness(activeParty == MILIZ ? 7 : 0); disp_FAC_2.setBrightness(activeFaction == FACTION_2 ? 7 : 0);
disp_KGG.setBrightness(activeParty == KGG ? 7 : 0); disp_FAC_3.setBrightness(activeFaction == FACTION_3 ? 7 : 0);
disp_GOF.showNumberDecEx(Count_GOF / 20, GOF_dot, true, 4, 0); disp_FAC_1.showNumberDecEx(Count_Faction_1 / 20, Faction_1_dot, true, 4, 0);
disp_MIL.showNumberDecEx(Count_MILIZ / 20, MIL_dot, true, 4, 0); disp_FAC_2.showNumberDecEx(Count_Faction_2 / 20, Faction_2_dot, true, 4, 0);
disp_KGG.showNumberDecEx(Count_KGG / 20, KGG_dot, true, 4, 0); disp_FAC_3.showNumberDecEx(Count_Faction_3 / 20, Faction_3_dot, true, 4, 0);
} }
void ticker_callback() void FactionTicker_callback()
{ {
switch (activeParty) switch (activeFaction)
{ {
case GOF: case FACTION_1:
Count_GOF++; Count_Faction_1++;
GOF_dot = GOF_dot == 0x80 || GOF_dot == 0x00 ? 0x10 : GOF_dot << 1; Faction_1_dot = Faction_1_dot == 0x80 || Faction_1_dot == 0x00 ? 0x10 : Faction_1_dot << 1;
MIL_dot = 0; Faction_2_dot = 0;
KGG_dot = 0; Faction_3_dot = 0;
break; break;
case MILIZ: case FACTION_2:
Count_MILIZ++; Count_Faction_2++;
MIL_dot = MIL_dot == 0x80 || MIL_dot == 0x00 ? 0x10 : MIL_dot << 1; Faction_2_dot = Faction_2_dot == 0x80 || Faction_2_dot == 0x00 ? 0x10 : Faction_2_dot << 1;
GOF_dot = 0; Faction_1_dot = 0;
KGG_dot = 0; Faction_3_dot = 0;
break; break;
case KGG: case FACTION_3:
Count_KGG++; Count_Faction_3++;
KGG_dot = KGG_dot == 0x80 || KGG_dot == 0x00 ? 0x10 : KGG_dot << 1; Faction_3_dot = Faction_3_dot == 0x80 || Faction_3_dot == 0x00 ? 0x10 : Faction_3_dot << 1;
GOF_dot = 0; Faction_1_dot = 0;
MIL_dot = 0; Faction_2_dot = 0;
break; break;
default: default:
@ -196,63 +210,70 @@ void ticker_callback()
} }
} }
void serialOut_callback() void serialOutTicker_callback()
{ {
static uint32_t SerialPrintCount = 0; static uint32_t SerialPrintCount = 0;
if (SerialPrintCount % 10 == 0) if (SerialPrintCount % 10 == 0)
{ {
Serial.println("| GOF | MILIZ | KGG |"); Serial.printf("| %8s | %8s | %8s |\n", FACTION_1_NAME, FACTION_2_NAME, FACTION_3_NAME);
} }
Serial.printf(" %9d %9d %9d\n", Count_GOF, Count_MILIZ, Count_KGG); Serial.printf(" %8d %8d %8d\n", Count_Faction_1, Count_Faction_2, Count_Faction_3);
SerialPrintCount++; SerialPrintCount++;
} }
void inputGetter_callback() void inputGetterTicker_callback()
{ {
activeParty = NONE; activeFaction = NONE;
if (digitalRead(DIO_GOF_TRG) + digitalRead(DIO_MIL_TRG) + digitalRead(DIO_KGG_TRG) < 2) if (digitalRead(DIO_FAC_1_TRG) + digitalRead(DIO_FAC_2_TRG) + digitalRead(DIO_FAC_3_TRG) < 2)
{ {
Serial.println("ERROR: More than one Flag active"); Serial.println("ERROR: More than one Flag active");
return; return;
} }
if (digitalRead(DIO_GOF_TRG) == LOW) if (digitalRead(DIO_FAC_1_TRG) == LOW)
activeParty = GOF; activeFaction = FACTION_1;
if (digitalRead(DIO_KGG_TRG) == LOW) if (digitalRead(DIO_FAC_2_TRG) == LOW)
activeParty = KGG; activeFaction = FACTION_2;
if (digitalRead(DIO_MIL_TRG) == LOW) if (digitalRead(DIO_FAC_3_TRG) == LOW)
activeParty = MILIZ; activeFaction = FACTION_3;
} }
void setup() void setup()
{ {
pinMode(DIO_GOF_TRG, INPUT_PULLUP); pinMode(DIO_FAC_1_TRG, INPUT_PULLUP);
pinMode(DIO_MIL_TRG, INPUT_PULLUP); pinMode(DIO_FAC_2_TRG, INPUT_PULLUP);
pinMode(DIO_KGG_TRG, INPUT_PULLUP); pinMode(DIO_FAC_3_TRG, INPUT_PULLUP);
Serial.begin(9600); Serial.begin(9600);
Serial.print("\n\n\n");
LittleFS.begin(); LittleFS.begin();
WiFi.softAP("Dark Emergency CTF Timer"); WiFi.persistent(false);
WiFi.mode(WIFI_AP);
WiFi.softAP(WIFI_SSID, WIFI_PASS);
stationConnectedHandler = WiFi.onSoftAPModeStationConnected(&onStationConnected);
stationDisconnectedHandler = WiFi.onSoftAPModeStationDisconnected(&onStationDisconnected);
dnsServer.start(53, "*", WiFi.softAPIP()); dnsServer.start(53, "*", WiFi.softAPIP());
server.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER); //only when requested from AP server.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER); //only when requested from AP
server.begin(); server.begin();
PartyTicker.start(); FactionTicker.start();
SerialOutputTicker.start(); SerialOutputTicker.start();
InputGetterTicker.start(); InputGetterTicker.start();
} }
void loop() void loop()
{ {
PartyTicker.update(); FactionTicker.update();
SerialOutputTicker.update(); SerialOutputTicker.update();
InputGetterTicker.update(); InputGetterTicker.update();
@ -266,19 +287,19 @@ void loop()
switch (input) switch (input)
{ {
case 'n': case 'n':
activeParty = NONE; activeFaction = NONE;
break; break;
case 'g': case 'g':
activeParty = GOF; activeFaction = FACTION_1;
break; break;
case 'k': case 'k':
activeParty = KGG; activeFaction = FACTION_3;
break; break;
case 'm': case 'm':
activeParty = MILIZ; activeFaction = FACTION_2;
break; break;
case 'x': case 'x':