Parcourir la source

GxEPD2_SD_Example fix

ZinggJM il y a 8 ans
Parent
commit
b019e9adf9

+ 4 - 1
README.md

@@ -33,7 +33,10 @@ New Simplified Version of GxEPD for Arduino
 - Waveshare e-paper displays with SPI: http://forum.arduino.cc/index.php?topic=487007.0
 - Good Dispay ePaper for Arduino : https://forum.arduino.cc/index.php?topic=436411.0
 
-### Version 1.0.2
+### Version 1.0.3
+- fix GxEPD2_SD_Example & GxEPD2_SD_AVR_Example
+- add GxEPD2_MultiDisplayExample (preliminary version)
+#### Version 1.0.2
 - initial release version 1.0.2
 - tested with ESP8266, ESP32, STM32F103C8T6, AVR Arduino (Pro Mini 3.3V)
 - 1.54" 3-color GxEPD2_154c can be used with paging for AVR

+ 25 - 10
examples/GxEPD2_SD_AVR_Example/GxEPD2_SD_AVR_Example.ino

@@ -88,6 +88,8 @@ void setup()
 
   drawBitmaps_200x200();
   drawBitmaps_other();
+
+  //drawBitmaps_test();
 }
 
 void loop(void)
@@ -148,6 +150,16 @@ void drawBitmaps_other()
   delay(2000);
   drawBitmapFromSD("woof.bmp", w2 - 120, h2 - 160);
   delay(2000);
+  drawBitmapFromSD("bitmap640x384_1.bmp", 0, 0);
+  delay(2000);
+}
+
+void drawBitmaps_test()
+{
+  int16_t w2 = display.WIDTH / 2;
+  int16_t h2 = display.HEIGHT / 2;
+  drawBitmapFromSD("betty_4.bmp", w2 - 102, h2 - 126);
+  delay(2000);
 }
 
 static const uint16_t input_buffer_pixels = 20; // may affect performance
@@ -220,7 +232,7 @@ void drawBitmapFromSD(const char *filename, int16_t x, int16_t y, bool with_colo
       uint16_t h = height;
       if ((x + w - 1) >= int16_t(display.WIDTH))  w = int16_t(display.WIDTH)  - x;
       if ((y + h - 1) >= int16_t(display.HEIGHT)) h = int16_t(display.HEIGHT) - y;
-      if (w < max_row_width) // handle with direct drawing
+      if (w <= max_row_width) // handle with direct drawing
       {
         valid = true;
         uint8_t bitmask = 0xFF;
@@ -255,8 +267,8 @@ void drawBitmapFromSD(const char *filename, int16_t x, int16_t y, bool with_colo
           uint32_t in_bytes = 0;
           uint8_t in_byte = 0; // for depth <= 8
           uint8_t in_bits = 0; // for depth <= 8
-          uint8_t out_byte = 0;
-          uint8_t out_color_byte = 0;
+          uint8_t out_byte = 0xFF; // white (for w%8!=0 boarder)
+          uint8_t out_color_byte = 0xFF; // white (for w%8!=0 boarder)
           uint32_t out_idx = 0;
           file.seekSet(rowPosition);
           for (uint16_t col = 0; col < w; col++) // for each pixel
@@ -316,23 +328,26 @@ void drawBitmapFromSD(const char *filename, int16_t x, int16_t y, bool with_colo
             }
             if (whitish)
             {
-              out_byte |= 0x80 >> col % 8; // not black
-              out_color_byte |= 0x80 >> col % 8; // not colored
+              //out_byte |= 0x80 >> col % 8; // not black
+              //out_color_byte |= 0x80 >> col % 8; // not colored
+              // keep white
             }
             else if (colored && with_color)
             {
-              out_byte |= 0x80 >> col % 8; // not black
+              //out_byte |= 0x80 >> col % 8; // not black
+              out_color_byte &= ~(0x80 >> col % 8); // colored
             }
             else
             {
-              out_color_byte |= 0x80 >> col % 8; // not colored
+              //out_color_byte |= 0x80 >> col % 8; // not colored
+              out_byte &= ~(0x80 >> col % 8); // black
             }
-            if (7 == col % 8)
+            if ((7 == col % 8) || (col == w - 1)) // write that last byte! (for w%8!=0 boarder)
             {
               output_row_color_buffer[out_idx] = out_color_byte;
               output_row_mono_buffer[out_idx++] = out_byte;
-              out_byte = 0;
-              out_color_byte = 0;
+              out_byte = 0xFF; // white (for w%8!=0 boarder)
+              out_color_byte = 0xFF; // white (for w%8!=0 boarder)
             }
           } // end pixel
           uint16_t yrow = y + (flip ? h - row - 1 : row);

+ 25 - 10
examples/GxEPD2_SD_Example/GxEPD2_SD_Example.ino

@@ -176,6 +176,8 @@ void setup()
 
   drawBitmaps_200x200();
   drawBitmaps_other();
+
+  //drawBitmaps_test();
 }
 
 void loop(void)
@@ -236,6 +238,16 @@ void drawBitmaps_other()
   delay(2000);
   drawBitmapFromSD("woof.bmp", w2 - 120, h2 - 160);
   delay(2000);
+  drawBitmapFromSD("bitmap640x384_1.bmp", 0, 0);
+  delay(2000);
+}
+
+void drawBitmaps_test()
+{
+  int16_t w2 = display.width() / 2;
+  int16_t h2 = display.height() / 2;
+  drawBitmapFromSD("betty_4.bmp", w2 - 102, h2 - 126);
+  delay(2000);
 }
 
 static const uint16_t input_buffer_pixels = 20; // may affect performance
