Add the possibility to the screen to handle a touch gesture.

A default action is taken if the current screen doesn't handle it.
This commit is contained in:
JF 2020-03-15 21:01:24 +01:00
parent 2c55ab20b4
commit 8ed6ffaaf8
7 changed files with 61 additions and 25 deletions

View file

@ -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})

View file

@ -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) {

View file

@ -15,6 +15,7 @@
#include "LittleVgl.h"
#include <date/date.h>
#include <DisplayApp/Screens/Clock.h>
#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&,

View file

@ -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()));
}

View file

@ -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();
};
}
}

View file

@ -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;
};

View file

@ -0,0 +1,8 @@
#pragma once
namespace Pinetime {
namespace Applications {
enum class TouchEvents { None, Tap, SwipeLeft, SwipeRight, SwipeUp, SwipeDown, LongTap, DoubleTap};
}
}