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

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