From 41da436b93bb6e50df6a75c54a33e8e97013c567 Mon Sep 17 00:00:00 2001 From: Th3maz1ng Date: Sat, 14 Jan 2023 14:47:32 +0100 Subject: [PATCH] Added the temperature reading on the compass screen --- .../app/gfx/compass_screen.c | 29 +++++++++++++++++++ .../app/gfx/compass_screen.h | 10 +++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/W800 SDK v1.00.08/app/gfx/compass_screen.c b/src/W800 SDK v1.00.08/app/gfx/compass_screen.c index 3c7420f..bcd1844 100644 --- a/src/W800 SDK v1.00.08/app/gfx/compass_screen.c +++ b/src/W800 SDK v1.00.08/app/gfx/compass_screen.c @@ -137,6 +137,22 @@ void compass_screen_set_azimuth(CompassScreen_t * const compassScreen, uint16_t rotate_cardinal(&compassScreen->westCardinal, azimuth); } +void compass_screen_set_temperature(CompassScreen_t * const compassScreen, float temperature) +{ + if(!compassScreen) + { + LV_LOG_ERROR("NULL pointer given !"); + return; + } + + //Mandatory, if the screen is not displayed anymore, we should still be able to call this function ! + if(!compassScreen->display) return; + + //Update the temperature label + sprintf(compassScreen->compassTemperature.text, "%.2f°C", temperature); + lv_label_set_text_static(compassScreen->compassTemperature.label, compassScreen->compassTemperature.text); +} + bool compass_screen_is_in_use(CompassScreen_t *const compassScreen) { if(!compassScreen) @@ -209,6 +225,18 @@ void compass_screen_create(CompassScreen_t * const compassScreen) lv_obj_set_style_text_font(compassScreen->compassAzimuth.label, &lv_font_montserrat_28, LV_PART_MAIN); lv_obj_center(compassScreen->compassAzimuth.label); + //Temperature label is created here + if(compassScreen->compassTemperature.label) + { + LV_LOG_ERROR("label should be NULL here !"); + lv_obj_del(compassScreen->compassTemperature.label); + compassScreen->compassTemperature.label = NULL; + } + compassScreen->compassTemperature.label = lv_label_create(compassScreen->display); + lv_label_set_text_static(compassScreen->compassTemperature.label, compassScreen->compassTemperature.text); + lv_obj_set_style_text_font(compassScreen->compassTemperature.label, &lv_font_montserrat_24, LV_PART_MAIN); + lv_obj_align(compassScreen->compassTemperature.label, LV_ALIGN_CENTER, 0, -22); + //Add some graduation : ( was nice but is too CPU intensive :( ) /*if(compassScreen->compassGraduation.meter) { @@ -287,6 +315,7 @@ void compass_screen_destroy(CompassScreen_t * const compassScreen) compassScreen->display = NULL; compassScreen->compassAzimuth.label = NULL; + compassScreen->compassTemperature.label = NULL; compassScreen->northCardinal.label = NULL; compassScreen->eastCardinal.label = NULL; compassScreen->southCardinal.label = NULL; diff --git a/src/W800 SDK v1.00.08/app/gfx/compass_screen.h b/src/W800 SDK v1.00.08/app/gfx/compass_screen.h index 60db726..a6db404 100644 --- a/src/W800 SDK v1.00.08/app/gfx/compass_screen.h +++ b/src/W800 SDK v1.00.08/app/gfx/compass_screen.h @@ -3,11 +3,11 @@ #include "lvgl.h" -typedef struct CompassAzimuthLabel +typedef struct CompassLabel { lv_obj_t *label; char text[9]; -} CompassAzimuth_t; +} CompassLabel_t; typedef struct CompassCardinal { @@ -35,7 +35,8 @@ typedef struct CompassScreen lv_obj_t *northMarker; lv_obj_t *display; - CompassAzimuth_t compassAzimuth; + CompassLabel_t compassAzimuth; + CompassLabel_t compassTemperature; } CompassScreen_t; /* Initializes the compass screen context object */ @@ -44,6 +45,9 @@ void compass_screen_init(CompassScreen_t * const compassScreen); /* Set the compassAzimuth in degrees to show */ void compass_screen_set_azimuth(CompassScreen_t * const compassScreen, uint16_t azimuth); +/* Set the compassTemperature in degrees celsius to show */ +void compass_screen_set_temperature(CompassScreen_t * const compassScreen, float temperature); + bool compass_screen_is_in_use(CompassScreen_t * const compassScreen); /* Builds the compass screen graphically */