acid-drop

- Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.acid.vegas/-c.git
Log | Files | Refs | Archive | README | LICENSE

commit a5e208755e9655ce98fa639d2eb7f9c2db1f17d1
parent 995529af02344e4fc351ff3a3bda329eff5054f6
Author: acidvegas <acid.vegas@acid.vegas>
Date: Thu, 6 Jun 2024 16:50:21 -0400

Fixed QUIT messages not displaying, started mainlining gotify code

Diffstat:
Asrc/Gotify.cpp | 47+++++++++++++++++++++++++++++++++++++++++++++++
Asrc/Gotify.h | 18++++++++++++++++++
Dsrc/apps/gotify.cpp | 43-------------------------------------------
Msrc/main.ino | 41+++++------------------------------------

4 files changed, 70 insertions(+), 79 deletions(-)

diff --git a/src/Gotify.cpp b/src/Gotify.cpp
@@ -0,0 +1,47 @@
+#include "Gotify.h"
+
+
+WebsocketsClient gotifyClient;
+
+const char* gotify_server = "ws://your.gotify.server.com/stream"; // Use ws:// or wss:// based on your server configuration
+const char* gotify_token = "your_gotify_app_token";
+
+unsigned long lastAttemptTime = 0;
+const unsigned long reconnectInterval = 60000; // 1 minute
+
+
+void onMessageCallback(WebsocketsMessage message) {
+    Serial.println("Gotify Notification:");
+    Serial.println(message.data());
+    playNotificationSound();
+}
+
+
+void connectToGotify() {
+    String url = String(gotify_server) + "?token=" + gotify_token;
+    gotifyClient.onMessage(onMessageCallback);
+    gotifyClient.connect(url);
+
+    if (gotifyClient.available())
+        Serial.println("Connected to Gotify WebSocket");
+    else
+        Serial.println("Failed to connect to Gotify WebSocket");
+}
+
+
+void loopGotifyWebSocket() {
+    while (true) {
+        if (!gotifyClient.available()) {
+            unsigned long currentTime = millis();
+            if (currentTime - lastAttemptTime > reconnectInterval) {
+                Serial.println("Attempting to reconnect to Gotify WebSocket...");
+                lastAttemptTime = currentTime;
+                connectToGotify();
+            }
+        } else {
+            gotifyClient.poll();
+        }
+
+        delay(10);
+    }
+}
diff --git a/src/Gotify.h b/src/Gotify.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#include <ArduinoWebsockets.h>
+
+#include "Speaker.h"
+
+using namespace websockets;
+
+extern WebsocketsClient gotifyClient;
+extern const char* gotify_server;
+extern const char* gotify_token;
+extern unsigned long lastAttemptTime;
+extern const unsigned long reconnectInterval;
+
+void onMessageCallback(WebsocketsMessage message);
+void connectToGotify();
+void loopGotifyWebSocket();
+\ No newline at end of file
diff --git a/src/apps/gotify.cpp b/src/apps/gotify.cpp
@@ -1,42 +0,0 @@
-#include <ArduinoWebsockets.h>
-
-using namespace websockets;
-
-WebsocketsClient gotifyClient;
-
-const char* gotify_server = "ws://your.gotify.server.com/stream"; // Use ws:// or wss:// based on your server configuration
-const char* gotify_token = "your_gotify_app_token";
-
-// Reconnection parameters
-unsigned long lastAttemptTime = 0;
-const unsigned long reconnectInterval = 60000; // 1 minute
-
-void onMessageCallback(WebsocketsMessage message) {
-    Serial.println("Gotify Notification:");
-    Serial.println(message.data());
-}
-
-void connectToGotify() {
-    String url = String(gotify_server) + "?token=" + gotify_token;
-    gotifyClient.onMessage(onMessageCallback);
-    gotifyClient.connect(url);
-
-    if (gotifyClient.available()) {
-        Serial.println("Connected to Gotify WebSocket");
-    } else {
-        Serial.println("Failed to connect to Gotify WebSocket");
-    }
-}
-
-void checkGotifyWebSocket() {
-    if (!gotifyClient.available()) {
-        unsigned long currentTime = millis();
-        if (currentTime - lastAttemptTime > reconnectInterval) {
-            Serial.println("Attempting to reconnect to Gotify WebSocket...");
-            lastAttemptTime = currentTime;
-            connectToGotify();
-        }
-    } else {
-        gotifyClient.poll();
-    }
-}
-\ No newline at end of file
diff --git a/src/main.ino b/src/main.ino
@@ -48,9 +48,6 @@ std::map<String, uint32_t> nickColors;
 std::vector<String> lines; // Possible rename to bufferLines ?
 std::vector<bool> mentions;
 std::vector<WiFiNetwork> wifiNetworks;
-
-// Global variables to cache preferences and buffers
-
 String inputBuffer = "";
 
 // Leftover crack variables (will be removed when preferences are done)
