Skip to content

Commit c7dc8e2

Browse files
authored
Fix M5.Power.powerOFF() exception bug (#225)
* Fix M5Power.powerOFF() exception bug, adapt related example to new Power-API. * wifi check better using esp_wifi_get_mode()
1 parent 999adb3 commit c7dc8e2

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

examples/Basics/PowerOFF/PowerOFF.ino

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ void setup(){
1414
M5.Power.begin();
1515

1616
// Lcd display
17-
M5.Lcd.println("This is software power off demo");
18-
M5.Lcd.println("Press the button A to power off.");
17+
M5.Lcd.setTextSize(2);
18+
M5.Lcd.println("Software Power-OFF Demo");
19+
M5.Lcd.println("Press Button A ...");
1920
}
2021

2122
// the loop routine runs over and over again forever
2223
void loop() {
2324

2425
if(M5.BtnA.wasPressed()) {
25-
M5.powerOFF();
26+
M5.Power.powerOFF();
2627
}
2728

2829
M5.update();

src/utility/Power.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,12 @@ void POWER::powerOFF(){
392392
M5.I2C.writeByte(IP5306_ADDR, IP5306_REG_SYS_CTL1, (data & (~BOOST_ENABLE_BIT)));
393393
}
394394

395-
//stop wifi
396-
esp_wifi_disconnect();
397-
esp_wifi_stop();
395+
// if wifi was initialized, stop it
396+
wifi_mode_t mode;
397+
if (esp_wifi_get_mode(&mode) == ESP_OK) {
398+
esp_wifi_disconnect();
399+
esp_wifi_stop();
400+
}
398401

399402
//stop bt
400403
esp_bluedroid_disable();

0 commit comments

Comments
 (0)