diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 670f0630..34a7e250 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -242,6 +242,7 @@ set(INCLUDE_FILES Logging/NrfLogger.h BlinkApp/BlinkApp.h DisplayApp/DisplayApp.h + DisplayApp/TouchEvents.h DisplayApp/Screens/Screen.h DisplayApp/Screens/Clock.h DisplayApp/Screens/Message.h @@ -288,4 +289,4 @@ link_directories( ../ ) -nRF5x_addExecutable(pinetime-app "${SOURCE_FILES}") +nRF5x_addExecutable(pinetime-app "${SOURCE_FILES}" ${INCLUDE_FILES}) diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp index 3f58e4b3..14545d2e 100644 --- a/src/DisplayApp/DisplayApp.cpp +++ b/src/DisplayApp/DisplayApp.cpp @@ -110,17 +110,19 @@ void DisplayApp::Refresh() { case Messages::TouchEvent: { if (state != States::Running) break; auto gesture = OnTouchEvent(); - switch (gesture) { - case DisplayApp::TouchEvents::SwipeUp: - currentScreen->OnButtonPushed(); - lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::Up); - break; - case DisplayApp::TouchEvents::SwipeDown: - currentScreen->OnButtonPushed(); - lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::Down); - break; - default: - break; + if(!currentScreen->OnTouchEvent(gesture)) { + switch (gesture) { + case TouchEvents::SwipeUp: + currentScreen->OnButtonPushed(); + lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::Up); + break; + case TouchEvents::SwipeDown: + currentScreen->OnButtonPushed(); + lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::Down); + break; + default: + break; + } } } break; @@ -189,32 +191,31 @@ void DisplayApp::PushMessage(DisplayApp::Messages msg) { } } -DisplayApp::TouchEvents DisplayApp::OnTouchEvent() { +TouchEvents DisplayApp::OnTouchEvent() { auto info = touchPanel.GetTouchInfo(); if(info.isTouch) { switch(info.gesture) { case Pinetime::Drivers::Cst816S::Gestures::SingleTap: - // TODO set x,y to LittleVgl lvgl.SetNewTapEvent(info.x, info.y); - return DisplayApp::TouchEvents::Tap; + return TouchEvents::Tap; case Pinetime::Drivers::Cst816S::Gestures::LongPress: - return DisplayApp::TouchEvents::LongTap; + return TouchEvents::LongTap; case Pinetime::Drivers::Cst816S::Gestures::DoubleTap: - return DisplayApp::TouchEvents::DoubleTap; + return TouchEvents::DoubleTap; case Pinetime::Drivers::Cst816S::Gestures::SlideRight: - return DisplayApp::TouchEvents::SwipeRight; + return TouchEvents::SwipeRight; case Pinetime::Drivers::Cst816S::Gestures::SlideLeft: - return DisplayApp::TouchEvents::SwipeLeft; + return TouchEvents::SwipeLeft; case Pinetime::Drivers::Cst816S::Gestures::SlideDown: - return DisplayApp::TouchEvents::SwipeDown; + return TouchEvents::SwipeDown; case Pinetime::Drivers::Cst816S::Gestures::SlideUp: - return DisplayApp::TouchEvents::SwipeUp; + return TouchEvents::SwipeUp; case Pinetime::Drivers::Cst816S::Gestures::None: default: - return DisplayApp::TouchEvents::None; + return TouchEvents::None; } } - return DisplayApp::TouchEvents::None; + return TouchEvents::None; } void DisplayApp::StartApp(DisplayApp::Apps app) { diff --git a/src/DisplayApp/DisplayApp.h b/src/DisplayApp/DisplayApp.h index ccbca4c3..38edd056 100644 --- a/src/DisplayApp/DisplayApp.h +++ b/src/DisplayApp/DisplayApp.h @@ -15,6 +15,7 @@ #include "LittleVgl.h" #include #include +#include "TouchEvents.h" namespace Pinetime { @@ -26,8 +27,7 @@ namespace Pinetime { public: enum class States {Idle, Running}; enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, SwitchScreen,ButtonPushed} ; - enum class TouchEvents { None, Tap, SwipeLeft, SwipeRight, SwipeUp, SwipeDown, LongTap, DoubleTap - }; + DisplayApp(Pinetime::Drivers::St7789& lcd, Pinetime::Components::LittleVgl& lvgl, Pinetime::Drivers::Cst816S&, diff --git a/src/DisplayApp/Screens/Brightness.cpp b/src/DisplayApp/Screens/Brightness.cpp index a87a62a8..9e3416c0 100644 --- a/src/DisplayApp/Screens/Brightness.cpp +++ b/src/DisplayApp/Screens/Brightness.cpp @@ -70,3 +70,23 @@ uint8_t Brightness::LevelToInt(Pinetime::Controllers::BrightnessController::Leve default : return 0; } } + +bool Brightness::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + switch(event) { + case TouchEvents::SwipeLeft: + brightness.Lower(); + SetValue(); + return true; + case TouchEvents::SwipeRight: + brightness.Higher(); + SetValue(); + return true; + default: + return false; + } +} + +void Brightness::SetValue() { + lv_slider_set_value(slider, LevelToInt(brightness.Level()), LV_ANIM_OFF); + lv_label_set_text(slider_label, LevelToString(brightness.Level())); +} diff --git a/src/DisplayApp/Screens/Brightness.h b/src/DisplayApp/Screens/Brightness.h index 31861f8a..37cbcd7e 100644 --- a/src/DisplayApp/Screens/Brightness.h +++ b/src/DisplayApp/Screens/Brightness.h @@ -13,6 +13,7 @@ namespace Pinetime { ~Brightness() override; bool Refresh() override; bool OnButtonPushed() override; + bool OnTouchEvent(TouchEvents event) override; void OnValueChanged(); private: @@ -25,6 +26,7 @@ namespace Pinetime { const char* LevelToString(Controllers::BrightnessController::Levels level); uint8_t LevelToInt(Controllers::BrightnessController::Levels level); void SetValue(uint8_t value); + void SetValue(); }; } } diff --git a/src/DisplayApp/Screens/Screen.h b/src/DisplayApp/Screens/Screen.h index 6cbd41ad..d8902317 100644 --- a/src/DisplayApp/Screens/Screen.h +++ b/src/DisplayApp/Screens/Screen.h @@ -1,4 +1,5 @@ #pragma once +#include "../TouchEvents.h" namespace Pinetime { namespace Applications { @@ -15,6 +16,9 @@ namespace Pinetime { // Return false if the button hasn't been handled by the app, true if it has been handled virtual bool OnButtonPushed() { return false; } + // Return false if the event hasn't been handled by the app, true if it has been handled + virtual bool OnTouchEvent(TouchEvents event) { return false; } + protected: DisplayApp* app; }; diff --git a/src/DisplayApp/TouchEvents.h b/src/DisplayApp/TouchEvents.h new file mode 100644 index 00000000..cf2f88dd --- /dev/null +++ b/src/DisplayApp/TouchEvents.h @@ -0,0 +1,8 @@ +#pragma once + +namespace Pinetime { + namespace Applications { + + enum class TouchEvents { None, Tap, SwipeLeft, SwipeRight, SwipeUp, SwipeDown, LongTap, DoubleTap}; + } +} \ No newline at end of file