Przeglądaj źródła

:i
:q!

Please enter the commit message for your changes. Lines starting

HoMetz 6 lat temu
rodzic
commit
6f64c20b7e
3 zmienionych plików z 73 dodań i 19 usunięć
  1. 1 0
      lib/gfx-lib_blueforcer
  2. 5 4
      platformio.ini
  3. 67 15
      src/AWTRIXController.cpp

+ 1 - 0
lib/gfx-lib_blueforcer

@@ -0,0 +1 @@
+Subproject commit 5dc2075e343f5a73d17665ac250617e8e715614c

+ 5 - 4
platformio.ini

@@ -14,11 +14,12 @@ env_default = nodemcuv2
 [common]
 lib_deps_builtin =
     SPI
-    
+
 lib_deps =
     PubSubClient
     Adafruit NeoPixel
-    https://github.com/awtrix/Adafruit-GFX-Library
+    #https://github.com/awtrix/Adafruit-GFX-Library
+    #https://git.metzner.myhome-server.de/hmetzner/gfx-lib_blueforcer
     https://github.com/awtrix/FastLED_NeoMatrix
     ArduinoJson
     FastLED
@@ -28,8 +29,8 @@ lib_deps =
 platform = espressif8266
 #board = nodemcuv2
 board = d1_mini
-build_flags = -w -Wl,-Teagle.flash.4m.ld -DMQTT_MAX_PACKET_SIZE=3000
-board_build.f_cpu = 80000000L 
+build_flags = -w -Wl,-Tesp8266.flash.4m.ld -DMQTT_MAX_PACKET_SIZE=3000
+board_build.f_cpu = 80000000L
 framework = arduino
 monitor_speed = 115200
 upload_speed = 921600

+ 67 - 15
src/AWTRIXController.cpp

@@ -13,15 +13,17 @@
 #include <Fonts/TomThumb.h>
 #include <LightDependentResistor.h>
 
+String version = "0.33j";
+
 ////////////////////////////////////////////////////////////////
 ///////////////////////// Config begin /////////////////////////
 // Wifi Config
-const char *ssid = "xxxxx";
-const char *password = "xxxxx";
-char *awtrix_server = "192.168.178.39";
+const char *ssid = "SilberfishAtHome";
+const char *password = "6457328324132300AE";
+char *awtrix_server = "192.168.1.146";
 
 /// LDR Config
-#define LDR_RESISTOR 10000 //ohms
+#define LDR_RESISTOR 1000 //ohms
 #define LDR_PIN A0
 #define LDR_PHOTOCELL LightDependentResistor::GL5516
 
@@ -38,7 +40,7 @@ char *awtrix_server = "192.168.178.39";
 char *topics = "awtrixmatrix/";
 #define NUMMATRIX (32 * 8)
 CRGB leds[NUMMATRIX];
-String version = "0.32";
+
 #ifdef MATRIX_MODEV2
 FastLED_NeoMatrix *matrix = new FastLED_NeoMatrix(leds, 32, 8, NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG);
 #endif
@@ -56,6 +58,54 @@ unsigned long startTime = 0;
 unsigned long endTime = 0;
 unsigned long duration;
 
