void part2_ex7_real_imu_display(void)
{
/* ===== HARDWARE INITIALIZATION ===== */
#ifdef CYBSP_ENABLED
aic_sensors_init(); /* Initialize BMI270 IMU */
#endif
/* ===== Background ===== */
lv_obj_set_style_bg_color(lv_screen_active(),
lv_color_hex(0x16213e), LV_PART_MAIN);
/* ===== Title ===== */
lv_obj_t * title = lv_label_create(lv_screen_active());
lv_label_set_text(title, "Part 2 Ex7: Real IMU Display");
lv_obj_set_style_text_color(title, lv_color_hex(0xFFFFFF), 0);
lv_obj_set_style_text_font(title, &lv_font_montserrat_16, 0);
lv_obj_align(title, LV_ALIGN_TOP_MID, 0, 5);
/* Subtitle - บอกว่าใช้ data จริง */
lv_obj_t * subtitle = lv_label_create(lv_screen_active());
lv_label_set_text(subtitle, "Accelerometer - REAL BMI270 DATA");
lv_obj_set_style_text_color(subtitle, lv_color_hex(0x00FF88), 0);
lv_obj_set_style_text_font(subtitle, &lv_font_montserrat_14, 0);
lv_obj_align(subtitle, LV_ALIGN_TOP_MID, 0, 25);
/* ===== Chart ===== */
ex7_chart = lv_chart_create(lv_screen_active());
lv_obj_set_size(ex7_chart, 440, 230);
lv_obj_align(ex7_chart, LV_ALIGN_CENTER, -10, 15);
lv_chart_set_type(ex7_chart, LV_CHART_TYPE_LINE);
lv_chart_set_point_count(ex7_chart, CHART_POINTS);
/* Range: -1500 to 1500 (สำหรับ +/-15 m/s2 x 100) */
lv_chart_set_range(ex7_chart, LV_CHART_AXIS_PRIMARY_Y, -1500, 1500);
/* ซ่อน point indicator */
lv_obj_set_style_size(ex7_chart, 0, 0, LV_PART_INDICATOR);
lv_obj_set_style_line_width(ex7_chart, 2, LV_PART_ITEMS);
lv_chart_set_div_line_count(ex7_chart, 5, 8);
/* สีพื้นหลัง chart */
lv_obj_set_style_bg_color(ex7_chart, lv_color_hex(0x1a1a2e), 0);
lv_obj_set_style_bg_opa(ex7_chart, LV_OPA_COVER, 0);
lv_obj_set_style_border_color(ex7_chart, lv_color_hex(0x333355), 0);
/* ===== Series: X(Red), Y(Green), Z(Blue) ===== */
lv_color_t colors[] = {
lv_palette_main(LV_PALETTE_RED),
lv_palette_main(LV_PALETTE_GREEN),
lv_palette_main(LV_PALETTE_BLUE)
};
ex7_ser_x = lv_chart_add_series(ex7_chart, colors[0],
LV_CHART_AXIS_PRIMARY_Y);
ex7_ser_y = lv_chart_add_series(ex7_chart, colors[1],
LV_CHART_AXIS_PRIMARY_Y);
ex7_ser_z = lv_chart_add_series(ex7_chart, colors[2],
LV_CHART_AXIS_PRIMARY_Y);
/* ===== Value Labels ===== */
const char * names[] = {"X:", "Y:", "Z:"};
for(int i = 0; i < 3; i++) {
ex7_labels[i] = lv_label_create(lv_screen_active());
lv_label_set_text_fmt(ex7_labels[i], "%s 0.00", names[i]);
lv_obj_set_style_text_color(ex7_labels[i], colors[i], 0);
lv_obj_set_style_text_font(ex7_labels[i], &lv_font_montserrat_16, 0);
lv_obj_align(ex7_labels[i], LV_ALIGN_RIGHT_MID, -5, -30 + i * 30);
}
/* ===== Footer Label ===== */
lv_obj_t * footer = lv_label_create(lv_screen_active());
lv_label_set_text(footer, "[HW] Using imu_shared_read_accel()");
lv_obj_set_style_text_color(footer, lv_color_hex(0x888888), 0);
lv_obj_set_style_text_font(footer, &lv_font_montserrat_12, 0);
lv_obj_align(footer, LV_ALIGN_BOTTOM_MID, 0, -5);
/* ===== Timer - Polling ทุก 50ms (20 Hz) ===== */
ex7_timer = lv_timer_create(ex7_timer_cb, 50, NULL);
}