优化睡眠功能

This commit is contained in:
Yu Xifeng 2024-08-26 15:33:42 +08:00
parent 73122e5ff1
commit 7dc1ade08f
4 changed files with 50 additions and 31 deletions

View File

@ -20,7 +20,7 @@ static const char *TAG = "main";
#define BLINK_GPIO 4
extern void light_sleep_task(void *args);
extern esp_err_t register_gpio_wakeup(void);
extern void Usb_Virtual_serial_port_init(void);
QueueHandle_t User_data_queue;
user_data_t Receive_All_data;
@ -62,21 +62,22 @@ void app_main(void)
Printer_group = xEventGroupCreate();
button_init();
register_gpio_wakeup();
Printer_Bsp_Init();
Printer_run_init();
// xTaskCreate(light_sleep_task, "light_sleep_task", 4096, NULL, 6, NULL);
while (1) {
// if(xQueueReceive(User_data_queue, &Receive_All_data, portMAX_DELAY))
// {
// uint16_t Spaces = uxQueueSpacesAvailable(User_data_queue);
// ESP_LOGI(TAG,"Spaces:%d Type:%d Size:%d",Spaces,Receive_All_data.type,Receive_All_data.size);
// if(Receive_All_data.type == USB)
// {
// input_Print_data(CMD_CUSTON,&Receive_All_data.data[0],Receive_All_data.size);
// }
// }
if(xQueueReceive(User_data_queue, &Receive_All_data, portMAX_DELAY))
{
uint16_t Spaces = uxQueueSpacesAvailable(User_data_queue);
ESP_LOGI(TAG,"Spaces:%d Type:%d Size:%d",Spaces,Receive_All_data.type,Receive_All_data.size);
if(Receive_All_data.type == USB)
{
input_Print_data(CMD_CUSTON,&Receive_All_data.data[0],Receive_All_data.size);
}
}
// ESP_LOGI(TAG, "LED State:%d",!s_led_state);
vTaskDelay(1000/ portTICK_PERIOD_MS);
// vTaskDelay(1000/ portTICK_PERIOD_MS);
}
fflush(stdout);
esp_restart();

View File

@ -9,18 +9,16 @@
// #include "esp_idf_version.h"
static const char* TAG = "Printer_run.c";
EXT_RAM_BSS_ATTR uint8_t uheap_1[1024*512];
uint8_t Sleep_mode = 0;//0:运行 1:休眠
Receive_data_t Rev_USB_data = {
.type = USB,
.read = 0,
.write = 0,
.buffer = (char*)&uheap_1[0],
.max_size = 1024*512,
};
// Receive_data_t Rev_USB_data = {
// .type = USB,
// .read = 0,
// .write = 0,
// .buffer = (char*)&uheap_1[0],
// .max_size = 1024*512,
// };
typedef struct _Heat_block
{
@ -128,7 +126,6 @@ void Fill_char2block_Buff(char ch,uint8_t SetPosX,uint16_t SetPosY,FontType_t fo
uint16_t Addchar2PrintArea(char ch)
{
ESP_LOGI(TAG,"ch:%c",ch);
Fill_char2block_Buff(ch,Heat58MM.Heat_block.PosX,Heat58MM.Heat_block.PosY,FontASCII_24x24);
Heat58MM.Heat_block.PosX += FontASCII_24x24.width/8;
if(Heat58MM.Heat_block.PosX >= TH_ACTUAL_WIDTH ||ch == '\n')
@ -253,7 +250,7 @@ uint16_t input_Print_data(Cmd_Type cmd,char* data,size_t size)
void Printer_Run_task(void *pvParameter)
{
uint16_t counts = 0;
uint16_t counts = 1;
char ch = 0;
while (1)
{
@ -267,8 +264,24 @@ void Printer_Run_task(void *pvParameter)
if (xSemaphoreTake(Motor_is_Running, 10 / portTICK_PERIOD_MS) == pdTRUE)
{
xEventGroupSetBits(Printer_group,EVENT_Motor_Sleep);
Sleep_mode = 1;
xSemaphoreGive(Motor_is_Running);//解锁
}
}
}else if(counts%9000 == 0)
{
if(Sleep_mode == 1)
{
ESP_LOGI(TAG,"Entering light sleep\n");
vTaskDelay(500/ portTICK_PERIOD_MS);
/* Enter sleep mode */
esp_light_sleep_start();
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_GPIO) {
/* Waiting for the gpio inactive, or the chip will continuously trigger wakeup*/
// wait_gpio_inactive();
}
Sleep_mode = 0;
}
counts = 0;
}
}
@ -397,11 +410,16 @@ void Printer_Heat_task(void *pvParameter)
ESP_LOGI(TAG,"EVENT_Motor_Sleep");
Motor_GO(0xff);
Set_gpio_state(&STB,0);
// Sleep_mode = 1;
xEventGroupClearBits(Printer_group,EVENT_Motor_Sleep);
break;
default:
break;
}
if(bits != EVENT_Motor_Sleep)
{
Sleep_mode = 0;
}
}
}
@ -413,6 +431,6 @@ void Printer_run_init()
Heat58MM.Heat_block_buff = malloc(TH_ACTUAL_WIDTH*100*8);
memset(&Heat58MM.Heat_Page_buff[0],0x00,TH_ACTUAL_WIDTH*500*8);
memset(&Heat58MM.Heat_block_buff[0],0x00,TH_ACTUAL_WIDTH*100*8);
xTaskCreatePinnedToCore(Printer_Heat_task, "Printer_Heat_task", 1024 * 10, NULL, 28, NULL, 1);//核心1
xTaskCreatePinnedToCore(Printer_Heat_task, "Printer_Heat_task", 1024 * 10, NULL, 20, NULL, 1);//核心1
xTaskCreatePinnedToCore(Printer_Run_task, "Printer_Run_task", 1024 * 100, NULL, 12, NULL, 0);//核心1
}

