Integration of lvgl : continued...
This commit is contained in:
@@ -2,17 +2,46 @@
|
||||
#include <libs/date/includes/date/date.h>
|
||||
#include <Components/DateTime/DateTimeController.h>
|
||||
#include <Version.h>
|
||||
#include <libs/lvgl/lvgl.h>
|
||||
#include "Clock.h"
|
||||
|
||||
using namespace Pinetime::Applications::Screens;
|
||||
extern lv_font_t jetbrains_mono_extrabold_compressedextrabold_compressed;
|
||||
extern lv_font_t jetbrains_mono_bold_20;
|
||||
|
||||
Clock::Clock(Pinetime::Components::Gfx &gfx) : Screen(gfx), currentDateTime{{}}, version {{}} {
|
||||
label_battery = lv_label_create(lv_scr_act(), NULL);
|
||||
lv_obj_align(label_battery, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -80, 0);
|
||||
|
||||
labelStyle = const_cast<lv_style_t *>(lv_label_get_style(label_battery, LV_LABEL_STYLE_MAIN));
|
||||
labelStyle->text.font = &jetbrains_mono_bold_20;
|
||||
|
||||
lv_style_copy(&labelBigStyle, labelStyle);
|
||||
labelBigStyle.text.font = &jetbrains_mono_extrabold_compressedextrabold_compressed;
|
||||
|
||||
lv_label_set_style(label_battery, LV_LABEL_STYLE_MAIN, labelStyle);
|
||||
|
||||
label_ble = lv_label_create(lv_scr_act(), NULL);
|
||||
lv_label_set_style(label_ble, LV_LABEL_STYLE_MAIN, labelStyle);
|
||||
lv_obj_align(label_ble, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 10, 0);
|
||||
|
||||
label_time = lv_label_create(lv_scr_act(), NULL);
|
||||
lv_label_set_style(label_time, LV_LABEL_STYLE_MAIN, &labelBigStyle);
|
||||
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 0);
|
||||
|
||||
|
||||
label_date = lv_label_create(lv_scr_act(), NULL);
|
||||
lv_label_set_style(label_date, LV_LABEL_STYLE_MAIN, labelStyle);
|
||||
lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 80);
|
||||
|
||||
label_version = lv_label_create(lv_scr_act(), NULL);
|
||||
lv_label_set_style(label_version, LV_LABEL_STYLE_MAIN, labelStyle);
|
||||
lv_obj_align(label_version, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 100);
|
||||
|
||||
}
|
||||
|
||||
void Clock::Refresh(bool fullRefresh) {
|
||||
if(fullRefresh) {
|
||||
gfx.FillRectangle(0,0,240,240,0x0000);
|
||||
currentChar[0] = 1;
|
||||
currentChar[1] = 2;
|
||||
currentChar[2] = 3;
|
||||
currentChar[3] = 4;
|
||||
auto dummy = currentDateTime.Get();
|
||||
}
|
||||
|
||||
@@ -23,12 +52,14 @@ void Clock::Refresh(bool fullRefresh) {
|
||||
newBatteryValue = (newBatteryValue < 0) ? 0 : newBatteryValue;
|
||||
|
||||
sprintf(batteryChar, "BAT: %d%%", newBatteryValue);
|
||||
gfx.DrawString((240 - 108), 0, 0xffff, batteryChar, &smallFont, false);
|
||||
lv_label_set_text(label_battery, batteryChar);
|
||||
}
|
||||
|
||||
if (fullRefresh || bleState.IsUpdated()) {
|
||||
uint16_t color = (bleState.Get() == BleConnectionStates::Connected) ? 0xffff : 0x0000;
|
||||
gfx.DrawString(10, 0, color, "BLE", &smallFont, false);
|
||||
lv_label_set_text(label_ble, "BLE");
|
||||
// TODO color
|
||||
}
|
||||
|
||||
if(fullRefresh || currentDateTime.IsUpdated()) {
|
||||
@@ -53,35 +84,16 @@ void Clock::Refresh(bool fullRefresh) {
|
||||
char hoursChar[3];
|
||||
sprintf(hoursChar, "%02d", hour);
|
||||
|
||||
uint8_t x = 7;
|
||||
if (hoursChar[0] != currentChar[0]) {
|
||||
gfx.DrawChar(&largeFont, hoursChar[0], &x, 78, 0xffff);
|
||||
currentChar[0] = hoursChar[0];
|
||||
}
|
||||
|
||||
x = 61;
|
||||
if (hoursChar[1] != currentChar[1]) {
|
||||
gfx.DrawChar(&largeFont, hoursChar[1], &x, 78, 0xffff);
|
||||
currentChar[1] = hoursChar[1];
|
||||
}
|
||||
|
||||
x = 127;
|
||||
if (minutesChar[0] != currentChar[2]) {
|
||||
gfx.DrawChar(&largeFont, minutesChar[0], &x, 78, 0xffff);
|
||||
currentChar[2] = minutesChar[0];
|
||||
}
|
||||
|
||||
x = 181;
|
||||
if (minutesChar[1] != currentChar[3]) {
|
||||
gfx.DrawChar(&largeFont, minutesChar[1], &x, 78, 0xffff);
|
||||
currentChar[3] = minutesChar[1];
|
||||
}
|
||||
char timeStr[6];
|
||||
sprintf(timeStr, "%c%c:%c%c", hoursChar[0],hoursChar[1],minutesChar[0], minutesChar[1]);
|
||||
lv_label_set_text(label_time, timeStr);
|
||||
|
||||
if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) {
|
||||
gfx.FillRectangle(0,180, 240, 15, 0x0000);
|
||||
char dateStr[22];
|
||||
sprintf(dateStr, "%s %d %s %d", DayOfWeekToString(dayOfWeek), day, MonthToString(month), year);
|
||||
gfx.DrawString(10, 180, 0xffff, dateStr, &smallFont, false);
|
||||
lv_label_set_text(label_date, dateStr);
|
||||
|
||||
|
||||
currentYear = year;
|
||||
currentMonth = month;
|
||||
@@ -93,8 +105,9 @@ void Clock::Refresh(bool fullRefresh) {
|
||||
if(fullRefresh || version.IsUpdated()) {
|
||||
char version[20];
|
||||
sprintf(version, "VERSION: %d.%d.%d", Version::Major(), Version::Minor(), Version::Patch());
|
||||
gfx.DrawString(20, 220, 0xffff, version, &smallFont, false);
|
||||
lv_label_set_text(label_version, version);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const char *Clock::MonthToString(Pinetime::Controllers::DateTime::Months month) {
|
||||
@@ -131,3 +144,5 @@ char const *Clock::MonthsString[] = {
|
||||
"NOV",
|
||||
"DEC"
|
||||
};
|
||||
|
||||
|
||||
|
@@ -5,6 +5,8 @@
|
||||
#include <Components/Gfx/Gfx.h>
|
||||
#include "Screen.h"
|
||||
#include <bits/unique_ptr.h>
|
||||
#include <libs/lvgl/src/lv_core/lv_style.h>
|
||||
#include <libs/lvgl/src/lv_core/lv_obj.h>
|
||||
#include "../Fonts/lcdfont14.h"
|
||||
#include "../Fonts/lcdfont70.h"
|
||||
#include "../../Version.h"
|
||||
@@ -33,7 +35,7 @@ namespace Pinetime {
|
||||
class Clock : public Screen{
|
||||
public:
|
||||
enum class BleConnectionStates{ NotConnected, Connected};
|
||||
Clock(Components::Gfx& gfx) : Screen(gfx), currentDateTime{{}}, version {{}} {}
|
||||
Clock(Components::Gfx& gfx);
|
||||
void Refresh(bool fullRefresh) override;
|
||||
|
||||
void SetBatteryPercentRemaining(uint8_t percent) { batteryPercentRemaining = percent; }
|
||||
@@ -49,7 +51,6 @@ namespace Pinetime {
|
||||
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};
|
||||
|
||||
char currentChar[4];
|
||||
uint16_t currentYear = 1970;
|
||||
Pinetime::Controllers::DateTime::Months currentMonth = Pinetime::Controllers::DateTime::Months::Unknown;
|
||||
Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
|
||||
@@ -59,6 +60,16 @@ namespace Pinetime {
|
||||
DirtyValue<BleConnectionStates> bleState {BleConnectionStates::NotConnected};
|
||||
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>> currentDateTime;
|
||||
DirtyValue<Pinetime::Version> version;
|
||||
|
||||
lv_style_t* labelStyle;
|
||||
lv_style_t labelBigStyle;
|
||||
lv_obj_t * label_battery;
|
||||
|
||||
lv_obj_t * label_ble;
|
||||
lv_obj_t* label_time;
|
||||
lv_obj_t* label_date;
|
||||
lv_obj_t* label_version;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -3,19 +3,26 @@
|
||||
#include <Components/DateTime/DateTimeController.h>
|
||||
#include <Version.h>
|
||||
#include <libs/lvgl/src/lv_core/lv_obj.h>
|
||||
#include <libs/lvgl/src/lv_font/lv_font.h>
|
||||
#include <libs/lvgl/lvgl.h>
|
||||
#include "Message.h"
|
||||
|
||||
using namespace Pinetime::Applications::Screens;
|
||||
|
||||
extern lv_font_t jetbrains_mono_extrabold_compressedextrabold_compressed;
|
||||
|
||||
lv_obj_t * label;
|
||||
int x = 0;
|
||||
void Message::Refresh(bool fullRefresh) {
|
||||
if(fullRefresh) {
|
||||
lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL); /*Add a button the current screen*/
|
||||
lv_obj_set_pos(btn, 10, 10); /*Set its position*/
|
||||
lv_obj_set_size(btn, 100, 50); /*Set its size*/
|
||||
label = lv_label_create(btn, NULL); /*Add a label to the button*/
|
||||
lv_label_set_text(label, "Button"); /*Set the labels text*/
|
||||
label = lv_label_create(lv_scr_act(), NULL); /*Add a label to the button*/
|
||||
labelStyle = const_cast<lv_style_t *>(lv_label_get_style(label, LV_LABEL_STYLE_MAIN));
|
||||
labelStyle->text.font = &jetbrains_mono_extrabold_compressedextrabold_compressed;
|
||||
lv_label_set_style(label, LV_LABEL_STYLE_MAIN, labelStyle);
|
||||
lv_label_set_text(label, "01:23"); /*Set the labels text*/
|
||||
} else {
|
||||
lv_obj_set_pos(label, 0, x++);
|
||||
if(x > 200) x = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@
|
||||
#include "../Fonts/lcdfont14.h"
|
||||
#include "../Fonts/lcdfont70.h"
|
||||
#include "../../Version.h"
|
||||
#include <lvgl/src/lv_core/lv_style.h>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Applications {
|
||||
@@ -20,6 +21,8 @@ namespace Pinetime {
|
||||
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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user