forked from fmueller/esp8266-led-marquee-sign-controller
		
	Compare commits
	
		
			3 Commits
		
	
	
		
			c78fde5d9f
			...
			165540c120
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 165540c120 | |||
| ad4ee16f19 | |||
| 610f86750b | 
@@ -14,7 +14,7 @@ framework = arduino
 | 
				
			|||||||
monitor_speed = 115200
 | 
					monitor_speed = 115200
 | 
				
			||||||
upload_speed = 500000
 | 
					upload_speed = 500000
 | 
				
			||||||
upload_protocol = espota
 | 
					upload_protocol = espota
 | 
				
			||||||
upload_port = led-marquee-sign.fablab.local
 | 
					upload_port = led-marquee-sign
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Serial1 (sign data) maps to D4 by default
 | 
					# Serial1 (sign data) maps to D4 by default
 | 
				
			||||||
[env:d1_mini]
 | 
					[env:d1_mini]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,6 +19,7 @@ static SocketServer socketServer;
 | 
				
			|||||||
#define AIO_SERVERPORT  credentials::mqtt_port
 | 
					#define AIO_SERVERPORT  credentials::mqtt_port
 | 
				
			||||||
#define AIO_USERNAME    credentials::mqtt_username.c_str()
 | 
					#define AIO_USERNAME    credentials::mqtt_username.c_str()
 | 
				
			||||||
#define AIO_KEY         credentials::mqtt_password.c_str()
 | 
					#define AIO_KEY         credentials::mqtt_password.c_str()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WiFiClient client;
 | 
					WiFiClient client;
 | 
				
			||||||
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
 | 
					Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
 | 
				
			||||||
Adafruit_MQTT_Subscribe mqtt_subscribe_topic = Adafruit_MQTT_Subscribe(&mqtt, "homeassistant/marquee_sign/text");
 | 
					Adafruit_MQTT_Subscribe mqtt_subscribe_topic = Adafruit_MQTT_Subscribe(&mqtt, "homeassistant/marquee_sign/text");
 | 
				
			||||||
