void part2_ex4_scale_temperature(void)
{
/* ---- Initialize styles ---- */
init_section_styles();
/* ---- Background ---- */
lv_obj_set_style_bg_color(lv_screen_active(),
lv_color_hex(0x0f0f23), 0);
/* ---- Title ---- */
lv_obj_t * title = lv_label_create(lv_screen_active());
lv_label_set_text(title, "Temperature Gauge");
lv_obj_set_style_text_color(title, lv_color_hex(0x00d4ff), 0);
lv_obj_set_style_text_font(title, &lv_font_montserrat_24, 0);
lv_obj_align(title, LV_ALIGN_TOP_MID, 0, 5);
/* ---- Scale Widget ---- */
temp_scale = lv_scale_create(lv_screen_active());
lv_obj_set_size(temp_scale, SCALE_SIZE, SCALE_SIZE);
lv_obj_align(temp_scale, LV_ALIGN_CENTER, 0, 0);
/* Round mode (gauge) */
lv_scale_set_mode(temp_scale, LV_SCALE_MODE_ROUND_OUTER);
lv_scale_set_range(temp_scale, TEMP_MIN, TEMP_MAX);
/* Angle: 270-degree sweep เริ่มจากล่างซ้าย */
lv_scale_set_rotation(temp_scale, 135);
lv_scale_set_angle_range(temp_scale, 270);
/* Tick configuration */
lv_scale_set_total_tick_count(temp_scale, 31); /* 31 ticks */
lv_scale_set_major_tick_every(temp_scale, 5); /* ทุก 5 ticks = major */
lv_scale_set_label_show(temp_scale, true);
/* Tick styling - major */
lv_obj_set_style_length(temp_scale, 12, LV_PART_INDICATOR);
lv_obj_set_style_line_width(temp_scale, 2, LV_PART_INDICATOR);
lv_obj_set_style_line_color(temp_scale,
lv_color_hex(0xcccccc), LV_PART_INDICATOR);
/* Tick styling - minor */
lv_obj_set_style_length(temp_scale, 6, LV_PART_ITEMS);
lv_obj_set_style_line_width(temp_scale, 1, LV_PART_ITEMS);
lv_obj_set_style_line_color(temp_scale,
lv_color_hex(0x666666), LV_PART_ITEMS);
/* Label styling */
lv_obj_set_style_text_color(temp_scale,
lv_color_hex(0xaaaaaa), LV_PART_INDICATOR);
/* Main arc (background track) */
lv_obj_set_style_arc_color(temp_scale,
lv_color_hex(0x333344), LV_PART_MAIN);
lv_obj_set_style_arc_width(temp_scale, 4, LV_PART_MAIN);
/* ---- Color Sections ---- */
/* Section 1: Cold (-10 to 10) - Blue */
lv_scale_section_t * sec_cold = lv_scale_add_section(temp_scale);
lv_scale_section_set_range(sec_cold, TEMP_MIN, 10);
lv_scale_section_set_style(sec_cold, LV_PART_MAIN, &style_cold);
lv_scale_section_set_style(sec_cold, LV_PART_INDICATOR, &style_cold);
lv_scale_section_set_style(sec_cold, LV_PART_ITEMS, &style_cold);
/* Section 2: Normal (10 to 35) - Green */
lv_scale_section_t * sec_normal = lv_scale_add_section(temp_scale);
lv_scale_section_set_range(sec_normal, 10, 35);
lv_scale_section_set_style(sec_normal, LV_PART_MAIN, &style_normal);
lv_scale_section_set_style(sec_normal, LV_PART_INDICATOR, &style_normal);
lv_scale_section_set_style(sec_normal, LV_PART_ITEMS, &style_normal);
/* Section 3: Hot (35 to 50) - Red */
lv_scale_section_t * sec_hot = lv_scale_add_section(temp_scale);
lv_scale_section_set_range(sec_hot, 35, TEMP_MAX);
lv_scale_section_set_style(sec_hot, LV_PART_MAIN, &style_hot);
lv_scale_section_set_style(sec_hot, LV_PART_INDICATOR, &style_hot);
lv_scale_section_set_style(sec_hot, LV_PART_ITEMS, &style_hot);
/* ---- Needle Line ---- */
needle_line = lv_line_create(lv_screen_active());
lv_obj_set_style_line_width(needle_line, 3, 0);
lv_obj_set_style_line_color(needle_line,
lv_color_hex(0xff8800), 0);
lv_obj_set_style_line_rounded(needle_line, true, 0);
/* ตำแหน่งเริ่มต้น (20 degC) */
update_needle_position(20);
/* ---- Center pivot dot ---- */
lv_obj_t * pivot = lv_obj_create(lv_screen_active());
lv_obj_set_size(pivot, 10, 10);
lv_obj_set_style_radius(pivot, LV_RADIUS_CIRCLE, 0);
lv_obj_set_style_bg_color(pivot, lv_color_hex(0xff8800), 0);
lv_obj_set_style_border_width(pivot, 0, 0);
lv_obj_align(pivot, LV_ALIGN_CENTER, 0, 0);
/* ---- Value Label ---- */
value_label = lv_label_create(lv_screen_active());
lv_label_set_text(value_label, "20 degC");
lv_obj_set_style_text_color(value_label,
lv_palette_main(LV_PALETTE_GREEN), 0);
lv_obj_set_style_text_font(value_label, &lv_font_montserrat_24, 0);
lv_obj_align(value_label, LV_ALIGN_CENTER, 0, 40);
/* ---- Status Label ---- */
status_label = lv_label_create(lv_screen_active());
lv_label_set_text(status_label, "NORMAL");
lv_obj_set_style_text_color(status_label,
lv_palette_main(LV_PALETTE_GREEN), 0);
lv_obj_align(status_label, LV_ALIGN_BOTTOM_MID, 0, -8);
/* ---- Timer: อัพเดททุก 300ms ---- */
temp_timer = lv_timer_create(temp_timer_cb, 300, NULL);
}