summaryrefslogtreecommitdiff
path: root/src/displayapp/screens
diff options
context:
space:
mode:
Diffstat (limited to 'src/displayapp/screens')
-rw-r--r--src/displayapp/screens/ApplicationList.cpp2
-rw-r--r--src/displayapp/screens/StopWatch.cpp200
-rw-r--r--src/displayapp/screens/StopWatch.h91
-rw-r--r--src/displayapp/screens/Timer.cpp161
-rw-r--r--src/displayapp/screens/Timer.h39
-rw-r--r--src/displayapp/screens/settings/Settings.cpp4
6 files changed, 2 insertions, 495 deletions
diff --git a/src/displayapp/screens/ApplicationList.cpp b/src/displayapp/screens/ApplicationList.cpp
index e584bf7..eac2dfb 100644
--- a/src/displayapp/screens/ApplicationList.cpp
+++ b/src/displayapp/screens/ApplicationList.cpp
@@ -40,10 +40,8 @@ bool ApplicationList::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
std::unique_ptr<Screen> ApplicationList::CreateScreen1() {
std::array<Screens::Tile::Applications, 6> applications {{
- {Symbols::stopWatch, Apps::StopWatch},
{Symbols::shoe, Apps::Steps},
{Symbols::heartBeat, Apps::HeartRate},
- {Symbols::hourGlass, Apps::Timer},
}};
return std::make_unique<Screens::Tile>(0, 2, app, settingsController, batteryController, dateTimeController, applications);
diff --git a/src/displayapp/screens/StopWatch.cpp b/src/displayapp/screens/StopWatch.cpp
deleted file mode 100644
index 8749839..0000000
--- a/src/displayapp/screens/StopWatch.cpp
+++ /dev/null
@@ -1,200 +0,0 @@
-#include "displayapp/screens/StopWatch.h"
-
-#include "displayapp/screens/Screen.h"
-#include "displayapp/screens/Symbols.h"
-#include <lvgl/lvgl.h>
-#include <FreeRTOS.h>
-#include <task.h>
-
-using namespace Pinetime::Applications::Screens;
-
-// Anonymous namespace for local functions
-namespace {
- TimeSeparated_t convertTicksToTimeSegments(const TickType_t timeElapsed) {
- const int timeElapsedMillis = (static_cast<float>(timeElapsed) / static_cast<float>(configTICK_RATE_HZ)) * 1000;
-
- const int hundredths = (timeElapsedMillis % 1000) / 10; // Get only the first two digits and ignore the last
- const int secs = (timeElapsedMillis / 1000) % 60;
- const int mins = (timeElapsedMillis / 1000) / 60;
- return TimeSeparated_t {mins, secs, hundredths};
- }
-
- TickType_t calculateDelta(const TickType_t startTime, const TickType_t currentTime) {
- TickType_t delta = 0;
- // Take care of overflow
- if (startTime > currentTime) {
- delta = 0xffffffff - startTime;
- delta += (currentTime + 1);
- } else {
- delta = currentTime - startTime;
- }
- return delta;
- }
-}
-
-static void play_pause_event_handler(lv_obj_t* obj, lv_event_t event) {
- auto stopWatch = static_cast<StopWatch*>(obj->user_data);
- stopWatch->playPauseBtnEventHandler(event);
-}
-
-static void stop_lap_event_handler(lv_obj_t* obj, lv_event_t event) {
- auto stopWatch = static_cast<StopWatch*>(obj->user_data);
- stopWatch->stopLapBtnEventHandler(event);
-}
-
-StopWatch::StopWatch(DisplayApp* app, System::SystemTask& systemTask)
- : Screen(app),
- systemTask {systemTask},
- currentState {States::Init},
- startTime {},
- oldTimeElapsed {},
- currentTimeSeparated {},
- lapBuffer {},
- lapNr {} {
-
- time = lv_label_create(lv_scr_act(), nullptr);
- lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
- lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
- lv_label_set_text(time, "00:00");
- lv_obj_align(time, lv_scr_act(), LV_ALIGN_CENTER, 0, -45);
-
- msecTime = lv_label_create(lv_scr_act(), nullptr);
- // lv_obj_set_style_local_text_font(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
- lv_obj_set_style_local_text_color(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
- lv_label_set_text(msecTime, "00");
- lv_obj_align(msecTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 3);
-
- btnPlayPause = lv_btn_create(lv_scr_act(), nullptr);
- btnPlayPause->user_data = this;
- lv_obj_set_event_cb(btnPlayPause, play_pause_event_handler);
- lv_obj_set_height(btnPlayPause, 50);
- lv_obj_set_width(btnPlayPause, 115);
- lv_obj_align(btnPlayPause, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
- txtPlayPause = lv_label_create(btnPlayPause, nullptr);
- lv_label_set_text(txtPlayPause, Symbols::play);
-
- btnStopLap = lv_btn_create(lv_scr_act(), nullptr);
- btnStopLap->user_data = this;
- lv_obj_set_event_cb(btnStopLap, stop_lap_event_handler);
- lv_obj_set_height(btnStopLap, 50);
- lv_obj_set_width(btnStopLap, 115);
- lv_obj_align(btnStopLap, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
- lv_obj_set_style_local_bg_color(btnStopLap, LV_BTN_PART_MAIN, LV_STATE_DISABLED, lv_color_hex(0x080808));
- txtStopLap = lv_label_create(btnStopLap, nullptr);
- lv_obj_set_style_local_text_color(txtStopLap, LV_BTN_PART_MAIN, LV_STATE_DISABLED, lv_color_hex(0x888888));
- lv_label_set_text(txtStopLap, Symbols::stop);
- lv_obj_set_state(btnStopLap, LV_STATE_DISABLED);
- lv_obj_set_state(txtStopLap, LV_STATE_DISABLED);
-
- lapOneText = lv_label_create(lv_scr_act(), nullptr);
- // lv_obj_set_style_local_text_font(lapOneText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
- lv_obj_set_style_local_text_color(lapOneText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
- lv_obj_align(lapOneText, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 50, 30);
- lv_label_set_text(lapOneText, "");
-
- lapTwoText = lv_label_create(lv_scr_act(), nullptr);
- // lv_obj_set_style_local_text_font(lapTwoText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
- lv_obj_set_style_local_text_color(lapTwoText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
- lv_obj_align(lapTwoText, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 50, 55);
- lv_label_set_text(lapTwoText, "");
-
- taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
-}
-
-StopWatch::~StopWatch() {
- lv_task_del(taskRefresh);
- systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
- lv_obj_clean(lv_scr_act());
-}
-
-void StopWatch::reset() {
- currentState = States::Init;
- oldTimeElapsed = 0;
- lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
- lv_obj_set_style_local_text_color(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
-
- lv_label_set_text(time, "00:00");
- lv_label_set_text(msecTime, "00");
-
- lv_label_set_text(lapOneText, "");
- lv_label_set_text(lapTwoText, "");
- lapBuffer.clearBuffer();
- lapNr = 0;
- lv_obj_set_state(btnStopLap, LV_STATE_DISABLED);
- lv_obj_set_state(txtStopLap, LV_STATE_DISABLED);
-}
-
-void StopWatch::start() {
- lv_obj_set_state(btnStopLap, LV_STATE_DEFAULT);
- lv_obj_set_state(txtStopLap, LV_STATE_DEFAULT);
- lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
- lv_obj_set_style_local_text_color(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
- lv_label_set_text(txtPlayPause, Symbols::pause);
- lv_label_set_text(txtStopLap, Symbols::lapsFlag);
- startTime = xTaskGetTickCount();
- currentState = States::Running;
- systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping);
-}
-
-void StopWatch::pause() {
- startTime = 0;
- // Store the current time elapsed in cache
- oldTimeElapsed += timeElapsed;
- currentState = States::Halted;
- lv_label_set_text(txtPlayPause, Symbols::play);
- lv_label_set_text(txtStopLap, Symbols::stop);
- lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
- lv_obj_set_style_local_text_color(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
- systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
-}
-
-void StopWatch::Refresh() {
- if (currentState == States::Running) {
- timeElapsed = calculateDelta(startTime, xTaskGetTickCount());
- currentTimeSeparated = convertTicksToTimeSegments((oldTimeElapsed + timeElapsed));
-
- lv_label_set_text_fmt(time, "%02d:%02d", currentTimeSeparated.mins, currentTimeSeparated.secs);
- lv_label_set_text_fmt(msecTime, "%02d", currentTimeSeparated.hundredths);
- }
-}
-
-void StopWatch::playPauseBtnEventHandler(lv_event_t event) {
- if (event != LV_EVENT_CLICKED) {
- return;
- }
- if (currentState == States::Init) {
- start();
- } else if (currentState == States::Running) {
- pause();
- } else if (currentState == States::Halted) {
- start();
- }
-}
-
-void StopWatch::stopLapBtnEventHandler(lv_event_t event) {
- if (event != LV_EVENT_CLICKED) {
- return;
- }
- // If running, then this button is used to save laps
- if (currentState == States::Running) {
- lapBuffer.addLaps(currentTimeSeparated);
- lapNr++;
- if (lapBuffer[1]) {
- lv_label_set_text_fmt(
- lapOneText, "#%2d %2d:%02d.%02d", (lapNr - 1), lapBuffer[1]->mins, lapBuffer[1]->secs, lapBuffer[1]->hundredths);
- }
- if (lapBuffer[0]) {
- lv_label_set_text_fmt(lapTwoText, "#%2d %2d:%02d.%02d", lapNr, lapBuffer[0]->mins, lapBuffer[0]->secs, lapBuffer[0]->hundredths);
- }
- } else if (currentState == States::Halted) {
- reset();
- }
-}
-
-bool StopWatch::OnButtonPushed() {
- if (currentState == States::Running) {
- pause();
- return true;
- }
- return false;
-}
diff --git a/src/displayapp/screens/StopWatch.h b/src/displayapp/screens/StopWatch.h
deleted file mode 100644
index 06193f6..0000000
--- a/src/displayapp/screens/StopWatch.h
+++ /dev/null
@@ -1,91 +0,0 @@
-#pragma once
-
-#include "displayapp/screens/Screen.h"
-#include "components/datetime/DateTimeController.h"
-#include "displayapp/LittleVgl.h"
-
-#include <FreeRTOS.h>
-#include "portmacro_cmsis.h"
-
-#include <array>
-#include "systemtask/SystemTask.h"
-
-namespace Pinetime::Applications::Screens {
-
- enum class States { Init, Running, Halted };
-
- struct TimeSeparated_t {
- int mins;
- int secs;
- int hundredths;
- };
-
- // A simple buffer to hold the latest two laps
- template <int N> struct LapTextBuffer_t {
- LapTextBuffer_t() : buffer {}, currentSize {}, capacity {N}, head {-1} {
- }
-
- void addLaps(const TimeSeparated_t& timeVal) {
- head++;
- head %= capacity;
- buffer[head] = timeVal;
-
- if (currentSize < capacity) {
- currentSize++;
- }
- }
-
- void clearBuffer() {
- buffer = {};
- currentSize = 0;
- head = -1;
- }
-
- TimeSeparated_t* operator[](std::size_t idx) {
- // Sanity check for out-of-bounds
- if (idx >= 0 && idx < capacity) {
- if (idx < currentSize) {
- // This transformation is to ensure that head is always pointing to index 0.
- const auto transformed_idx = (head - idx) % capacity;
- return (&buffer[transformed_idx]);
- }
- }
- return nullptr;
- }
-
- private:
- std::array<TimeSeparated_t, N> buffer;
- uint8_t currentSize;
- uint8_t capacity;
- int8_t head;
- };
-
- class StopWatch : public Screen {
- public:
- StopWatch(DisplayApp* app, System::SystemTask& systemTask);
- ~StopWatch() override;
- void Refresh() override;
-
- void playPauseBtnEventHandler(lv_event_t event);
- void stopLapBtnEventHandler(lv_event_t event);
- bool OnButtonPushed() override;
-
- void reset();
- void start();
- void pause();
-
- private:
- Pinetime::System::SystemTask& systemTask;
- TickType_t timeElapsed;
- States currentState;
- TickType_t startTime;
- TickType_t oldTimeElapsed;
- TimeSeparated_t currentTimeSeparated; // Holds Mins, Secs, millisecs
- LapTextBuffer_t<2> lapBuffer;
- int lapNr = 0;
- lv_obj_t *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap;
- lv_obj_t *lapOneText, *lapTwoText;
-
- lv_task_t* taskRefresh;
- };
-}
diff --git a/src/displayapp/screens/Timer.cpp b/src/displayapp/screens/Timer.cpp
deleted file mode 100644
index a5e4019..0000000
--- a/src/displayapp/screens/Timer.cpp
+++ /dev/null
@@ -1,161 +0,0 @@
-#include "displayapp/screens/Timer.h"
-
-#include "displayapp/screens/Screen.h"
-#include "displayapp/screens/Symbols.h"
-#include <lvgl/lvgl.h>
-
-using namespace Pinetime::Applications::Screens;
-
-static void btnEventHandler(lv_obj_t* obj, lv_event_t event) {
- Timer* screen = static_cast<Timer*>(obj->user_data);
- screen->OnButtonEvent(obj, event);
-}
-
-void Timer::createButtons() {
- btnMinutesUp = lv_btn_create(lv_scr_act(), nullptr);
- btnMinutesUp->user_data = this;
- lv_obj_set_event_cb(btnMinutesUp, btnEventHandler);
- lv_obj_align(btnMinutesUp, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, -80);
- lv_obj_set_height(btnMinutesUp, 40);
- lv_obj_set_width(btnMinutesUp, 60);
- txtMUp = lv_label_create(btnMinutesUp, nullptr);
- lv_label_set_text(txtMUp, "+");
-
- btnMinutesDown = lv_btn_create(lv_scr_act(), nullptr);
- btnMinutesDown->user_data = this;
- lv_obj_set_event_cb(btnMinutesDown, btnEventHandler);
- lv_obj_align(btnMinutesDown, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, +40);
- lv_obj_set_height(btnMinutesDown, 40);
- lv_obj_set_width(btnMinutesDown, 60);
- txtMDown = lv_label_create(btnMinutesDown, nullptr);
- lv_label_set_text(txtMDown, "-");
-
- btnSecondsUp = lv_btn_create(lv_scr_act(), nullptr);
- btnSecondsUp->user_data = this;
- lv_obj_set_event_cb(btnSecondsUp, btnEventHandler);
- lv_obj_align(btnSecondsUp, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 10, -80);
- lv_obj_set_height(btnSecondsUp, 40);
- lv_obj_set_width(btnSecondsUp, 60);
- txtSUp = lv_label_create(btnSecondsUp, nullptr);
- lv_label_set_text(txtSUp, "+");
-
- btnSecondsDown = lv_btn_create(lv_scr_act(), nullptr);
- btnSecondsDown->user_data = this;
- lv_obj_set_event_cb(btnSecondsDown, btnEventHandler);
- lv_obj_align(btnSecondsDown, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 10, +40);
- lv_obj_set_height(btnSecondsDown, 40);
- lv_obj_set_width(btnSecondsDown, 60);
- txtSDown = lv_label_create(btnSecondsDown, nullptr);
- lv_label_set_text(txtSDown, "-");
-}
-
-Timer::Timer(DisplayApp* app, Controllers::TimerController& timerController)
- : Screen(app), running {true}, timerController {timerController} {
-
- time = lv_label_create(lv_scr_act(), nullptr);
- lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
- lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
-
- uint32_t seconds = timerController.GetTimeRemaining() / 1000;
- lv_label_set_text_fmt(time, "%02lu:%02lu", seconds / 60, seconds % 60);
-
- lv_obj_align(time, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -20);
-
- btnPlayPause = lv_btn_create(lv_scr_act(), nullptr);
- btnPlayPause->user_data = this;
- lv_obj_set_event_cb(btnPlayPause, btnEventHandler);
- lv_obj_align(btnPlayPause, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, -10);
- lv_obj_set_height(btnPlayPause, 40);
- txtPlayPause = lv_label_create(btnPlayPause, nullptr);
- if (timerController.IsRunning()) {
- lv_label_set_text(txtPlayPause, Symbols::pause);
- } else {
- lv_label_set_text(txtPlayPause, Symbols::play);
- createButtons();
- }
-
- taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
-}
-
-Timer::~Timer() {
- lv_task_del(taskRefresh);
- lv_obj_clean(lv_scr_act());
-}
-
-void Timer::Refresh() {
- if (timerController.IsRunning()) {
- uint32_t seconds = timerController.GetTimeRemaining() / 1000;
- lv_label_set_text_fmt(time, "%02lu:%02lu", seconds / 60, seconds % 60);
- }
-}
-
-void Timer::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
- if (event == LV_EVENT_CLICKED) {
- if (obj == btnPlayPause) {
- if (timerController.IsRunning()) {
- lv_label_set_text(txtPlayPause, Symbols::play);
- uint32_t seconds = timerController.GetTimeRemaining() / 1000;
- minutesToSet = seconds / 60;
- secondsToSet = seconds % 60;
- timerController.StopTimer();
- createButtons();
-
- } else if (secondsToSet + minutesToSet > 0) {
- lv_label_set_text(txtPlayPause, Symbols::pause);
- timerController.StartTimer((secondsToSet + minutesToSet * 60) * 1000);
-
- lv_obj_del(btnSecondsDown);
- btnSecondsDown = nullptr;
- lv_obj_del(btnSecondsUp);
- btnSecondsUp = nullptr;
- lv_obj_del(btnMinutesDown);
- btnMinutesDown = nullptr;
- lv_obj_del(btnMinutesUp);
- btnMinutesUp = nullptr;
- }
- } else {
- if (!timerController.IsRunning()) {
- if (obj == btnMinutesUp) {
- if (minutesToSet >= 59) {
- minutesToSet = 0;
- } else {
- minutesToSet++;
- }
- lv_label_set_text_fmt(time, "%02d:%02d", minutesToSet, secondsToSet);
-
- } else if (obj == btnMinutesDown) {
- if (minutesToSet == 0) {
- minutesToSet = 59;
- } else {
- minutesToSet--;
- }
- lv_label_set_text_fmt(time, "%02d:%02d", minutesToSet, secondsToSet);
-
- } else if (obj == btnSecondsUp) {
- if (secondsToSet >= 59) {
- secondsToSet = 0;
- } else {
- secondsToSet++;
- }
- lv_label_set_text_fmt(time, "%02d:%02d", minutesToSet, secondsToSet);
-
- } else if (obj == btnSecondsDown) {
- if (secondsToSet == 0) {
- secondsToSet = 59;
- } else {
- secondsToSet--;
- }
- lv_label_set_text_fmt(time, "%02d:%02d", minutesToSet, secondsToSet);
- }
- }
- }
- }
-}
-
-void Timer::setDone() {
- lv_label_set_text(time, "00:00");
- lv_label_set_text(txtPlayPause, Symbols::play);
- secondsToSet = 0;
- minutesToSet = 0;
- createButtons();
-}
diff --git a/src/displayapp/screens/Timer.h b/src/displayapp/screens/Timer.h
deleted file mode 100644
index 23c8734..0000000
--- a/src/displayapp/screens/Timer.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#pragma once
-
-#include "displayapp/screens/Screen.h"
-#include "components/datetime/DateTimeController.h"
-#include "systemtask/SystemTask.h"
-#include "displayapp/LittleVgl.h"
-
-#include "components/timer/TimerController.h"
-
-namespace Pinetime::Applications::Screens {
-
- class Timer : public Screen {
- public:
- enum class Modes { Normal, Done };
-
- Timer(DisplayApp* app, Controllers::TimerController& timerController);
-
- ~Timer() override;
-
- void Refresh() override;
-
- void setDone();
-
- void OnButtonEvent(lv_obj_t* obj, lv_event_t event);
-
- private:
- bool running;
- uint8_t secondsToSet = 0;
- uint8_t minutesToSet = 0;
- Controllers::TimerController& timerController;
-
- void createButtons();
-
- lv_obj_t *time, *msecTime, *btnPlayPause, *txtPlayPause, *btnMinutesUp, *btnMinutesDown, *btnSecondsUp, *btnSecondsDown, *txtMUp,
- *txtMDown, *txtSUp, *txtSDown;
-
- lv_task_t* taskRefresh;
- };
-}
diff --git a/src/displayapp/screens/settings/Settings.cpp b/src/displayapp/screens/settings/Settings.cpp
index 4b53ba0..6950090 100644
--- a/src/displayapp/screens/settings/Settings.cpp
+++ b/src/displayapp/screens/settings/Settings.cpp
@@ -51,8 +51,8 @@ std::unique_ptr<Screen> Settings::CreateScreen1() {
std::unique_ptr<Screen> Settings::CreateScreen2() {
std::array<Screens::List::Applications, 4> applications {{
{Symbols::shoe, "Steps", Apps::SettingSteps},
- {Symbols::none, "None", Apps::None}
- {Symbols::none, "None", Apps::None}
+ {Symbols::none, "None", Apps::None},
+ {Symbols::none, "None", Apps::None},
{Symbols::batteryHalf, "Battery", Apps::BatteryInfo}}};
return std::make_unique<Screens::List>(1, 4, app, settingsController, applications);