changed Fixed Naming of Factions to defines.
This commit is contained in:
parent
ce7f4ce364
commit
dcfec5e759
@ -20,7 +20,7 @@
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h3>
|
||||
Dark Emergency CTF Timer
|
||||
%TITLE%
|
||||
</h3>
|
||||
<table class="table">
|
||||
<thead>
|
||||
@ -40,46 +40,46 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="table-kgg">
|
||||
<tr class="table-fac-1">
|
||||
<td>
|
||||
1
|
||||
</td>
|
||||
<td>
|
||||
KGG
|
||||
%NAME_FAC_1%
|
||||
</td>
|
||||
<td>
|
||||
%POINTS_KGG%
|
||||
%POINTS_FAC_1%
|
||||
</td>
|
||||
<td>
|
||||
%ACTIVE_KGG%
|
||||
%STATUS_FAC_1%
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="table-miliz">
|
||||
<tr class="table-fac-2">
|
||||
<td>
|
||||
2
|
||||
</td>
|
||||
<td>
|
||||
Miliz
|
||||
%NAME_FAC_2%
|
||||
</td>
|
||||
<td>
|
||||
%POINTS_MILIZ%
|
||||
%POINTS_FAC_2%
|
||||
</td>
|
||||
<td>
|
||||
%ACTIVE_MILIZ%
|
||||
%STATUS_FAC_2%
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="table-gof">
|
||||
<tr class="table-fac-3">
|
||||
<td>
|
||||
3
|
||||
</td>
|
||||
<td>
|
||||
GOF
|
||||
%NAME_FAC_3%
|
||||
</td>
|
||||
<td>
|
||||
%POINTS_GOF%
|
||||
%POINTS_FAC_3%
|
||||
</td>
|
||||
<td>
|
||||
%ACTIVE_GOF%
|
||||
%STATUS_FAC_3%
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -15,6 +15,13 @@ board_build.filesystem = littlefs
|
||||
board_build.f_flash = 80000000L
|
||||
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
|
||||
lib_deps =
|
||||
smougenot/TM1637@0.0.0-alpha+sha.9486982048
|
||||
|
24
src/defaults.h
Normal file
24
src/defaults.h
Normal 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
|
193
src/main.cpp
193
src/main.cpp
@ -9,73 +9,87 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESPAsyncTCP.h>
|
||||
#endif
|
||||
#include "ESPAsyncWebServer.h"
|
||||
#include "LittleFS.h"
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <LittleFS.h>
|
||||
// local includes
|
||||
#include "defaults.h"
|
||||
|
||||
// Module connection pins (Digital Pins)
|
||||
// Module connection pins (ESP GPIO-Nums)
|
||||
#define CLK 2
|
||||
#define DIO_GOF_7SEG 0
|
||||
#define DIO_MIL_7SEG 5
|
||||
#define DIO_KGG_7SEG 4
|
||||
#define DIO_FAC_1_7SEG 0
|
||||
#define DIO_FAC_2_7SEG 5
|
||||
#define DIO_FAC_3_7SEG 4
|
||||
|
||||
#define DIO_GOF_TRG 12
|
||||
#define DIO_MIL_TRG 13
|
||||
#define DIO_KGG_TRG 14
|
||||
#define DIO_FAC_1_TRG 12
|
||||
#define DIO_FAC_2_TRG 13
|
||||
#define DIO_FAC_3_TRG 14
|
||||
|
||||
enum Parties
|
||||
enum Factions
|
||||
{
|
||||
NONE,
|
||||
GOF,
|
||||
MILIZ,
|
||||
KGG
|
||||
FACTION_1,
|
||||
FACTION_2,
|
||||
FACTION_3
|
||||
};
|
||||
|
||||
void SevenSeg_Output();
|
||||
void ticker_callback();
|
||||
void serialOut_callback();
|
||||
void inputGetter_callback();
|
||||
void FactionTicker_callback();
|
||||
void serialOutTicker_callback();
|
||||
void inputGetterTicker_callback();
|
||||
|
||||
TM1637Display disp_GOF(CLK, DIO_GOF_7SEG);
|
||||
TM1637Display disp_MIL(CLK, DIO_MIL_7SEG);
|
||||
TM1637Display disp_KGG(CLK, DIO_KGG_7SEG);
|
||||
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);
|
||||
|
||||
DNSServer dnsServer;
|
||||
AsyncWebServer server(80);
|
||||
|
||||
Ticker PartyTicker(ticker_callback, 500, 0, MILLIS);
|
||||
Ticker SerialOutputTicker(serialOut_callback, 5000, 0, MILLIS);
|
||||
Ticker InputGetterTicker(inputGetter_callback, 500, 0, MILLIS);
|
||||
Ticker FactionTicker(FactionTicker_callback, 500, 0, MILLIS);
|
||||
Ticker SerialOutputTicker(serialOutTicker_callback, 5000, 0, MILLIS);
|
||||
Ticker InputGetterTicker(inputGetterTicker_callback, 500, 0, MILLIS);
|
||||
|
||||
Parties activeParty = NONE;
|
||||
Factions activeFaction = NONE;
|
||||
|
||||
uint32_t Count_GOF = 0;
|
||||
uint32_t Count_MILIZ = 0;
|
||||
uint32_t Count_KGG = 0;
|
||||
uint8_t KGG_dot = 0;
|
||||
uint8_t GOF_dot = 0;
|
||||
uint8_t MIL_dot = 0;
|
||||
uint32_t Count_Faction_1 = 0;
|
||||
uint32_t Count_Faction_2 = 0;
|
||||
uint32_t Count_Faction_3 = 0;
|
||||
uint8_t Faction_1_dot = 0;
|
||||
uint8_t Faction_2_dot = 0;
|
||||
uint8_t Faction_3_dot = 0;
|
||||
|
||||
String processor(const String &var)
|
||||
{
|
||||
char buffer[16] = {0};
|
||||
|
||||
if (var == "POINTS_KGG")
|
||||
itoa(Count_KGG, buffer, 10);
|
||||
if (var == "POINTS_FAC_1")
|
||||
itoa(Count_Faction_1, buffer, 10);
|
||||
|
||||
if (var == "POINTS_GOF")
|
||||
itoa(Count_GOF, buffer, 10);
|
||||
if (var == "POINTS_FAC_2")
|
||||
itoa(Count_Faction_2, buffer, 10);
|
||||
|
||||
if (var == "POINTS_MILIZ")
|
||||
itoa(Count_MILIZ, buffer, 10);
|
||||
if (var == "POINTS_FAC_3")
|
||||
itoa(Count_Faction_3, buffer, 10);
|
||||
|
||||
if (var == "ACTIVE_KGG")
|
||||
return activeParty == KGG ? "ACTIVE" : "INACTIVE";
|
||||
if (var == "STATUS_FAC_1")
|
||||
return activeFaction == FACTION_1 ? "ACTIVE" : "INACTIVE";
|
||||
|
||||
if (var == "ACTIVE_GOF")
|
||||
return activeParty == GOF ? "ACTIVE" : "INACTIVE";
|
||||
if (var == "STATUS_FAC_2")
|
||||
return activeFaction == FACTION_2 ? "ACTIVE" : "INACTIVE";
|
||||
|
||||
if (var == "ACTIVE_MILIZ")
|
||||
return activeParty == MILIZ ? "ACTIVE" : "INACTIVE";
|
||||
if (var == "STATUS_FAC_3")
|
||||
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);
|
||||
}
|
||||
@ -157,38 +171,38 @@ public:
|
||||
|
||||
void SevenSeg_Output()
|
||||
{
|
||||
disp_GOF.setBrightness(activeParty == GOF ? 7 : 0);
|
||||
disp_MIL.setBrightness(activeParty == MILIZ ? 7 : 0);
|
||||
disp_KGG.setBrightness(activeParty == KGG ? 7 : 0);
|
||||
disp_FAC_1.setBrightness(activeFaction == FACTION_1 ? 7 : 0);
|
||||
disp_FAC_2.setBrightness(activeFaction == FACTION_2 ? 7 : 0);
|
||||
disp_FAC_3.setBrightness(activeFaction == FACTION_3 ? 7 : 0);
|
||||
|
||||
disp_GOF.showNumberDecEx(Count_GOF / 20, GOF_dot, true, 4, 0);
|
||||
disp_MIL.showNumberDecEx(Count_MILIZ / 20, MIL_dot, true, 4, 0);
|
||||
disp_KGG.showNumberDecEx(Count_KGG / 20, KGG_dot, true, 4, 0);
|
||||
disp_FAC_1.showNumberDecEx(Count_Faction_1 / 20, Faction_1_dot, true, 4, 0);
|
||||
disp_FAC_2.showNumberDecEx(Count_Faction_2 / 20, Faction_2_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:
|
||||
Count_GOF++;
|
||||
GOF_dot = GOF_dot == 0x80 || GOF_dot == 0x00 ? 0x10 : GOF_dot << 1;
|
||||
MIL_dot = 0;
|
||||
KGG_dot = 0;
|
||||
case FACTION_1:
|
||||
Count_Faction_1++;
|
||||
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 MILIZ:
|
||||
Count_MILIZ++;
|
||||
MIL_dot = MIL_dot == 0x80 || MIL_dot == 0x00 ? 0x10 : MIL_dot << 1;
|
||||
GOF_dot = 0;
|
||||
KGG_dot = 0;
|
||||
case FACTION_2:
|
||||
Count_Faction_2++;
|
||||
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 KGG:
|
||||
Count_KGG++;
|
||||
KGG_dot = KGG_dot == 0x80 || KGG_dot == 0x00 ? 0x10 : KGG_dot << 1;
|
||||
GOF_dot = 0;
|
||||
MIL_dot = 0;
|
||||
case FACTION_3:
|
||||
Count_Faction_3++;
|
||||
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:
|
||||
@ -196,63 +210,70 @@ void ticker_callback()
|
||||
}
|
||||
}
|
||||
|
||||
void serialOut_callback()
|
||||
void serialOutTicker_callback()
|
||||
{
|
||||
|
||||
static uint32_t SerialPrintCount = 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++;
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
|
||||
if (digitalRead(DIO_GOF_TRG) == LOW)
|
||||
activeParty = GOF;
|
||||
if (digitalRead(DIO_FAC_1_TRG) == LOW)
|
||||
activeFaction = FACTION_1;
|
||||
|
||||
if (digitalRead(DIO_KGG_TRG) == LOW)
|
||||
activeParty = KGG;
|
||||
if (digitalRead(DIO_FAC_2_TRG) == LOW)
|
||||
activeFaction = FACTION_2;
|
||||
|
||||
if (digitalRead(DIO_MIL_TRG) == LOW)
|
||||
activeParty = MILIZ;
|
||||
if (digitalRead(DIO_FAC_3_TRG) == LOW)
|
||||
activeFaction = FACTION_3;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(DIO_GOF_TRG, INPUT_PULLUP);
|
||||
pinMode(DIO_MIL_TRG, INPUT_PULLUP);
|
||||
pinMode(DIO_KGG_TRG, INPUT_PULLUP);
|
||||
pinMode(DIO_FAC_1_TRG, INPUT_PULLUP);
|
||||
pinMode(DIO_FAC_2_TRG, INPUT_PULLUP);
|
||||
pinMode(DIO_FAC_3_TRG, INPUT_PULLUP);
|
||||
|
||||
Serial.begin(9600);
|
||||
Serial.print("\n\n\n");
|
||||
|
||||
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());
|
||||
|
||||
server.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER); //only when requested from AP
|
||||
server.begin();
|
||||
|
||||
PartyTicker.start();
|
||||
FactionTicker.start();
|
||||
SerialOutputTicker.start();
|
||||
InputGetterTicker.start();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
PartyTicker.update();
|
||||
FactionTicker.update();
|
||||
SerialOutputTicker.update();
|
||||
InputGetterTicker.update();
|
||||
|
||||
@ -266,19 +287,19 @@ void loop()
|
||||
switch (input)
|
||||
{
|
||||
case 'n':
|
||||
activeParty = NONE;
|
||||
activeFaction = NONE;
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
activeParty = GOF;
|
||||
activeFaction = FACTION_1;
|
||||
break;
|
||||
|
||||
case 'k':
|
||||
activeParty = KGG;
|
||||
activeFaction = FACTION_3;
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
activeParty = MILIZ;
|
||||
activeFaction = FACTION_2;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
|
Loading…
x
Reference in New Issue
Block a user