From 24e2607f6b0d5e18d06540bb1877d783c6fbcc40 Mon Sep 17 00:00:00 2001 From: Wojtek Rzepecki Date: Tue, 22 Dec 2020 13:10:24 +0100 Subject: [PATCH] [EGD-4727] Change Torch hardware control Change way of button usage --- changelog.md | 3 ++ module-apps/Application.cpp | 12 ++------ module-apps/Application.hpp | 2 +- module-apps/windows/AppWindow.cpp | 48 +++++++++++++++++-------------- 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/changelog.md b/changelog.md index 38dcb77170dd03bc646e4522956fbf051718a78b..068472fb456b37b20f9459d953aba43a3707f564 100644 --- a/changelog.md +++ b/changelog.md @@ -14,6 +14,9 @@ * Fix missing texts for ApplicationDesktop windows +### Changed + +* `[UserInterface]` Torch light control button press time recognition. ## [0.51.1 2020-12-18] ### Added diff --git a/module-apps/Application.cpp b/module-apps/Application.cpp index 1baec801c7f8a7a8a5efbfcd6ae1e511978e64a6..340494002a62f8ccd363849b03cf8e69c118a253 100644 --- a/module-apps/Application.cpp +++ b/module-apps/Application.cpp @@ -540,7 +540,7 @@ namespace app return AudioServiceAPI::GetSetting(this, audio::Setting::Volume, volume); } - void Application::toggleTorchAndColourTemps() + void Application::toggleTorch(bsp::torch::ColourTemperature temperature) { using namespace bsp; @@ -558,16 +558,10 @@ namespace app switch (msgGetState->state) { case torch::State::off: msgSetState->state = torch::State::on; - msgSetState->colourTemp = torch::warmest; + msgSetState->colourTemp = temperature; break; case torch::State::on: - if (msgGetState->colourTemp == torch::warmest) { // toggle colour temp - msgSetState->state = torch::State::on; - msgSetState->colourTemp = torch::coldest; - } - else { - msgSetState->state = torch::State::off; - } + msgSetState->state = torch::State::off; break; } sys::Bus::SendUnicast(msgSetState, service::name::evt_manager, this); diff --git a/module-apps/Application.hpp b/module-apps/Application.hpp index b6f3f7c2fdc2366411d4dd9e74911faafe979d40..f59bfc417da320d6c62e6d1a7ac7f498252b05c7 100644 --- a/module-apps/Application.hpp +++ b/module-apps/Application.hpp @@ -280,7 +280,7 @@ namespace app } audio::RetCode getCurrentVolume(audio::Volume &volume); - void toggleTorchAndColourTemps(); + void toggleTorch(bsp::torch::ColourTemperature temperature); /// @defgroup Application Application static functions /// All this functions are meant to be used in ApplicationManager only diff --git a/module-apps/windows/AppWindow.cpp b/module-apps/windows/AppWindow.cpp index 2cd8fcfcc3c44d7003d7880ba340edc77f726a47..a1f74b8c1cbd04acfbb4f5e47afa295641d63cd5 100644 --- a/module-apps/windows/AppWindow.cpp +++ b/module-apps/windows/AppWindow.cpp @@ -127,29 +127,35 @@ namespace gui LOG_INFO("exit to main menu"); app::manager::Controller::sendAction(application, app::manager::actions::Home); } - // process only if key is released - if ((inputEvent.state != InputEvent::State::keyReleasedShort)) - return false; - switch (inputEvent.keyCode) { - case KeyCode::KEY_VOLUP: { - application->increaseCurrentVolume(); - return true; - } - case KeyCode::KEY_VOLDN: { - application->decreaseCurrentVolume(); - return true; - } - case KeyCode::KEY_RF: { - application->returnToPreviousWindow(); - return true; + if ((inputEvent.isShortPress())) { + switch (inputEvent.keyCode) { + case KeyCode::KEY_VOLUP: { + application->increaseCurrentVolume(); + return true; + } + case KeyCode::KEY_VOLDN: { + application->decreaseCurrentVolume(); + return true; + } + case KeyCode::KEY_RF: { + application->returnToPreviousWindow(); + return true; + } + default: + break; + } } - case KeyCode::KEY_TORCH: { - application->toggleTorchAndColourTemps(); - return true; - } - default: - break; + + if (inputEvent.keyCode == KeyCode::KEY_TORCH) { + if (inputEvent.isLongPress()) { + application->toggleTorch(bsp::torch::ColourTemperature::warmest); + return true; + } + else if (inputEvent.isShortPress()) { + application->toggleTorch(bsp::torch::ColourTemperature::coldest); + return true; + } } return false;