Skip to content

Commit

Permalink
Added different text colours to the setup sequence (#94)
Browse files Browse the repository at this point in the history
* Added some colours to the setup sequence

* Removed format stuff
  • Loading branch information
Martinius79 authored Oct 31, 2024
1 parent 4b23b15 commit 0f2e28e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 36 deletions.
25 changes: 13 additions & 12 deletions EleksTubeHAX_pio/src/WiFi_WPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ void WifiBegin() {
} else {
// data is saved, connect now
// WiFi credentials are known, connect
tfts.println("Joining wifi");
tfts.println("Joining WiFi");
tfts.println(stored_config.config.wifi.ssid);
Serial.print("Joining wifi ");
Serial.print("Joining WiFi ");
Serial.println(stored_config.config.wifi.ssid);

// https://stackoverflow.com/questions/48024780/esp32-wps-reconnect-on-power-on
Expand All @@ -121,18 +121,20 @@ void WifiBegin() {
}
}
}
#else ////NO WPS -- Hard coded credentials
#else //NO WPS -- Try using hard coded credentials

WiFi.begin(WIFI_SSID, WIFI_PASSWD);
WiFi.onEvent(WiFiEvent);
unsigned long StartTime = millis();
while ((WiFi.status() != WL_CONNECTED)) {
delay(500);
tfts.print(".");
Serial.print(".");
tfts.print(">");
Serial.print(">");
if ((millis() - StartTime) > (WIFI_CONNECT_TIMEOUT_SEC * 1000)) {
Serial.println("\r\nWiFi connection timeout!");
tfts.setTextColor(TFT_RED, TFT_BLACK);
tfts.println("\nTIMEOUT!");
tfts.setTextColor(TFT_WHITE, TFT_BLACK);
Serial.println("\r\nWiFi connection timeout!");
WifiState = disconnected;
return; // exit loop, exit procedure, continue clock startup
}
Expand All @@ -142,10 +144,9 @@ void WifiBegin() {


WifiState = connected;

tfts.println("\n Connected!");
tfts.println(WiFi.localIP());

tfts.println("\nConnected! IP:");
tfts.println(WiFi.localIP());
Serial.println("");
Serial.print("Connected to ");
Serial.println(WiFi.SSID());
Expand All @@ -168,7 +169,7 @@ void WiFiStartWps() {
sprintf(stored_config.config.wifi.ssid, "");
sprintf(stored_config.config.wifi.password, "");
stored_config.config.wifi.WPS_connected = 0x11; // invalid = different than 0x55
Serial.print("Saving config.");
Serial.println(""); Serial.print("Saving config! Triggered from WPS start...");
stored_config.save();
Serial.println(" Done.");

Expand Down Expand Up @@ -199,13 +200,13 @@ void WiFiStartWps() {
Serial.print(".");
}
tfts.setTextColor(TFT_WHITE, TFT_BLACK);
Serial.print("Saving config.");
sprintf(stored_config.config.wifi.ssid, "%s", WiFi.SSID());
sprintf(stored_config.config.wifi.ssid, "%s", WiFi.SSID());
// memset(stored_config.config.wifi.ssid, '\0', sizeof(stored_config.config.wifi.ssid));
// strcpy(stored_config.config.wifi.ssid, WiFi.SSID());

sprintf(stored_config.config.wifi.password, ""); // can't save a password from WPS
stored_config.config.wifi.WPS_connected = StoredConfig::valid;
Serial.println(); Serial.print("Saving config! Triggered from WPS success...");
stored_config.save();
Serial.println(" WPS finished.");
}
Expand Down
75 changes: 51 additions & 24 deletions EleksTubeHAX_pio/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,52 +74,78 @@ void setup() {
buttons.begin();
menu.begin();

#ifdef HARDWARE_NovelLife_SE_CLOCK // NovelLife_SE Clone XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//Init the Gesture sensor
tfts.println("Gesture sensor start");
GestureStart(); //TODO put into class
#endif

// Setup the displays (TFTs) initaly and show bootup message(s)
tfts.begin(); // and count number of clock faces available
tfts.fillScreen(TFT_BLACK);
tfts.setTextColor(TFT_WHITE, TFT_BLACK);
tfts.setCursor(0, 0, 2); // Font 2. 16 pixel high
tfts.println("setup...");
tfts.println("Starting Setup...");

#ifdef HARDWARE_NovelLife_SE_CLOCK // NovelLife_SE Clone XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//Init the Gesture sensor
tfts.setTextColor(TFT_ORANGE, TFT_BLACK);
tfts.print("Gest start...");
Serial.print("Gesture Sensor start...");
GestureStart(); //TODO put into class
tfts.println("Done!");
Serial.println("Done!");
tfts.setTextColor(TFT_WHITE, TFT_BLACK);
#endif

// Setup WiFi connection. Must be done before setting up Clock.
// This is done outside Clock so the network can be used for other things.
// WiFiBegin(&stored_config.config.wifi);
tfts.println("WiFi start");
tfts.setTextColor(TFT_DARKGREEN, TFT_BLACK);
tfts.println("WiFi start...");
Serial.println("WiFi start...");
WifiBegin();

// wait for a bit before querying NTP
tfts.setTextColor(TFT_WHITE, TFT_BLACK);

// wait a bit (5x100ms = 0.5 sec) before querying NTP
for (uint8_t ndx=0; ndx < 5; ndx++) {
tfts.print(">");
delay(100);
}
tfts.println("");

// Setup the clock. It needs WiFi to be established already.
tfts.println("Clock start");
tfts.setTextColor(TFT_MAGENTA, TFT_BLACK);
tfts.print("Clock start...");
Serial.print("Clock start...");
uclock.begin(&stored_config.config.uclock);
tfts.println("Done!");
Serial.println("Done!");
tfts.setTextColor(TFT_WHITE, TFT_BLACK);

// Setup MQTT
tfts.println("MQTT start");
tfts.setTextColor(TFT_YELLOW, TFT_BLACK);
tfts.print("MQTT start...");
Serial.print("MQTT start...");
MqttStart();
tfts.println("Done!");
Serial.println("Done!");
tfts.setTextColor(TFT_WHITE, TFT_BLACK);

#ifdef GEOLOCATION_ENABLED
tfts.println("Geoloc query");
tfts.setTextColor(TFT_NAVY, TFT_BLACK);
tfts.println("GeoLoc query...");
Serial.println("GeoLoc query...");
if (GetGeoLocationTimeZoneOffset()) {
tfts.print("TZ: ");
Serial.print("TZ: ");
tfts.println(GeoLocTZoffset);
Serial.println(GeoLocTZoffset);
uclock.setTimeZoneOffset(GeoLocTZoffset * 3600);
Serial.print("Saving config...");
stored_config.save();
Serial.println(" Done.");
Serial.println();
Serial.print("Saving config! Triggerd by timezone change...");
stored_config.save();
tfts.println("Done!");
Serial.println("Done!");
tfts.setTextColor(TFT_WHITE, TFT_BLACK);
} else {
Serial.println("Geolocation failed.");
tfts.println("Geo FAILED");
tfts.setTextColor(TFT_RED, TFT_BLACK);
tfts.println("GeoLoc FAILED");
Serial.println("GeoLoc failed!");
tfts.setTextColor(TFT_WHITE, TFT_BLACK);
}
#endif

Expand All @@ -133,9 +159,11 @@ void setup() {
}
tfts.current_graphic = uclock.getActiveGraphicIdx();

tfts.println("Done with setup.");
tfts.setTextColor(TFT_WHITE, TFT_BLACK);
tfts.println("Done with Setup!");
Serial.println("Done with Setup!");

// Leave boot up messages on screen for a few seconds.
// Leave boot up messages on screen for a few seconds (10x200ms = 2 sec)
for (uint8_t ndx=0; ndx < 10; ndx++) {
tfts.print(">");
delay(200);
Expand All @@ -144,7 +172,7 @@ void setup() {
// Start up the clock displays.
tfts.fillScreen(TFT_BLACK);
uclock.loop();
updateClockDisplay(TFTs::force);
updateClockDisplay(TFTs::force); // Draw all the clock digits
Serial.println("Setup finished.");
}

Expand Down Expand Up @@ -383,8 +411,7 @@ void loop() {

EveryFullHour(true); // night or daytime

// Update the clock.
updateClockDisplay();
updateClockDisplay(); // Draw only the changed clock digits!

UpdateDstEveryNight();

Expand Down

0 comments on commit 0f2e28e

Please sign in to comment.