void lab4_scale_temperature(void)
{
/* Title */
lv_obj_t * title = lv_label_create(lv_screen_active());
lv_label_set_text(title, "Lab 4: Temperature Gauge");
lv_obj_align(title, LV_ALIGN_TOP_MID, 0, 10);
/*=========================================================
* Create Scale
*=========================================================*/
temp_scale = lv_scale_create(lv_screen_active());
lv_obj_set_size(temp_scale, 200, 200);
lv_scale_set_mode(temp_scale, LV_SCALE_MODE_ROUND_OUTER);
lv_scale_set_label_show(temp_scale, true);
lv_obj_center(temp_scale);
/* Tick configuration */
lv_scale_set_total_tick_count(temp_scale, 21);
lv_scale_set_major_tick_every(temp_scale, 5);
/* Tick length */
lv_obj_set_style_length(temp_scale, 5, LV_PART_ITEMS); /* Minor */
lv_obj_set_style_length(temp_scale, 10, LV_PART_INDICATOR); /* Major */
/* Range */
lv_scale_set_range(temp_scale, 0, 100);
/* Custom labels */
static const char * labels[] = {
"0 °C", "25 °C", "50 °C", "75 °C", "100 °C", NULL
};
lv_scale_set_text_src(temp_scale, labels);
/*=========================================================
* Style: Blue theme for normal
*=========================================================*/
static lv_style_t indicator_style;
lv_style_init(&indicator_style);
lv_style_set_text_color(&indicator_style,
lv_palette_darken(LV_PALETTE_BLUE, 3));
lv_style_set_line_color(&indicator_style,
lv_palette_darken(LV_PALETTE_BLUE, 3));
lv_obj_add_style(temp_scale, &indicator_style, LV_PART_INDICATOR);
/*=========================================================
* Section: Hot zone (75-100) - Red
*=========================================================*/
lv_scale_section_t * hot_sec = lv_scale_add_section(temp_scale);
lv_scale_section_set_range(hot_sec, 75, 100);
static lv_style_t hot_style;
lv_style_init(&hot_style);
lv_style_set_arc_color(&hot_style, lv_palette_main(LV_PALETTE_RED));
lv_style_set_line_color(&hot_style, lv_palette_main(LV_PALETTE_RED));
lv_scale_section_set_style(hot_sec, LV_PART_MAIN, &hot_style);
static lv_style_t hot_ind_style;
lv_style_init(&hot_ind_style);
lv_style_set_line_color(&hot_ind_style,
lv_palette_darken(LV_PALETTE_RED, 3));
lv_style_set_text_color(&hot_ind_style,
lv_palette_darken(LV_PALETTE_RED, 3));
lv_scale_section_set_style(hot_sec, LV_PART_INDICATOR, &hot_ind_style);
/*=========================================================
* Needle Line
*=========================================================*/
needle_line = lv_line_create(temp_scale);
static lv_style_t needle_style;
lv_style_init(&needle_style);
lv_style_set_line_width(&needle_style, 2);
lv_style_set_line_color(&needle_style,
lv_palette_main(LV_PALETTE_ORANGE));
lv_style_set_line_rounded(&needle_style, true);
lv_obj_add_style(needle_line, &needle_style, 0);
/* Set initial needle position */
lv_scale_set_line_needle_value(temp_scale, needle_line,
needle_length, current_temp);
/*=========================================================
* Value Label (center)
*=========================================================*/
temp_label = lv_label_create(lv_screen_active());
lv_label_set_text(temp_label, "50 °C");
lv_obj_set_style_text_font(temp_label, &lv_font_montserrat_24, 0);
lv_obj_center(temp_label);
/* Timer for updates */
scale_timer = lv_timer_create(scale_timer_cb, 500, NULL);
}