1
1
#include " M5Display.h"
2
2
3
+ // WiFi 功能的条件编译
4
+ #ifdef ESP32
5
+ #include < WiFi.h>
6
+ #include < HTTPClient.h>
7
+ #define M5_WIFI_ENABLED
8
+ #endif
9
+
3
10
#define BLK_PWM_CHANNEL 7 // LEDC_CHANNEL_7
4
11
5
12
M5Display::M5Display () : TFT_eSPI() {
@@ -10,10 +17,20 @@ void M5Display::begin() {
10
17
setRotation (1 );
11
18
fillScreen (0 );
12
19
20
+ #if defined(ESP_IDF_VERSION_MAJOR) && (ESP_IDF_VERSION_MAJOR >= 5)
21
+ // ESP32 Arduino 3.x 新 API
22
+ ledcAttach (TFT_BL, 44100 , 8 );
23
+ ledcWrite (TFT_BL, 80 ); // 直接使用 TFT_BL 引脚
24
+ #else
25
+ // ESP32 Arduino 2.x 旧 API
26
+ ledcSetup (BLK_PWM_CHANNEL, 44100 , 8 );
27
+ ledcAttachPin (TFT_BL, BLK_PWM_CHANNEL);
28
+ ledcWrite (BLK_PWM_CHANNEL, 80 );
29
+ #endif
30
+
13
31
// Init the back-light LED PWM
14
- ledcSetup (BLK_PWM_CHANNEL, 44100 , 8 );
15
- ledcAttachPin (TFT_BL, BLK_PWM_CHANNEL);
16
- ledcWrite (BLK_PWM_CHANNEL, 80 );
32
+ // ledcSetup(BLK_PWM_CHANNEL, 44100, 8);
33
+ // ledcAttachPin(TFT_BL, BLK_PWM_CHANNEL);
17
34
}
18
35
19
36
void M5Display::sleep () {
@@ -344,7 +361,7 @@ static bool jpgDecode(jpg_file_decoder_t *jpeg,
344
361
static uint8_t work[3100 ];
345
362
JDEC decoder;
346
363
347
- JRESULT jres = jd_prepare (&decoder, reader, work, 3100 , jpeg);
364
+ JRESULT jres = jd_prepare (&decoder, ( UINT (*)(JDEC*,BYTE*,UINT)) reader, work, 3100 , jpeg);
348
365
if (jres != JDR_OK) {
349
366
log_e (" jd_prepare failed! %s" , jd_errors[jres]);
350
367
return false ;
@@ -366,7 +383,7 @@ static bool jpgDecode(jpg_file_decoder_t *jpeg,
366
383
jpeg->outHeight =
367
384
(jpgMaxHeight > jpeg->maxHeight ) ? jpeg->maxHeight : jpgMaxHeight;
368
385
369
- jres = jd_decomp (&decoder, jpgWrite, (uint8_t )jpeg->scale );
386
+ jres = jd_decomp (&decoder, ( UINT (*)(JDEC*, void *,JRECT*)) jpgWrite, (uint8_t )jpeg->scale );
370
387
if (jres != JDR_OK) {
371
388
log_e (" jd_decomp failed! %s" , jd_errors[jres]);
372
389
return false ;
@@ -558,6 +575,8 @@ void M5Display::drawPngUrl(const char *url, uint16_t x, uint16_t y,
558
575
uint16_t maxWidth, uint16_t maxHeight, uint16_t offX,
559
576
uint16_t offY, double scale,
560
577
uint8_t alphaThreshold) {
578
+ #ifdef M5_WIFI_ENABLED
579
+
561
580
HTTPClient http;
562
581
563
582
if (WiFi.status () != WL_CONNECTED) {
@@ -632,4 +651,10 @@ void M5Display::drawPngUrl(const char *url, uint16_t x, uint16_t y,
632
651
633
652
pngle_destroy (pngle);
634
653
http.end ();
654
+
655
+ #else
656
+ // WiFi 未启用时的处理
657
+ Serial.println (" WiFi functionality disabled - drawPngUrl not available" );
658
+ Serial.printf (" Requested URL: %s\n " , url);
659
+ #endif
635
660
}
0 commit comments