Browse Source

GxEPD2_SD_Example & GxEPD2_WiFi_Example for ESP32

ZinggJM 8 năm trước cách đây
mục cha
commit
f4fc11687d

+ 26 - 3
examples/GxEPD2_SD_Example/GxEPD2_SD_Example.ino

@@ -44,16 +44,28 @@
 #include <GxEPD2_3C.h>
 #include <Fonts/FreeMonoBold9pt7b.h>
 
+#if defined(ESP32)
+
+// has support for FAT32 support with long filenames
+#include "FS.h"
+#include "SD.h"
+#include "SPI.h"
+#define SdFile File
+#define seekSet seek
+
+#else
+
 // include SdFat for FAT32 support with long filenames; available through Library Manager
 #include <SdFat.h>
-
 SdFat SD;
 
+#endif
+
 #if defined (ESP8266)
 #define SD_CS SS  // e.g. for RobotDyn Wemos D1 mini SD board
 #define EPD_CS D1 // alternative I use with RobotDyn Wemos D1 mini SD board
 // select one and adapt to your mapping, can use full buffer size (full HEIGHT)
-GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
+//GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
 //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
 //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
 //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
@@ -95,6 +107,8 @@ GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=D8*/ EPD_CS, /
 #endif
 
 #if defined(ESP32)
+#define SD_CS 2  // adapt to your wiring
+#define EPD_CS SS // adapt to your wiring
 // select one and adapt to your mapping, can use full buffer size (full HEIGHT)
 //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
 //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
@@ -194,7 +208,7 @@ void drawBitmaps_200x200()
   delay(2000);
   drawBitmapFromSD("sixth200x200.bmp", x, y);
   delay(2000);
-  drawBitmapFromSD("senventh200x200.bmp", x, y);
+  drawBitmapFromSD("seventh200x200.bmp", x, y);
   delay(2000);
   drawBitmapFromSD("eighth200x200.bmp", x, y);
   delay(2000);
@@ -254,11 +268,20 @@ void drawBitmapFromSD(const char *filename, int16_t x, int16_t y, bool with_colo
   Serial.print("Loading image '");
   Serial.print(filename);
   Serial.println('\'');
+#if defined(ESP32)
+  file = SD.open(String("/") + filename, FILE_READ);
+  if (!file)
+  {
+    Serial.print("File not found");
+    return;
+  }
+#else
   if (!file.open(filename, FILE_READ))
   {
     Serial.print("File not found");
     return;
   }
+#endif
   // Parse BMP header
   if (read16(file) == 0x4D42) // BMP signature
   {

+ 11 - 8
examples/GxEPD2_WiFi_Example/GxEPD2_WiFi_Example.ino

@@ -42,7 +42,7 @@
 
 #if defined (ESP8266)
 // select one and adapt to your mapping, can use full buffer size (full HEIGHT)
-GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
+//GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
 //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
 //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
 //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
@@ -138,8 +138,9 @@ GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=D8*/ EPD_CS, /
 //GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT(GxEPD2_750c)> display(GxEPD2_750c(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
 #endif
 
-
+#if defined (ESP8266)
 #include <ESP8266WiFi.h>
+#endif
 #include <WiFiClient.h>
 #include <WiFiClientSecure.h>
 
@@ -527,6 +528,7 @@ void showBitmapFrom_HTTPS(const char* host, const char* path, const char* filena
     Serial.println("connection failed");
     return;
   }
+#if defined (ESP8266)
   if (fingerprint)
   {
     if (client.verify(fingerprint, host))
@@ -539,6 +541,7 @@ void showBitmapFrom_HTTPS(const char* host, const char* path, const char* filena
       return;
     }
   }
+#endif
   Serial.print("requesting URL: ");
   Serial.println(String("https://") + host + path + filename);
   client.print(String("GET ") + path + filename + " HTTP/1.1\r\n" +
@@ -689,15 +692,15 @@ void showBitmapFrom_HTTPS(const char* host, const char* path, const char* filena
                   uint8_t msb = input_buffer[in_idx++];
                   if (format == 0) // 555
                   {
-                    blue  = (lsb & 0x1F);
-                    green = ((msb & 0x03) << 3) | ((lsb & 0xE0) >> 5);
-                    red   = (msb & 0x7C) >> 2;
+                    blue  = (lsb & 0x1F) << 3;
+                    green = ((msb & 0x03) << 6) | ((lsb & 0xE0) >> 2);
+                    red   = (msb & 0x7C) << 1;
                   }
                   else // 565
                   {
-                    blue  = (lsb & 0x1F);
-                    green = ((msb & 0x07) << 3) | ((lsb & 0xE0) >> 5);
-                    red   = (msb & 0xF8) >> 3;
+                    blue  = (lsb & 0x1F) << 3;
+                    green = ((msb & 0x07) << 5) | ((lsb & 0xE0) >> 3);
+                    red   = (msb & 0xF8);
                   }
                   whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
                   colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?