Touch and display driver subsystems reworked (and more) (#302)
- Refactored `TouchDevice`: it can now start/stop LVGL separately, and it has an optional `TouchDriver` interface - Refactored `DisplayDevice`: it can now start/stop LVGL separately, and it has an optional `DisplayDriver` interface - Updated all boards and drivers for above changes - LVGL can now be stopped and (re)started on the fly - Fixed issues with restarting Gui and Statusbar services - Refactored `Gui` service to be class and renamed `Gui` to `GuiService` - Fixed `Statusbar` service: forgot to deregister one of the icons - Updated `esp_lcd_st7701` to v1.1.3 - `lv_textarea_create()` now automatically registers the hardware keyboard hooks (by wrapping the function) - Fixed and updated `tactility.py` - Cleanup of a lot of code - `BootInitLvglBegin` and `BootInitLvglEnd` are replaced by `LvglStarted` and `LvglStopped`. - Introduced `tt::service::State` which is accessible via `tt::service::getState()` (and internally via `ServiceInstance`) - Started replacing `#define TAG` with `constexpr auto TAG = "..";`
This commit is contained in:
committed by
GitHub
parent
15f4fbfdc6
commit
d875ade8cb
@@ -5,26 +5,29 @@
|
||||
|
||||
namespace tt::service {
|
||||
|
||||
class ServiceInstance : public ServiceContext {
|
||||
|
||||
private:
|
||||
class ServiceInstance final : public ServiceContext {
|
||||
|
||||
Mutex mutex = Mutex(Mutex::Type::Normal);
|
||||
std::shared_ptr<const ServiceManifest> manifest;
|
||||
std::shared_ptr<Service> service;
|
||||
State state = State::Stopped;
|
||||
|
||||
public:
|
||||
|
||||
explicit ServiceInstance(std::shared_ptr<const service::ServiceManifest> manifest);
|
||||
explicit ServiceInstance(std::shared_ptr<const ServiceManifest> manifest);
|
||||
~ServiceInstance() override = default;
|
||||
|
||||
/** @return a reference ot the service's manifest */
|
||||
const service::ServiceManifest& getManifest() const override;
|
||||
/** @return a reference to the service's manifest */
|
||||
const ServiceManifest& getManifest() const override;
|
||||
|
||||
/** Retrieve the paths that are relevant to this service */
|
||||
std::unique_ptr<Paths> getPaths() const override;
|
||||
|
||||
std::shared_ptr<Service> getService() const { return service; }
|
||||
|
||||
State getState() const { return state; }
|
||||
|
||||
void setState(State newState) { state = newState; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/MessageQueue.h>
|
||||
#include <Tactility/Mutex.h>
|
||||
#include <Tactility/PubSub.h>
|
||||
|
||||
#include "Tactility/app/AppContext.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
namespace tt::service::gui {
|
||||
|
||||
#define GUI_THREAD_FLAG_DRAW (1 << 0)
|
||||
#define GUI_THREAD_FLAG_INPUT (1 << 1)
|
||||
#define GUI_THREAD_FLAG_EXIT (1 << 2)
|
||||
#define GUI_THREAD_FLAG_ALL (GUI_THREAD_FLAG_DRAW | GUI_THREAD_FLAG_INPUT | GUI_THREAD_FLAG_EXIT)
|
||||
|
||||
/** Gui structure */
|
||||
struct Gui {
|
||||
// Thread and lock
|
||||
Thread* thread = nullptr;
|
||||
Mutex mutex = Mutex(Mutex::Type::Recursive);
|
||||
PubSub::SubscriptionHandle loader_pubsub_subscription = nullptr;
|
||||
|
||||
// Layers and Canvas
|
||||
lv_obj_t* appRootWidget = nullptr;
|
||||
lv_obj_t* statusbarWidget = nullptr;
|
||||
|
||||
// App-specific
|
||||
std::shared_ptr<app::AppContext> appToRender = nullptr;
|
||||
|
||||
lv_obj_t* _Nullable keyboard = nullptr;
|
||||
lv_group_t* keyboardGroup = nullptr;
|
||||
};
|
||||
|
||||
/** Update GUI, request redraw */
|
||||
void requestDraw();
|
||||
|
||||
/** Lock GUI */
|
||||
void lock();
|
||||
|
||||
/** Unlock GUI */
|
||||
void unlock();
|
||||
|
||||
/**
|
||||
* Set the app viewport in the gui state and request the gui to draw it.
|
||||
* @param[in] app
|
||||
*/
|
||||
void showApp(std::shared_ptr<app::AppContext> app);
|
||||
|
||||
/**
|
||||
* Hide the current app's viewport.
|
||||
* Does not request a re-draw because after hiding the current app,
|
||||
* we always show the previous app, and there is always at least 1 app running.
|
||||
*/
|
||||
void hideApp();
|
||||
|
||||
/**
|
||||
* Show the on-screen keyboard.
|
||||
* @param[in] textarea the textarea to focus the input for
|
||||
*/
|
||||
void softwareKeyboardShow(lv_obj_t* textarea);
|
||||
|
||||
/**
|
||||
* Hide the on-screen keyboard.
|
||||
* Has no effect when the keyboard is not visible.
|
||||
*/
|
||||
void softwareKeyboardHide();
|
||||
|
||||
/**
|
||||
* The on-screen keyboard is only shown when both of these conditions are true:
|
||||
* - there is no hardware keyboard
|
||||
* - TT_CONFIG_FORCE_ONSCREEN_KEYBOARD is set to true in tactility_config.h
|
||||
* @return if we should show a on-screen keyboard for text input inside our apps
|
||||
*/
|
||||
bool softwareKeyboardIsEnabled();
|
||||
|
||||
/**
|
||||
* Glue code for the on-screen keyboard and the hardware keyboard:
|
||||
* - Attach automatic hide/show parameters for the on-screen keyboard.
|
||||
* - Registers the textarea to the default lv_group_t for hardware keyboards.
|
||||
* @param[in] textarea
|
||||
*/
|
||||
void keyboardAddTextArea(lv_obj_t* textarea);
|
||||
|
||||
} // namespace
|
||||
@@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/MessageQueue.h>
|
||||
#include <Tactility/Mutex.h>
|
||||
#include <Tactility/PubSub.h>
|
||||
#include <Tactility/service/Service.h>
|
||||
|
||||
#include "Tactility/app/AppContext.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
namespace tt::service::gui {
|
||||
|
||||
#define GUI_THREAD_FLAG_DRAW (1 << 0)
|
||||
#define GUI_THREAD_FLAG_INPUT (1 << 1)
|
||||
#define GUI_THREAD_FLAG_EXIT (1 << 2)
|
||||
#define GUI_THREAD_FLAG_ALL (GUI_THREAD_FLAG_DRAW | GUI_THREAD_FLAG_INPUT | GUI_THREAD_FLAG_EXIT)
|
||||
|
||||
class GuiService : public Service {
|
||||
|
||||
// Thread and lock
|
||||
Thread* thread = nullptr;
|
||||
Mutex mutex = Mutex(Mutex::Type::Recursive);
|
||||
PubSub::SubscriptionHandle loader_pubsub_subscription = nullptr;
|
||||
|
||||
// Layers and Canvas
|
||||
lv_obj_t* appRootWidget = nullptr;
|
||||
lv_obj_t* statusbarWidget = nullptr;
|
||||
|
||||
// App-specific
|
||||
std::shared_ptr<app::AppContext> appToRender = nullptr;
|
||||
|
||||
lv_obj_t* _Nullable keyboard = nullptr;
|
||||
lv_group_t* keyboardGroup = nullptr;
|
||||
|
||||
bool isStarted = false;
|
||||
|
||||
static void onLoaderMessage(const void* message, TT_UNUSED void* context);
|
||||
|
||||
static int32_t guiMain();
|
||||
|
||||
lv_obj_t* createAppViews(lv_obj_t* parent);
|
||||
|
||||
void redraw();
|
||||
|
||||
void lock() const {
|
||||
tt_check(mutex.lock(pdMS_TO_TICKS(1000)));
|
||||
}
|
||||
|
||||
void unlock() const {
|
||||
tt_check(mutex.unlock());
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
void onStart(TT_UNUSED ServiceContext& service) override;
|
||||
|
||||
void onStop(TT_UNUSED ServiceContext& service) override;
|
||||
|
||||
void requestDraw();
|
||||
|
||||
void showApp(std::shared_ptr<app::AppContext> app);
|
||||
|
||||
void hideApp();
|
||||
|
||||
|
||||
/**
|
||||
* Show the on-screen keyboard.
|
||||
* @param[in] textarea the textarea to focus the input for
|
||||
*/
|
||||
void softwareKeyboardShow(lv_obj_t* textarea);
|
||||
|
||||
/**
|
||||
* Hide the on-screen keyboard.
|
||||
* Has no effect when the keyboard is not visible.
|
||||
*/
|
||||
void softwareKeyboardHide();
|
||||
|
||||
/**
|
||||
* The on-screen keyboard is only shown when both of these conditions are true:
|
||||
* - there is no hardware keyboard
|
||||
* - TT_CONFIG_FORCE_ONSCREEN_KEYBOARD is set to true in tactility_config.h
|
||||
* @return if we should show a on-screen keyboard for text input inside our apps
|
||||
*/
|
||||
bool softwareKeyboardIsEnabled();
|
||||
|
||||
/**
|
||||
* Glue code for the on-screen keyboard and the hardware keyboard:
|
||||
* - Attach automatic hide/show parameters for the on-screen keyboard.
|
||||
* - Registers the textarea to the default lv_group_t for hardware keyboards.
|
||||
* @param[in] textarea
|
||||
*/
|
||||
void keyboardAddTextArea(lv_obj_t* textarea);
|
||||
|
||||
};
|
||||
|
||||
std::shared_ptr<GuiService> findService();
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user