11#include " display.h"
2- // #include "svgs/svgs.h"
3-
4- // Add more as needed, with appropriate external declarations
52
63// Assuming dimensions for simplicity
74#define BITMAP_WIDTH 128
@@ -17,140 +14,61 @@ Display::begin()
1714{
1815 tft.init ();
1916 tft.setRotation (2 );
20- tft.fillScreen (TFT_WHITE); // Start with a black screen
17+ tft.fillScreen (TFT_WHITE); // Start with a white screen
18+
19+ // Initialize SD card
20+ if (!SD.begin ()) {
21+ Serial.println (" SD card initialization failed!" );
22+ return ;
23+ }
2124}
2225
2326bool
2427Display::showEmotion (const String& emotion)
2528{
26- const unsigned short * bitmap = nullptr ;
27- return true ;
29+ String fileName = emotion + " .bmp" ;
2830
29- // if (!emotion) {
30- // bitmap = image_smiley;
31- // // } else if (emotion == "grinning") {
32- // // bitmap = image_grinning;
33- // // } else if (emotion == "grin") {
34- // // bitmap = image_grin;
35- // // } else if (emotion == "joy") {
36- // // bitmap = image_joy;
37- // } else if (emotion == "smiley") {
38- // bitmap = image_smiley;
39- // // } else if (emotion == "smile") {
40- // // bitmap = image_smile;
41- // // } else if (emotion == "sweat_smile") {
42- // // bitmap = image_sweat_smile;
43- // // } else if (emotion == "laughing") {
44- // // bitmap = image_laughing;
45- // // } else if (emotion == "innocent") {
46- // // bitmap = image_innocent;
47- // // } else if (emotion == "wink") {
48- // // bitmap = image_wink;
49- // // } else if (emotion == "neutral_face") {
50- // // bitmap = image_neutral_face;
51- // // } else if (emotion == "expressionless") {
52- // // bitmap = image_expressionless;
53- // // } else if (emotion == "unamused") {
54- // // bitmap = image_unamused;
55- // // } else if (emotion == "sweat") {
56- // // bitmap = image_sweat;
57- // // } else if (emotion == "pensive") {
58- // // bitmap = image_pensive;
59- // // } else if (emotion == "confused") {
60- // // bitmap = image_confused;
61- // // } else if (emotion == "confounded") {
62- // // bitmap = image_confounded;
63- // // } else if (emotion == "kissing") {
64- // // bitmap = image_kissing;
65- // // } else if (emotion == "kissing_heart") {
66- // // bitmap = image_kissing_heart;
67- // // } else if (emotion == "kissing_smiling_eyes") {
68- // // bitmap = image_kissing_smiling_eyes;
69- // // } else if (emotion == "angry") {
70- // // bitmap = image_angry;
71- // // } else if (emotion == "cry") {
72- // // bitmap = image_cry;
73- // // } else if (emotion == "persevere") {
74- // // bitmap = image_persevere;
75- // // } else if (emotion == "triumph") {
76- // // bitmap = image_triumph;
77- // // } else if (emotion == "disappointed_relieved") {
78- // // bitmap = image_disappointed_relieved;
79- // // } else if (emotion == "frowning") {
80- // // bitmap = image_frowning;
81- // // } else if (emotion == "anguished") {
82- // // bitmap = image_anguished;
83- // // } else if (emotion == "fearful") {
84- // // bitmap = image_fearful;
85- // // } else if (emotion == "weary") {
86- // // bitmap = image_weary;
87- // // } else if (emotion == "cold_sweat") {
88- // // bitmap = image_cold_sweat;
89- // // } else if (emotion == "scream") {
90- // // bitmap = image_scream;
91- // // } else if (emotion == "astonished") {
92- // // bitmap = image_astonished;
93- // // } else if (emotion == "flushed") {
94- // // bitmap = image_flushed;
95- // // } else if (emotion == "sleeping") {
96- // // bitmap = image_sleeping;
97- // // } else if (emotion == "dizzy_face") {
98- // // bitmap = image_dizzy_face;
99- // // } else if (emotion == "dizzy_face") {
100- // // bitmap = image_dizzy_face;
101- // // } else if (emotion == "mask") {
102- // // bitmap = image_mask;
103- // // } else if (emotion == "slightly_frowning_face") {
104- // // bitmap = image_slightly_frowning_face;
105- // // } else if (emotion == "slightly_smiling_face") {
106- // // bitmap = image_slightly_smiling_face;
107- // // } else if (emotion == "face_with_rolling_eyes") {
108- // // bitmap = image_face_with_rolling_eyes;
109- // // } else if (emotion == "zipper_mouth_face") {
110- // // bitmap = image_zipper_mouth_face;
111- // // } else if (emotion == "money_mouth_face") {
112- // // bitmap = image_money_mouth_face;
113- // // } else if (emotion == "nerd_face") {
114- // // bitmap = image_nerd_face;
115- // } else if (emotion == "thinking_face") {
116- // bitmap = image_thinking_face;
117- // // } else if (emotion == "hugging_face") {
118- // // bitmap = image_hugging_face;
119- // } else if (emotion == "cowboy_hat_face") {
120- // bitmap = image_cowboy_hat_face;
121- // // } else if (emotion == "nauseated_face") {
122- // // bitmap = image_nauseated_face;
123- // // } else if (emotion == "rofl") {
124- // // bitmap = image_rofl;
125- // // } else if (emotion == "drooling_face") {
126- // // bitmap = image_drooling_face;
127- // // } else if (emotion == "sneezing_face") {
128- // // bitmap = image_sneezing_face;
129- // // } else if (emotion == "face_with_raised_eyebrow") {
130- // // bitmap = image_face_with_raised_eyebrow;
131- // // } else if (emotion == "starstruck") {
132- // // bitmap = image_starstruck;
133- // }
31+ if (SD.exists (fileName)) {
32+ File bitmapFile = SD.open (fileName, FILE_READ);
33+ if (bitmapFile) {
34+ displayBitmap (bitmapFile);
35+ bitmapFile.close ();
36+ return true ;
37+ } else {
38+ Serial.println (" Failed to open bitmap file: " + fileName);
39+ }
40+ } else {
41+ Serial.println (" Bitmap file not found: " + fileName);
42+ }
13443
135- // if (bitmap != nullptr) {
136- // displayBitmap(bitmap, 0, 0, BITMAP_WIDTH, BITMAP_HEIGHT);
137- // return true;
138- // } else {
139- // // Emotion not found, you could clear the display or leave as is.
140- // // tft.fillScreen(TFT_BLACK); // Optional: clear screen if emotion not
141- // found return false;
142- // }
44+ return false ;
14345}
14446
14547void
146- Display::displayBitmap (const unsigned short * bitmap, int x, int y, int w, int h )
48+ Display::displayBitmap (File& bitmapFile )
14749{
50+ // Read the bitmap header
51+ char header[54 ];
52+ bitmapFile.read ((uint8_t *)header, 54 );
53+
54+ // Get the image dimensions
55+ uint32_t width = *((uint32_t *)&header[18 ]);
56+ uint32_t height = *((uint32_t *)&header[22 ]);
57+
58+ // Prepare the TFT display
59+ tft.startWrite ();
60+ tft.setAddrWindow (0 , 0 , width, height);
61+
62+ // Read and display the bitmap pixels
63+ uint8_t buffer[BITMAP_WIDTH * 2 ]; // Adjust buffer size based on bitmap width
64+ uint16_t color;
65+ uint32_t pixelCount = width * height;
14866
149- tft.setSwapBytes (false );
150- tft.invertDisplay (1 );
67+ while (pixelCount--) {
68+ bitmapFile.read (&buffer[0 ], 2 );
69+ color = ((buffer[1 ] << 8 ) | buffer[0 ]);
70+ tft.pushColor (color);
71+ }
15172
152- tft.startWrite (); // Begin write operation
153- // tft.setAddrWindow(x, y, w, h);
154- tft.pushImage (0 , 0 , 128 , 128 , bitmap);
155- tft.endWrite (); // End write operation
73+ tft.endWrite ();
15674}
0 commit comments