@@ -232,7 +229,7 @@ void loop() {
             if (readyToJoinChannel && millis() >= joinChannelTime) {
                 tft.fillScreen(TFT_BLACK);
                 updateStatusBar();
-                sendIRC("JOIN " + String(channel));
+                sendIRC("JOIN " + String(irc_channel));
                 readyToJoinChannel = false;
             }
 
@@ -244,9 +241,8 @@ void loop() {
             }
 
             // Handle inactivity timeout
-            if (screenOn && millis() - lastActivityTime > INACTIVITY_TIMEOUT) {
+            if (screenOn && millis() - lastActivityTime > INACTIVITY_TIMEOUT)
                 turnOffScreen();
-            }
         }
     }
 }
@@ -648,10 +644,10 @@ uint32_t generateRandomColor() {
 
 
 uint16_t getColorFromPercentage(int percentage) {
-    if (percentage > 75) return TFT_GREEN;
+    if      (percentage > 75) return TFT_GREEN;
     else if (percentage > 50) return TFT_YELLOW;
     else if (percentage > 25) return TFT_ORANGE;
-    else return TFT_RED;
+    else                      return TFT_RED;
 }
 
 
@@ -1169,7 +1165,7 @@ void parseAndDisplay(String line) {
         } else if (command == "PART" && line.indexOf(channel) != -1) {
             String senderNick = line.substring(1, line.indexOf('!'));
             addLine(senderNick, " has EMO-QUIT " + String(channel), "part");
-        } else if (command == "QUIT" && line.indexOf(channel) != -1) {
+        } else if (command == "QUIT")  {
             String senderNick = line.substring(1, line.indexOf('!'));
             addLine(senderNick, "", "quit");
         } else if (command == "NICK") {
@@ -1287,7 +1283,6 @@ void updateStatusBar() {
     uint16_t darkerGrey = tft.color565(25, 25, 25);
     tft.fillRect(0, 0, SCREEN_WIDTH, STATUS_BAR_HEIGHT, darkerGrey);
 
-
     // Display the time
     struct tm timeinfo;
     char timeStr[9];
@@ -1415,30 +1410,4 @@ void printDeviceInfo() {
         Serial.println("  Local IP: " + wifiLocalIP);
         Serial.println("  Gateway IP: " + wifiGatewayIP);
     }
-
-    // Display on TFT
-    tft.fillScreen(TFT_BLACK);
-    int line = 0;
-    tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print("Chip ID:       "); tft.setTextColor(TFT_WHITE); tft.println(String(chipId, HEX)); line++;
-    tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print("MAC Address:   "); tft.setTextColor(TFT_WHITE); tft.println(macAddress); line++;
-    tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print("Chip Info:     "); tft.setTextColor(TFT_WHITE); tft.println(chipInfo); line++;
-    tft.setCursor(0, line * 16); tft.setTextColor(TFT_CYAN); tft.print("Battery:       "); tft.setTextColor(TFT_WHITE); tft.println(""); line++;
-    tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print("  Pin Value:   "); tft.setTextColor(TFT_WHITE); tft.println(analogRead(34)); line++;
-    tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print("  Avg Pin Val: "); tft.setTextColor(TFT_WHITE); tft.println(BL.pinRead()); line++;
-    tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print("  Volts:       "); tft.setTextColor(TFT_WHITE); tft.println(BL.getBatteryVolts()); line++;
-    tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print("  Charge Level:"); tft.setTextColor(TFT_WHITE); tft.println(BL.getBatteryChargeLevel() + "%"); line++;
-    tft.setCursor(0, line * 16); tft.setTextColor(TFT_CYAN); tft.print("Memory:        "); tft.setTextColor(TFT_WHITE); tft.println(""); line++;
-    tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print("  Flash:       "); tft.setTextColor(TFT_WHITE); tft.println(flashInfo); line++;
-    tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print("  PSRAM:       "); tft.setTextColor(TFT_WHITE); tft.println(psramInfo); line++;
-    tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print("  Heap:        "); tft.setTextColor(TFT_WHITE); tft.println(heapInfo); line++;
-    if (WiFi.status() == WL_CONNECTED) {
-        tft.setCursor(0, line * 16); tft.setTextColor(TFT_CYAN); tft.print("WiFi Info:     "); tft.setTextColor(TFT_WHITE); tft.println(""); line++;
-        tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print("  SSID:        "); tft.setTextColor(TFT_WHITE); tft.println(wifiSSID); line++;
-        tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print("  Channel:     "); tft.setTextColor(TFT_WHITE); tft.println(wifiChannel); line++;
-        tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print("  Signal:      "); tft.setTextColor(TFT_WHITE); tft.println(wifiSignal); line++;
-        tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print("  Local IP:    "); tft.setTextColor(TFT_WHITE); tft.println(wifiLocalIP); line++;
-        tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print("  Gateway IP:  "); tft.setTextColor(TFT_WHITE); tft.println(wifiGatewayIP); line++;
-    } else {
-        tft.setCursor(0, line * 16); tft.setTextColor(TFT_CYAN); tft.print("WiFi Info:     "); tft.setTextColor(TFT_WHITE); tft.println("Not connected"); line++;
-    }
 }
 \ No newline at end of file