From 1d3742e14f09316a1d795527713eb8f9742f0ffb Mon Sep 17 00:00:00 2001 From: Joaquim Date: Sun, 4 Apr 2021 03:08:51 +0100 Subject: Big UI and navigation Rewrite new navigation add some color to the apps redesign menus new settings menu new quick settings code clean up size reduction by converting navigation images to font and more... --- src/displayapp/screens/SystemInfo.cpp | 129 +++++++++++++++++++++++++--------- 1 file changed, 96 insertions(+), 33 deletions(-) (limited to 'src/displayapp/screens/SystemInfo.cpp') diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp index 949fd345..f3ac7490 100644 --- a/src/displayapp/screens/SystemInfo.cpp +++ b/src/displayapp/screens/SystemInfo.cpp @@ -25,7 +25,8 @@ SystemInfo::SystemInfo(Pinetime::Applications::DisplayApp *app, { [this]() -> std::unique_ptr { return CreateScreen1(); }, [this]() -> std::unique_ptr { return CreateScreen2(); }, - [this]() -> std::unique_ptr { return CreateScreen3(); } + [this]() -> std::unique_ptr { return CreateScreen3(); }, + [this]() -> std::unique_ptr { return CreateScreen4(); } }, Screens::ScreenListModes::UpDown } {} @@ -49,16 +50,46 @@ bool SystemInfo::OnTouchEvent(Pinetime::Applications::TouchEvents event) { return screens.OnTouchEvent(event); } +void SystemInfo::CreateContainer() { + + if ( container1 ) { + container1 = lv_cont_create(lv_scr_act(), nullptr); + + lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); + lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); + lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); + lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); + + lv_obj_set_pos(container1, 0, 0); + lv_obj_set_width(container1, LV_HOR_RES - 10); + lv_obj_set_height(container1, LV_VER_RES); + lv_cont_set_layout(container1, LV_LAYOUT_CENTER); + } +} + std::unique_ptr SystemInfo::CreateScreen1() { + CreateContainer(); + + lv_obj_t * label = lv_label_create(container1, nullptr); + lv_label_set_recolor(label, true); + lv_label_set_text_fmt(label, + "#FFFF00 InfiniTime#\n\n" + "#444444 Version# %ld.%ld.%ld\n\n" + "#444444 Build date#\n" + "\t%s\n" + "\t%s\n", + Version::Major(), Version::Minor(), Version::Patch(), + __DATE__, __TIME__); + lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); + return std::unique_ptr(new Screens::Label(0, 4, app, label)); +} + +std::unique_ptr SystemInfo::CreateScreen2() { + CreateContainer(); + auto batteryPercent = static_cast(batteryController.PercentRemaining()); + float batteryVoltage = batteryController.Voltage(); - uint8_t brightness = 0; - switch(brightnessController.Level()) { - case Controllers::BrightnessController::Levels::Off: brightness = 0; break; - case Controllers::BrightnessController::Levels::Low: brightness = 1; break; - case Controllers::BrightnessController::Levels::Medium: brightness = 2; break; - case Controllers::BrightnessController::Levels::High: brightness = 3; break; - } auto resetReason = [this]() { switch (watchdog.ResetReason()) { case Drivers::Watchdog::ResetReasons::Watchdog: return "wtdg"; @@ -87,41 +118,73 @@ std::unique_ptr SystemInfo::CreateScreen1() { uptimeSeconds = uptimeSeconds % secondsInAMinute; // TODO handle more than 100 days of uptime - sprintf(t1, "InfiniTime\n" - "Version:%ld.%ld.%ld\n" - "Build: %s\n" - " %s\n" - "Date: %02d/%02d/%04d\n" - "Time: %02d:%02d:%02d\n" - "Uptime: %02lud %02lu:%02lu:%02lu\n" - "Battery: %d%%\n" - "Backlight: %d/3\n" - "Last reset: %s\n", - Version::Major(), Version::Minor(), Version::Patch(), - __DATE__, __TIME__, + if (batteryPercent == -1) batteryPercent = 0; + + // hack to not use the flot functions from printf + uint8_t batteryVoltageBytes[2]; + batteryVoltageBytes[1] = static_cast(batteryVoltage); //truncate whole numbers + batteryVoltageBytes[0] = static_cast((batteryVoltage - batteryVoltageBytes[1]) * 100); //remove whole part of flt and shift 2 places over + // + + lv_obj_t * label = lv_label_create(container1, nullptr); + lv_label_set_recolor(label, true); + lv_label_set_text_fmt(label, + "#444444 Date# %02d/%02d/%04d\n" + "#444444 Time# %02d:%02d:%02d\n" + "#444444 Uptime#\n %02lud %02lu:%02lu:%02lu\n" + "#444444 Battery# %d%%/%1i.%02iv\n" + "#444444 Backlight# %s\n" + "#444444 Last reset# %s\n", dateTimeController.Day(), static_cast(dateTimeController.Month()), dateTimeController.Year(), dateTimeController.Hours(), dateTimeController.Minutes(), dateTimeController.Seconds(), uptimeDays, uptimeHours, uptimeMinutes, uptimeSeconds, - batteryPercent, brightness, resetReason); + batteryPercent, batteryVoltageBytes[1], batteryVoltageBytes[0], brightnessController.ToString(), resetReason + ); + return std::unique_ptr(new Screens::Label(1, 4, app, label)); - return std::make_unique(app, t1); } -std::unique_ptr SystemInfo::CreateScreen2() { +std::unique_ptr SystemInfo::CreateScreen3() { + lv_mem_monitor_t mon; + lv_mem_monitor(&mon); + CreateContainer(); + + lv_obj_t * label = lv_label_create(container1, nullptr); + lv_label_set_recolor(label, true); auto& bleAddr = bleController.Address(); - sprintf(t2, "BLE MAC: \n %02x:%02x:%02x:%02x:%02x:%02x", - bleAddr[5], bleAddr[4], bleAddr[3], bleAddr[2], bleAddr[1], bleAddr[0]); - return std::make_unique(app, t2); + lv_label_set_text_fmt(label, + "#444444 BLE MAC#\n" + " %02x:%02x:%02x:%02x:%02x:%02x" + "\n" + "#444444 Memory#\n" + " #444444 used# %d (%d%%)\n" + " #444444 frag# %d%%\n" + " #444444 free# %d" + "\n" + "#444444 Steps# %li", + bleAddr[5], bleAddr[4], bleAddr[3], bleAddr[2], bleAddr[1], bleAddr[0], + (int)mon.total_size - mon.free_size, + mon.used_pct, + mon.frag_pct, + (int)mon.free_biggest_size, + 0 + ); + + return std::unique_ptr(new Screens::Label(2, 4, app, label)); } -std::unique_ptr SystemInfo::CreateScreen3() { - sprintf(t3, "Hello from\nthe developer!\n" +std::unique_ptr SystemInfo::CreateScreen4() { + CreateContainer(); + lv_obj_t * label = lv_label_create(container1, nullptr); + lv_label_set_recolor(label, true); + lv_label_set_text_static(label, "Software Licensed\n" "under the terms of\n" "the GNU General\n" "Public License v3\n" - "Source code:\n" - "https://github.com/\n" - " JF002/InfiniTime"); - return std::make_unique(app, t3); -} + "#444444 Source code#\n" + "#FFFF00 https://github.com/#\n" + "#FFFF00 JF002/InfiniTime#"); + lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); + return std::unique_ptr(new Screens::Label(3, 4, app, label)); +} \ No newline at end of file -- cgit v1.2.3