Skip to content

Commit 4f4dd86

Browse files
author
Zhiquan Yeo
committed
SPECIAL: XRP Party Competition Firmware
1 parent 950b83f commit 4f4dd86

File tree

4 files changed

+51
-16
lines changed

4 files changed

+51
-16
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0
1+
1.0.0-xrpparty

include/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ class XRPConfiguration {
2424
};
2525

2626
XRPConfiguration loadConfiguration(std::string defaultAPName);
27-
NetworkMode configureNetwork(XRPConfiguration config);
27+
NetworkMode configureNetwork(XRPConfiguration config, bool fmsMode = false);
2828
XRPConfiguration generateDefaultConfig(std::string defaultAP);

src/config.cpp

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,47 @@
66

77
#include "config.h"
88

9-
NetworkMode configureNetwork(XRPConfiguration config) {
9+
NetworkMode configureNetwork(XRPConfiguration config, bool fmsMode) {
10+
// For XRP Party, we have 2 choices
11+
// If we are NOT in FMS mode (default):
12+
// Only set up AP according to the config
13+
// If we are in FMS mode
14+
// Attempt connection to the XRP FMS and fallback if necessary
1015
bool shouldUseAP = false;
1116
WiFiMulti multi;
1217

13-
if (config.networkConfig.mode == NetworkMode::AP) {
18+
if (!fmsMode) {
1419
shouldUseAP = true;
1520
}
16-
else if (config.networkConfig.mode == NetworkMode::STA) {
17-
Serial.println("[NET] Attempting to start in STA Mode");
18-
Serial.println("[NET] Trying the following networks:");
19-
for (auto netInfo : config.networkConfig.networkList) {
20-
Serial.printf("* %s\n", netInfo.first.c_str());
21-
multi.addAP(netInfo.first.c_str(), netInfo.second.c_str());
22-
}
21+
else {
22+
Serial.println("[NET] Attempting to connect to FMS");
23+
multi.addAP("XRP-FMS-NET", "xrp-fms-network");
2324

24-
// Attempt to connect
25+
// Attempt connect
2526
if (multi.run() != WL_CONNECTED) {
26-
Serial.println("[NET] Failed to connect to any network on list. Falling back to AP");
27+
Serial.println("[NET] FAILED to connect to FMS. Falling back to AP");
2728
shouldUseAP = true;
2829
}
2930
}
3031

32+
// if (config.networkConfig.mode == NetworkMode::AP || forceAP) {
33+
// shouldUseAP = true;
34+
// }
35+
// else if (config.networkConfig.mode == NetworkMode::STA) {
36+
// Serial.println("[NET] Attempting to start in STA Mode");
37+
// Serial.println("[NET] Trying the following networks:");
38+
// for (auto netInfo : config.networkConfig.networkList) {
39+
// Serial.printf("* %s\n", netInfo.first.c_str());
40+
// multi.addAP(netInfo.first.c_str(), netInfo.second.c_str());
41+
// }
42+
43+
// // Attempt to connect
44+
// if (multi.run() != WL_CONNECTED) {
45+
// Serial.println("[NET] Failed to connect to any network on list. Falling back to AP");
46+
// shouldUseAP = true;
47+
// }
48+
// }
49+
3150
if (shouldUseAP) {
3251
Serial.println("[NET] Attempting to start in AP mode");
3352
bool result = WiFi.softAP(

src/main.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const unsigned char* GetResource_VERSION(size_t* len);
2727
char chipID[20];
2828
char DEFAULT_SSID[32];
2929

30+
bool useFMSMode = false;
31+
3032
XRPConfiguration config;
3133
NetworkMode netConfigResult;
3234

@@ -57,6 +59,11 @@ void writeStatusToDisk() {
5759
size_t len;
5860
std::string versionString{reinterpret_cast<const char*>(GetResource_VERSION(&len)), len};
5961
f.printf("Version: %s\n", versionString.c_str());
62+
63+
if (useFMSMode) {
64+
f.printf("FMS MODE SELECTED\n\n");
65+
}
66+
6067
f.printf("Chip ID: %s\n", chipID);
6168
f.printf("WiFi Mode: %s\n", netConfigResult == NetworkMode::AP ? "AP" : "STA");
6269
if (netConfigResult == NetworkMode::AP) {
@@ -68,6 +75,7 @@ void writeStatusToDisk() {
6875
}
6976

7077
f.printf("IP Address: %s\n", WiFi.localIP().toString().c_str());
78+
f.printf("MAC Address: %s\n", WiFi.macAddress().c_str());
7179
f.close();
7280
}
7381

@@ -245,7 +253,6 @@ void updateLoopTime(unsigned long loopStart) {
245253
_avgLoopTimeUs = (totalTime + loopTime) / _loopTimeMeasurementCount;
246254
}
247255

248-
249256
void setup() {
250257
// Generate the default SSID using the flash ID
251258
pico_unique_board_id_t id_out;
@@ -263,6 +270,14 @@ void setup() {
263270

264271
delay(2000);
265272

273+
// SPECIAL FOR XRP PARTY
274+
// Hold down button until flashing starts to switch into FMS mode
275+
pinMode(XRP_BUILTIN_BUTTON, INPUT_PULLUP);
276+
delay(500);
277+
if (digitalRead(XRP_BUILTIN_BUTTON) == LOW) {
278+
useFMSMode = true;
279+
}
280+
266281
// Read Config
267282
config = loadConfiguration(DEFAULT_SSID);
268283

@@ -283,7 +298,8 @@ void setup() {
283298
WiFi.setHostname(DEFAULT_SSID);
284299

285300
// Use configuration information
286-
netConfigResult = configureNetwork(config);
301+
Serial.printf("[NET] Use FMS Mode? %s\n", useFMSMode ? "true" : "false");
302+
netConfigResult = configureNetwork(config, useFMSMode);
287303
Serial.printf("[NET] Actual WiFi Mode: %s\n", netConfigResult == NetworkMode::AP ? "AP" : "STA");
288304

289305
// Set up HTTP server routes
@@ -357,6 +373,6 @@ void loop1() {
357373
if (xrp::rangefinderInitialized()) {
358374
xrp::rangefinderPeriodic();
359375
}
360-
376+
361377
delay(50);
362378
}

0 commit comments

Comments
 (0)