Compare commits

..

No commits in common. "2915399de6614532211ab96cd379ef4fa04ca2a9" and "f6014f27c2c9c393ea2fb6ec29bbd47ea98f59e2" have entirely different histories.

2 changed files with 45 additions and 69 deletions

View File

@ -43,7 +43,6 @@ The device will scan for WiFi networks on boot. Once the list is displayed, you
| --------------- | --------------------------- | | --------------- | --------------------------- |
| `/debug` | Show hardware information | | `/debug` | Show hardware information |
| `/me <message>` | Send an ACTION message | | `/me <message>` | Send an ACTION message |
| `/nick <new>` | Change your NICK on IRC |
| `/raw <data>` | Send RAW data to the server | | `/raw <data>` | Send RAW data to the server |
# Debugging over Serial # Debugging over Serial

View File

@ -293,51 +293,50 @@ void displayLines() {
tft.print(kicker); tft.print(kicker);
cursorY += CHAR_HEIGHT; cursorY += CHAR_HEIGHT;
} else if (line.startsWith("MODE ")) { } else if (line.startsWith("MODE ")) {
tft.setTextColor(TFT_YELLOW); tft.setTextColor(TFT_BLUE);
tft.print("MODE "); tft.print("MODE ");
String modeChange = line.substring(5); String modeChange = line.substring(5);
tft.setTextColor(TFT_WHITE); tft.setTextColor(TFT_WHITE);
tft.print(modeChange); tft.print(modeChange);
cursorY += CHAR_HEIGHT; cursorY += CHAR_HEIGHT;
} else if (line.startsWith("ERROR ")) { } else if (line.startsWith("* ")) { // Check for action message
tft.setTextColor(TFT_RED); int spacePos = line.indexOf(' ', 2);
tft.print("ERROR "); String senderNick = line.substring(2, spacePos);
String errorReason = line.substring(6); String actionMessage = line.substring(spacePos + 1);
tft.setTextColor(TFT_DARKGREY);
tft.print(errorReason);
cursorY += CHAR_HEIGHT;
} else if (line.startsWith("* ")) {
tft.setTextColor(TFT_MAGENTA);
tft.print("* ");
int startIndex = 2;
int endIndex = line.indexOf(' ', startIndex);
String senderNick = line.substring(startIndex, endIndex);
String actionMessage = line.substring(endIndex + 1);
tft.setTextColor(nickColors[senderNick]);
tft.print(senderNick);
tft.setTextColor(TFT_MAGENTA);
tft.print(" " + actionMessage);
cursorY += CHAR_HEIGHT;
} else {
int colonIndex = line.indexOf(':');
String senderNick = line.substring(0, colonIndex);
String message = line.substring(colonIndex + 1);
if (mention) {
tft.setTextColor(TFT_YELLOW, TFT_RED);
} else {
tft.setTextColor(nickColors[senderNick]);
}
tft.print(senderNick);
tft.setTextColor(TFT_WHITE); tft.setTextColor(TFT_WHITE);
tft.print(":" + message); tft.print("* ");
tft.setTextColor(nickColors[senderNick]);
tft.print(senderNick + " ");
tft.setTextColor(TFT_WHITE);
tft.print(actionMessage);
cursorY += CHAR_HEIGHT; cursorY += CHAR_HEIGHT;
} else {
int colonPos = line.indexOf(':');
String senderNick = line.substring(0, colonPos);
String message = line.substring(colonPos + 2);
tft.setTextColor(nickColors[senderNick]);
tft.print(senderNick + ": ");
tft.setTextColor(TFT_WHITE);
// Check if the message contains the nick and highlight it
int nickPos = message.indexOf(nick);
if (mention && nickPos != -1) {
cursorY = renderFormattedMessage(message, cursorY, CHAR_HEIGHT, true);
} else {
cursorY = renderFormattedMessage(message, cursorY, CHAR_HEIGHT, false);
} }
} }
} }
void addLine(String senderNick, String message, String type, uint16_t errorColor = TFT_WHITE, uint16_t reasonColor = TFT_WHITE) { displayInputLine();
if (type != "error" && nickColors.find(senderNick) == nickColors.end()) }
void addLine(String senderNick, String message, String type, bool mention = false) {
if (nickColors.find(senderNick) == nickColors.end())
nickColors[senderNick] = generateRandomColor(); nickColors[senderNick] = generateRandomColor();
String formattedMessage; String formattedMessage;
@ -361,9 +360,6 @@ void addLine(String senderNick, String message, String type, uint16_t errorColor
formattedMessage = "MODE " + message; formattedMessage = "MODE " + message;
} else if (type == "action") { } else if (type == "action") {
formattedMessage = "* " + senderNick + " " + message; formattedMessage = "* " + senderNick + " " + message;
} else if (type == "error") {
formattedMessage = "ERROR " + message;
senderNick = "ERROR"; // Use ERROR as senderNick to highlight it in red
} else { } else {
formattedMessage = senderNick + ": " + message; formattedMessage = senderNick + ": " + message;
} }
@ -375,17 +371,13 @@ void addLine(String senderNick, String message, String type, uint16_t errorColor
mentions.erase(mentions.begin()); mentions.erase(mentions.begin());
} }
if (type == "error") {
lines.push_back("ERROR " + message);
mentions.push_back(false);
} else {
lines.push_back(formattedMessage); lines.push_back(formattedMessage);
mentions.push_back(false); mentions.push_back(mention);
}
displayLines(); displayLines();
} }
void displayDeviceInfo() { void displayDeviceInfo() {
tft.fillScreen(TFT_BLACK); tft.fillScreen(TFT_BLACK);
printDeviceInfo(); printDeviceInfo();
@ -536,6 +528,7 @@ void parseAndDisplay(String line) {
String senderNick = line.substring(1, line.indexOf('!')); String senderNick = line.substring(1, line.indexOf('!'));
bool mention = message.indexOf(nick) != -1; bool mention = message.indexOf(nick) != -1;
// This doesn't work for some annoying reason... even with \001
if (message.startsWith("\x01ACTION ") && message.endsWith("\x01")) { if (message.startsWith("\x01ACTION ") && message.endsWith("\x01")) {
String actionMessage = message.substring(8, message.length() - 1); String actionMessage = message.substring(8, message.length() - 1);
addLine(senderNick, actionMessage, "action"); addLine(senderNick, actionMessage, "action");
@ -553,19 +546,9 @@ void parseAndDisplay(String line) {
String senderNick = line.substring(1, line.indexOf('!')); String senderNick = line.substring(1, line.indexOf('!'));
addLine(senderNick, "", "quit"); addLine(senderNick, "", "quit");
} else if (command == "NICK") { } else if (command == "NICK") {
String prefix = line.startsWith(":") ? line.substring(1, firstSpace) : ""; String oldNick = line.substring(1, line.indexOf('!'));
String newNick = line.substring(line.lastIndexOf(':') + 1); String newNick = line.substring(line.lastIndexOf(':') + 1);
if (prefix == "") { // Our own NICK changes
addLine(nick, " -> " + newNick, "nick");
nick = newNick;
} else { // Other peoples NICK change
String oldNick = prefix.substring(0, prefix.indexOf('!'));
if (oldNick == nick) {
nick = newNick; // Update global nick when we get confirmation
}
addLine(oldNick, " -> " + newNick, "nick"); addLine(oldNick, " -> " + newNick, "nick");
}
} else if (command == "KICK") { } else if (command == "KICK") {
int thirdSpace = line.indexOf(' ', secondSpace + 1); int thirdSpace = line.indexOf(' ', secondSpace + 1);
int fourthSpace = line.indexOf(' ', thirdSpace + 1); int fourthSpace = line.indexOf(' ', thirdSpace + 1);
@ -575,10 +558,6 @@ void parseAndDisplay(String line) {
} else if (command == "MODE") { } else if (command == "MODE") {
String modeChange = line.substring(secondSpace + 1); String modeChange = line.substring(secondSpace + 1);
addLine("", modeChange, "mode"); addLine("", modeChange, "mode");
} else if (command == "432") { // ERR_ERRONEUSNICKNAME
addLine("ERROR", "ERR_ERRONEUSNICKNAME", "error", TFT_RED, TFT_DARKGREY);
} else if (command == "433") { // ERR_NICKNAMEINUSE
addLine("ERROR", "ERR_NICKNAMEINUSE", "error", TFT_RED, TFT_DARKGREY);
} }
} }
} }
@ -587,12 +566,7 @@ void parseAndDisplay(String line) {
void handleKeyboardInput(char key) { void handleKeyboardInput(char key) {
if (key == '\n' || key == '\r') { // Enter if (key == '\n' || key == '\r') { // Enter
if (inputBuffer.startsWith("/nick ")) { if (inputBuffer.startsWith("/debug")) {
String newNick = inputBuffer.substring(6);
sendIRC("NICK " + newNick);
inputBuffer = "";
displayInputLine();
} else if (inputBuffer.startsWith("/debug")) {
debugMode = true; debugMode = true;
debugStartTime = millis(); debugStartTime = millis();
displayDeviceInfo(); displayDeviceInfo();
@ -611,29 +585,30 @@ void handleKeyboardInput(char key) {
} }
inputBuffer = ""; inputBuffer = "";
displayInputLine(); displayInputLine();
lastActivityTime = millis(); lastActivityTime = millis(); // Reset activity timer
if (!screenOn) { if (!screenOn) {
turnOnScreen(); turnOnScreen(); // Turn on screen and backlight
} }
} else if (key == '\b') { // Backspace } else if (key == '\b') { // Backspace
if (inputBuffer.length() > 0) { if (inputBuffer.length() > 0) {
inputBuffer.remove(inputBuffer.length() - 1); inputBuffer.remove(inputBuffer.length() - 1);
displayInputLine(); displayInputLine();
lastActivityTime = millis(); lastActivityTime = millis(); // Reset activity timer
if (!screenOn) { if (!screenOn) {
turnOnScreen(); turnOnScreen(); // Turn on screen and backlight
} }
} }
} else { } else {
inputBuffer += key; inputBuffer += key;
displayInputLine(); displayInputLine();
lastActivityTime = millis(); lastActivityTime = millis(); // Reset activity timer
if (!screenOn) { if (!screenOn) {
turnOnScreen(); turnOnScreen(); // Turn on screen and backlight
} }
} }
} }
void sendRawCommand(String command) { void sendRawCommand(String command) {
if (client.connected()) { if (client.connected()) {
sendIRC(command); sendIRC(command);
@ -649,6 +624,8 @@ char getKeyboardInput() {
if (Wire.available()) { if (Wire.available()) {
incoming = Wire.read(); incoming = Wire.read();
if (incoming != (char)0x00) { if (incoming != (char)0x00) {
Serial.print("Key: ");
Serial.println(incoming);
return incoming; return incoming;
} }
} }