From faed0d49006605e33905f1914f04c90f6138bf6e Mon Sep 17 00:00:00 2001 From: hubmartin Date: Sun, 15 Aug 2021 16:47:41 +0200 Subject: Remove unnecessary pin_set, save 50ms --- src/drivers/Cst816s.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index fd9792b3..affc432f 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -19,8 +19,8 @@ Cst816S::Cst816S(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster {twiMaste void Cst816S::Init() { nrf_gpio_cfg_output(pinReset); - nrf_gpio_pin_set(pinReset); - vTaskDelay(50); + //nrf_gpio_pin_set(pinReset); + //vTaskDelay(5); nrf_gpio_pin_clear(pinReset); vTaskDelay(5); nrf_gpio_pin_set(pinReset); -- cgit v1.2.3 From 099364e619374c4ad9bc0ba9136c31c35a82faf7 Mon Sep 17 00:00:00 2001 From: hubmartin Date: Sun, 15 Aug 2021 16:48:41 +0200 Subject: Remove LCD reset and more cmds, save over 200ms --- src/drivers/St7789.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/drivers/St7789.cpp b/src/drivers/St7789.cpp index 0f1dc02e..74038b2b 100644 --- a/src/drivers/St7789.cpp +++ b/src/drivers/St7789.cpp @@ -171,15 +171,15 @@ void St7789::Sleep() { void St7789::Wakeup() { nrf_gpio_cfg_output(pinDataCommand); // TODO why do we need to reset the controller? - HardwareReset(); - SoftwareReset(); + //HardwareReset(); + //SoftwareReset(); SleepOut(); - ColMod(); - MemoryDataAccessControl(); - ColumnAddressSet(); - RowAddressSet(); - DisplayInversionOn(); - NormalModeOn(); + //ColMod(); + //MemoryDataAccessControl(); + //ColumnAddressSet(); + //RowAddressSet(); + //DisplayInversionOn(); + //NormalModeOn(); VerticalScrollStartAddress(verticalScrollingStartAddress); DisplayOn(); NRF_LOG_INFO("[LCD] Wakeup") -- cgit v1.2.3 From db50131ed49f2fdb639799ca12839862340f8396 Mon Sep 17 00:00:00 2001 From: hubmartin Date: Mon, 23 Aug 2021 15:02:40 +0200 Subject: Remove commented commands completely --- src/drivers/Cst816s.cpp | 2 -- src/drivers/St7789.cpp | 9 --------- 2 files changed, 11 deletions(-) (limited to 'src') diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index affc432f..2e70a469 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -19,8 +19,6 @@ Cst816S::Cst816S(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster {twiMaste void Cst816S::Init() { nrf_gpio_cfg_output(pinReset); - //nrf_gpio_pin_set(pinReset); - //vTaskDelay(5); nrf_gpio_pin_clear(pinReset); vTaskDelay(5); nrf_gpio_pin_set(pinReset); diff --git a/src/drivers/St7789.cpp b/src/drivers/St7789.cpp index 74038b2b..4d81cf27 100644 --- a/src/drivers/St7789.cpp +++ b/src/drivers/St7789.cpp @@ -170,16 +170,7 @@ void St7789::Sleep() { void St7789::Wakeup() { nrf_gpio_cfg_output(pinDataCommand); - // TODO why do we need to reset the controller? - //HardwareReset(); - //SoftwareReset(); SleepOut(); - //ColMod(); - //MemoryDataAccessControl(); - //ColumnAddressSet(); - //RowAddressSet(); - //DisplayInversionOn(); - //NormalModeOn(); VerticalScrollStartAddress(verticalScrollingStartAddress); DisplayOn(); NRF_LOG_INFO("[LCD] Wakeup") -- cgit v1.2.3 From fd4fbfddb9508ea6ed9073523edd3a5f29e8195a Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Wed, 13 Oct 2021 13:04:40 +0300 Subject: Flashlight brightness control --- src/displayapp/DisplayApp.cpp | 2 +- src/displayapp/screens/FlashLight.cpp | 114 +++++++++++++++++----- src/displayapp/screens/FlashLight.h | 16 ++- src/displayapp/screens/settings/QuickSettings.cpp | 2 +- 4 files changed, 102 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index e763cda6..20a67088 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -390,7 +390,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) break; case Apps::FlashLight: currentScreen = std::make_unique(this, *systemTask, brightnessController); - ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::None); + ReturnApp(Apps::QuickSettings, FullRefreshDirections::Down, TouchEvents::SwipeDown); break; case Apps::StopWatch: currentScreen = std::make_unique(this, *systemTask); diff --git a/src/displayapp/screens/FlashLight.cpp b/src/displayapp/screens/FlashLight.cpp index 4bc5b558..dcb31a7f 100644 --- a/src/displayapp/screens/FlashLight.cpp +++ b/src/displayapp/screens/FlashLight.cpp @@ -5,30 +5,41 @@ using namespace Pinetime::Applications::Screens; namespace { - static void event_handler(lv_obj_t* obj, lv_event_t event) { - FlashLight* screen = static_cast(obj->user_data); + void event_handler(lv_obj_t* obj, lv_event_t event) { + auto* screen = static_cast(obj->user_data); screen->OnClickEvent(obj, event); } } FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app, System::SystemTask& systemTask, - Controllers::BrightnessController& brightness) + Controllers::BrightnessController& brightnessController) : Screen(app), systemTask {systemTask}, - brightness {brightness} + brightnessController {brightnessController} { - brightness.Backup(); - brightness.Set(Controllers::BrightnessController::Levels::High); - // Set the background - lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF)); + brightnessController.Backup(); - flashLight = lv_label_create(lv_scr_act(), NULL); - lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); + brightnessLevel = brightnessController.Level(); + + flashLight = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48); lv_label_set_text_static(flashLight, Symbols::highlight); - lv_obj_align(flashLight, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_align(flashLight, nullptr, LV_ALIGN_CENTER, 0, 0); + + for (auto & i : indicators) { + i = lv_obj_create(lv_scr_act(), nullptr); + lv_obj_set_size(i, 15, 10); + lv_obj_set_style_local_border_width(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 2); + } + + lv_obj_align(indicators[1], flashLight, LV_ALIGN_OUT_BOTTOM_MID, 0, 5); + lv_obj_align(indicators[0], indicators[1], LV_ALIGN_OUT_LEFT_MID, -8, 0); + lv_obj_align(indicators[2], indicators[1], LV_ALIGN_OUT_RIGHT_MID, 8, 0); + + SetIndicators(); + SetColors(); backgroundAction = lv_label_create(lv_scr_act(), nullptr); lv_label_set_long_mode(backgroundAction, LV_LABEL_LONG_CROP); @@ -44,27 +55,80 @@ FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app, FlashLight::~FlashLight() { lv_obj_clean(lv_scr_act()); - lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); - brightness.Restore(); + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); + brightnessController.Restore(); systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping); } -void FlashLight::OnClickEvent(lv_obj_t* obj, lv_event_t event) { - if (obj == backgroundAction) { - if (event == LV_EVENT_CLICKED) { - isOn = !isOn; - - if (isOn) { - lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF)); - lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); - } else { - lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); - lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF)); - } +void FlashLight::SetColors() { + if (isOn) { + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); + for (auto & i : indicators) { + lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); + lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DISABLED, LV_COLOR_WHITE); + lv_obj_set_style_local_border_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); } + } else { + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); + lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + for (auto & i : indicators) { + lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DISABLED, LV_COLOR_BLACK); + lv_obj_set_style_local_border_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + } + } +} + +void FlashLight::SetIndicators() { + using namespace Pinetime::Controllers; + + if (brightnessLevel == BrightnessController::Levels::High) { + lv_obj_set_state(indicators[1], LV_STATE_DEFAULT); + lv_obj_set_state(indicators[2], LV_STATE_DEFAULT); + } else if (brightnessLevel == BrightnessController::Levels::Medium) { + lv_obj_set_state(indicators[1], LV_STATE_DEFAULT); + lv_obj_set_state(indicators[2], LV_STATE_DISABLED); + } else { + lv_obj_set_state(indicators[1], LV_STATE_DISABLED); + lv_obj_set_state(indicators[2], LV_STATE_DISABLED); + } +} + +void FlashLight::OnClickEvent(lv_obj_t* obj, lv_event_t event) { + if (obj == backgroundAction && event == LV_EVENT_CLICKED) { + isOn = !isOn; + SetColors(); } } bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + using namespace Pinetime::Controllers; + + if (event == TouchEvents::SwipeLeft) { + if (brightnessLevel == BrightnessController::Levels::High) { + brightnessLevel = BrightnessController::Levels::Medium; + brightnessController.Set(brightnessLevel); + SetIndicators(); + } else if (brightnessLevel == BrightnessController::Levels::Medium) { + brightnessLevel = BrightnessController::Levels::Low; + brightnessController.Set(brightnessLevel); + SetIndicators(); + } + return true; + } + if (event == TouchEvents::SwipeRight) { + if (brightnessLevel == BrightnessController::Levels::Low) { + brightnessLevel = BrightnessController::Levels::Medium; + brightnessController.Set(brightnessLevel); + SetIndicators(); + } else if (brightnessLevel == BrightnessController::Levels::Medium) { + brightnessLevel = BrightnessController::Levels::High; + brightnessController.Set(brightnessLevel); + SetIndicators(); + } + return true; + } + return false; } diff --git a/src/displayapp/screens/FlashLight.h b/src/displayapp/screens/FlashLight.h index 7f5ca6c5..f2c65bbe 100644 --- a/src/displayapp/screens/FlashLight.h +++ b/src/displayapp/screens/FlashLight.h @@ -1,10 +1,10 @@ #pragma once -#include #include "Screen.h" -#include -#include "systemtask/SystemTask.h" #include "components/brightness/BrightnessController.h" +#include "systemtask/SystemTask.h" +#include +#include namespace Pinetime { @@ -20,12 +20,18 @@ namespace Pinetime { void OnClickEvent(lv_obj_t* obj, lv_event_t event); private: + void SetIndicators(); + void SetColors(); + Pinetime::System::SystemTask& systemTask; - Controllers::BrightnessController& brightness; + Controllers::BrightnessController& brightnessController; + + Controllers::BrightnessController::Levels brightnessLevel; lv_obj_t* flashLight; lv_obj_t* backgroundAction; - bool isOn = true; + lv_obj_t* indicators[3]; + bool isOn = false; }; } } diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp index 691c40c8..dd626072 100644 --- a/src/displayapp/screens/settings/QuickSettings.cpp +++ b/src/displayapp/screens/settings/QuickSettings.cpp @@ -131,7 +131,7 @@ void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) { if (object == btn2 && event == LV_EVENT_CLICKED) { running = false; - app->StartApp(Apps::FlashLight, DisplayApp::FullRefreshDirections::None); + app->StartApp(Apps::FlashLight, DisplayApp::FullRefreshDirections::Up); } else if (object == btn1 && event == LV_EVENT_CLICKED) { -- cgit v1.2.3