Skip to content

Commit

Permalink
add error correction for display
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefferson-Lopes committed Feb 24, 2024
1 parent 38d75a3 commit 0fd38ea
Showing 1 changed file with 89 additions and 75 deletions.
164 changes: 89 additions & 75 deletions components/display/src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ void task_display(void *arg) {
float percent;

/*Do basic configuration*/
nex_err_t nex_err = nextion_init(nextion_handle);
nex_err_t nex_init_err = nextion_init(nextion_handle);

if (nex_err != 0) {
if (nex_init_err != 0) {
ESP_LOGE(TAG, "Error initializing nextion display");

vTaskDelete(NULL);
}

// Start a task that will handle touch notifications.
Expand All @@ -45,16 +43,18 @@ void task_display(void *arg) {
callback_touch_event
);

/* display initialization routine */
nextion_page_set(nextion_handle, NEX_PAGE_NAME_INTRO);
current_page_num = NEX_PAGE_ID_INTRO;
ESP_LOGI(TAG, "page:%i", current_page_num);

vTaskDelay(pdMS_TO_TICKS(2000));
if (nex_init_err == 0) {
/* display initialization routine */
nextion_page_set(nextion_handle, NEX_PAGE_NAME_INTRO);
current_page_num = NEX_PAGE_ID_INTRO;
ESP_LOGI(TAG, "page:%i", current_page_num);

vTaskDelay(pdMS_TO_TICKS(2000));

nextion_page_set(nextion_handle, NEX_PAGE_NAME_DARK);
current_page_num = NEX_PAGE_ID_DARK;
ESP_LOGI(TAG, "page:%i", current_page_num);
nextion_page_set(nextion_handle, NEX_PAGE_NAME_DARK);
current_page_num = NEX_PAGE_ID_DARK;
ESP_LOGI(TAG, "page:%i", current_page_num);
}

print_task_remaining_space();

Expand All @@ -66,126 +66,140 @@ void task_display(void *arg) {
if (xQueueReceive(qh_speed, &recv_sensor, pdMS_TO_TICKS(1))){
// update global system var in a protected environment
xSemaphoreTake(sh_global_vars, portMAX_DELAY);
system_global.speed = recv_sensor.value;
system_global.speed = recv_sensor.value;
xSemaphoreGive(sh_global_vars);

// print to display
snprintf(msg_buffer, 10, "%d", (int)recv_sensor.value);
if (current_page_num == NEX_PAGE_ID_DARK) {
nextion_component_set_text(nextion_handle, NEX_TEXT_SPEED_D, msg_buffer);
}
else if (current_page_num == NEX_PAGE_ID_LIGHT) {
nextion_component_set_text(nextion_handle, NEX_TEXT_SPEED_L, msg_buffer);
if (nex_init_err == 0) {
// print to display
snprintf(msg_buffer, 10, "%d", (int)recv_sensor.value);
if (current_page_num == NEX_PAGE_ID_DARK) {
nextion_component_set_text(nextion_handle, NEX_TEXT_SPEED_D, msg_buffer);
}
else if (current_page_num == NEX_PAGE_ID_LIGHT) {
nextion_component_set_text(nextion_handle, NEX_TEXT_SPEED_L, msg_buffer);
}
memset(msg_buffer, 0, sizeof(msg_buffer)); // clear buffer
}
memset(msg_buffer, 0, sizeof(msg_buffer)); // clear buffer
}

// RPM
else if (xQueueReceive(qh_rpm, &recv_sensor, pdMS_TO_TICKS(1))){
// update global system var in a protected environment
xSemaphoreTake(sh_global_vars, portMAX_DELAY);
system_global.rpm = recv_sensor.value;
system_global.rpm = recv_sensor.value;
xSemaphoreGive(sh_global_vars);

percent = convert_to_percent(recv_sensor.value, NEX_RPM_MAX, NEX_RPM_MIN);
if (nex_init_err == 0) {
percent = convert_to_percent(recv_sensor.value, NEX_RPM_MAX, NEX_RPM_MIN);

// print to display
if (current_page_num == NEX_PAGE_ID_DARK) {
nextion_component_set_value(nextion_handle, NEX_PROGRESSBAR_RPM_D, percent);
}
else if (current_page_num == NEX_PAGE_ID_LIGHT) {
nextion_component_set_value(nextion_handle, NEX_PROGRESSBAR_RPM_L, percent);
// print to display
if (current_page_num == NEX_PAGE_ID_DARK) {
nextion_component_set_value(nextion_handle, NEX_PROGRESSBAR_RPM_D, percent);
}
else if (current_page_num == NEX_PAGE_ID_LIGHT) {
nextion_component_set_value(nextion_handle, NEX_PROGRESSBAR_RPM_L, percent);
}
}
}

// fuel
else if (xQueueReceive(qh_fuel_emer, &recv_sensor, pdMS_TO_TICKS(1))){
// update global system var in a protected environment
xSemaphoreTake(sh_global_vars, portMAX_DELAY);
system_global.fuel_em = recv_sensor.value;
system_global.fuel_em = recv_sensor.value;
xSemaphoreGive(sh_global_vars);

// print to display
if (current_page_num == NEX_PAGE_ID_DARK) {
nextion_component_set_boolean(nextion_handle, NEX_DSBUTTON_FUEL_EM_D, (bool)recv_sensor.value);
}
else if (current_page_num == NEX_PAGE_ID_LIGHT) {
nextion_component_set_boolean(nextion_handle, NEX_DSBUTTON_FUEL_EM_L, (bool)recv_sensor.value);
if (nex_init_err == 0) {
// print to display
if (current_page_num == NEX_PAGE_ID_DARK) {
nextion_component_set_boolean(nextion_handle, NEX_DSBUTTON_FUEL_EM_D, (bool)recv_sensor.value);
}
else if (current_page_num == NEX_PAGE_ID_LIGHT) {
nextion_component_set_boolean(nextion_handle, NEX_DSBUTTON_FUEL_EM_L, (bool)recv_sensor.value);
}
}
}

// battery
else if (xQueueReceive(qh_battery, &recv_sensor, pdMS_TO_TICKS(1))){
// update global system var in a protected environment
xSemaphoreTake(sh_global_vars, portMAX_DELAY);
system_global.battery = recv_sensor.value;
system_global.battery = recv_sensor.value;
xSemaphoreGive(sh_global_vars);

percent = convert_to_percent(recv_sensor.value, NEX_BAT_MAX, NEX_BAT_MIN);

// print to display
snprintf(msg_buffer, 10, "%d%c", (int)percent, NEX_SYMBOL_PERCENT);
if (current_page_num == NEX_PAGE_ID_DARK) {
nextion_component_set_text(nextion_handle, NEX_TEXT_BATTERY_D, msg_buffer);
}
else if (current_page_num == NEX_PAGE_ID_LIGHT) {
nextion_component_set_text(nextion_handle, NEX_TEXT_BATTERY_L, msg_buffer);
if (nex_init_err == 0) {
percent = convert_to_percent(recv_sensor.value, NEX_BAT_MAX, NEX_BAT_MIN);

// print to display
snprintf(msg_buffer, 10, "%d%c", (int)percent, NEX_SYMBOL_PERCENT);
if (current_page_num == NEX_PAGE_ID_DARK) {
nextion_component_set_text(nextion_handle, NEX_TEXT_BATTERY_D, msg_buffer);
}
else if (current_page_num == NEX_PAGE_ID_LIGHT) {
nextion_component_set_text(nextion_handle, NEX_TEXT_BATTERY_L, msg_buffer);
}
memset(msg_buffer, 0, sizeof(msg_buffer)); // clear buffer
}
memset(msg_buffer, 0, sizeof(msg_buffer)); // clear buffer
}

// temperature
else if (xQueueReceive(qh_temp, &recv_sensor, pdMS_TO_TICKS(1))){
// update global system var in a protected environment
xSemaphoreTake(sh_global_vars, portMAX_DELAY);
system_global.temp = recv_sensor.value;
system_global.temp = recv_sensor.value;
xSemaphoreGive(sh_global_vars);

// print to display
snprintf(msg_buffer, 10, "%d%cC", (int)recv_sensor.value, NEX_SYMBOL_DEGREE);
if (current_page_num == NEX_PAGE_ID_DARK) {
nextion_component_set_text(nextion_handle, NEX_TEXT_TEMP_D, msg_buffer);
if (nex_init_err == 0) {
// print to display
snprintf(msg_buffer, 10, "%d%cC", (int)recv_sensor.value, NEX_SYMBOL_DEGREE);
if (current_page_num == NEX_PAGE_ID_DARK) {
nextion_component_set_text(nextion_handle, NEX_TEXT_TEMP_D, msg_buffer);
}
else if (current_page_num == NEX_PAGE_ID_LIGHT) {
nextion_component_set_text(nextion_handle, NEX_TEXT_TEMP_L, msg_buffer);
}
memset(msg_buffer, 0, sizeof(msg_buffer)); // clear buffer
}
else if (current_page_num == NEX_PAGE_ID_LIGHT) {
nextion_component_set_text(nextion_handle, NEX_TEXT_TEMP_L, msg_buffer);
}
memset(msg_buffer, 0, sizeof(msg_buffer)); // clear buffer
}

// tilt_x - pitch
else if (xQueueReceive(qh_tilt_x, &recv_sensor, pdMS_TO_TICKS(1))){
// update global system var in a protected environment
xSemaphoreTake(sh_global_vars, portMAX_DELAY);
system_global.tilt_x = recv_sensor.value;
system_global.tilt_x = recv_sensor.value;
xSemaphoreGive(sh_global_vars);

// print to display
snprintf(msg_buffer, 10, "%d%c", (int)recv_sensor.value, NEX_SYMBOL_DEGREE);
if (current_page_num == NEX_PAGE_ID_DARK) {
nextion_component_set_text(nextion_handle, NEX_TEXT_PITCH_D, msg_buffer);
}
else if (current_page_num == NEX_PAGE_ID_LIGHT) {
nextion_component_set_text(nextion_handle, NEX_TEXT_PITCH_L, msg_buffer);
if (nex_init_err == 0) {
// print to display
snprintf(msg_buffer, 10, "%d%c", (int)recv_sensor.value, NEX_SYMBOL_DEGREE);
if (current_page_num == NEX_PAGE_ID_DARK) {
nextion_component_set_text(nextion_handle, NEX_TEXT_PITCH_D, msg_buffer);
}
else if (current_page_num == NEX_PAGE_ID_LIGHT) {
nextion_component_set_text(nextion_handle, NEX_TEXT_PITCH_L, msg_buffer);
}
memset(msg_buffer, 0, sizeof(msg_buffer)); // clear buffer
}
memset(msg_buffer, 0, sizeof(msg_buffer)); // clear buffer
}

// tilt_y - roll
else if (xQueueReceive(qh_tilt_y, &recv_sensor, pdMS_TO_TICKS(1))){
// update global system var in a protected environment
xSemaphoreTake(sh_global_vars, portMAX_DELAY);
system_global.tilt_y = recv_sensor.value;
system_global.tilt_y = recv_sensor.value;
xSemaphoreGive(sh_global_vars);

// print to display
snprintf(msg_buffer, 10, "%d%c", (int)recv_sensor.value, NEX_SYMBOL_DEGREE);
if (current_page_num == NEX_PAGE_ID_DARK) {
nextion_component_set_text(nextion_handle, NEX_TEXT_ROLL_D, msg_buffer);
}
else if (current_page_num == NEX_PAGE_ID_LIGHT) {
nextion_component_set_text(nextion_handle, NEX_TEXT_ROLL_L, msg_buffer);
if (nex_init_err == 0) {
// print to display
snprintf(msg_buffer, 10, "%d%c", (int)recv_sensor.value, NEX_SYMBOL_DEGREE);
if (current_page_num == NEX_PAGE_ID_DARK) {
nextion_component_set_text(nextion_handle, NEX_TEXT_ROLL_D, msg_buffer);
}
else if (current_page_num == NEX_PAGE_ID_LIGHT) {
nextion_component_set_text(nextion_handle, NEX_TEXT_ROLL_L, msg_buffer);
}
memset(msg_buffer, 0, sizeof(msg_buffer)); // clear buffer
}
memset(msg_buffer, 0, sizeof(msg_buffer)); // clear buffer
}

vTaskDelay(pdMS_TO_TICKS(10));
Expand Down

0 comments on commit 0fd38ea

Please sign in to comment.