优化睡眠功能
This commit is contained in:
parent
73122e5ff1
commit
7dc1ade08f
23
main/main.c
23
main/main.c
@ -20,7 +20,7 @@ static const char *TAG = "main";
|
|||||||
|
|
||||||
#define BLINK_GPIO 4
|
#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);
|
extern void Usb_Virtual_serial_port_init(void);
|
||||||
QueueHandle_t User_data_queue;
|
QueueHandle_t User_data_queue;
|
||||||
user_data_t Receive_All_data;
|
user_data_t Receive_All_data;
|
||||||
@ -62,21 +62,22 @@ void app_main(void)
|
|||||||
|
|
||||||
Printer_group = xEventGroupCreate();
|
Printer_group = xEventGroupCreate();
|
||||||
button_init();
|
button_init();
|
||||||
|
register_gpio_wakeup();
|
||||||
Printer_Bsp_Init();
|
Printer_Bsp_Init();
|
||||||
Printer_run_init();
|
Printer_run_init();
|
||||||
// xTaskCreate(light_sleep_task, "light_sleep_task", 4096, NULL, 6, NULL);
|
// xTaskCreate(light_sleep_task, "light_sleep_task", 4096, NULL, 6, NULL);
|
||||||
while (1) {
|
while (1) {
|
||||||
// if(xQueueReceive(User_data_queue, &Receive_All_data, portMAX_DELAY))
|
if(xQueueReceive(User_data_queue, &Receive_All_data, portMAX_DELAY))
|
||||||
// {
|
{
|
||||||
// uint16_t Spaces = uxQueueSpacesAvailable(User_data_queue);
|
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);
|
ESP_LOGI(TAG,"Spaces:%d Type:%d Size:%d",Spaces,Receive_All_data.type,Receive_All_data.size);
|
||||||
// if(Receive_All_data.type == USB)
|
if(Receive_All_data.type == USB)
|
||||||
// {
|
{
|
||||||
// input_Print_data(CMD_CUSTON,&Receive_All_data.data[0],Receive_All_data.size);
|
input_Print_data(CMD_CUSTON,&Receive_All_data.data[0],Receive_All_data.size);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// ESP_LOGI(TAG, "LED State:%d",!s_led_state);
|
// ESP_LOGI(TAG, "LED State:%d",!s_led_state);
|
||||||
vTaskDelay(1000/ portTICK_PERIOD_MS);
|
// vTaskDelay(1000/ portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
esp_restart();
|
esp_restart();
|
||||||
|
|||||||
@ -9,18 +9,16 @@
|
|||||||
// #include "esp_idf_version.h"
|
// #include "esp_idf_version.h"
|
||||||
|
|
||||||
static const char* TAG = "Printer_run.c";
|
static const char* TAG = "Printer_run.c";
|
||||||
|
uint8_t Sleep_mode = 0;//0:运行 1:休眠
|
||||||
EXT_RAM_BSS_ATTR uint8_t uheap_1[1024*512];
|
|
||||||
|
|
||||||
|
|
||||||
|
// Receive_data_t Rev_USB_data = {
|
||||||
Receive_data_t Rev_USB_data = {
|
// .type = USB,
|
||||||
.type = USB,
|
// .read = 0,
|
||||||
.read = 0,
|
// .write = 0,
|
||||||
.write = 0,
|
// .buffer = (char*)&uheap_1[0],
|
||||||
.buffer = (char*)&uheap_1[0],
|
// .max_size = 1024*512,
|
||||||
.max_size = 1024*512,
|
// };
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct _Heat_block
|
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)
|
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);
|
Fill_char2block_Buff(ch,Heat58MM.Heat_block.PosX,Heat58MM.Heat_block.PosY,FontASCII_24x24);
|
||||||
Heat58MM.Heat_block.PosX += FontASCII_24x24.width/8;
|
Heat58MM.Heat_block.PosX += FontASCII_24x24.width/8;
|
||||||
if(Heat58MM.Heat_block.PosX >= TH_ACTUAL_WIDTH ||ch == '\n')
|
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)
|
void Printer_Run_task(void *pvParameter)
|
||||||
{
|
{
|
||||||
uint16_t counts = 0;
|
uint16_t counts = 1;
|
||||||
char ch = 0;
|
char ch = 0;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
@ -267,8 +264,24 @@ void Printer_Run_task(void *pvParameter)
|
|||||||
if (xSemaphoreTake(Motor_is_Running, 10 / portTICK_PERIOD_MS) == pdTRUE)
|
if (xSemaphoreTake(Motor_is_Running, 10 / portTICK_PERIOD_MS) == pdTRUE)
|
||||||
{
|
{
|
||||||
xEventGroupSetBits(Printer_group,EVENT_Motor_Sleep);
|
xEventGroupSetBits(Printer_group,EVENT_Motor_Sleep);
|
||||||
|
Sleep_mode = 1;
|
||||||
xSemaphoreGive(Motor_is_Running);//解锁
|
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;
|
counts = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -397,11 +410,16 @@ void Printer_Heat_task(void *pvParameter)
|
|||||||
ESP_LOGI(TAG,"EVENT_Motor_Sleep");
|
ESP_LOGI(TAG,"EVENT_Motor_Sleep");
|
||||||
Motor_GO(0xff);
|
Motor_GO(0xff);
|
||||||
Set_gpio_state(&STB,0);
|
Set_gpio_state(&STB,0);
|
||||||
|
// Sleep_mode = 1;
|
||||||
xEventGroupClearBits(Printer_group,EVENT_Motor_Sleep);
|
xEventGroupClearBits(Printer_group,EVENT_Motor_Sleep);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
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);
|
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_Page_buff[0],0x00,TH_ACTUAL_WIDTH*500*8);
|
||||||
memset(&Heat58MM.Heat_block_buff[0],0x00,TH_ACTUAL_WIDTH*100*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
|
xTaskCreatePinnedToCore(Printer_Run_task, "Printer_Run_task", 1024 * 100, NULL, 12, NULL, 0);//核心1
|
||||||
}
|
}
|
||||||
@ -23,7 +23,7 @@
|
|||||||
#define GPIO_WAKEUP_LEVEL 0
|
#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);
|
printf("Waiting for GPIO%d to go high...\n", GPIO_WAKEUP_NUM);
|
||||||
while (gpio_get_level(GPIO_WAKEUP_NUM) == GPIO_WAKEUP_LEVEL) {
|
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 */
|
/* Initialize GPIO */
|
||||||
gpio_config_t config = {
|
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");
|
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 */
|
/* 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");
|
ESP_LOGI(TAG, "gpio wakeup source is ready");
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
@ -59,7 +59,7 @@ esp_err_t example_register_gpio_wakeup(void)
|
|||||||
void light_sleep_task(void *args)
|
void light_sleep_task(void *args)
|
||||||
{
|
{
|
||||||
/* Enable wakeup from light sleep by gpio */
|
/* Enable wakeup from light sleep by gpio */
|
||||||
example_register_gpio_wakeup();
|
// example_register_gpio_wakeup();
|
||||||
vTaskDelay(1000/ portTICK_PERIOD_MS);
|
vTaskDelay(1000/ portTICK_PERIOD_MS);
|
||||||
while (true) {
|
while (true) {
|
||||||
printf("Entering light sleep\n");
|
printf("Entering light sleep\n");
|
||||||
@ -111,7 +111,7 @@ void light_sleep_task(void *args)
|
|||||||
#endif
|
#endif
|
||||||
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_GPIO) {
|
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_GPIO) {
|
||||||
/* Waiting for the gpio inactive, or the chip will continuously trigger wakeup*/
|
/* Waiting for the gpio inactive, or the chip will continuously trigger wakeup*/
|
||||||
example_wait_gpio_inactive();
|
wait_gpio_inactive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
|
|||||||
@ -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 Sys_Key_motion_cb(void *arg, void *data);
|
||||||
extern void Timer_State_machine_cb(uint16_t time_ms);
|
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 uint16_t input_Print_data(Cmd_Type cmd,char* data,size_t size);
|
||||||
|
extern void wait_gpio_inactive();
|
||||||
#endif
|
#endif
|
||||||
Loading…
Reference in New Issue
Block a user