Added the temperature reading on the compass screen

This commit is contained in:
Th3maz1ng 2023-01-14 14:47:32 +01:00
parent 7117ac348c
commit 41da436b93
2 changed files with 36 additions and 3 deletions

View File

@ -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;

View File

@ -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 */