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 2f3d2c6..6abebae 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,17 @@ void compass_screen_set_azimuth(CompassScreen_t * const compassScreen, uint16_t rotate_cardinal(&compassScreen->westCardinal, azimuth); } +bool compass_screen_is_in_use(CompassScreen_t *const compassScreen) +{ + if(!compassScreen) + { + LV_LOG_ERROR("NULL pointer given !"); + return; + } + + return compassScreen->display != NULL; +} + void compass_screen_create(CompassScreen_t * const compassScreen) { if(!compassScreen) 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 ae1a705..60db726 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 @@ -44,6 +44,8 @@ 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); +bool compass_screen_is_in_use(CompassScreen_t * const compassScreen); + /* Builds the compass screen graphically */ void compass_screen_create(CompassScreen_t * const compassScreen); diff --git a/src/W800 SDK v1.00.08/app/gfx/gfx_task.c b/src/W800 SDK v1.00.08/app/gfx/gfx_task.c index 6297ba5..112f0bc 100644 --- a/src/W800 SDK v1.00.08/app/gfx/gfx_task.c +++ b/src/W800 SDK v1.00.08/app/gfx/gfx_task.c @@ -9,6 +9,8 @@ #include "settings_screen.h" #include "i2c.h" #include "QMC5883L.h" +#include "BMP280.h" +#include "bma456w.h" #include "lv_port_indev.h" @@ -31,31 +33,10 @@ static void lcd_draw_finished_cb(void *arg) lv_disp_flush_ready((lv_disp_drv_t *)arg); } -struct tm temptm = {0}; - static void date_time_cb(struct tm * const dateTime) { if(!dateTime)return; - - /*time_t time_type = time(NULL); - struct tm *tm = localtime(&time_type);*/ - - temptm.tm_min++; - temptm.tm_sec = 1; - - if(temptm.tm_min == 60) - { - temptm.tm_min = 0; - temptm.tm_hour++; - } - - if(temptm.tm_hour == 24) - temptm.tm_hour = 0; - - *dateTime = temptm; - - //LV_LOG_USER("Time is : %llu, Time : %d:%d:%d", time_type, tm->tm_hour, tm->tm_min, tm->tm_sec); - LV_LOG_USER("Time : %d:%d:%d", dateTime->tm_hour, dateTime->tm_min, dateTime->tm_sec); + tls_get_rtc(dateTime); } WatchFace_t watchFace; @@ -63,11 +44,79 @@ MenuScreen_t menuScreen; CompassScreen_t compassScreen; SettingsScreen_t settingsScreen; +struct bma4_dev bma; +struct bma4_accel_config accel_conf; +struct bma456w_wrist_wear_wakeup_params setting; +uint16_t int_status; + +static void setBrightnessCb(uint8_t brightness) +{ + lcd_set_backlight(&LCDConfig, brightness); +} + +static void setTimeCb(uint8_t hour, uint8_t minute, uint8_t second, uint8_t day, uint8_t month, uint8_t year) +{ + struct tm timeToSet; + + //First we get the current time from the RTC + tls_get_rtc(&timeToSet); + + if(hour != 0xFF) + timeToSet.tm_hour = hour; + + if(minute != 0xFF) + timeToSet.tm_min = minute; + + if(second != 0xFF) + timeToSet.tm_sec = second; + + if(day != 0xFF) + timeToSet.tm_mday = day; + + if(month != 0xFF) + timeToSet.tm_mon = month; + + if(year != 0xFF) + timeToSet.tm_year = year + 100; + + tls_set_rtc(&timeToSet); +} + +SettingsScreenAPIInterface_t settingsScreenAPIInterface = +{ + .setBrightnessSettingsCb = setBrightnessCb, + .setTimeSettingsCb = setTimeCb +}; + static uint16_t angle_with_offset(uint16_t angle, uint16_t offset) { return (angle + offset) >= 360 ? angle + offset - 360 : angle + offset; } +static BMA4_INTF_RET_TYPE bma4_i2c_read(uint8_t reg_addr, uint8_t *read_data, uint32_t len, void *intf_ptr) +{ + uint8_t dev_address = *(uint8_t*)intf_ptr; + + return !i2c_read(dev_address, reg_addr, read_data, len); +} + +static BMA4_INTF_RET_TYPE bma4_i2c_write(uint8_t reg_addr, const uint8_t *read_data, uint32_t len, void *intf_ptr) +{ + uint8_t dev_address = *(uint8_t*)intf_ptr; + + return !i2c_write(dev_address, reg_addr, read_data, len); +} + +static void delay_us(uint32_t period, void *intf_ptr) +{ + (void) intf_ptr; + + if(period < 1000) + tls_os_time_delay(1); + else + tls_os_time_delay(pdMS_TO_TICKS(period / 1000)); +} + void gfx_task(void *param) { @@ -121,6 +170,7 @@ void gfx_task(void *param) menu_screen_init(&menuScreen); compass_screen_init(&compassScreen); settings_screen_init(&settingsScreen); + settings_screen_register_API_interface(&settingsScreen, &settingsScreenAPIInterface); watch_face_register_cb(&watchFace, &(date_time_cb)); watch_face_create(&watchFace); @@ -132,33 +182,101 @@ void gfx_task(void *param) uint8_t aliveCounter = 0; - //QMC5883L_MData_calibrated_t temp; - //uint8_t average = 0; - //uint16_t angle; - + /* Init the magnetometer */ if(!QMC5883L_init()) APP_LOG_INFO("Failed to init QMC5883L"); else APP_LOG_INFO("Inited QMC5883L"); + tls_os_time_delay(2); if(!QMC5883L_set_power_mode(Continuous)) APP_LOG_INFO("Failed to set QMC5883L mode"); else APP_LOG_INFO("QMC5883L Mode set"); + tls_os_time_delay(2); if(!QMC5883L_configure_1(ODR_10HZ, FS_2G, OSR_512)) APP_LOG_INFO("Failed to configure 1 QMC5883L"); else APP_LOG_INFO("QMC5883L configured"); - + QMC5883L_set_calibration_data(-900, 2500, -1400, 1400, 2300, 7500, 0.0); + /* Init the BMP280 */ + if(!BMP280_init()) + APP_LOG_INFO("Failed to init BMP280"); + else + APP_LOG_INFO("Inited BMP280"); + + if(!BMP280_configure(BMP280_Forced, BMP280_Oversampling_x16, BMP280_Oversampling_x16, BMP280_Filter_x16, BMP280_Standby_4000MS)) + APP_LOG_INFO("Failed to configure BMP280"); + else + APP_LOG_INFO("BMP280 configured"); + + /* Init the BMA456 */ + bma.intf = BMA4_I2C_INTF; + uint8_t dev_addr = BMA4_I2C_ADDR_SECONDARY; + bma.intf_ptr = &dev_addr; + bma.bus_read = &(bma4_i2c_read); + bma.bus_write = &(bma4_i2c_write); + bma.variant = BMA45X_VARIANT; + bma.delay_us = &(delay_us); + bma.read_write_len = 46; + bma.perf_mode_status = BMA4_DISABLE; + + if(bma456w_init(&bma) == BMA4_OK) + APP_LOG_INFO("BMA456 init"); + else + APP_LOG_INFO("Failed to init BMA456"); + + bma4_soft_reset(&bma); + tls_os_time_delay(2); + + if(bma456w_write_config_file(&bma) == BMA4_OK) + APP_LOG_INFO("BMA456 config ok"); + else + APP_LOG_INFO("BMA456 config failed"); + + accel_conf.odr = BMA4_OUTPUT_DATA_RATE_100HZ; + accel_conf.range = BMA4_ACCEL_RANGE_2G; + accel_conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4; + accel_conf.perf_mode = BMA4_CIC_AVG_MODE; + + if(bma4_set_accel_config(&accel_conf, &bma) == BMA4_OK) + APP_LOG_INFO("BMA456 accel conf ok"); + else + APP_LOG_INFO("BMA456 accel conf failed"); + + if(bma4_set_accel_enable(1, &bma) == BMA4_OK) + APP_LOG_INFO("BMA456 accel en ok"); + else + APP_LOG_INFO("BMA456 accel en failed"); + + bma456w_feature_enable(BMA456W_WRIST_WEAR_WAKEUP, 1, &bma); + + bma456w_get_wrist_wear_wakeup_param_config(&setting, &bma); + + APP_LOG_DEBUG("%d %d %d %d %d %d %d %d", setting.min_angle_focus, setting.min_angle_non_focus, setting.angle_landscape_right, setting.angle_landscape_left, setting.angle_portrait_up, setting.angle_portrait_down, setting.min_dur_moved, setting.min_dur_quite); + + bma456w_map_interrupt(BMA4_INTR1_MAP, BMA456W_WRIST_WEAR_WAKEUP_INT, BMA4_ENABLE, &bma); + + //bma456w_map_interrupt(BMA4_INTR1_MAP, (BMA456W_ANY_MOT_INT | BMA456W_NO_MOT_INT), BMA4_ENABLE, &bma); + + /*struct bma456w_any_no_mot_config any_no_mot = {.threshold = 10, .duration = 4, .axes_en = BMA456W_EN_ALL_AXIS}; + bma456w_set_any_mot_config(&any_no_mot, &bma); + + bma456w_set_no_mot_config(&any_no_mot, &bma);*/ + + + + + for(;;) { lv_timer_handler(); tls_os_time_delay(5); - if(QMC5883L_is_data_available()) + if(compass_screen_is_in_use(&compassScreen) && QMC5883L_is_data_available()) { //QMC5883L_MData_t MDataRaw = QMC5883L_get_MFields_raw(); //APP_LOG_TRACE("X %d Y %d Z %d", MDataRaw.MFieldX, MDataRaw.MFieldY, MDataRaw.MFieldZ); @@ -167,9 +285,27 @@ void gfx_task(void *param) compass_screen_set_azimuth(&compassScreen, angle_with_offset(QMC5883L_get_azimuth(MData), 180)); } + uint8_t rslt = bma456w_read_int_status(&int_status, &bma); + if(rslt != BMA4_OK) + APP_LOG_DEBUG("Failed to read int status"); + + /* Check if step counter interrupt is triggered */ + if((BMA4_OK == rslt) && (int_status & BMA456W_ANY_MOT_INT)) + { + APP_LOG_DEBUG("Motion detected"); + } + + if((BMA4_OK == rslt) && (int_status & BMA456W_WRIST_WEAR_WAKEUP_INT)) + { + APP_LOG_DEBUG("Wrist tilt"); + } + if(++aliveCounter % 200 == 0) { - APP_LOG_DEBUG("GFX thread"); + float temp = BMP280_get_temperature(); + BMP280_trigger_measurement(); + APP_LOG_DEBUG("GFX thread, temp : %0.2f", temp); + aliveCounter = 0; } } diff --git a/src/W800 SDK v1.00.08/app/gfx/gfx_task.h b/src/W800 SDK v1.00.08/app/gfx/gfx_task.h index c343b74..ab81ccb 100644 --- a/src/W800 SDK v1.00.08/app/gfx/gfx_task.h +++ b/src/W800 SDK v1.00.08/app/gfx/gfx_task.h @@ -4,7 +4,7 @@ #include "wm_include.h" -#define GFX_STACK_SIZE_IN_BYTES (1024 * sizeof(StackType_t)) +#define GFX_STACK_SIZE_IN_BYTES (1100 * sizeof(StackType_t)) #define GFX_STACK_PRIORITY (5) static u8 gfx_task_stack[GFX_STACK_SIZE_IN_BYTES]; diff --git a/src/W800 SDK v1.00.08/app/gfx/settings_screen.c b/src/W800 SDK v1.00.08/app/gfx/settings_screen.c index e5e2b58..427edb2 100644 --- a/src/W800 SDK v1.00.08/app/gfx/settings_screen.c +++ b/src/W800 SDK v1.00.08/app/gfx/settings_screen.c @@ -3,12 +3,15 @@ #include "settings_screen.h" #include "menu_screen.h" -const char *day_options = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31"; -const char *month_options = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12"; -const char *year_options = "22\n23\n24\n25\n26\n27\n28\n29\n30"; +static const char *day_options = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31"; +static const char *month_options = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12"; +static const char *year_options = "22\n23\n24\n25\n26\n27\n28\n29\n30"; -const char *hour_options = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23"; -const char *sec_min_options = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59"; +static const char *hour_options = "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23"; +static const char *minute_options = "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59"; +static const char *second_options = "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59"; + +const char *date_format = "dd/mm/yyyy\ndd/mm/yy\nyyyy/mm/dd\nyy/mm/dd"; static void gesture_event_cb(lv_event_t * e) { @@ -45,6 +48,52 @@ static void cleanup_event_cb(lv_event_t * e) LV_LOG_USER("cleanup"); } +static void time_roller_cb(lv_event_t * e) +{ + SettingsScreen_t *settingsScreen = e->user_data; + if(!settingsScreen->settingsScreenAPIInterface.setTimeSettingsCb) return; + + lv_obj_t *roller = lv_event_get_target(e); + uint8_t index = lv_roller_get_selected(roller); + + if(roller == settingsScreen->hour_roller) + { + settingsScreen->settingsScreenAPIInterface.setTimeSettingsCb(index, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); + } + else if(roller == settingsScreen->minute_roller) + { + settingsScreen->settingsScreenAPIInterface.setTimeSettingsCb(0xFF, index, 0xFF, 0xFF, 0xFF, 0xFF); + } + else if(roller == settingsScreen->second_roller) + { + settingsScreen->settingsScreenAPIInterface.setTimeSettingsCb(0xFF, 0xFF, index, 0xFF, 0xFF, 0xFF); + } + else if(roller == settingsScreen->day_roller) + { + settingsScreen->settingsScreenAPIInterface.setTimeSettingsCb(0xFF, 0xFF, 0xFF, index + 1, 0xFF, 0xFF); + } + else if(roller == settingsScreen->month_roller) + { + settingsScreen->settingsScreenAPIInterface.setTimeSettingsCb(0xFF, 0xFF, 0xFF, 0xFF, index + 1, 0xFF); + } + else + { + settingsScreen->settingsScreenAPIInterface.setTimeSettingsCb(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, index + 22); + } +} + +static void brightness_slider_cb(lv_event_t * e) +{ + SettingsScreen_t *settingsScreen = e->user_data; + if(!settingsScreen->settingsScreenAPIInterface.setBrightnessSettingsCb) return; + + lv_obj_t * slider = lv_event_get_target(e); + uint8_t brightness = (float)lv_slider_get_value(slider) * 2.55; + + if(brightness > 5) + settingsScreen->settingsScreenAPIInterface.setBrightnessSettingsCb(brightness); +} + static lv_obj_t* add_sidebar_entry_to_menu(lv_obj_t *parent, const char *title, lv_obj_t *menu, lv_obj_t *pageToShow) { lv_obj_t *container = lv_menu_cont_create(parent); @@ -136,8 +185,8 @@ void settings_screen_create(SettingsScreen_t * const settingsScreen) lv_obj_t *section = create_menu_page_section(menu_page_1); - lv_obj_t *menu_page_1_label = lv_label_create(section); - lv_label_set_text_static(menu_page_1_label, "Set Time & Date :"); + lv_obj_t *menu_page_label = lv_label_create(section); + lv_label_set_text_static(menu_page_label, "Set Time & Date :"); lv_obj_t *container = create_section_container(section); lv_obj_t *toggle = lv_switch_create(container); @@ -145,22 +194,10 @@ void settings_screen_create(SettingsScreen_t * const settingsScreen) lv_label_set_text_static(toggle_label, "Automatic"); lv_obj_set_style_pad_top(toggle_label, 5, LV_PART_MAIN); - menu_page_1_label = lv_label_create(section); - lv_label_set_text_static(menu_page_1_label, "Time :"); + menu_page_label = lv_label_create(section); + lv_label_set_text_static(menu_page_label, "Time :"); container = create_section_container(section); - lv_obj_t *hour_drop = lv_dropdown_create(container); - lv_dropdown_set_options_static(hour_drop, hour_options); - lv_obj_set_width(hour_drop, lv_pct(30)); - - hour_drop = lv_dropdown_create(container); - lv_dropdown_set_options_static(hour_drop, sec_min_options); - lv_obj_set_width(hour_drop, lv_pct(30)); - - hour_drop = lv_dropdown_create(container); - lv_dropdown_set_options_static(hour_drop, sec_min_options); - lv_obj_set_width(hour_drop, lv_pct(30)); - /*container = lv_obj_create(section); lv_obj_set_style_pad_right(container,0, LV_PART_MAIN); lv_obj_set_style_pad_left(container,0, LV_PART_MAIN); @@ -185,47 +222,97 @@ void settings_screen_create(SettingsScreen_t * const settingsScreen) lv_obj_set_style_arc_width(arc, 1, LV_PART_INDICATOR); lv_obj_set_style_arc_width(arc, 1, LV_PART_MAIN);*/ - /*lv_obj_t *hour_roller = lv_roller_create(container);, *minute_roller = lv_roller_create(container), *second_roller = lv_roller_create(container); - lv_roller_set_options(hour_roller, hour_options, LV_ROLLER_MODE_INFINITE); - lv_roller_set_visible_row_count(hour_roller, 1); - lv_obj_set_style_anim_time(hour_roller, 0, LV_PART_MAIN);*/ + settingsScreen->hour_roller = lv_roller_create(container); + settingsScreen->minute_roller = lv_roller_create(container); + settingsScreen->second_roller = lv_roller_create(container); + + lv_roller_set_options(settingsScreen->hour_roller, hour_options, LV_ROLLER_MODE_NORMAL); + lv_roller_set_visible_row_count(settingsScreen->hour_roller, 2); + lv_obj_add_event_cb(settingsScreen->hour_roller, &(time_roller_cb), LV_EVENT_RELEASED, settingsScreen); + + lv_roller_set_options(settingsScreen->minute_roller, minute_options, LV_ROLLER_MODE_NORMAL); + lv_roller_set_visible_row_count(settingsScreen->minute_roller, 2); + lv_obj_add_event_cb(settingsScreen->minute_roller, &(time_roller_cb), LV_EVENT_RELEASED, settingsScreen); + + lv_roller_set_options(settingsScreen->second_roller, second_options, LV_ROLLER_MODE_NORMAL); + lv_roller_set_visible_row_count(settingsScreen->second_roller, 2); + lv_obj_add_event_cb(settingsScreen->second_roller, &(time_roller_cb), LV_EVENT_RELEASED, settingsScreen); + + menu_page_label = lv_label_create(section); + lv_label_set_text_static(menu_page_label, "Time Format :"); + container = create_section_container(section); + + lv_obj_t *checkbox_12 = lv_checkbox_create(container), *checkbox_24 = lv_checkbox_create(container); + lv_checkbox_set_text(checkbox_12, "12H"); + lv_obj_set_style_radius(checkbox_12, LV_RADIUS_CIRCLE, LV_PART_INDICATOR); + lv_checkbox_set_text(checkbox_24, "24H"); + lv_obj_add_state(checkbox_24, LV_STATE_CHECKED); + lv_obj_set_style_radius(checkbox_24, LV_RADIUS_CIRCLE, LV_PART_INDICATOR); + + menu_page_label = lv_label_create(section); + lv_label_set_text_static(menu_page_label, "Date :"); + container = create_section_container(section); + + settingsScreen->day_roller = lv_roller_create(container); + settingsScreen->month_roller = lv_roller_create(container); + settingsScreen->year_roller = lv_roller_create(container); + + lv_roller_set_options(settingsScreen->day_roller, day_options, LV_ROLLER_MODE_NORMAL); + lv_roller_set_visible_row_count(settingsScreen->day_roller, 2); + lv_obj_add_event_cb(settingsScreen->day_roller, &(time_roller_cb), LV_EVENT_RELEASED, settingsScreen); + + lv_roller_set_options(settingsScreen->month_roller, month_options, LV_ROLLER_MODE_NORMAL); + lv_roller_set_visible_row_count(settingsScreen->month_roller, 2); + lv_obj_add_event_cb(settingsScreen->month_roller, &(time_roller_cb), LV_EVENT_RELEASED, settingsScreen); + + lv_roller_set_options(settingsScreen->year_roller, year_options, LV_ROLLER_MODE_NORMAL); + lv_roller_set_visible_row_count(settingsScreen->year_roller, 2); + lv_obj_add_event_cb(settingsScreen->year_roller, &(time_roller_cb), LV_EVENT_RELEASED, settingsScreen); + + menu_page_label = lv_label_create(section); + lv_label_set_text_static(menu_page_label, "Date Format :"); + container = create_section_container(section); + + lv_obj_t *date_dropdown = lv_dropdown_create(container); + lv_dropdown_set_options_static(date_dropdown, date_format); - /*lv_roller_set_options(minute_roller, sec_min_options, LV_ROLLER_MODE_INFINITE); - lv_roller_set_visible_row_count(minute_roller, 2); + //We create the menu page for the display settings + lv_obj_t *menu_page_2 = lv_menu_page_create(menu, NULL); - lv_roller_set_options(second_roller, sec_min_options, LV_ROLLER_MODE_INFINITE); - lv_roller_set_visible_row_count(second_roller, 2);*/ - - - menu_page_1_label = lv_label_create(section); - lv_label_set_text_static(menu_page_1_label, "Date :"); - /*container = create_section_container(section); - - lv_obj_t *day_roller = lv_roller_create(container), *month_roller = lv_roller_create(container), *year_roller = lv_roller_create(container); - lv_roller_set_options(day_roller, day_options, LV_ROLLER_MODE_INFINITE); - lv_roller_set_visible_row_count(day_roller, 2); - - lv_roller_set_options(month_roller, month_options, LV_ROLLER_MODE_INFINITE); - lv_roller_set_visible_row_count(month_roller, 2); - - lv_roller_set_options(year_roller, year_options, LV_ROLLER_MODE_INFINITE); - lv_roller_set_visible_row_count(year_roller, 2);*/ + section = create_menu_page_section(menu_page_2); + menu_page_label = lv_label_create(section); + lv_label_set_text_static(menu_page_label, "Brightness :"); + container = create_section_container(section); + lv_obj_t *slider = lv_slider_create(container); + lv_obj_clear_flag(slider, LV_OBJ_FLAG_GESTURE_BUBBLE); + lv_obj_set_width(slider, lv_pct(90)); + lv_obj_set_align(slider, LV_ALIGN_CENTER); + lv_obj_add_event_cb(slider, &(brightness_slider_cb), LV_EVENT_VALUE_CHANGED, settingsScreen); + menu_page_label = lv_label_create(section); + lv_label_set_text_static(menu_page_label, "Sleep Timeout :"); + container = create_section_container(section); + lv_obj_t *timeout = lv_roller_create(container); + lv_roller_set_options(timeout, second_options, LV_ROLLER_MODE_NORMAL); + lv_roller_set_visible_row_count(timeout, 2); + lv_obj_t *timeout_label = lv_label_create(container); + lv_label_set_text_static(timeout_label, "Second(s)"); + lv_obj_set_style_pad_top(timeout_label, 25, LV_PART_MAIN); //We create the side bar page lv_obj_t *sidebar_page = lv_menu_page_create(menu, NULL); lv_obj_t *settings_section_1 = lv_menu_section_create(sidebar_page); lv_obj_set_style_pad_all(settings_section_1, 0, LV_PART_MAIN); - lv_obj_set_style_pad_bottom(settings_section_1, 50, LV_PART_MAIN); - lv_obj_set_style_pad_hor(settings_section_1,-10,LV_PART_MAIN); + lv_obj_set_style_pad_bottom(settings_section_1, 50 , LV_PART_MAIN); + lv_obj_set_style_pad_hor(settings_section_1, -10 ,LV_PART_MAIN); lv_obj_t *selected = add_sidebar_entry_to_menu(settings_section_1, "Time & Date", menu, menu_page_1); - add_sidebar_entry_to_menu(settings_section_1, "Display", menu, NULL); + add_sidebar_entry_to_menu(settings_section_1, "Display", menu, menu_page_2); add_sidebar_entry_to_menu(settings_section_1, "Notifications", menu, NULL); @@ -252,10 +339,16 @@ void settings_screen_destroy(SettingsScreen_t * const settingsScreen) return; } - settingsScreen->display = NULL; + settingsScreen->hour_roller = NULL; + settingsScreen->minute_roller = NULL; + settingsScreen->second_roller = NULL; + settingsScreen->day_roller = NULL; + settingsScreen->month_roller = NULL; + settingsScreen->year_roller = NULL; + settingsScreen->display = NULL; } -/*const char *date_format = "dd/mm/yyyy\ndd/mm/yy\nyyyy/mm/dd\nyy/mm/dd"; +/* const char *lang_options = "English\nFrench\nGerman\nItalian"; diff --git a/src/W800 SDK v1.00.08/app/gfx/settings_screen.h b/src/W800 SDK v1.00.08/app/gfx/settings_screen.h index b785ce9..c761310 100644 --- a/src/W800 SDK v1.00.08/app/gfx/settings_screen.h +++ b/src/W800 SDK v1.00.08/app/gfx/settings_screen.h @@ -5,12 +5,19 @@ typedef struct SettingsScreenAPIInterface { - + void (*setBrightnessSettingsCb)(uint8_t brightness); + void (*setTimeSettingsCb)(uint8_t hour, uint8_t minute, uint8_t second, uint8_t day, uint8_t month, uint8_t year); } SettingsScreenAPIInterface_t; typedef struct SettingsScreen { SettingsScreenAPIInterface_t settingsScreenAPIInterface; + lv_obj_t *hour_roller; + lv_obj_t *minute_roller; + lv_obj_t *second_roller; + lv_obj_t *day_roller; + lv_obj_t *month_roller; + lv_obj_t *year_roller; lv_obj_t *display; } SettingsScreen_t; diff --git a/src/W800 SDK v1.00.08/lvgl/lvgl_port/lv_conf.h b/src/W800 SDK v1.00.08/lvgl/lvgl_port/lv_conf.h index a022751..214d33a 100644 --- a/src/W800 SDK v1.00.08/lvgl/lvgl_port/lv_conf.h +++ b/src/W800 SDK v1.00.08/lvgl/lvgl_port/lv_conf.h @@ -268,14 +268,14 @@ *-----------*/ /*1: Show CPU usage and FPS count*/ -#define LV_USE_PERF_MONITOR 1 +#define LV_USE_PERF_MONITOR 0 #if LV_USE_PERF_MONITOR #define LV_USE_PERF_MONITOR_POS LV_ALIGN_BOTTOM_RIGHT #endif /*1: Show the used memory and the memory fragmentation * Requires LV_MEM_CUSTOM = 0*/ -#define LV_USE_MEM_MONITOR 1 +#define LV_USE_MEM_MONITOR 0 #if LV_USE_MEM_MONITOR #define LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_LEFT #endif @@ -466,9 +466,9 @@ #define LV_USE_BTN 1 -#define LV_USE_BTNMATRIX 1 +#define LV_USE_BTNMATRIX 0 -#define LV_USE_CANVAS 1 +#define LV_USE_CANVAS 0 #define LV_USE_CHECKBOX 1 @@ -509,7 +509,7 @@ *----------*/ #define LV_USE_ANIMIMG 1 -#define LV_USE_CALENDAR 1 +#define LV_USE_CALENDAR 0 #if LV_USE_CALENDAR #define LV_CALENDAR_WEEK_STARTS_MONDAY 0 #if LV_CALENDAR_WEEK_STARTS_MONDAY diff --git a/src/lvgl_win_sim/lv_port_win_codeblocks/settings_screen.c b/src/lvgl_win_sim/lv_port_win_codeblocks/settings_screen.c index 4c114d2..2ac722e 100644 --- a/src/lvgl_win_sim/lv_port_win_codeblocks/settings_screen.c +++ b/src/lvgl_win_sim/lv_port_win_codeblocks/settings_screen.c @@ -3,12 +3,15 @@ #include "settings_screen.h" #include "menu_screen.h" -const char *day_options = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31"; -const char *month_options = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12"; -const char *year_options = "22\n23\n24\n25\n26\n27\n28\n29\n30"; +static const char *day_options = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31"; +static const char *month_options = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12"; +static const char *year_options = "22\n23\n24\n25\n26\n27\n28\n29\n30"; -const char *hour_options = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23"; -const char *sec_min_options = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59"; +static const char *hour_options = "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23"; +static const char *minute_options = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59"; +static const char *second_options = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59"; + +const char *date_format = "dd/mm/yyyy\ndd/mm/yy\nyyyy/mm/dd\nyy/mm/dd"; static void gesture_event_cb(lv_event_t * e) { @@ -45,6 +48,25 @@ static void cleanup_event_cb(lv_event_t * e) LV_LOG_USER("cleanup"); } +static void time_roller_cb(lv_event_t * e) +{ + SettingsScreen_t *settingsScreen = e->user_data; + lv_obj_t *roller = lv_event_get_target(e); + + if(roller == settingsScreen->hour_roller) + { + LV_LOG_USER("hour : %u", lv_roller_get_selected(roller)); + } + else if(roller == settingsScreen->minute_roller) + { + LV_LOG_USER("minute : %u", lv_roller_get_selected(roller)); + } + else + { + LV_LOG_USER("second : %u", lv_roller_get_selected(roller)); + } +} + static lv_obj_t* add_sidebar_entry_to_menu(lv_obj_t *parent, const char *title, lv_obj_t *menu, lv_obj_t *pageToShow) { lv_obj_t *container = lv_menu_cont_create(parent); @@ -136,8 +158,8 @@ void settings_screen_create(SettingsScreen_t * const settingsScreen) lv_obj_t *section = create_menu_page_section(menu_page_1); - lv_obj_t *menu_page_1_label = lv_label_create(section); - lv_label_set_text_static(menu_page_1_label, "Set Time & Date :"); + lv_obj_t *menu_page_label = lv_label_create(section); + lv_label_set_text_static(menu_page_label, "Set Time & Date :"); lv_obj_t *container = create_section_container(section); lv_obj_t *toggle = lv_switch_create(container); @@ -145,23 +167,10 @@ void settings_screen_create(SettingsScreen_t * const settingsScreen) lv_label_set_text_static(toggle_label, "Automatic"); lv_obj_set_style_pad_top(toggle_label, 5, LV_PART_MAIN); - menu_page_1_label = lv_label_create(section); - lv_label_set_text_static(menu_page_1_label, "Time :"); - + menu_page_label = lv_label_create(section); + lv_label_set_text_static(menu_page_label, "Time :"); container = create_section_container(section); - lv_obj_t *hour_drop = lv_dropdown_create(container); - lv_dropdown_set_options_static(hour_drop, hour_options); - lv_obj_set_width(hour_drop, lv_pct(30)); - - hour_drop = lv_dropdown_create(container); - lv_dropdown_set_options_static(hour_drop, sec_min_options); - lv_obj_set_width(hour_drop, lv_pct(30)); - - hour_drop = lv_dropdown_create(container); - lv_dropdown_set_options_static(hour_drop, sec_min_options); - lv_obj_set_width(hour_drop, lv_pct(30)); - /*container = lv_obj_create(section); lv_obj_set_style_pad_right(container,0, LV_PART_MAIN); lv_obj_set_style_pad_left(container,0, LV_PART_MAIN); @@ -181,42 +190,87 @@ void settings_screen_create(SettingsScreen_t * const settingsScreen) lv_obj_set_style_arc_width(arc, 1, LV_PART_MAIN); arc = lv_arc_create(container); - lv_obj_set_size(arc, 75, 75); + lv_obj_set_size(arc, 70, 70); lv_obj_center(arc); lv_obj_set_style_arc_width(arc, 1, LV_PART_INDICATOR); lv_obj_set_style_arc_width(arc, 1, LV_PART_MAIN);*/ - /*container = create_section_container(section); + settingsScreen->hour_roller = lv_roller_create(container); + settingsScreen->minute_roller = lv_roller_create(container); + settingsScreen->second_roller = lv_roller_create(container); - lv_obj_t *hour_roller = lv_roller_create(container), *minute_roller = lv_roller_create(container), *second_roller = lv_roller_create(container); - lv_roller_set_options(hour_roller, hour_options, LV_ROLLER_MODE_INFINITE); - lv_roller_set_visible_row_count(hour_roller, 2); + lv_roller_set_options(settingsScreen->hour_roller, hour_options, LV_ROLLER_MODE_NORMAL); + lv_roller_set_visible_row_count(settingsScreen->hour_roller, 2); + lv_obj_add_event_cb(settingsScreen->hour_roller, &(time_roller_cb), LV_EVENT_RELEASED, settingsScreen); + lv_roller_set_options(settingsScreen->minute_roller, minute_options, LV_ROLLER_MODE_NORMAL); + lv_roller_set_visible_row_count(settingsScreen->minute_roller, 2); + lv_obj_add_event_cb(settingsScreen->minute_roller, &(time_roller_cb), LV_EVENT_RELEASED, settingsScreen); - lv_roller_set_options(minute_roller, sec_min_options, LV_ROLLER_MODE_INFINITE); - lv_roller_set_visible_row_count(minute_roller, 2); + lv_roller_set_options(settingsScreen->second_roller, second_options, LV_ROLLER_MODE_NORMAL); + lv_roller_set_visible_row_count(settingsScreen->second_roller, 2); + lv_obj_add_event_cb(settingsScreen->second_roller, &(time_roller_cb), LV_EVENT_RELEASED, settingsScreen); - lv_roller_set_options(second_roller, sec_min_options, LV_ROLLER_MODE_INFINITE); - lv_roller_set_visible_row_count(second_roller, 2); - - - menu_page_1_label = lv_label_create(section); - lv_label_set_text_static(menu_page_1_label, "Date :"); + menu_page_label = lv_label_create(section); + lv_label_set_text_static(menu_page_label, "Time Format :"); container = create_section_container(section); - lv_obj_t *day_roller = lv_roller_create(container), *month_roller = lv_roller_create(container), *year_roller = lv_roller_create(container); - lv_roller_set_options(day_roller, day_options, LV_ROLLER_MODE_INFINITE); - lv_roller_set_visible_row_count(day_roller, 2); + lv_obj_t *checkbox_12 = lv_checkbox_create(container), *checkbox_24 = lv_checkbox_create(container); + lv_checkbox_set_text(checkbox_12, "12H"); + lv_obj_set_style_radius(checkbox_12, LV_RADIUS_CIRCLE, LV_PART_INDICATOR); + lv_checkbox_set_text(checkbox_24, "24H"); + lv_obj_add_state(checkbox_24, LV_STATE_CHECKED); + lv_obj_set_style_radius(checkbox_24, LV_RADIUS_CIRCLE, LV_PART_INDICATOR); - lv_roller_set_options(month_roller, month_options, LV_ROLLER_MODE_INFINITE); - lv_roller_set_visible_row_count(month_roller, 2); + menu_page_label = lv_label_create(section); + lv_label_set_text_static(menu_page_label, "Date :"); + container = create_section_container(section); - lv_roller_set_options(year_roller, year_options, LV_ROLLER_MODE_INFINITE); - lv_roller_set_visible_row_count(year_roller, 2);*/ + settingsScreen->day_roller = lv_roller_create(container); + settingsScreen->month_roller = lv_roller_create(container); + settingsScreen->year_roller = lv_roller_create(container); + + lv_roller_set_options(settingsScreen->day_roller, day_options, LV_ROLLER_MODE_NORMAL); + lv_roller_set_visible_row_count(settingsScreen->day_roller, 2); + + lv_roller_set_options(settingsScreen->month_roller, month_options, LV_ROLLER_MODE_NORMAL); + lv_roller_set_visible_row_count(settingsScreen->month_roller, 2); + + lv_roller_set_options(settingsScreen->year_roller, year_options, LV_ROLLER_MODE_NORMAL); + lv_roller_set_visible_row_count(settingsScreen->year_roller, 2); + + menu_page_label = lv_label_create(section); + lv_label_set_text_static(menu_page_label, "Date Format :"); + container = create_section_container(section); + + lv_obj_t *date_dropdown = lv_dropdown_create(container); + lv_dropdown_set_options_static(date_dropdown, date_format); + //We create the menu page for the display settings + lv_obj_t *menu_page_2 = lv_menu_page_create(menu, NULL); + section = create_menu_page_section(menu_page_2); + menu_page_label = lv_label_create(section); + lv_label_set_text_static(menu_page_label, "Brightness :"); + container = create_section_container(section); + + lv_obj_t *slider = lv_slider_create(container); + lv_obj_clear_flag(slider, LV_OBJ_FLAG_GESTURE_BUBBLE); + lv_obj_set_width(slider, lv_pct(90)); + lv_obj_set_align(slider, LV_ALIGN_CENTER); + + menu_page_label = lv_label_create(section); + lv_label_set_text_static(menu_page_label, "Sleep Timeout :"); + container = create_section_container(section); + + lv_obj_t *timeout = lv_roller_create(container); + lv_roller_set_options(timeout, second_options, LV_ROLLER_MODE_NORMAL); + lv_roller_set_visible_row_count(timeout, 2); + lv_obj_t *timeout_label = lv_label_create(container); + lv_label_set_text_static(timeout_label, "Second(s)"); + lv_obj_set_style_pad_top(timeout_label, 25, LV_PART_MAIN); //We create the side bar page lv_obj_t *sidebar_page = lv_menu_page_create(menu, NULL); @@ -256,7 +310,13 @@ void settings_screen_destroy(SettingsScreen_t * const settingsScreen) return; } - settingsScreen->display = NULL; + settingsScreen->hour_roller = NULL; + settingsScreen->minute_roller = NULL; + settingsScreen->second_roller = NULL; + settingsScreen->day_roller = NULL; + settingsScreen->month_roller = NULL; + settingsScreen->year_roller = NULL; + settingsScreen->display = NULL; } diff --git a/src/lvgl_win_sim/lv_port_win_codeblocks/settings_screen.h b/src/lvgl_win_sim/lv_port_win_codeblocks/settings_screen.h index b785ce9..5869b54 100644 --- a/src/lvgl_win_sim/lv_port_win_codeblocks/settings_screen.h +++ b/src/lvgl_win_sim/lv_port_win_codeblocks/settings_screen.h @@ -11,6 +11,12 @@ typedef struct SettingsScreenAPIInterface typedef struct SettingsScreen { SettingsScreenAPIInterface_t settingsScreenAPIInterface; + lv_obj_t *hour_roller; + lv_obj_t *minute_roller; + lv_obj_t *second_roller; + lv_obj_t *day_roller; + lv_obj_t *month_roller; + lv_obj_t *year_roller; lv_obj_t *display; } SettingsScreen_t;