Files

89 lines
3.2 KiB
C++
Raw Permalink Normal View History

2024-12-24 10:45:27 +08:00
#include "event_task.h"
#include "esp_log.h"
2024-12-24 17:36:01 +08:00
#include "events_init.h"
#include "http_client.h"
2025-01-04 18:04:46 +08:00
#include "programmer.h"
#include "cJSON.h"
2024-12-24 10:45:27 +08:00
static const char *TAG = "event_task";
2024-12-24 17:36:01 +08:00
static uint8_t flash_status = 0;
static uint8_t last_flash_status = 0;
static TickType_t flash_counter = 0;
2025-01-04 18:04:46 +08:00
static void update_prog_progress_and_status_locally(void)
{
char buffer[100] = {0};
int encode_len = 0;
programmer_get_status(buffer, 100, encode_len);
ESP_LOGI(TAG, "%s", buffer);
cJSON *root = NULL;
root = cJSON_Parse(buffer);
if (root) {
cJSON *p = cJSON_GetObjectItem(root, "progress");
if (p) {
ESP_LOGI(TAG, "progress:%d", p->valueint);
set_prog_progress(p->valueint);
}
cJSON *s = cJSON_GetObjectItem(root, "status");
if (s) {
ESP_LOGI(TAG, "status:%s", s->valuestring);
if (strcmp(s->valuestring, "idle") == 0) {
set_prog_status(PROG_STATUS_IDLE);
}
else if (strcmp(s->valuestring, "busy") == 0) {
set_prog_status(PROG_STATUS_BUSY);
}
}
}
cJSON_Delete(root);
}
2024-12-24 10:45:27 +08:00
void screen_timer_cb(lv_timer_t *t)
{
2024-12-24 17:36:01 +08:00
flash_status = get_flash_begin_status();
if (flash_status != last_flash_status) {
if (flash_status) {
flash_counter = xTaskGetTickCount();
}
last_flash_status = flash_status;
}
if (flash_status) {
2025-01-04 18:04:46 +08:00
update_prog_progress_and_status_locally();
2024-12-24 17:36:01 +08:00
prog_status_t s = get_prog_status();
int p = get_prog_progress();
if (s == PROG_STATUS_IDLE && p == 0) {
if ((xTaskGetTickCount() - flash_counter) * portTICK_PERIOD_MS > 5000) {
2024-12-31 16:24:41 +08:00
lv_obj_set_style_bg_color(guider_ui.screen_btn_1, lv_color_hex(0x2195f6), LV_PART_MAIN|LV_STATE_DEFAULT);
2024-12-24 17:36:01 +08:00
lv_label_set_text(guider_ui.screen_btn_1_label, "Idle");
ESP_LOGI(TAG, "TIMEOUT");
set_flash_begin_status(0);
}
}
2024-12-31 16:24:41 +08:00
else if (s == PROG_STATUS_IDLE && (p > 0 && p < 100)) {
if ((xTaskGetTickCount() - flash_counter) * portTICK_PERIOD_MS > 10000) {
lv_obj_set_style_bg_color(guider_ui.screen_btn_1, lv_color_hex(0xff0000), LV_PART_MAIN|LV_STATE_DEFAULT);
lv_label_set_text(guider_ui.screen_btn_1_label, "Failed");
ESP_LOGI(TAG, "Failed");
set_flash_begin_status(0);
}
}
2024-12-24 17:36:01 +08:00
else {
lv_bar_set_value(guider_ui.screen_bar_1, p, LV_ANIM_OFF);
if (p >= 100) {
2024-12-31 16:24:41 +08:00
lv_obj_set_style_bg_color(guider_ui.screen_btn_1, lv_color_hex(0x00660b), LV_PART_MAIN|LV_STATE_DEFAULT);
2024-12-24 17:36:01 +08:00
lv_label_set_text(guider_ui.screen_btn_1_label, "Done");
ESP_LOGI(TAG, "DONE");
set_flash_begin_status(0);
}
else {
2024-12-31 16:24:41 +08:00
lv_obj_set_style_bg_color(guider_ui.screen_btn_1, lv_color_hex(0x000247), LV_PART_MAIN|LV_STATE_DEFAULT);
2024-12-24 17:36:01 +08:00
lv_label_set_text(guider_ui.screen_btn_1_label, "Busy");
}
}
}
2024-12-25 15:31:02 +08:00
lv_label_set_text_fmt(guider_ui.screen_label_4, "%d,%d", get_prog_progress(), get_prog_status());
2024-12-24 10:45:27 +08:00
}