From a7659ee567ed41251ac4a13b61b1c71ffb110380 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Sun, 31 May 2020 23:57:39 +0200 Subject: [PATCH] Added hostname display --- src/displays/statusdisplay.h | 30 ++++++++++++++++++------------ src/globals.h | 2 +- src/main.cpp | 21 +++++++++++++++++---- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/displays/statusdisplay.h b/src/displays/statusdisplay.h index 8430745..860a80c 100644 --- a/src/displays/statusdisplay.h +++ b/src/displays/statusdisplay.h @@ -95,12 +95,15 @@ private: BoardStatus m_frontStatus{42}; BoardStatus m_backStatus{142}; - Label m_labelWifiStatus{35, 266}; // 120, 15 - Label m_labelLimit0{205, 266}; // 35, 15 - Label m_labelIpAddress{25, 281}; // 130, 15 - Label m_labelLimit1{205, 281}; // 35, 15 - Label m_labelPerformance{85, 296}; // 40, 15 - Label m_labelMode{165, 296}; // 75, 15 + Label m_labelWifiStatus{35, bottomLines[0]}; // 120, 15 + Label m_labelLimit0{205, bottomLines[0]}; // 35, 15 + Label m_labelIpAddress{25, bottomLines[1]}; // 130, 15 + Label m_labelLimit1{205, bottomLines[1]}; // 35, 15 + Label m_labelPerformance{85, bottomLines[2]}; // 40, 15 + Label m_labelMode{165, bottomLines[2]}; // 75, 15 + Label m_labelName{40, bottomLines[3]}; // 40, 15 + + static const constexpr int bottomLines[4] { 251, 266, 281, 296 }; }; void StatusDisplay::initScreen() @@ -122,18 +125,20 @@ void StatusDisplay::initScreen() m_backStatus.start(); tft.setTextFont(2); - tft.drawString("WiFi:", 0, 266); + tft.drawString("WiFi:", 0, bottomLines[0]); m_labelWifiStatus.start(); - tft.drawString("Limit0:", 160, 266); + tft.drawString("Limit0:", 160, bottomLines[0]); m_labelLimit0.start(); - tft.drawString("IP:", 0, 281); + tft.drawString("IP:", 0, bottomLines[1]); m_labelIpAddress.start(); - tft.drawString("Limit1:", 160, 281); + tft.drawString("Limit1:", 160, bottomLines[1]); m_labelLimit1.start(); - tft.drawString("Performance:", 0, 296); + tft.drawString("Performance:", 0, bottomLines[2]); m_labelPerformance.start(); - tft.drawString("Mode:", 125, 296); + tft.drawString("Mode:", 125, bottomLines[2]); m_labelMode.start(); + tft.drawString("Name:", 0, bottomLines[3]); + m_labelName.start(); tft.setTextColor(TFT_WHITE, TFT_BLACK); } @@ -158,6 +163,7 @@ void StatusDisplay::redraw() m_labelLimit1.redraw(String{front.command.left.iDcMax} + "A"); m_labelPerformance.redraw(String{performance.last}); m_labelMode.redraw(currentMode->displayName()); + m_labelName.redraw(&deviceName[0]); } void StatusDisplay::rotate(int offset) diff --git a/src/globals.h b/src/globals.h index e36702c..8195bc7 100644 --- a/src/globals.h +++ b/src/globals.h @@ -24,7 +24,7 @@ float gametrakX, gametrakY, gametrakDist; #endif float avgSpeed, avgSpeedKmh, sumCurrent, sumAbsoluteCurrent; -char deviceName[16]; +char deviceName[32]; Settings settings; SettingsSaver settingsSaver; diff --git a/src/main.cpp b/src/main.cpp index 3095bb2..a3dc37f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -67,12 +67,25 @@ void setup() { uint8_t macAddress[6]; WiFi.macAddress(&macAddress[0]); - std::sprintf(deviceName, __STRINGIFY(DEVICE_PREFIX) "_%02hhx%02hhx%02hhx", macAddress[3], macAddress[4], macAddress[5]); + #define STRING2(s) #s + #define STRING(s) STRING2(s) + std::sprintf(deviceName, STRING(DEVICE_PREFIX) "_%02hhx%02hhx%02hhx", macAddress[3], macAddress[4], macAddress[5]); } - WiFi.mode(WIFI_AP_STA); - WiFi.softAP(deviceName, "Passwort_123"); - WiFi.begin("realraum", "r3alraum"); + if (!WiFi.setHostname(deviceName)) + Serial.println("Could not setHostname"); + + if (!WiFi.softAPsetHostname(deviceName)) + Serial.println("Could not softAPsetHostname"); + + if (!WiFi.mode(WIFI_AP_STA)) + Serial.println("Could not set mode to WIFI_AP_STA"); + + if (!WiFi.softAP(deviceName, "Passwort_123")) + Serial.println("Could not softAP"); + + if (!WiFi.begin("realraum", "r3alraum")) + Serial.println("Could not begin WiFi"); if (settings.bluetoothMode == BluetoothMode::Master) {