Do not compile GFX and older fonts anymore.

Refactor SystemTask in its own class.
Refactor Screen to be able to close current screen and open a new one.
Re-enable sleep/wake up and propagate button event to Screens.
This commit is contained in:
JF
2020-02-23 13:44:39 +01:00
parent 2bdff7ed2b
commit 02772b996f
13 changed files with 313 additions and 200 deletions

View File

@@ -13,25 +13,26 @@
#include <string>
#include <lvgl/lvgl.h>
#include <DisplayApp/Screens/Tile.h>
#include <DisplayApp/Screens/Tab.h>
#include "../SystemTask/SystemTask.h"
//#include <DisplayApp/Screens/Tab.h>
using namespace Pinetime::Applications;
DisplayApp::DisplayApp(Pinetime::Drivers::St7789& lcd,
Pinetime::Components::Gfx& gfx,
Pinetime::Components::LittleVgl& lvgl,
Pinetime::Drivers::Cst816S& touchPanel,
Controllers::Battery &batteryController,
Controllers::Ble &bleController,
Controllers::DateTime &dateTimeController) :
Controllers::DateTime &dateTimeController,
Pinetime::System::SystemTask& systemTask) :
lcd{lcd},
gfx{gfx},
lvgl{lvgl},
touchPanel{touchPanel},
batteryController{batteryController},
bleController{bleController},
dateTimeController{dateTimeController},
currentScreen{new Screens::Clock(this, gfx, dateTimeController) } {
currentScreen{new Screens::Clock(this, dateTimeController) },
systemTask{systemTask} {
msgQueue = xQueueCreate(queueSize, itemSize);
}
@@ -48,7 +49,7 @@ void DisplayApp::Process(void *instance) {
while (1) {
app->Refresh();
lv_task_handler();
}
}
@@ -114,36 +115,28 @@ void DisplayApp::Refresh() {
OnTouchEvent();
break;
case Messages::ButtonPushed:
currentScreen->OnButtonPushed();
if(!currentScreen->OnButtonPushed()) {
systemTask.PushMessage(System::SystemTask::Messages::GoToSleep);
}
break;
}
}
}
bool first = true;
void DisplayApp::RunningState() {
// clockScreen.SetCurrentDateTime(dateTimeController.CurrentDateTime());
if(currentScreen != nullptr) {
currentScreen->Refresh(first);
if(currentScreen->GetNextScreen() != Screens::Screen::NextScreen::None) {
switch(currentScreen->GetNextScreen()) {
case Screens::Screen::NextScreen::Clock:
currentScreen.reset(nullptr);
currentScreen.reset(new Screens::Clock(this, gfx, dateTimeController));
break;
case Screens::Screen::NextScreen::Menu:
currentScreen.reset(nullptr);
currentScreen.reset(new Screens::Tile(this, gfx));
break;
case Screens::Screen::NextScreen::App:
currentScreen.reset(nullptr);
currentScreen.reset(new Screens::Message(this, gfx));
break;
}
if(!currentScreen->Refresh(true)) {
currentScreen.reset(nullptr);
switch(nextApp) {
case Apps::None:
case Apps::Launcher: currentScreen.reset(new Screens::Tile(this)); break;
case Apps::Clock: currentScreen.reset(new Screens::Clock(this, dateTimeController)); break;
// case Apps::Test: currentScreen.reset(new Screens::Message(this)); break;
}
first = false;
nextApp = Apps::None;
}
lv_task_handler();
}
void DisplayApp::IdleState() {
@@ -169,3 +162,7 @@ void DisplayApp::OnTouchEvent() {
// pointColor+=10;
// }
}
void DisplayApp::StartApp(DisplayApp::Apps app) {
nextApp = app;
}

View File

@@ -14,35 +14,37 @@
#include "LittleVgl.h"
#include <date/date.h>
#include <DisplayApp/Screens/Clock.h>
#include <DisplayApp/Screens/Message.h>
//#include <DisplayApp/Screens/Message.h>
extern const FONT_INFO lCD_70ptFontInfo;
namespace Pinetime {
namespace System {
class SystemTask;
};
namespace Applications {
class DisplayApp {
public:
enum class States {Idle, Running};
enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, SwitchScreen,ButtonPushed} ;
DisplayApp(Pinetime::Drivers::St7789& lcd,
Pinetime::Components::Gfx& gfx,
Pinetime::Components::LittleVgl& lvgl,
Pinetime::Drivers::Cst816S&,
Controllers::Battery &batteryController,
Controllers::Ble &bleController,
Controllers::DateTime& dateTimeController);
Controllers::DateTime& dateTimeController,
Pinetime::System::SystemTask& systemTask);
void Start();
void PushMessage(Messages msg);
enum class Apps {None, Launcher, Clock, Test};
void StartApp(Apps app);
private:
TaskHandle_t taskHandle;
static void Process(void* instance);
void InitHw();
Pinetime::Drivers::St7789& lcd;
Pinetime::Components::Gfx& gfx;
Pinetime::Components::LittleVgl lvgl;
const FONT_INFO largeFont {lCD_70ptFontInfo.height, lCD_70ptFontInfo.startChar, lCD_70ptFontInfo.endChar, lCD_70ptFontInfo.spacePixels, lCD_70ptFontInfo.charInfo, lCD_70ptFontInfo.data};
const FONT_INFO smallFont {lCD_14ptFontInfo.height, lCD_14ptFontInfo.startChar, lCD_14ptFontInfo.endChar, lCD_14ptFontInfo.spacePixels, lCD_14ptFontInfo.charInfo, lCD_14ptFontInfo.data};
void Refresh();
States state = States::Running;
@@ -66,6 +68,9 @@ namespace Pinetime {
static constexpr uint8_t pinLcdBacklight3 = 23;
bool isClock = true;
Pinetime::System::SystemTask& systemTask;
Apps nextApp = Apps::None;
};
}
}

View File

@@ -15,7 +15,7 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) {
screen->OnObjectEvent(obj, event);
}
Clock::Clock(DisplayApp* app, Pinetime::Components::Gfx &gfx, Controllers::DateTime& dateTimeController) : Screen(app, gfx), currentDateTime{{}}, version {{}}, dateTimeController{dateTimeController} {
Clock::Clock(DisplayApp* app, Controllers::DateTime& dateTimeController) : Screen(app), currentDateTime{{}}, version {{}}, dateTimeController{dateTimeController} {
displayedChar[0] = 0;
displayedChar[1] = 0;
displayedChar[2] = 0;
@@ -65,7 +65,7 @@ Clock::~Clock() {
lv_obj_clean(lv_scr_act());
}
void Clock::Refresh(bool fullRefresh) {
bool Clock::Refresh(bool fullRefresh) {
if(fullRefresh) {
auto currentDateTime = dateTimeController.CurrentDateTime();
}
@@ -145,6 +145,7 @@ void Clock::Refresh(bool fullRefresh) {
lv_label_set_text(label_version, versionStr);
}
return running;
}
const char *Clock::MonthToString(Pinetime::Controllers::DateTime::Months month) {
@@ -185,9 +186,14 @@ char const *Clock::MonthsString[] = {
void Clock::OnObjectEvent(lv_obj_t *obj, lv_event_t event) {
if(obj == backgroundLabel) {
if (event == LV_EVENT_CLICKED) {
nextScreen = NextScreen::Menu;
running = false;
}
}
}
bool Clock::OnButtonPushed() {
return Screen::OnButtonPushed();
}

View File

@@ -35,9 +35,11 @@ namespace Pinetime {
class Clock : public Screen{
public:
enum class BleConnectionStates{ NotConnected, Connected};
Clock(DisplayApp* app, Components::Gfx& gfx, Controllers::DateTime& dateTimeController);
Clock(DisplayApp* app, Controllers::DateTime& dateTimeController);
~Clock() override;
void Refresh(bool fullRefresh) override;
bool Refresh(bool fullRefresh) override;
bool OnButtonPushed() override;
void SetBatteryPercentRemaining(uint8_t percent) { batteryPercentRemaining = percent; }
void SetBleConnectionState(BleConnectionStates state) { bleState = state; }
@@ -52,9 +54,6 @@ namespace Pinetime {
char displayedChar[5];
const FONT_INFO largeFont {lCD_70ptFontInfo.height, lCD_70ptFontInfo.startChar, lCD_70ptFontInfo.endChar, lCD_70ptFontInfo.spacePixels, lCD_70ptFontInfo.charInfo, lCD_70ptFontInfo.data};
const FONT_INFO smallFont {lCD_14ptFontInfo.height, lCD_14ptFontInfo.startChar, lCD_14ptFontInfo.endChar, lCD_14ptFontInfo.spacePixels, lCD_14ptFontInfo.charInfo, lCD_14ptFontInfo.data};
uint16_t currentYear = 1970;
Pinetime::Controllers::DateTime::Months currentMonth = Pinetime::Controllers::DateTime::Months::Unknown;
Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
@@ -77,6 +76,8 @@ namespace Pinetime {
Controllers::DateTime& dateTimeController;
bool running = true;
};
}
}

View File

@@ -9,16 +9,18 @@ namespace Pinetime {
class Screen {
public:
enum class NextScreen {None, Clock, Menu, App};
Screen(DisplayApp* app, Components::Gfx& gfx) : app{app}, gfx{gfx} {}
Screen(DisplayApp* app) : app{app} {}
virtual ~Screen() = default;
virtual void Refresh(bool fullRefresh) = 0;
NextScreen GetNextScreen() {return nextScreen;}
virtual void OnButtonPushed() {};
// Return false if the app can be closed, true if it must continue to run
virtual bool Refresh(bool fullRefresh) = 0;
// Return false if the button hasn't been handled by the app, true if it has been handled
virtual bool OnButtonPushed() { return false; }
protected:
DisplayApp* app;
Components::Gfx& gfx;
NextScreen nextScreen = NextScreen::None;
};
}
}

View File

@@ -22,8 +22,7 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) {
static const char * btnm_map1[] = {"App1", "App2", "App3", "\n", "App4", "App5", "App11", ""};
Tile::Tile(DisplayApp* app, Pinetime::Components::Gfx &gfx) : Screen(app, gfx) {
Tile::Tile(DisplayApp* app) : Screen(app) {
static lv_point_t valid_pos[] = {{0,0}, {LV_COORD_MIN, LV_COORD_MIN}};
tileview = lv_tileview_create(lv_scr_act(), NULL);
lv_tileview_set_valid_positions(tileview, valid_pos, 1);
@@ -38,11 +37,16 @@ Tile::Tile(DisplayApp* app, Pinetime::Components::Gfx &gfx) : Screen(app, gfx) {
lv_btnm_set_map(btnm1, btnm_map1);
lv_obj_set_size(btnm1, LV_HOR_RES, LV_VER_RES);
labelStyle = const_cast<lv_style_t *>(lv_label_get_style(btnm1, LV_BTNM_STYLE_BTN_REL));
labelStyle->text.font = &jetbrains_mono_bold_20;
labelStyle->body.grad_color = labelStyle->body.main_color;
lv_btnm_set_style(btnm1, LV_BTNM_STYLE_BTN_REL, labelStyle);
lv_btnm_set_style(btnm1, LV_BTNM_STYLE_BTN_PR, labelStyle);
labelRelStyle = const_cast<lv_style_t *>(lv_label_get_style(btnm1, LV_BTNM_STYLE_BTN_REL));
labelRelStyle->text.font = &jetbrains_mono_bold_20;
labelRelStyle->body.grad_color = labelRelStyle->body.main_color;
lv_btnm_set_style(btnm1, LV_BTNM_STYLE_BTN_REL, labelRelStyle);
labelPrStyle = const_cast<lv_style_t *>(lv_label_get_style(btnm1, LV_BTNM_STYLE_BTN_PR));
labelPrStyle->text.font = &jetbrains_mono_bold_20;
labelPrStyle->body.grad_color = labelPrStyle->body.shadow.color;
// lv_btnm_set_style(btnm1, LV_BTNM_STYLE_BTN_PR, labelPrStyle);
//TODO better style handling
lv_obj_align(btnm1, tile1, LV_ALIGN_CENTER, 0, 0);
btnm1->user_data = this;
@@ -100,17 +104,28 @@ Tile::~Tile() {
lv_obj_clean(lv_scr_act());
}
void Tile::Refresh(bool fullRefresh) {
bool Tile::Refresh(bool fullRefresh) {
return running;
}
void Tile::OnObjectEvent(lv_obj_t *obj, lv_event_t event) {
auto* tile = static_cast<Tile*>(obj->user_data);
if(event == LV_EVENT_CLICKED) {
NRF_LOG_INFO("Clicked");
nextScreen = Screen::NextScreen::App;
tile->StartApp();
clickCount++;
}
else if(event == LV_EVENT_VALUE_CHANGED) {
NRF_LOG_INFO("Toggled");
}
}
bool Tile::OnButtonPushed() {
app->StartApp(DisplayApp::Apps::Clock);
running = false;
return true;
}
void Tile::StartApp() {
app->StartApp(DisplayApp::Apps::Clock);
running = false;
}

View File

@@ -15,18 +15,18 @@ namespace Pinetime {
namespace Screens {
class Tile : public Screen {
public:
explicit Tile(DisplayApp* app, Components::Gfx& gfx);
explicit Tile(DisplayApp* app);
~Tile() override;
void Refresh(bool fullRefresh) override;
bool Refresh(bool fullRefresh) override;
bool OnButtonPushed() override;
void OnObjectEvent(lv_obj_t* obj, lv_event_t event);
void OnButtonPushed() override {nextScreen = NextScreen::Clock;}
private:
const FONT_INFO largeFont {lCD_70ptFontInfo.height, lCD_70ptFontInfo.startChar, lCD_70ptFontInfo.endChar, lCD_70ptFontInfo.spacePixels, lCD_70ptFontInfo.charInfo, lCD_70ptFontInfo.data};
const FONT_INFO smallFont {lCD_14ptFontInfo.height, lCD_14ptFontInfo.startChar, lCD_14ptFontInfo.endChar, lCD_14ptFontInfo.spacePixels, lCD_14ptFontInfo.charInfo, lCD_14ptFontInfo.data};
lv_style_t* labelStyle;
lv_style_t* labelRelStyle;
lv_style_t* labelPrStyle;
lv_obj_t * label1;
lv_obj_t * label2;
lv_obj_t * label3;
@@ -50,6 +50,8 @@ namespace Pinetime {
uint32_t clickCount = 0 ;
uint32_t previousClickCount = 0;
void StartApp();
bool running = true;
};
}
}