@@ -90,7 +91,8 @@ void MQTT_connect() {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    uint8_t retries = 6;
 | 
					    uint8_t retries = 6;
 | 
				
			||||||
    while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
 | 
					    // connect will return 0 for connected
 | 
				
			||||||
 | 
					    while ((ret = mqtt.connect()) != 0) {
 | 
				
			||||||
        mqtt.disconnect();
 | 
					        mqtt.disconnect();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // wait 10s till next try
 | 
					        // wait 10s till next try
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										85
									
								
								src/util.h
									
									
									
									
									
								
							
							
						
						
									
										85
									
								
								src/util.h
									
									
									
									
									
								
							@@ -1,5 +1,9 @@
 | 
				
			|||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <map>
 | 
				
			||||||
 | 
					#include <set>
 | 
				
			||||||
 | 
					#include <unordered_map>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TODO: reverse engineer builtin and custom bitmaps
 | 
					// TODO: reverse engineer builtin and custom bitmaps
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// seems like our sign listens to messages on this address
 | 
					// seems like our sign listens to messages on this address
 | 
				
			||||||
@@ -246,6 +250,82 @@ enum class ExtendedChar {
 | 
				
			|||||||
    GreekSmallLetterPhi = 0xed,
 | 
					    GreekSmallLetterPhi = 0xed,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					std::unordered_map<uint16_t, uint8_t> createUnicodeToCP437Map() {
 | 
				
			||||||
 | 
					    std::unordered_map<uint16_t, uint8_t> cp437_map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    cp437_map[0x00E4] = 0x84;  // ä in UTF-16
 | 
				
			||||||
 | 
					    cp437_map[0xC3A4] = 0x84;  // ä in UTF-8
 | 
				
			||||||
 | 
					    cp437_map[0x00F6] = 0x94;  // ö in UTF-16
 | 
				
			||||||
 | 
					    cp437_map[0xC3B6] = 0x94;  // ö in UTF-8
 | 
				
			||||||
 | 
					    cp437_map[0x00FC] = 0x81;  // ü in UTF-16
 | 
				
			||||||
 | 
					    cp437_map[0xC3BC] = 0x81;  // ü in UTF-8
 | 
				
			||||||
 | 
					    cp437_map[0x00C4] = 0x8E;  // Ä in UTF-16
 | 
				
			||||||
 | 
					    cp437_map[0xC384] = 0x8E;  // Ä in UTF-8
 | 
				
			||||||
 | 
					    cp437_map[0x00D6] = 0x99;  // Ö in UTF-16
 | 
				
			||||||
 | 
					    cp437_map[0xC396] = 0x99;  // Ö in UTF-8
 | 
				
			||||||
 | 
					    cp437_map[0x00DC] = 0x9A;  // Ü in UTF-16
 | 
				
			||||||
 | 
					    cp437_map[0xC39C] = 0x9A;  // Ü in UTF-8
 | 
				
			||||||
 | 
					    cp437_map[0x00DF] = 0xE1;  // ß in UTF-16
 | 
				
			||||||
 | 
					    cp437_map[0xC39F] = 0xE1;  // ß in UTF-8
 | 
				
			||||||
 | 
					    cp437_map[0x20AC] = 0xB1;  // € in UTF-16
 | 
				
			||||||
 | 
					    cp437_map[0xE282AC] = 0xB1;  // € in UTF-8 (3 Bytes)
 | 
				
			||||||
 | 
					    cp437_map[0x00B5] = 0xE6;  // µ in UTF-16
 | 
				
			||||||
 | 
					    cp437_map[0xC2B5] = 0xE6;  // µ in UTF-8
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return cp437_map;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					String convertToCP437(const String& input) {
 | 
				
			||||||
 | 
					    std::unordered_map<uint16_t, uint8_t> cp437_map = createUnicodeToCP437Map();
 | 
				
			||||||
 | 
					    String output = "";
 | 
				
			||||||
 | 
					    size_t len = input.length();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (size_t i = 0; i < len; i++) {
 | 
				
			||||||
 | 
					        char ch = input[i];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // UTF-8 detection: check for 3 byte UTF-8
 | 
				
			||||||
 | 
					        if ((ch & 0xF0) == 0xE0) {
 | 
				
			||||||
 | 
					            if (i + 2 < len) {
 | 
				
			||||||
 | 
					                uint32_t utf8_char = ((uint8_t)input[i] << 16) | ((uint8_t)input[i + 1] << 8) | (uint8_t)input[i + 2];
 | 
				
			||||||
 | 
					                // skip 2 additional bytes
 | 
				
			||||||
 | 
					                i += 2;
 | 
				
			||||||
 | 
					                if (cp437_map.find(utf8_char) != cp437_map.end()) {
 | 
				
			||||||
 | 
					                    output += static_cast<char>(cp437_map[utf8_char]);
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        // UTF-8 detection: check for 2 byte UTF-8
 | 
				
			||||||
 | 
					        else if ((ch & 0xE0) == 0xC0) {
 | 
				
			||||||
 | 
					            if (i + 1 < len) {
 | 
				
			||||||
 | 
					                uint16_t utf8_char = ((uint8_t)input[i] << 8) | (uint8_t)input[i + 1];
 | 
				
			||||||
 | 
					                // skip second byte
 | 
				
			||||||
 | 
					                i++;
 | 
				
			||||||
 | 
					                if (cp437_map.find(utf8_char) != cp437_map.end()) {
 | 
				
			||||||
 | 
					                    output += static_cast<char>(cp437_map[utf8_char]);
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        // single UTF-16 character (or plain ANSI character)
 | 
				
			||||||
 | 
					        else if ((uint8_t)ch < 0x80) {
 | 
				
			||||||
 | 
					            // keep ASCII as is
 | 
				
			||||||
 | 
					            output += ch;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else {
 | 
				
			||||||
 | 
					            uint16_t utf16_char = (uint8_t)ch;
 | 
				
			||||||
 | 
					            // check if character is in UTF-16 range, fallback to ?
 | 
				
			||||||
 | 
					            if (cp437_map.find(utf16_char) != cp437_map.end()) {
 | 
				
			||||||
 | 
					                output += static_cast<char>(cp437_map[utf16_char]);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                output += '?';
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return output;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
String hexDump(String in) {
 | 
					String hexDump(String in) {
 | 
				
			||||||
    String out;
 | 
					    String out;
 | 
				
			||||||
    for (size_t i = 0; i < in.length(); ++i) {
 | 
					    for (size_t i = 0; i < in.length(); ++i) {
 | 
				
			||||||
@@ -287,7 +367,6 @@ String hexDump(String in) {
 | 
				
			|||||||
 *   - stay time: 4
 | 
					 *   - stay time: 4
 | 
				
			||||||
 *   - brightness: bright
 | 
					 *   - brightness: bright
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					 | 
				
			||||||
void sendTextToSign(
 | 
					void sendTextToSign(
 | 
				
			||||||
    const String &text,
 | 
					    const String &text,
 | 
				
			||||||
    const Method method = Method::Cyclic,
 | 
					    const Method method = Method::Cyclic,
 | 
				
			||||||
@@ -307,7 +386,9 @@ void sendTextToSign(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    Serial.println("Sending text: \"" + text + "\"");
 | 
					    Serial.println("Sending text: \"" + text + "\"");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    String toSend = "~" + String(SIGN_ADDRESS, DEC) + "~f01" + (char) method + "\\" + (char) brightness + "\\Y" + String(speed, DEC) + "\\Z" + String(stayTime, DEC) + "\\" + (char) fontType + text + "\r\r\r";
 | 
					    String translatedText = convertToCP437(text);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    String toSend = "~" + String(SIGN_ADDRESS, DEC) + "~f01" + (char) method + "\\" + (char) brightness + "\\Y" + String(speed, DEC) + "\\Z" + String(stayTime, DEC) + "\\" + (char) fontType + translatedText + "\r\r\r";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Serial1.print(toSend);
 | 
					    Serial1.print(toSend);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user