增加软件定时器配置,周期更新电池电量百分比

This commit is contained in:
YuXifeng 2025-04-08 17:37:07 +08:00
parent e399d40a90
commit cf2bf25ef8
4 changed files with 69 additions and 3 deletions

View File

@ -239,6 +239,12 @@ extern "C" int Axp_PEKPress_IRQ()
return 0;
}
extern "C" int getBattPercentage(void)
{
return axp.getBattPercentage();
}
extern "C" void Axp202_task(void *pvParameter)
{
axp_init();
@ -265,15 +271,17 @@ extern "C" void Axp202_task(void *pvParameter)
if (xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
if (io_num == AXP_ISR_GPIO) {
axp.readIRQ();
ESP_LOGI(TAG,"axp-irq");
if (axp.isPEKLongtPressIRQ()) {
ESP_LOGI("sleep","esp_light_sleep_start");
esp_timer_stop(SysTick_timer);
axp.setGPIOMode(AXP_GPIO_0, AXP_IO_INPUT_MODE); // 屏幕供电
vTaskDelay(500/ portTICK_PERIOD_MS);
esp_light_sleep_start();
ESP_LOGI(TAG, "AXP202 PEK key Click:%.2f,%.2f,%.2f,%d",axp.getBattVoltage(),axp.getCoulombData(),axp.getBattDischargeCurrent(),axp.getBattPercentage());
// axp.shutdown();
axp.setGPIOMode(AXP_GPIO_0, AXP_IO_LDO_MODE); // 屏幕供电
esp_timer_start_periodic(SysTick_timer,1000);
}
axp.clearIRQ();
}

View File

@ -3,7 +3,7 @@
#include "public.h"
#define LV_EVENT_CUSTOM_UPDATE _LV_EVENT_LAST + 1
#define EVENT_CONNECT BIT10
#define EVENT_BURN_BEGIN BIT11

View File

@ -43,6 +43,8 @@
#include "i2c_port.h"
#include "gui_guider.h"
static const char *TAG = "main";
@ -61,6 +63,54 @@ uint8_t* load_html2Ram(wifi_html_t html)
return NULL;
}
esp_timer_handle_t SysTick_timer;
extern int getBattPercentage(void);
void IRAM_ATTR SysTick_Handler(void)
{
static uint32_t SysTick_ms_cnt = 0;
static uint8_t wdt_status = 0;
if(SysTick_ms_cnt % 1000 == 0)//1s
{
// xEventGroupSetBits(Printer_group,EVENT_GET_Batterylevel);
lv_event_send(guider_ui.screen_label_1, LV_EVENT_CUSTOM_UPDATE, (void *)getBattPercentage());
}
SysTick_ms_cnt ++;
}
void Timer_Config_Init()
{
esp_timer_create_args_t args = {
.callback = SysTick_Handler,
.arg = (void*)1,
.dispatch_method = ESP_TIMER_TASK,
.name = "Tiemr1",
.skip_unhandled_events = false,
};
esp_timer_create(&args, &SysTick_timer);
esp_timer_start_periodic(SysTick_timer, 1000);
// ESP_ERROR_CHECK(gptimer_new_timer(&timer_config, &gptimer_PrintLoop));
// gptimer_event_callbacks_t PrintLoop_cbs = {
// .on_alarm = PrintLoop_callback,
// };
// EventGrou_PrintLoop = xEventGroupCreate();
// ESP_ERROR_CHECK(gptimer_register_event_callbacks(gptimer_PrintLoop, &PrintLoop_cbs, NULL));
// ESP_LOGI(TAG, "Enable timer");
// ESP_ERROR_CHECK(gptimer_enable(gptimer_PrintLoop));
// gptimer_alarm_config_t alarm_config_PrintLoop = {
// .alarm_count = 1000,
// .flags.auto_reload_on_alarm = false,
// };
// ESP_ERROR_CHECK(gptimer_set_alarm_action(gptimer_PrintLoop, &alarm_config_PrintLoop));
// ESP_ERROR_CHECK(gptimer_start(gptimer_PrintLoop));
}
extern uint8_t* home_html_data;
@ -156,7 +206,7 @@ void app_main(void)
ESP_LOGI(TAG, "mem free:%ld %d",esp_get_free_heap_size(),sizeof(Sys_config_t));
// Write_ESPFlash(0x40,0x00,&System_Config,sizeof(Sys_config_t));
Timer_Config_Init();
while (1)
{
// if(gpio_get_level(GPIO_NUM_9) == 0 || gpio_get_level(GPIO_NUM_2) == 0)

View File

@ -29,6 +29,10 @@
#include "driver/uart.h"
#include "driver/gpio.h"
#include "esp_timer.h"
#include "driver/gptimer.h"
#include "driver/timer.h"
#include "wifi_task.h"
#include "spiffs.h"
@ -39,6 +43,8 @@
#include "esp_efuse.h"
#include "stream.h"
#define LV_EVENT_CUSTOM_UPDATE _LV_EVENT_LAST + 1
typedef struct Device_info_
{
uint8_t Device_SN[12];
@ -60,6 +66,8 @@ extern Device_info_t off_line_tool;
extern stream_data_t uart_interface_data;
extern esp_timer_handle_t SysTick_timer;
extern void usb_serial2Uart(void *pvParameters);
extern void Read_CMD_task(void *pvParameter);