@@ -307,7 +319,7 @@ void drawBitmapFromSD(const char *filename, int16_t x, int16_t y, bool with_colo
       uint16_t h = height;
       if ((x + w - 1) >= display.width())  w = display.width()  - x;
       if ((y + h - 1) >= display.height()) h = display.height() - y;
-      if (w < max_row_width) // handle with direct drawing
+      if (w <= max_row_width) // handle with direct drawing
       {
         valid = true;
         uint8_t bitmask = 0xFF;
@@ -342,8 +354,8 @@ void drawBitmapFromSD(const char *filename, int16_t x, int16_t y, bool with_colo
           uint32_t in_bytes = 0;
           uint8_t in_byte = 0; // for depth <= 8
           uint8_t in_bits = 0; // for depth <= 8
-          uint8_t out_byte = 0;
-          uint8_t out_color_byte = 0;
+          uint8_t out_byte = 0xFF; // white (for w%8!=0 boarder)
+          uint8_t out_color_byte = 0xFF; // white (for w%8!=0 boarder)
           uint32_t out_idx = 0;
           file.seekSet(rowPosition);
           for (uint16_t col = 0; col < w; col++) // for each pixel
@@ -403,23 +415,26 @@ void drawBitmapFromSD(const char *filename, int16_t x, int16_t y, bool with_colo
             }
             if (whitish)
             {
-              out_byte |= 0x80 >> col % 8; // not black
-              out_color_byte |= 0x80 >> col % 8; // not colored
+              //out_byte |= 0x80 >> col % 8; // not black
+              //out_color_byte |= 0x80 >> col % 8; // not colored
+              // keep white
             }
             else if (colored && with_color)
             {
-              out_byte |= 0x80 >> col % 8; // not black
+              //out_byte |= 0x80 >> col % 8; // not black
+              out_color_byte &= ~(0x80 >> col % 8); // colored
             }
             else
             {
-              out_color_byte |= 0x80 >> col % 8; // not colored
+              //out_color_byte |= 0x80 >> col % 8; // not colored
+              out_byte &= ~(0x80 >> col % 8); // black
             }
-            if (7 == col % 8)
+            if ((7 == col % 8) || (col == w - 1)) // write that last byte! (for w%8!=0 boarder)
             {
               output_row_color_buffer[out_idx] = out_color_byte;
               output_row_mono_buffer[out_idx++] = out_byte;
-              out_byte = 0;
-              out_color_byte = 0;
+              out_byte = 0xFF; // white (for w%8!=0 boarder)
+              out_color_byte = 0xFF; // white (for w%8!=0 boarder)
             }
           } // end pixel
           uint16_t yrow = y + (flip ? h - row - 1 : row);

+ 1 - 1
library.properties

@@ -1,5 +1,5 @@
 name=GxEPD2
-version=1.0.2
+version=1.0.3
 author=Jean-Marc Zingg
 maintainer=Jean-Marc Zingg
 sentence=Display Library for SPI e-paper panels from Dalian Good Display and boards from Waveshare.