Add new Screens (gauge, meter,...)

This commit is contained in:
JF 2020-02-26 20:49:26 +01:00
parent 0aa1803ea2
commit 179b14f48c
13 changed files with 354 additions and 7 deletions

View file

@ -48,6 +48,8 @@ set(LVGL_SRC
libs/lvgl/src/lv_misc/lv_anim.c
libs/lvgl/src/lv_misc/lv_anim.h
libs/lvgl/src/lv_misc/lv_async.h
libs/lvgl/src/lv_misc/lv_async.c
libs/lvgl/src/lv_misc/lv_fs.c
libs/lvgl/src/lv_misc/lv_fs.h
libs/lvgl/src/lv_misc/lv_task.c
@ -149,6 +151,15 @@ set(LVGL_SRC
libs/lvgl/src/lv_objx/lv_page.h
libs/lvgl/src/lv_objx/lv_img.c
libs/lvgl/src/lv_objx/lv_img.h
libs/lvgl/src/lv_objx/lv_lmeter.c
libs/lvgl/src/lv_objx/lv_lmeter.h
libs/lvgl/src/lv_objx/lv_arc.c
libs/lvgl/src/lv_objx/lv_arc.h
libs/lvgl/src/lv_objx/lv_gauge.c
libs/lvgl/src/lv_objx/lv_gauge.h
libs/lvgl/src/lv_objx/lv_mbox.c
libs/lvgl/src/lv_objx/lv_mbox.h
)
@ -160,6 +171,9 @@ list(APPEND SOURCE_FILES
DisplayApp/Screens/Clock.cpp
DisplayApp/Screens/Message.cpp
DisplayApp/Screens/Tile.cpp
DisplayApp/Screens/Meter.cpp
DisplayApp/Screens/Gauge.cpp
DisplayApp/Screens/Modal.cpp
main.cpp
drivers/St7789.cpp
drivers/SpiMaster.cpp
@ -190,6 +204,9 @@ set(INCLUDE_FILES
DisplayApp/Screens/Clock.h
DisplayApp/Screens/Message.h
DisplayApp/Screens/Tile.h
DisplayApp/Screens/Meter.h
DisplayApp/Screens/Gauge.h
DisplayApp/Screens/Modal.h
# DisplayApp/Screens/Tab.h
drivers/St7789.h
drivers/SpiMaster.h

View file

@ -11,6 +11,8 @@
#include <lvgl/lvgl.h>
#include <DisplayApp/Screens/Tile.h>
#include <DisplayApp/Screens/Message.h>
#include <DisplayApp/Screens/Meter.h>
#include <DisplayApp/Screens/Gauge.h>
#include "../SystemTask/SystemTask.h"
using namespace Pinetime::Applications;
@ -130,6 +132,8 @@ void DisplayApp::RunningState() {
case Apps::Launcher: currentScreen.reset(new Screens::Tile(this)); break;
case Apps::Clock: currentScreen.reset(new Screens::Clock(this, dateTimeController, batteryController, bleController)); break;
case Apps::Test: currentScreen.reset(new Screens::Message(this)); break;
case Apps::Meter: currentScreen.reset(new Screens::Meter(this)); break;
case Apps::Gauge: currentScreen.reset(new Screens::Gauge(this)); break;
}
nextApp = Apps::None;
}

View file

@ -35,7 +35,7 @@ namespace Pinetime {
void Start();
void PushMessage(Messages msg);
enum class Apps {None, Launcher, Clock, Test};
enum class Apps {None, Launcher, Clock, Test, Meter, Gauge};
void StartApp(Apps app);
private:

View file

@ -0,0 +1,57 @@
#include <libs/lvgl/lvgl.h>
#include "Gauge.h"
#include "../DisplayApp.h"
using namespace Pinetime::Applications::Screens;
extern lv_font_t jetbrains_mono_extrabold_compressedextrabold_compressed;
extern lv_font_t jetbrains_mono_bold_20;
Gauge::Gauge(Pinetime::Applications::DisplayApp *app) : Screen(app) {
/*Create a style*/
lv_style_copy(&style, &lv_style_pretty_color);
style.body.main_color = LV_COLOR_CYAN; /*Line color at the beginning*/
style.body.grad_color = LV_COLOR_RED; /*Line color at the end*/
style.body.padding.left = 10; /*Scale line length*/
style.body.padding.inner = 8 ; /*Scale label padding*/
style.body.border.color = lv_color_hex3(0x333); /*Needle middle circle color*/
style.line.width = 3;
style.text.color = LV_COLOR_WHITE;
style.line.color = LV_COLOR_RED; /*Line color after the critical value*/
/*Describe the color for the needles*/
needle_colors[0] = LV_COLOR_ORANGE;
/*Create a gauge*/
gauge1 = lv_gauge_create(lv_scr_act(), NULL);
lv_gauge_set_style(gauge1, LV_GAUGE_STYLE_MAIN, &style);
lv_gauge_set_needle_count(gauge1, 1, needle_colors);
lv_obj_set_size(gauge1, 180, 180);
lv_obj_align(gauge1, NULL, LV_ALIGN_CENTER, 0, 0);
lv_gauge_set_scale(gauge1, 360, 60, 0);
lv_gauge_set_range(gauge1, 0, 59);
/*Set the values*/
lv_gauge_set_value(gauge1, 0, value);
}
Gauge::~Gauge() {
lv_obj_clean(lv_scr_act());
}
bool Gauge::Refresh() {
// lv_lmeter_set_value(lmeter, value++); /*Set the current value*/
// if(value>=60) value = 0;
lv_gauge_set_value(gauge1, 0, value++);
if(value == 59) value = 0;
return running;
}
bool Gauge::OnButtonPushed() {
running = false;
return true;
}

View file

@ -0,0 +1,39 @@
#pragma once
#include <cstdint>
#include <chrono>
#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 <Components/Battery/BatteryController.h>
#include <Components/Ble/BleController.h>
#include "../Fonts/lcdfont14.h"
#include "../Fonts/lcdfont70.h"
#include "../../Version.h"
namespace Pinetime {
namespace Applications {
namespace Screens {
class Gauge : public Screen{
public:
Gauge(DisplayApp* app);
~Gauge() override;
bool Refresh() override;
bool OnButtonPushed() override;
private:
lv_style_t style;
lv_color_t needle_colors[3];
lv_obj_t * gauge1;
uint32_t value=30;
bool running = true;
};
}
}
}

View file

@ -0,0 +1,47 @@
#include <libs/lvgl/lvgl.h>
#include "Meter.h"
#include "../DisplayApp.h"
using namespace Pinetime::Applications::Screens;
extern lv_font_t jetbrains_mono_extrabold_compressedextrabold_compressed;
extern lv_font_t jetbrains_mono_bold_20;
Meter::Meter(Pinetime::Applications::DisplayApp *app) : Screen(app) {
lv_style_copy(&style_lmeter, &lv_style_pretty_color);
style_lmeter.line.width = 2;
style_lmeter.line.color = LV_COLOR_SILVER;
style_lmeter.body.main_color = lv_color_make(255,0,0);
style_lmeter.body.grad_color = lv_color_make(160,0,0);
style_lmeter.body.padding.left = 16; /*Line length*/
/*Create a line meter */
lmeter = lv_lmeter_create(lv_scr_act(), NULL);
lv_lmeter_set_range(lmeter, 0, 60); /*Set the range*/
lv_lmeter_set_value(lmeter, value); /*Set the current value*/
lv_lmeter_set_angle_offset(lmeter, 180);
lv_lmeter_set_scale(lmeter, 360, 60); /*Set the angle and number of lines*/
lv_lmeter_set_style(lmeter, LV_LMETER_STYLE_MAIN, &style_lmeter); /*Apply the new style*/
lv_obj_set_size(lmeter, 150, 150);
lv_obj_align(lmeter, NULL, LV_ALIGN_CENTER, 0, 0);
}
Meter::~Meter() {
lv_obj_clean(lv_scr_act());
}
bool Meter::Refresh() {
lv_lmeter_set_value(lmeter, value++); /*Set the current value*/
if(value>=60) value = 0;
return running;
}
bool Meter::OnButtonPushed() {
running = false;
return true;
}

View file

@ -0,0 +1,38 @@
#pragma once
#include <cstdint>
#include <chrono>
#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 <Components/Battery/BatteryController.h>
#include <Components/Ble/BleController.h>
#include "../Fonts/lcdfont14.h"
#include "../Fonts/lcdfont70.h"
#include "../../Version.h"
namespace Pinetime {
namespace Applications {
namespace Screens {
class Meter : public Screen{
public:
Meter(DisplayApp* app);
~Meter() override;
bool Refresh() override;
bool OnButtonPushed() override;
private:
lv_style_t style_lmeter;
lv_obj_t * lmeter;
uint32_t value=0;
bool running = true;
};
}
}
}

View file

@ -0,0 +1,77 @@
#include <libs/lvgl/lvgl.h>
#include "Modal.h"
#include "../DisplayApp.h"
using namespace Pinetime::Applications::Screens;
extern lv_font_t jetbrains_mono_extrabold_compressedextrabold_compressed;
extern lv_font_t jetbrains_mono_bold_20;
Modal::Modal(Pinetime::Applications::DisplayApp *app) : Screen(app) {
}
Modal::~Modal() {
lv_obj_clean(lv_scr_act());
}
bool Modal::Refresh() {
return running;
}
bool Modal::OnButtonPushed() {
running = false;
return true;
}
void Modal::Show() {
lv_style_copy(&modal_style, &lv_style_plain_color);
modal_style.body.main_color = modal_style.body.grad_color = LV_COLOR_BLACK;
modal_style.body.opa = LV_OPA_50;
obj = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_style(obj, &modal_style);
lv_obj_set_pos(obj, 0, 0);
lv_obj_set_size(obj, LV_HOR_RES, LV_VER_RES);
lv_obj_set_opa_scale_enable(obj, true); /* Enable opacity scaling for the animation */
static const char * btns2[] = {"Ok", "Cancel", ""};
/* Create the message box as a child of the modal background */
mbox = lv_mbox_create(obj, NULL);
lv_mbox_add_btns(mbox, btns2);
lv_mbox_set_text(mbox, "Hello world!");
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_event_cb(mbox, Modal::mbox_event_cb);
/* Fade the message box in with an animation */
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_time(&a, 500, 0);
lv_anim_set_values(&a, LV_OPA_TRANSP, LV_OPA_COVER);
lv_anim_set_exec_cb(&a, obj, (lv_anim_exec_xcb_t)lv_obj_set_opa_scale);
lv_anim_create(&a);
}
void Modal::Hide() {
/* Delete the parent modal background */
lv_obj_del_async(lv_obj_get_parent(mbox));
mbox = NULL; /* happens before object is actually deleted! */
}
void Modal::mbox_event_cb(lv_obj_t *obj, lv_event_t evt) {
auto* m = static_cast<Modal *>(obj->user_data);
m->OnEvent(obj, evt);
}
void Modal::OnEvent(lv_obj_t *event_obj, lv_event_t evt) {
if(evt == LV_EVENT_DELETE && event_obj == mbox) {
/* Delete the parent modal background */
lv_obj_del_async(lv_obj_get_parent(mbox));
mbox = NULL; /* happens before object is actually deleted! */
} else if(evt == LV_EVENT_VALUE_CHANGED) {
/* A button was clicked */
lv_mbox_start_auto_close(mbox, 100);
}
}

View file

@ -0,0 +1,44 @@
#pragma once
#include <cstdint>
#include <chrono>
#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 <Components/Battery/BatteryController.h>
#include <Components/Ble/BleController.h>
#include "../Fonts/lcdfont14.h"
#include "../Fonts/lcdfont70.h"
#include "../../Version.h"
namespace Pinetime {
namespace Applications {
namespace Screens {
class Modal : public Screen{
public:
Modal(DisplayApp* app);
~Modal() override;
void Show();
void Hide();
bool Refresh() override;
bool OnButtonPushed() override;
static void mbox_event_cb(lv_obj_t *obj, lv_event_t evt);
private:
void OnEvent(lv_obj_t *event_obj, lv_event_t evt);
lv_style_t modal_style;
lv_obj_t *obj;
lv_obj_t *mbox;
lv_obj_t *info;
bool running = true;
};
}
}
}

View file

@ -16,9 +16,11 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) {
screen->OnObjectEvent(obj, event, eventData);
}
static const char * btnm_map1[] = {"App1", "App2", "App3", "\n", "App4", "App5", "App11", ""};
static const char * btnm_map1[] = {"Meter", "Gauge", "Clock", "\n", "App4", "App5", "App11", ""};
Tile::Tile(DisplayApp* app) : Screen(app) {
modal.reset(new Modal(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);
@ -109,11 +111,17 @@ void Tile::OnObjectEvent(lv_obj_t *obj, lv_event_t event, uint32_t buttonId) {
if(event == LV_EVENT_VALUE_CHANGED) {
switch(buttonId) {
case 0:
tile->StartMeterApp();
break;
case 1:
tile->StartGaugeApp();
break;
case 2:
tile->StartClockApp();
break;
case 3:
modal->Show();
break;
case 4:
case 5:
tile->StartTestApp();
@ -139,3 +147,14 @@ void Tile::StartTestApp() {
app->StartApp(DisplayApp::Apps::Test);
running = false;
}
void Tile::StartMeterApp() {
app->StartApp(DisplayApp::Apps::Meter);
running = false;
}
void Tile::StartGaugeApp() {
app->StartApp(DisplayApp::Apps::Gauge);
running = false;
}

View file

@ -8,6 +8,7 @@
#include "../Fonts/lcdfont14.h"
#include "../Fonts/lcdfont70.h"
#include "../../Version.h"
#include "Modal.h"
#include <lvgl/src/lv_core/lv_style.h>
namespace Pinetime {
@ -52,7 +53,11 @@ namespace Pinetime {
uint32_t previousClickCount = 0;
void StartClockApp();
void StartTestApp();
void StartMeterApp();
void StartGaugeApp();
bool running = true;
std::unique_ptr<Modal> modal;
};
}
}

View file

@ -34,7 +34,7 @@ void SystemTask::Work() {
NRF_LOG_INFO("Last reset reason : %s", Pinetime::Drivers::Watchdog::ResetReasonToString(watchdog.ResetReason()));
APP_GPIOTE_INIT(2);
bool erase_bonds=false;
nrf_sdh_freertos_init(ble_manager_start_advertising, &erase_bonds);
// nrf_sdh_freertos_init(ble_manager_start_advertising, &erase_bonds);
spi.Init();
lcd.Init();

View file

@ -128,10 +128,10 @@ int main(void) {
systemTask.reset(new Pinetime::System::SystemTask(*spi, *lcd, *touchPanel, *lvgl, batteryController, bleController, dateTimeController));
systemTask->Start();
ble_manager_init();
ble_manager_set_new_time_callback(OnNewTime);
ble_manager_set_ble_connection_callback(OnBleConnection);
ble_manager_set_ble_disconnection_callback(OnBleDisconnection);
// ble_manager_init();
// ble_manager_set_new_time_callback(OnNewTime);
// ble_manager_set_ble_connection_callback(OnBleConnection);
// ble_manager_set_ble_disconnection_callback(OnBleDisconnection);
vTaskStartScheduler();