View File

@ -23,7 +23,7 @@
#define GPIO_WAKEUP_LEVEL 0
void example_wait_gpio_inactive(void)
void wait_gpio_inactive(void)
{
printf("Waiting for GPIO%d to go high...\n", GPIO_WAKEUP_NUM);
while (gpio_get_level(GPIO_WAKEUP_NUM) == GPIO_WAKEUP_LEVEL) {
@ -31,7 +31,7 @@ void example_wait_gpio_inactive(void)
}
}
esp_err_t example_register_gpio_wakeup(void)
esp_err_t register_gpio_wakeup(void)
{
/* Initialize GPIO */
gpio_config_t config = {
@ -49,7 +49,7 @@ esp_err_t example_register_gpio_wakeup(void)
ESP_RETURN_ON_ERROR(esp_sleep_enable_gpio_wakeup(), TAG, "Configure gpio as wakeup source failed");
/* Make sure the GPIO is inactive and it won't trigger wakeup immediately */
example_wait_gpio_inactive();
wait_gpio_inactive();
ESP_LOGI(TAG, "gpio wakeup source is ready");
return ESP_OK;
@ -59,7 +59,7 @@ esp_err_t example_register_gpio_wakeup(void)
void light_sleep_task(void *args)
{
/* Enable wakeup from light sleep by gpio */
example_register_gpio_wakeup();
// example_register_gpio_wakeup();
vTaskDelay(1000/ portTICK_PERIOD_MS);
while (true) {
printf("Entering light sleep\n");
@ -111,7 +111,7 @@ void light_sleep_task(void *args)
#endif
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_GPIO) {
/* Waiting for the gpio inactive, or the chip will continuously trigger wakeup*/
example_wait_gpio_inactive();
wait_gpio_inactive();
}
}
vTaskDelete(NULL);

View File

@ -112,5 +112,5 @@ extern void Feed_Key_motion_cb(void *arg, void *data);
extern void Sys_Key_motion_cb(void *arg, void *data);
extern void Timer_State_machine_cb(uint16_t time_ms);
extern uint16_t input_Print_data(Cmd_Type cmd,char* data,size_t size);
extern void wait_gpio_inactive();
#endif