This commit is contained in:
Jerry
2025-09-21 22:32:06 +08:00
parent f631e8632a
commit 64e5980d3d
10 changed files with 204 additions and 30 deletions

View File

@@ -7,6 +7,8 @@
#include <wiring.h>
#include "battery.h"
#include "led.h"
#include "_sntp.h"
#include "weather.h"
@@ -16,7 +18,7 @@
#include "version.h"
#include "OneButton.h"
OneButton button(PIN_BUTTON, true);
OneButton button(KEY_M, true);
void IRAM_ATTR checkTicks() {
button.tick();
@@ -54,7 +56,7 @@ void print_wakeup_reason() {
Serial.println("Wakeup caused by ULP program");
break;
default:
Serial.printf("Wakeup was not caused by deep sleep.\n");
Serial.printf("Wakeup was not caused by deep sleep.\r\n");
}
}
@@ -82,7 +84,7 @@ void setup() {
button.attachDoubleClick(buttonDoubleClick, &button);
// button.attachMultiClick()
button.attachLongPressStop(buttonLongPressStop, &button);
attachInterrupt(digitalPinToInterrupt(PIN_BUTTON), checkTicks, CHANGE);
attachInterrupt(digitalPinToInterrupt(KEY_M), checkTicks, CHANGE);
Serial.printf("***********************\r\n");
Serial.printf(" J-Calendar\r\n");
@@ -91,8 +93,24 @@ void setup() {
Serial.printf("Copyright © 2022-2025 JADE Software Co., Ltd. All Rights Reserved.\r\n\r\n");
led_init();
led_fast();
led_on();
delay(1000);
int voltage = readBatteryVoltage();
Serial.printf("Battery: %d mV\r\n", voltage);
if(voltage < 1000) {
Serial.println("[WARN]无电池。");
} else if(voltage < 3000) {
Serial.println("[WARN]电量低于3v系统休眠。");
go_sleep();
} else if (voltage < 3300) {
// 低于3.3v,电池电量用尽,屏幕给警告,然后关机。
Serial.println("[WARN]电量低于3.3v,警告并系统休眠。");
si_warning("电量不足,请充电!");
go_sleep();
}
Serial.println("Wm begin...");
led_fast();
wm.setHostname("J-Calendar");
wm.setEnableConfigPortal(false);
wm.setConnectTimeout(10);
@@ -350,12 +368,7 @@ void go_sleep() {
}
esp_sleep_enable_timer_wakeup(p * (uint64_t)uS_TO_S_FACTOR);
#ifdef CONFIG_IDF_TARGET_ESP32
esp_sleep_enable_ext0_wakeup(PIN_BUTTON, 0);
#elif CONFIG_IDF_TARGET_ESP32C3
esp_deep_sleep_enable_gpio_wakeup(PIN_BUTTON, ESP_GPIO_WAKEUP_GPIO_HIGH);
gpio_set_direction(PIN_BUTTON, GPIO_MODE_INPUT);
#endif
esp_sleep_enable_ext0_wakeup(KEY_M, 0);
// 省电考虑关闭RTC外设和存储器
// esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF); // RTC IO, sensors and ULP, 注意由于需要按键唤醒所以不能关闭否则会导致RTC_IO唤醒失败
@@ -363,7 +376,7 @@ void go_sleep() {
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_OFF);
// 省电考虑重置gpio平均每针脚能省8ua。
gpio_reset_pin(PIN_LED); // 减小deep-sleep电流
gpio_reset_pin(PIN_LED_R); // 减小deep-sleep电流
gpio_reset_pin(SPI_CS); // 减小deep-sleep电流
gpio_reset_pin(SPI_DC); // 减小deep-sleep电流
gpio_reset_pin(SPI_RST); // 减小deep-sleep电流