+// from http://playground.arduino.cc/Main/Utf8ascii
+// ****** UTF8-Decoder: convert UTF8-string to extended ASCII *******
+static byte cl;  // Last character buffer
+
+// Convert a single Character from UTF8 to Extended ASCII
+// Return "0" if a byte has to be ignored
+byte utf8ascii(byte ascii) {
+  if ( ascii < 128 ) // Standard ASCII-set 0..0x7F handling
+  { cl = 0;
+    return ( ascii );
+  }
+  // get previous input
+  byte last = cl;   // get last char
+  cl = ascii;       // remember actual character
+  switch (last)     // conversion depending on first UTF8-character
+  { case 0xC2: return  (ascii) - 34;  break;
+    case 0xC3: return  (ascii | 0xC0) - 34;  break;// TomThumb extended characters off by 34
+    case 0x82: if (ascii == 0xAC) return (0xEA);   // special case Euro-symbol
+  }
+  return  (0);                                     // otherwise: return zero, if character has to be ignored
+}
+
+// convert String object from UTF8 String to Extended ASCII
+String utf8ascii(String s) {
+  String r = "";
+  char c;
+  for (int i = 0; i < s.length(); i++)
+  {
+    c = utf8ascii(s.charAt(i));
+    if (c != 0) r += c;
+  }
+  return r;
+}
+
+// In Place conversion UTF8-string to Extended ASCII (ASCII is shorter!)
+void utf8ascii(char* s) {
+  int k = 0;
+  char c;
+  for (int i = 0; i < strlen(s); i++)
+  {
+    c = utf8ascii(s[i]);
+    if (c != 0)
+      s[k++] = c;
+  }
+  s[k] = 0;
+}
+
+
 String GetChipID()
 {
 	return String(ESP.getChipId());
@@ -90,6 +140,7 @@ void callback(char *topic, byte *payload, unsigned int length)
 {
 	String s_payload = String((char *)payload);
 
+
 	String s_topic = String(topic);
 	int last = s_topic.lastIndexOf("/") + 1;
 	String channel = s_topic.substring(last);
@@ -107,7 +158,7 @@ void callback(char *topic, byte *payload, unsigned int length)
 	}
 	else if (channel.equals("drawText"))
 	{
-		if (json["font"].as<String>().equals("big"))
+		 if (json["font"].as<String>().equals("big"))
 		{
 			matrix->setFont();
 			matrix->setCursor(json["x"].as<int16_t>(), json["y"].as<int16_t>() - 1);
@@ -119,7 +170,8 @@ void callback(char *topic, byte *payload, unsigned int length)
 		}
 		matrix->setTextColor(matrix->Color(json["color"][0].as<int16_t>(), json["color"][1].as<int16_t>(), json["color"][2].as<int16_t>()));
 		String text = json["text"];
-		matrix->print(text);
+
+		matrix->print(utf8ascii(text));
 	}
 	else if (channel.equals("drawBMP"))
 	{
@@ -194,13 +246,12 @@ void reconnect()
 	{
 
 		// Attempt to connect
-		if (client.connect(("AWTRIXController_" + GetChipID()).c_str(),"matrixstate",0,false,"diconnected"))
+		if (client.connect(("AWTRIXController_" + GetChipID()).c_str()))
 		{
 			// ... and resubscribe
 			client.subscribe((String(topics) + "#").c_str());
 			// ... and publish
 			client.publish("chipid", GetChipID().c_str(), true);
-			client.publish("ip", WiFi.localIP().toString().c_str(), true);
 			client.publish("matrixstate", "connected");
 		}
 		else
@@ -213,15 +264,16 @@ void reconnect()
 
 void setup()
 {
+	FastLED.addLeds<NEOPIXEL, MATRIX_PIN>(leds, NUMMATRIX).setCorrection(TypicalLEDStrip);
+	WiFi.mode(WIFI_STA);
+	WiFi.begin(ssid, password);
 	matrix->begin();
 	matrix->setTextWrap(false);
-	matrix->setBrightness(127);
+	matrix->setBrightness(80);
 	matrix->setFont(&TomThumb);
 	matrix->setCursor(0, 7);
-	matrix->print("WIFI...");
+	matrix->print("WiFi...");
 	matrix->show();
-	WiFi.mode(WIFI_STA);
-	WiFi.begin(ssid, password);
 	while (WiFi.status() != WL_CONNECTED)
 	{
 		delay(500);
@@ -230,10 +282,10 @@ void setup()
 	MDNS.begin("AWTRIXController");
 
 	photocell.setPhotocellPositionOnGround(false);
-	FastLED.addLeds<NEOPIXEL, MATRIX_PIN>(leds, NUMMATRIX).setCorrection(TypicalLEDStrip);
+
 	matrix->clear();
 	matrix->setCursor(0, 7);
-	matrix->print("READY!");
+	matrix->print("Ready!");
 	matrix->show();
 
 	httpUpdater.setup(&server);