Merge pull request #440 from mc-hamster/master

Merging from my fork into master for some cleanup, more code comments, reduce compile warnings and move the "Mode" text up a line.
pull/444/head^2
Jm Casler 2020-09-26 00:20:27 -07:00 zatwierdzone przez GitHub
commit 9c7aa02db8
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 25 dodań i 24 usunięć

Wyświetl plik

@ -33,7 +33,7 @@ void WiFiServerAPI::loop()
if (client.connected()) { if (client.connected()) {
StreamAPI::loop(); StreamAPI::loop();
} else { } else {
DEBUG_MSG("Client dropped connection, closing UDP server\n"); DEBUG_MSG("Client dropped connection, closing TCP server\n");
delete this; delete this;
} }
} }

Wyświetl plik

@ -942,7 +942,7 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i
} else if (getWifiDisconnectReason() == 200) { } else if (getWifiDisconnectReason() == 200) {
display->drawString(x, y + FONT_HEIGHT * 1, "BEACON_TIMEOUT"); display->drawString(x, y + FONT_HEIGHT * 1, "BEACON_TIMEOUT");
} else if (getWifiDisconnectReason() == 201) { } else if (getWifiDisconnectReason() == 201) {
display->drawString(x, y + FONT_HEIGHT * 1, "NO_AP_FOUND"); display->drawString(x, y + FONT_HEIGHT * 1, "AP Not Found");
} else if (getWifiDisconnectReason() == 202) { } else if (getWifiDisconnectReason() == 202) {
display->drawString(x, y + FONT_HEIGHT * 1, "AUTH_FAIL"); display->drawString(x, y + FONT_HEIGHT * 1, "AUTH_FAIL");
} else if (getWifiDisconnectReason() == 203) { } else if (getWifiDisconnectReason() == 203) {
@ -950,7 +950,7 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i
} else if (getWifiDisconnectReason() == 204) { } else if (getWifiDisconnectReason() == 204) {
display->drawString(x, y + FONT_HEIGHT * 1, "HANDSHAKE_TIMEOUT"); display->drawString(x, y + FONT_HEIGHT * 1, "HANDSHAKE_TIMEOUT");
} else if (getWifiDisconnectReason() == 205) { } else if (getWifiDisconnectReason() == 205) {
display->drawString(x, y + FONT_HEIGHT * 1, "CONNECTION_FAIL"); display->drawString(x, y + FONT_HEIGHT * 1, "Connection Failed");
} else { } else {
display->drawString(x, y + FONT_HEIGHT * 1, "Unknown Status"); display->drawString(x, y + FONT_HEIGHT * 1, "Unknown Status");
} }
@ -992,8 +992,10 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat
display->drawString(x, y, String("USB")); display->drawString(x, y, String("USB"));
} }
// TODO: Display status of the BT radio display->drawString(x + SCREEN_WIDTH - display->getStringWidth("Mode " + String(channelSettings.modem_config)),
// display->drawString(x + SCREEN_WIDTH - display->getStringWidth("BT On"), y, "BT On"); y, "Mode " + String(channelSettings.modem_config));
// Line 2 // Line 2
uint32_t currentMillis = millis(); uint32_t currentMillis = millis();
@ -1009,8 +1011,6 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat
display->drawString(x, y + FONT_HEIGHT * 1, display->drawString(x, y + FONT_HEIGHT * 1,
String(days) + "d " + (hours < 10 ? "0" : "") + String(hours) + ":" + (minutes < 10 ? "0" : "") + String(days) + "d " + (hours < 10 ? "0" : "") + String(hours) + ":" + (minutes < 10 ? "0" : "") +
String(minutes) + ":" + (seconds < 10 ? "0" : "") + String(seconds)); String(minutes) + ":" + (seconds < 10 ? "0" : "") + String(seconds));
display->drawString(x + SCREEN_WIDTH - display->getStringWidth("Mode " + String(channelSettings.modem_config)),
y + FONT_HEIGHT * 1, "Mode " + String(channelSettings.modem_config));
// Line 4 // Line 4
drawGPScoordinates(display, x, y + FONT_HEIGHT * 3, gpsStatus); drawGPScoordinates(display, x, y + FONT_HEIGHT * 3, gpsStatus);

Wyświetl plik

@ -8,9 +8,10 @@
#include <WiFi.h> #include <WiFi.h>
static void WiFiEvent(WiFiEvent_t event); static void WiFiEvent(WiFiEvent_t event);
// static void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info);
// DNS Server for the Captive Portal
DNSServer dnsServer; DNSServer dnsServer;
static WiFiServerPort *apiPort; static WiFiServerPort *apiPort;
uint8_t wifiDisconnectReason = 0; uint8_t wifiDisconnectReason = 0;
@ -60,18 +61,6 @@ void initWifi()
const char *wifiName = radioConfig.preferences.wifi_ssid; const char *wifiName = radioConfig.preferences.wifi_ssid;
const char *wifiPsw = radioConfig.preferences.wifi_password; const char *wifiPsw = radioConfig.preferences.wifi_password;
/*
if (0) {
radioConfig.preferences.wifi_ap_mode = 1;
strcpy(radioConfig.preferences.wifi_ssid, "MeshTest2");
strcpy(radioConfig.preferences.wifi_password, "12345678");
} else {
radioConfig.preferences.wifi_ap_mode = 0;
strcpy(radioConfig.preferences.wifi_ssid, "meshtastic");
strcpy(radioConfig.preferences.wifi_password, "meshtastic!");
}
*/
if (*wifiName && *wifiPsw) { if (*wifiName && *wifiPsw) {
if (radioConfig.preferences.wifi_ap_mode) { if (radioConfig.preferences.wifi_ap_mode) {
@ -89,11 +78,20 @@ void initWifi()
WiFi.onEvent(WiFiEvent); WiFi.onEvent(WiFiEvent);
// esp_wifi_set_ps(WIFI_PS_NONE); // Disable power saving // esp_wifi_set_ps(WIFI_PS_NONE); // Disable power saving
WiFiEventId_t eventID = WiFi.onEvent( //WiFiEventId_t eventID = WiFi.onEvent(
WiFi.onEvent(
[](WiFiEvent_t event, WiFiEventInfo_t info) { [](WiFiEvent_t event, WiFiEventInfo_t info) {
Serial.print("\nWiFi lost connection. Reason: "); Serial.print("\nWiFi lost connection. Reason: ");
Serial.println(info.disconnected.reason); Serial.println(info.disconnected.reason);
// wifiDisconnectReason = info.disconnected.reason;
/*
If we are disconnected from the AP for some reason,
save the error code.
For a reference to the codes:
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/wifi.html#wi-fi-reason-code
*/
wifiDisconnectReason = info.disconnected.reason;
}, },
WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED); WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
@ -125,6 +123,8 @@ static void initApiServer()
apiPort->init(); apiPort->init();
} }
} }
// Called by the Espressif SDK to
static void WiFiEvent(WiFiEvent_t event) static void WiFiEvent(WiFiEvent_t event)
{ {
DEBUG_MSG("************ [WiFi-event] event: %d ************\n", event); DEBUG_MSG("************ [WiFi-event] event: %d ************\n", event);

Wyświetl plik

@ -22,3 +22,4 @@ void handleDNSResponse();
void reconnectWiFi(); void reconnectWiFi();
uint8_t getWifiDisconnectReason(); uint8_t getWifiDisconnectReason();