Fixed actions and other issues

This commit is contained in:
Dionysus 2024-06-08 13:45:30 -04:00
parent a530492937
commit a15fae2fd9
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE
7 changed files with 86 additions and 59 deletions

View File

@ -1,12 +1,12 @@
#include "bootScreen.h"
#include "Display.h" #include "Display.h"
#include "IRC.h"
#include "pins.h"
#include "Speaker.h"
#include "Storage.h" #include "Storage.h"
#include "Utilities.h" #include "Utilities.h"
#include "Speaker.h"
#include "pins.h"
#include "bootScreen.h"
#include "IRC.h"
// External variables definitions
bool infoScreen = false; bool infoScreen = false;
bool configScreen = false; bool configScreen = false;
bool screenOn = true; bool screenOn = true;
@ -23,11 +23,13 @@ std::map<String, uint32_t> nickColors;
TFT_eSPI tft = TFT_eSPI(); TFT_eSPI tft = TFT_eSPI();
void addLine(String senderNick, String message, String type, bool mention, uint16_t errorColor, uint16_t reasonColor) { void addLine(String senderNick, String message, String type, bool mention, uint16_t errorColor, uint16_t reasonColor) {
if (type != "error" && nickColors.find(senderNick) == nickColors.end()) if (type != "error" && nickColors.find(senderNick) == nickColors.end())
nickColors[senderNick] = generateRandomColor(); nickColors[senderNick] = generateRandomColor();
String formattedMessage; String formattedMessage;
if (type == "join") { if (type == "join") {
formattedMessage = "JOIN " + senderNick + " has joined " + String(channel); formattedMessage = "JOIN " + senderNick + " has joined " + String(channel);
} else if (type == "part") { } else if (type == "part") {
@ -74,6 +76,7 @@ void addLine(String senderNick, String message, String type, bool mention, uint1
displayLines(); displayLines();
} }
int calculateLinesRequired(String message) { int calculateLinesRequired(String message) {
int linesRequired = 1; int linesRequired = 1;
int lineWidth = 0; int lineWidth = 0;
@ -103,6 +106,7 @@ int calculateLinesRequired(String message) {
return linesRequired; return linesRequired;
} }
void displayCenteredText(String text) { void displayCenteredText(String text) {
tft.fillScreen(TFT_BLACK); tft.fillScreen(TFT_BLACK);
tft.setTextDatum(MC_DATUM); tft.setTextDatum(MC_DATUM);
@ -110,6 +114,7 @@ void displayCenteredText(String text) {
tft.drawString(text, SCREEN_WIDTH / 2, (SCREEN_HEIGHT + STATUS_BAR_HEIGHT) / 2); tft.drawString(text, SCREEN_WIDTH / 2, (SCREEN_HEIGHT + STATUS_BAR_HEIGHT) / 2);
} }
void displayInputLine() { void displayInputLine() {
tft.fillRect(0, SCREEN_HEIGHT - INPUT_LINE_HEIGHT, SCREEN_WIDTH, INPUT_LINE_HEIGHT, TFT_BLACK); tft.fillRect(0, SCREEN_HEIGHT - INPUT_LINE_HEIGHT, SCREEN_WIDTH, INPUT_LINE_HEIGHT, TFT_BLACK);
tft.setCursor(0, SCREEN_HEIGHT - INPUT_LINE_HEIGHT); tft.setCursor(0, SCREEN_HEIGHT - INPUT_LINE_HEIGHT);
@ -132,6 +137,7 @@ void displayInputLine() {
tft.setTextColor(TFT_WHITE); tft.setTextColor(TFT_WHITE);
} }
void displayLines() { void displayLines() {
tft.fillRect(0, STATUS_BAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - STATUS_BAR_HEIGHT - INPUT_LINE_HEIGHT, TFT_BLACK); tft.fillRect(0, STATUS_BAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - STATUS_BAR_HEIGHT - INPUT_LINE_HEIGHT, TFT_BLACK);
@ -260,6 +266,7 @@ void displayLines() {
displayInputLine(); displayInputLine();
} }
void displayXBM() { void displayXBM() {
tft.fillScreen(TFT_BLACK); tft.fillScreen(TFT_BLACK);
@ -283,10 +290,12 @@ void displayXBM() {
} }
} }
uint32_t generateRandomColor() { uint32_t generateRandomColor() {
return tft.color565(random(0, 255), random(0, 255), random(0, 255)); return tft.color565(random(0, 255), random(0, 255), random(0, 255));
} }
uint16_t getColorFromCode(int colorCode) { uint16_t getColorFromCode(int colorCode) {
switch (colorCode) { switch (colorCode) {
case 0: return TFT_WHITE; case 0: return TFT_WHITE;
@ -392,6 +401,7 @@ uint16_t getColorFromCode(int colorCode) {
} }
} }
uint16_t getColorFromPercentage(int percentage) { 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 > 50) return TFT_YELLOW;
@ -399,6 +409,7 @@ uint16_t getColorFromPercentage(int percentage) {
else return TFT_RED; else return TFT_RED;
} }
void handleKeyboardInput(char key) { void handleKeyboardInput(char key) {
lastActivityTime = millis(); lastActivityTime = millis();
@ -450,6 +461,7 @@ void handleKeyboardInput(char key) {
} }
} }
void parseAndDisplay(String line) { void parseAndDisplay(String line) {
int firstSpace = line.indexOf(' '); int firstSpace = line.indexOf(' ');
int secondSpace = line.indexOf(' ', firstSpace + 1); int secondSpace = line.indexOf(' ', firstSpace + 1);
@ -518,6 +530,7 @@ void parseAndDisplay(String line) {
} }
} }
int renderFormattedMessage(String message, int cursorY, int lineHeight, bool highlightNick) { int renderFormattedMessage(String message, int cursorY, int lineHeight, bool highlightNick) {
uint16_t fgColor = TFT_WHITE; uint16_t fgColor = TFT_WHITE;
uint16_t bgColor = TFT_BLACK; uint16_t bgColor = TFT_BLACK;
@ -618,6 +631,18 @@ int renderFormattedMessage(String message, int cursorY, int lineHeight, bool hig
return cursorY; return cursorY;
} }
void setupScreen() {
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH);
setBrightness(8);
tft.begin();
tft.setRotation(1);
tft.invertDisplay(1);
Serial.println("TFT initialized");
}
void turnOffScreen() { void turnOffScreen() {
Serial.println("Screen turned off"); Serial.println("Screen turned off");
tft.writecommand(TFT_DISPOFF); tft.writecommand(TFT_DISPOFF);
@ -626,6 +651,7 @@ void turnOffScreen() {
screenOn = false; screenOn = false;
} }
void turnOnScreen() { void turnOnScreen() {
Serial.println("Screen turned on"); Serial.println("Screen turned on");
digitalWrite(TFT_BL, HIGH); digitalWrite(TFT_BL, HIGH);
@ -634,6 +660,7 @@ void turnOnScreen() {
screenOn = true; screenOn = true;
} }
void updateStatusBar() { void updateStatusBar() {
Serial.println("Updating status bar..."); Serial.println("Updating status bar...");
uint16_t darkerGrey = tft.color565(25, 25, 25); uint16_t darkerGrey = tft.color565(25, 25, 25);

View File

@ -1,19 +1,18 @@
#pragma once #pragma once
#include <TFT_eSPI.h>
#include <map> #include <map>
#include <vector> #include <vector>
#include <WiFi.h>
#include <time.h> #include <time.h>
// Constants #include <TFT_eSPI.h>
#include <WiFi.h>
#define CHAR_HEIGHT 10 #define CHAR_HEIGHT 10
#define LINE_SPACING 0 #define LINE_SPACING 0
#define STATUS_BAR_HEIGHT 10 #define STATUS_BAR_HEIGHT 10
#define INPUT_LINE_HEIGHT (CHAR_HEIGHT + LINE_SPACING) #define INPUT_LINE_HEIGHT (CHAR_HEIGHT + LINE_SPACING)
#define MAX_LINES ((SCREEN_HEIGHT - INPUT_LINE_HEIGHT - STATUS_BAR_HEIGHT) / (CHAR_HEIGHT + LINE_SPACING)) #define MAX_LINES ((SCREEN_HEIGHT - INPUT_LINE_HEIGHT - STATUS_BAR_HEIGHT) / (CHAR_HEIGHT + LINE_SPACING))
// External variables
extern bool infoScreen; extern bool infoScreen;
extern bool configScreen; extern bool configScreen;
extern bool screenOn; extern bool screenOn;
@ -30,7 +29,6 @@ extern std::map<String, uint32_t> nickColors;
extern TFT_eSPI tft; extern TFT_eSPI tft;
// Function declarations
void addLine(String senderNick, String message, String type, bool mention = false, uint16_t errorColor = TFT_WHITE, uint16_t reasonColor = TFT_WHITE); void addLine(String senderNick, String message, String type, bool mention = false, uint16_t errorColor = TFT_WHITE, uint16_t reasonColor = TFT_WHITE);
int calculateLinesRequired(String message); int calculateLinesRequired(String message);
void displayCenteredText(String text); void displayCenteredText(String text);
@ -43,6 +41,7 @@ uint16_t getColorFromPercentage(int percentage);
void handleKeyboardInput(char key); void handleKeyboardInput(char key);
void parseAndDisplay(String line); void parseAndDisplay(String line);
int renderFormattedMessage(String message, int cursorY, int lineHeight, bool highlightNick = false); int renderFormattedMessage(String message, int cursorY, int lineHeight, bool highlightNick = false);
void setupScreen();
void turnOffScreen(); void turnOffScreen();
void turnOnScreen(); void turnOnScreen();
void updateStatusBar(); void updateStatusBar();

View File

@ -7,6 +7,11 @@ bool readyToJoinChannel = false;
WiFiClient* client; WiFiClient* client;
void action(String target, String message) {
sendIRC("PRIVMSG " + String(target) + " :\001ACTION " + message + "\001");
}
bool connectToIRC() { bool connectToIRC() {
if (irc_tls) { if (irc_tls) {
Serial.println("Connecting to IRC with TLS: " + String(irc_server) + ":" + String(irc_port)); Serial.println("Connecting to IRC with TLS: " + String(irc_server) + ":" + String(irc_port));

View File

@ -9,6 +9,7 @@ extern WiFiClient* client;
extern unsigned long joinChannelTime; extern unsigned long joinChannelTime;
extern bool readyToJoinChannel; extern bool readyToJoinChannel;
void action(String target, String message);
bool connectToIRC(); bool connectToIRC();
void handleIRC(); void handleIRC();
void sendIRC(String command); void sendIRC(String command);

View File

@ -8,6 +8,7 @@ WireGuard wg;
void connectToWiFi(String ssid, String password) { void connectToWiFi(String ssid, String password) {
wifiNetworks.clear();
Serial.println("Connecting to WiFi network: " + ssid); Serial.println("Connecting to WiFi network: " + ssid);
WiFi.begin(ssid.c_str(), password.c_str()); WiFi.begin(ssid.c_str(), password.c_str());
@ -167,6 +168,14 @@ void handleWiFiSelection(char key) {
} }
void initializeNetwork() {
WiFi.mode(WIFI_STA);
WiFi.setHostname("acid-drop"); // Turn into a preference
WiFi.onEvent(WiFiEvent);
randomizeMacAddress();
}
void randomizeMacAddress() { void randomizeMacAddress() {
Serial.println("Current MAC Address: " + WiFi.macAddress()); Serial.println("Current MAC Address: " + WiFi.macAddress());
@ -178,7 +187,7 @@ void randomizeMacAddress() {
if (esp_wifi_set_mac(WIFI_IF_STA, new_mac) == ESP_OK) if (esp_wifi_set_mac(WIFI_IF_STA, new_mac) == ESP_OK)
Serial.println("New MAC Address: " + WiFi.macAddress()); Serial.println("New MAC Address: " + WiFi.macAddress());
else else
Serial.print("Failed to set new MAC Address"); Serial.println("Failed to set new MAC Address");
} }
@ -187,6 +196,8 @@ void scanWiFiNetworks() {
displayCenteredText("SCANNING WIFI"); displayCenteredText("SCANNING WIFI");
delay(1000); delay(1000);
wifiNetworks.clear();
int n = WiFi.scanNetworks(); int n = WiFi.scanNetworks();
if (n == 0) { if (n == 0) {

View File

@ -29,6 +29,7 @@ void displayWiFiNetwork(int index, int displayIndex);
String getEncryptionType(wifi_auth_mode_t encryptionType); String getEncryptionType(wifi_auth_mode_t encryptionType);
void handlePasswordInput(char key); void handlePasswordInput(char key);
void handleWiFiSelection(char key); void handleWiFiSelection(char key);
void initializeNetwork();
void randomizeMacAddress(); void randomizeMacAddress();
void scanWiFiNetworks(); void scanWiFiNetworks();
void updateSelectedNetwork(int delta); void updateSelectedNetwork(int delta);

View File

@ -2,15 +2,14 @@
#include <time.h> #include <time.h>
// Local includes // Local includes
#include "bootScreen.h"
#include "Lora.h"
#include "pins.h"
#include "Storage.h"
#include "Speaker.h"
#include "Utilities.h"
#include "Display.h" #include "Display.h"
#include "Network.h"
#include "IRC.h" #include "IRC.h"
#include "Lora.h"
#include "Network.h"
#include "pins.h"
#include "Speaker.h"
#include "Storage.h"
#include "Utilities.h"
// Timing constants // Timing constants
const unsigned long STATUS_UPDATE_INTERVAL = 15000; // 15 seconds const unsigned long STATUS_UPDATE_INTERVAL = 15000; // 15 seconds
@ -21,20 +20,21 @@ const unsigned long INACTIVITY_TIMEOUT = 30000; // 30 seconds
void setup() { void setup() {
// Initialize serial communication // Initialize serial communication
Serial.begin(115200); Serial.begin(115200);
// Wait for the serial monitor to open
//while (!Serial);
Serial.println("Booting device..."); Serial.println("Booting device...");
// Give power to the board peripherals // Give power to the board peripherals
pinMode(BOARD_POWERON, OUTPUT); pinMode(BOARD_POWERON, OUTPUT);
digitalWrite(BOARD_POWERON, HIGH); digitalWrite(BOARD_POWERON, HIGH);
// Give power to the screen // Start the I2C bus for the keyboard
pinMode(TFT_BL, OUTPUT); Wire.begin(BOARD_I2C_SDA, BOARD_I2C_SCL);
digitalWrite(TFT_BL, HIGH);
setBrightness(8); // Set the screen brightness to 50%) // Initialize the display
setupScreen();
displayXBM();
// Load preferences from storage
loadPreferences();
// Give power to the SD card // Give power to the SD card
//setupSD(); //setupSD();
@ -43,31 +43,14 @@ void setup() {
// Turn on power to the radio // Turn on power to the radio
//setupRadio(); //setupRadio();
// Start the I2C bus for the keyboard // Setup the WiFi
Wire.begin(BOARD_I2C_SDA, BOARD_I2C_SCL); initializeNetwork();
// Initialize the screen
tft.begin();
tft.setRotation(1);
tft.invertDisplay(1);
Serial.println("TFT initialized");
// Display the boot screen
displayXBM();
// Initialize the preferences
loadPreferences();
// Initialize the speaker // Initialize the speaker
setupI2S(); // Do we want to keep this open or uninstall after each use to keep resources free? setupI2S(); // Do we want to keep this open or uninstall after each use to keep resources free?
const char* rtttl_boot = "TakeOnMe:d=4,o=4,b=500:8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5,8f#5,8e5,8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5"; const char* rtttl_boot = "TakeOnMe:d=4,o=4,b=500:8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5,8f#5,8e5,8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5";
playRTTTL(rtttl_boot); playRTTTL(rtttl_boot);
// Setup the WiFi
WiFi.mode(WIFI_STA);
WiFi.setHostname("acid-drop"); // Turn into a preference
WiFi.onEvent(WiFiEvent);
randomizeMacAddress();
// Connect to WiFi if credentials are stored, otherwise scan for networks // Connect to WiFi if credentials are stored, otherwise scan for networks
if (wifi_ssid.length() > 0 && wifi_password.length() > 0) { if (wifi_ssid.length() > 0 && wifi_password.length() > 0) {