summaryrefslogtreecommitdiff
path: root/src/displayapp/screens
diff options
context:
space:
mode:
authorMichele Bini <michele.bini@gmail.com>2022-03-24 07:12:30 (GMT)
committerMichele Bini <michele.bini@gmail.com>2022-03-24 10:22:19 (GMT)
commit1bc6ab30000a735600bde31e6268e48f6e986948 (patch)
tree4180ee642655655b07bc5d9a228bc7a020115538 /src/displayapp/screens
parenta5af528d64429f23c6a6de91e660a19ed19e19c5 (diff)
sans music navigation metronome twos
Diffstat (limited to 'src/displayapp/screens')
-rw-r--r--src/displayapp/screens/ApplicationList.cpp6
-rw-r--r--src/displayapp/screens/Metronome.cpp152
-rw-r--r--src/displayapp/screens/Metronome.h39
-rw-r--r--src/displayapp/screens/Music.cpp301
-rw-r--r--src/displayapp/screens/Music.h88
-rw-r--r--src/displayapp/screens/Navigation.cpp198
-rw-r--r--src/displayapp/screens/Navigation.h57
-rw-r--r--src/displayapp/screens/Notifications.cpp1
-rw-r--r--src/displayapp/screens/Twos.cpp296
-rw-r--r--src/displayapp/screens/Twos.h38
10 files changed, 0 insertions, 1176 deletions
diff --git a/src/displayapp/screens/ApplicationList.cpp b/src/displayapp/screens/ApplicationList.cpp
index fa0c26b..e584bf7 100644
--- a/src/displayapp/screens/ApplicationList.cpp
+++ b/src/displayapp/screens/ApplicationList.cpp
@@ -41,8 +41,6 @@ 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::music, Apps::Music},
- {Symbols::map, Apps::Navigation},
{Symbols::shoe, Apps::Steps},
{Symbols::heartBeat, Apps::HeartRate},
{Symbols::hourGlass, Apps::Timer},
@@ -54,9 +52,7 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen1() {
std::unique_ptr<Screen> ApplicationList::CreateScreen2() {
std::array<Screens::Tile::Applications, 6> applications {{
{Symbols::paintbrush, Apps::Paint},
- {"2", Apps::Twos},
{Symbols::chartLine, Apps::Motion},
- {Symbols::drum, Apps::Metronome},
{Symbols::clock, Apps::Alarm},
}};
@@ -66,9 +62,7 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen2() {
/*std::unique_ptr<Screen> ApplicationList::CreateScreen3() {
std::array<Screens::Tile::Applications, 6> applications {
{{"A", Apps::Meter},
- {"B", Apps::Navigation},
{"C", Apps::Clock},
- {"D", Apps::Music},
{"E", Apps::SysInfo},
{"F", Apps::Brightness}
}
diff --git a/src/displayapp/screens/Metronome.cpp b/src/displayapp/screens/Metronome.cpp
deleted file mode 100644
index f6f269d..0000000
--- a/src/displayapp/screens/Metronome.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-#include "displayapp/screens/Metronome.h"
-#include "displayapp/screens/Symbols.h"
-
-using namespace Pinetime::Applications::Screens;
-
-namespace {
- void eventHandler(lv_obj_t* obj, lv_event_t event) {
- auto* screen = static_cast<Metronome*>(obj->user_data);
- screen->OnEvent(obj, event);
- }
-
- lv_obj_t* createLabel(const char* name, lv_obj_t* reference, lv_align_t align, lv_font_t* font, uint8_t x, uint8_t y) {
- lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
- lv_obj_set_style_local_text_font(label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font);
- lv_obj_set_style_local_text_color(label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
- lv_label_set_text(label, name);
- lv_obj_align(label, reference, align, x, y);
-
- return label;
- }
-}
-
-Metronome::Metronome(DisplayApp* app, Controllers::MotorController& motorController, System::SystemTask& systemTask)
- : Screen(app), motorController {motorController}, systemTask {systemTask} {
-
- bpmArc = lv_arc_create(lv_scr_act(), nullptr);
- bpmArc->user_data = this;
- lv_obj_set_event_cb(bpmArc, eventHandler);
- lv_arc_set_bg_angles(bpmArc, 0, 270);
- lv_arc_set_rotation(bpmArc, 135);
- lv_arc_set_range(bpmArc, 40, 220);
- lv_arc_set_value(bpmArc, bpm);
- lv_obj_set_size(bpmArc, 210, 210);
- lv_arc_set_adjustable(bpmArc, true);
- lv_obj_align(bpmArc, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0);
-
- bpmValue = createLabel("120", bpmArc, LV_ALIGN_IN_TOP_MID, &jetbrains_mono_76, 0, 55);
- createLabel("bpm", bpmValue, LV_ALIGN_OUT_BOTTOM_MID, &jetbrains_mono_bold_20, 0, 0);
-
- bpmTap = lv_btn_create(lv_scr_act(), nullptr);
- bpmTap->user_data = this;
- lv_obj_set_event_cb(bpmTap, eventHandler);
- lv_obj_set_style_local_bg_opa(bpmTap, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
- lv_obj_set_height(bpmTap, 80);
- lv_obj_align(bpmTap, bpmValue, LV_ALIGN_IN_TOP_MID, 0, 0);
-
- bpbDropdown = lv_dropdown_create(lv_scr_act(), nullptr);
- bpbDropdown->user_data = this;
- lv_obj_set_event_cb(bpbDropdown, eventHandler);
- lv_obj_set_style_local_pad_left(bpbDropdown, LV_DROPDOWN_PART_MAIN, LV_STATE_DEFAULT, 20);
- lv_obj_set_style_local_pad_left(bpbDropdown, LV_DROPDOWN_PART_LIST, LV_STATE_DEFAULT, 20);
- lv_obj_set_size(bpbDropdown, 115, 50);
- lv_obj_align(bpbDropdown, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
- lv_dropdown_set_options(bpbDropdown, "1\n2\n3\n4\n5\n6\n7\n8\n9");
- lv_dropdown_set_selected(bpbDropdown, bpb - 1);
- lv_dropdown_set_show_selected(bpbDropdown, false);
- lv_dropdown_set_text(bpbDropdown, "");
-
- currentBpbText = lv_label_create(bpbDropdown, nullptr);
- lv_label_set_text_fmt(currentBpbText, "%d bpb", bpb);
- lv_obj_align(currentBpbText, bpbDropdown, LV_ALIGN_CENTER, 0, 0);
-
- playPause = lv_btn_create(lv_scr_act(), nullptr);
- playPause->user_data = this;
- lv_obj_set_event_cb(playPause, eventHandler);
- lv_obj_set_size(playPause, 115, 50);
- lv_obj_align(playPause, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
- lv_obj_set_style_local_value_str(playPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Symbols::play);
-
- taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
-}
-
-Metronome::~Metronome() {
- lv_task_del(taskRefresh);
- systemTask.PushMessage(System::Messages::EnableSleeping);
- lv_obj_clean(lv_scr_act());
-}
-
-void Metronome::Refresh() {
- if (metronomeStarted) {
- if (xTaskGetTickCount() - startTime > 60u * configTICK_RATE_HZ / static_cast<uint16_t>(bpm)) {
- startTime += 60 * configTICK_RATE_HZ / bpm;
- counter--;
- if (counter == 0) {
- counter = bpb;
- motorController.RunForDuration(90);
- } else {
- motorController.RunForDuration(30);
- }
- }
- }
-}
-
-void Metronome::OnEvent(lv_obj_t* obj, lv_event_t event) {
- switch (event) {
- case LV_EVENT_VALUE_CHANGED: {
- if (obj == bpmArc) {
- bpm = lv_arc_get_value(bpmArc);
- lv_label_set_text_fmt(bpmValue, "%03d", bpm);
- } else if (obj == bpbDropdown) {
- bpb = lv_dropdown_get_selected(obj) + 1;
- lv_label_set_text_fmt(currentBpbText, "%d bpb", bpb);
- lv_obj_realign(currentBpbText);
- }
- break;
- }
- case LV_EVENT_PRESSED: {
- if (obj == bpmTap) {
- TickType_t delta = xTaskGetTickCount() - tappedTime;
- if (tappedTime != 0 && delta < configTICK_RATE_HZ * 3) {
- bpm = configTICK_RATE_HZ * 60 / delta;
- lv_arc_set_value(bpmArc, bpm);
- lv_label_set_text_fmt(bpmValue, "%03d", bpm);
- }
- tappedTime = xTaskGetTickCount();
- allowExit = true;
- }
- break;
- }
- case LV_EVENT_RELEASED:
- case LV_EVENT_PRESS_LOST:
- if (obj == bpmTap) {
- allowExit = false;
- }
- break;
- case LV_EVENT_CLICKED: {
- if (obj == playPause) {
- metronomeStarted = !metronomeStarted;
- if (metronomeStarted) {
- lv_obj_set_style_local_value_str(playPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Symbols::pause);
- systemTask.PushMessage(System::Messages::DisableSleeping);
- startTime = xTaskGetTickCount();
- counter = 1;
- } else {
- lv_obj_set_style_local_value_str(playPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Symbols::play);
- systemTask.PushMessage(System::Messages::EnableSleeping);
- }
- }
- break;
- }
- default:
- break;
- }
-}
-
-bool Metronome::OnTouchEvent(TouchEvents event) {
- if (event == TouchEvents::SwipeDown && allowExit) {
- running = false;
- return true;
- }
- return false;
-}
diff --git a/src/displayapp/screens/Metronome.h b/src/displayapp/screens/Metronome.h
deleted file mode 100644
index 6e6589f..0000000
--- a/src/displayapp/screens/Metronome.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#pragma once
-
-#include "systemtask/SystemTask.h"
-#include "components/motor/MotorController.h"
-#include "displayapp/screens/Screen.h"
-
-namespace Pinetime {
- namespace Applications {
- namespace Screens {
-
- class Metronome : public Screen {
- public:
- Metronome(DisplayApp* app, Controllers::MotorController& motorController, System::SystemTask& systemTask);
- ~Metronome() override;
- void Refresh() override;
- void OnEvent(lv_obj_t* obj, lv_event_t event);
- bool OnTouchEvent(TouchEvents event) override;
-
- private:
- TickType_t startTime = 0;
- TickType_t tappedTime = 0;
- Controllers::MotorController& motorController;
- System::SystemTask& systemTask;
- int16_t bpm = 120;
- uint8_t bpb = 4;
- uint8_t counter = 1;
-
- bool metronomeStarted = false;
- bool allowExit = false;
-
- lv_obj_t *bpmArc, *bpmTap, *bpmValue;
- lv_obj_t *bpbDropdown, *currentBpbText;
- lv_obj_t *playPause;
-
- lv_task_t* taskRefresh;
- };
- }
- }
-}
diff --git a/src/displayapp/screens/Music.cpp b/src/displayapp/screens/Music.cpp
deleted file mode 100644
index 9f17b95..0000000
--- a/src/displayapp/screens/Music.cpp
+++ /dev/null
@@ -1,301 +0,0 @@
-/* Copyright (C) 2020 JF, Adam Pigg, Avamander
-
- This file is part of InfiniTime.
-
- InfiniTime is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- InfiniTime is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-*/
-#include "displayapp/screens/Music.h"
-#include "displayapp/screens/Symbols.h"
-#include <cstdint>
-#include "displayapp/DisplayApp.h"
-#include "components/ble/MusicService.h"
-#include "displayapp/icons/music/disc.cpp"
-#include "displayapp/icons/music/disc_f_1.cpp"
-#include "displayapp/icons/music/disc_f_2.cpp"
-
-using namespace Pinetime::Applications::Screens;
-
-static void event_handler(lv_obj_t* obj, lv_event_t event) {
- Music* screen = static_cast<Music*>(obj->user_data);
- screen->OnObjectEvent(obj, event);
-}
-
-/**
- * Set the pixel array to display by the image
- * This just calls lv_img_set_src but adds type safety
- *
- * @param img pointer to an image object
- * @param data the image array
- */
-inline void lv_img_set_src_arr(lv_obj_t* img, const lv_img_dsc_t* src_img) {
- lv_img_set_src(img, src_img);
-}
-
-/**
- * Music control watchapp
- *
- * TODO: Investigate Apple Media Service and AVRCPv1.6 support for seamless integration
- */
-Music::Music(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::MusicService& music) : Screen(app), musicService(music) {
- lv_obj_t* label;
-
- lv_style_init(&btn_style);
- lv_style_set_radius(&btn_style, LV_STATE_DEFAULT, 20);
- lv_style_set_bg_color(&btn_style, LV_STATE_DEFAULT, LV_COLOR_AQUA);
- lv_style_set_bg_opa(&btn_style, LV_STATE_DEFAULT, LV_OPA_20);
-
- btnVolDown = lv_btn_create(lv_scr_act(), nullptr);
- btnVolDown->user_data = this;
- lv_obj_set_event_cb(btnVolDown, event_handler);
- lv_obj_set_size(btnVolDown, 76, 76);
- lv_obj_align(btnVolDown, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
- lv_obj_add_style(btnVolDown, LV_STATE_DEFAULT, &btn_style);
- label = lv_label_create(btnVolDown, nullptr);
- lv_label_set_text(label, Symbols::volumDown);
- lv_obj_set_hidden(btnVolDown, true);
-
- btnVolUp = lv_btn_create(lv_scr_act(), nullptr);
- btnVolUp->user_data = this;
- lv_obj_set_event_cb(btnVolUp, event_handler);
- lv_obj_set_size(btnVolUp, 76, 76);
- lv_obj_align(btnVolUp, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
- lv_obj_add_style(btnVolUp, LV_STATE_DEFAULT, &btn_style);
- label = lv_label_create(btnVolUp, nullptr);
- lv_label_set_text(label, Symbols::volumUp);
- lv_obj_set_hidden(btnVolUp, true);
-
- btnPrev = lv_btn_create(lv_scr_act(), nullptr);
- btnPrev->user_data = this;
- lv_obj_set_event_cb(btnPrev, event_handler);
- lv_obj_set_size(btnPrev, 76, 76);
- lv_obj_align(btnPrev, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
- lv_obj_add_style(btnPrev, LV_STATE_DEFAULT, &btn_style);
- label = lv_label_create(btnPrev, nullptr);
- lv_label_set_text(label, Symbols::stepBackward);
-
- btnNext = lv_btn_create(lv_scr_act(), nullptr);
- btnNext->user_data = this;
- lv_obj_set_event_cb(btnNext, event_handler);
- lv_obj_set_size(btnNext, 76, 76);
- lv_obj_align(btnNext, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
- lv_obj_add_style(btnNext, LV_STATE_DEFAULT, &btn_style);
- label = lv_label_create(btnNext, nullptr);
- lv_label_set_text(label, Symbols::stepForward);
-
- btnPlayPause = lv_btn_create(lv_scr_act(), nullptr);
- btnPlayPause->user_data = this;
- lv_obj_set_event_cb(btnPlayPause, event_handler);
- lv_obj_set_size(btnPlayPause, 76, 76);
- lv_obj_align(btnPlayPause, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
- lv_obj_add_style(btnPlayPause, LV_STATE_DEFAULT, &btn_style);
- txtPlayPause = lv_label_create(btnPlayPause, nullptr);
- lv_label_set_text(txtPlayPause, Symbols::play);
-
- txtTrackDuration = lv_label_create(lv_scr_act(), nullptr);
- lv_label_set_long_mode(txtTrackDuration, LV_LABEL_LONG_SROLL);
- lv_obj_align(txtTrackDuration, nullptr, LV_ALIGN_IN_TOP_LEFT, 12, 20);
- lv_label_set_text(txtTrackDuration, "--:--/--:--");
- lv_label_set_align(txtTrackDuration, LV_ALIGN_IN_LEFT_MID);
- lv_obj_set_width(txtTrackDuration, LV_HOR_RES);
-
- constexpr uint8_t FONT_HEIGHT = 12;
- constexpr uint8_t LINE_PAD = 15;
- constexpr int8_t MIDDLE_OFFSET = -25;
- txtArtist = lv_label_create(lv_scr_act(), nullptr);
- lv_label_set_long_mode(txtArtist, LV_LABEL_LONG_SROLL_CIRC);
- lv_obj_align(txtArtist, nullptr, LV_ALIGN_IN_LEFT_MID, 12, MIDDLE_OFFSET + 1 * FONT_HEIGHT);
- lv_label_set_align(txtArtist, LV_ALIGN_IN_LEFT_MID);
- lv_obj_set_width(txtArtist, LV_HOR_RES - 12);
- lv_label_set_text(txtArtist, "Artist Name");
-
- txtTrack = lv_label_create(lv_scr_act(), nullptr);
- lv_label_set_long_mode(txtTrack, LV_LABEL_LONG_SROLL_CIRC);
- lv_obj_align(txtTrack, nullptr, LV_ALIGN_IN_LEFT_MID, 12, MIDDLE_OFFSET + 2 * FONT_HEIGHT + LINE_PAD);
-
- lv_label_set_align(txtTrack, LV_ALIGN_IN_LEFT_MID);
- lv_obj_set_width(txtTrack, LV_HOR_RES - 12);
- lv_label_set_text(txtTrack, "This is a very long getTrack name");
-
- /** Init animation */
- imgDisc = lv_img_create(lv_scr_act(), nullptr);
- lv_img_set_src_arr(imgDisc, &disc);
- lv_obj_align(imgDisc, nullptr, LV_ALIGN_IN_TOP_RIGHT, -15, 15);
-
- imgDiscAnim = lv_img_create(lv_scr_act(), nullptr);
- lv_img_set_src_arr(imgDiscAnim, &disc_f_1);
- lv_obj_align(imgDiscAnim, nullptr, LV_ALIGN_IN_TOP_RIGHT, -15 - 32, 15);
-
- frameB = false;
-
- musicService.event(Controllers::MusicService::EVENT_MUSIC_OPEN);
-
- taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
-}
-
-Music::~Music() {
- lv_task_del(taskRefresh);
- lv_style_reset(&btn_style);
- lv_obj_clean(lv_scr_act());
-}
-
-void Music::Refresh() {
- if (artist != musicService.getArtist()) {
- artist = musicService.getArtist();
- currentLength = 0;
- lv_label_set_text(txtArtist, artist.data());
- }
-
- if (track != musicService.getTrack()) {
- track = musicService.getTrack();
- currentLength = 0;
- lv_label_set_text(txtTrack, track.data());
- }
-
- if (album != musicService.getAlbum()) {
- album = musicService.getAlbum();
- currentLength = 0;
- }
-
- if (playing != musicService.isPlaying()) {
- playing = musicService.isPlaying();
- }
-
- // Because we increment this ourselves,
- // we can't compare with the old data directly
- // have to update it when there's actually new data
- // just to avoid unnecessary draws that make UI choppy
- if (lastLength != musicService.getProgress()) {
- currentLength = musicService.getProgress();
- lastLength = currentLength;
- UpdateLength();
- }
-
- if (totalLength != musicService.getTrackLength()) {
- totalLength = musicService.getTrackLength();
- UpdateLength();
- }
-
- if (playing == Pinetime::Controllers::MusicService::MusicStatus::Playing) {
- lv_label_set_text(txtPlayPause, Symbols::pause);
- if (xTaskGetTickCount() - 1024 >= lastIncrement) {
-
- if (frameB) {
- lv_img_set_src(imgDiscAnim, &disc_f_1);
- } else {
- lv_img_set_src(imgDiscAnim, &disc_f_2);
- }
- frameB = !frameB;
-
- if (currentLength < totalLength) {
- currentLength +=
- static_cast<int>((static_cast<float>(xTaskGetTickCount() - lastIncrement) / 1024.0f) * musicService.getPlaybackSpeed());
- } else {
- // Let's assume the getTrack finished, paused when the timer ends
- // and there's no new getTrack being sent to us
- // TODO: ideally this would be configurable
- playing = false;
- }
- lastIncrement = xTaskGetTickCount();
-
- UpdateLength();
- }
- } else {
- lv_label_set_text(txtPlayPause, Symbols::play);
- }
-}
-
-void Music::UpdateLength() {
- if (totalLength > (99 * 60 * 60)) {
- lv_label_set_text(txtTrackDuration, "Inf/Inf");
- } else if (totalLength > (99 * 60)) {
- char timer[12];
- sprintf(timer,
- "%02d:%02d/%02d:%02d",
- (currentLength / (60 * 60)) % 100,
- ((currentLength % (60 * 60)) / 60) % 100,
- (totalLength / (60 * 60)) % 100,
- ((totalLength % (60 * 60)) / 60) % 100);
- lv_label_set_text(txtTrackDuration, timer);
- } else {
- char timer[12];
- sprintf(timer,
- "%02d:%02d/%02d:%02d",
- (currentLength / 60) % 100,
- (currentLength % 60) % 100,
- (totalLength / 60) % 100,
- (totalLength % 60) % 100);
- lv_label_set_text(txtTrackDuration, timer);
- }
-}
-
-void Music::OnObjectEvent(lv_obj_t* obj, lv_event_t event) {
- if (event == LV_EVENT_CLICKED) {
- if (obj == btnVolDown) {
- musicService.event(Controllers::MusicService::EVENT_MUSIC_VOLDOWN);
- } else if (obj == btnVolUp) {
- musicService.event(Controllers::MusicService::EVENT_MUSIC_VOLUP);
- } else if (obj == btnPrev) {
- musicService.event(Controllers::MusicService::EVENT_MUSIC_PREV);
- } else if (obj == btnPlayPause) {
- if (playing == Pinetime::Controllers::MusicService::MusicStatus::Playing) {
- musicService.event(Controllers::MusicService::EVENT_MUSIC_PAUSE);
-
- // Let's assume it stops playing instantly
- playing = Controllers::MusicService::NotPlaying;
- } else {
- musicService.event(Controllers::MusicService::EVENT_MUSIC_PLAY);
-
- // Let's assume it starts playing instantly
- // TODO: In the future should check for BT connection for better UX
- playing = Controllers::MusicService::Playing;
- }
- } else if (obj == btnNext) {
- musicService.event(Controllers::MusicService::EVENT_MUSIC_NEXT);
- }
- }
-}
-
-bool Music::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
- switch (event) {
- case TouchEvents::SwipeUp: {
- lv_obj_set_hidden(btnVolDown, false);
- lv_obj_set_hidden(btnVolUp, false);
-
- lv_obj_set_hidden(btnNext, true);
- lv_obj_set_hidden(btnPrev, true);
- return true;
- }
- case TouchEvents::SwipeDown: {
- if (lv_obj_get_hidden(btnNext)) {
- lv_obj_set_hidden(btnNext, false);
- lv_obj_set_hidden(btnPrev, false);
- lv_obj_set_hidden(btnVolDown, true);
- lv_obj_set_hidden(btnVolUp, true);
- return true;
- }
- return false;
- }
- case TouchEvents::SwipeLeft: {
- musicService.event(Controllers::MusicService::EVENT_MUSIC_NEXT);
- return true;
- }
- case TouchEvents::SwipeRight: {
- musicService.event(Controllers::MusicService::EVENT_MUSIC_PREV);
- return true;
- }
- default: {
- return false;
- }
- }
-}
diff --git a/src/displayapp/screens/Music.h b/src/displayapp/screens/Music.h
deleted file mode 100644
index 27b2d3d..0000000
--- a/src/displayapp/screens/Music.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/* Copyright (C) 2020 JF, Adam Pigg, Avamander
-
- This file is part of InfiniTime.
-
- InfiniTime is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- InfiniTime is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include <FreeRTOS.h>
-#include <lvgl/src/lv_core/lv_obj.h>
-#include <string>
-#include "displayapp/screens/Screen.h"
-
-namespace Pinetime {
- namespace Controllers {
- class MusicService;
- }
-
- namespace Applications {
- namespace Screens {
- class Music : public Screen {
- public:
- Music(DisplayApp* app, Pinetime::Controllers::MusicService& music);
-
- ~Music() override;
-
- void Refresh() override;
-
- void OnObjectEvent(lv_obj_t* obj, lv_event_t event);
-
- private:
- bool OnTouchEvent(TouchEvents event) override;
-
- void UpdateLength();
-
- lv_obj_t* btnPrev;
- lv_obj_t* btnPlayPause;
- lv_obj_t* btnNext;
- lv_obj_t* btnVolDown;
- lv_obj_t* btnVolUp;
- lv_obj_t* txtArtist;
- lv_obj_t* txtTrack;
- lv_obj_t* txtPlayPause;
-
- lv_obj_t* imgDisc;
- lv_obj_t* imgDiscAnim;
- lv_obj_t* txtTrackDuration;
-
- lv_style_t btn_style;
-
- /** For the spinning disc animation */
- bool frameB;
-
- Pinetime::Controllers::MusicService& musicService;
-
- std::string artist;
- std::string album;
- std::string track;
-
- /** Total length in seconds */
- int totalLength = 0;
- /** Current length in seconds */
- int currentLength;
- /** Last length */
- int lastLength;
- /** Last time an animation update or timer was incremented */
- TickType_t lastIncrement = 0;
-
- bool playing;
-
- lv_task_t* taskRefresh;
-
- /** Watchapp */
- };
- }
- }
-}
diff --git a/src/displayapp/screens/Navigation.cpp b/src/displayapp/screens/Navigation.cpp
deleted file mode 100644
index 674362a..0000000
--- a/src/displayapp/screens/Navigation.cpp
+++ /dev/null
@@ -1,198 +0,0 @@
-/* Copyright (C) 2021 Adam Pigg
-
- This file is part of InfiniTime.
-
- InfiniTime is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- InfiniTime is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-*/
-#include "displayapp/screens/Navigation.h"
-#include <cstdint>
-#include "displayapp/DisplayApp.h"
-#include "components/ble/NavigationService.h"
-
-using namespace Pinetime::Applications::Screens;
-
-LV_FONT_DECLARE(lv_font_navi_80)
-
-namespace {
- constexpr std::array<std::pair<const char*, const char*>, 86> m_iconMap = {{
- {"arrive-left", "\xEE\xA4\x81"},
- {"arrive-right", "\xEE\xA4\x82"},
- {"arrive-straight", "\xEE\xA4\x80"},
- {"arrive", "\xEE\xA4\x80"},
- {"close", "\xEE\xA4\x83"},
- {"continue-left", "\xEE\xA4\x85"},
- {"continue-right", "\xEE\xA4\x86"},
- {"continue-slight-left", "\xEE\xA4\x87"},
- {"continue-slight-right", "\xEE\xA4\x88"},
- {"continue-straight", "\xEE\xA4\x84"},
- {"continue-uturn", "\xEE\xA4\x89"},
- {"continue", "\xEE\xA4\x84"},
- {"depart-left", "\xEE\xA4\x8B"},
- {"depart-right", "\xEE\xA4\x8C"},
- {"depart-straight", "\xEE\xA4\x8A"},
- {"end-of-road-left", "\xEE\xA4\x8D"},
- {"end-of-road-right", "\xEE\xA4\x8E"},
- {"ferry", "\xEE\xA4\x8F"},
- {"flag", "\xEE\xA4\x90"},
- {"fork-left", "\xEE\xA4\x92"},
- {"fork-right", "\xEE\xA4\x93"},
- {"fork-slight-left", "\xEE\xA4\x94"},
- {"fork-slight-right", "\xEE\xA4\x95"},
- {"fork-straight", "\xEE\xA4\x96"},
- {"invalid", "\xEE\xA4\x84"},
- {"invalid-left", "\xEE\xA4\x85"},
- {"invalid-right", "\xEE\xA4\x86"},
- {"invalid-slight-left", "\xEE\xA4\x87"},
- {"invalid-slight-right", "\xEE\xA4\x88"},
- {"invalid-straight", "\xEE\xA4\x84"},
- {"invalid-uturn", "\xEE\xA4\x89"},
- {"merge-left", "\xEE\xA4\x97"},
- {"merge-right", "\xEE\xA4\x98"},
- {"merge-slight-left", "\xEE\xA4\x99"},
- {"merge-slight-right", "\xEE\xA4\x9A"},
- {"merge-straight", "\xEE\xA4\x84"},
- {"new-name-left", "\xEE\xA4\x85"},
- {"new-name-right", "\xEE\xA4\x86"},
- {"new-name-sharp-left", "\xEE\xA4\x9B"},
- {"new-name-sharp-right", "\xEE\xA4\x9C"},
- {"new-name-slight-left", "\xEE\xA4\x87"},
- {"new-name-slight-right", "\xEE\xA4\x88"},
- {"new-name-straight", "\xEE\xA4\x84"},
- {"notification-left", "\xEE\xA4\x85"},
- {"notification-right", "\xEE\xA4\x86"},
- {"notification-sharp-left", "\xEE\xA4\x9B"},
- {"notification-sharp-right", "\xEE\xA4\xA5"},
- {"notification-slight-left", "\xEE\xA4\x87"},
- {"notification-slight-right", "\xEE\xA4\x88"},
- {"notification-straight", "\xEE\xA4\x84"},
- {"off-ramp-left", "\xEE\xA4\x9D"},
- {"off-ramp-right", "\xEE\xA4\x9E"},
- {"off-ramp-slight-left", "\xEE\xA4\x9F"},
- {"off-ramp-slight-right", "\xEE\xA4\xA0"},
- {"on-ramp-left", "\xEE\xA4\x85"},
- {"on-ramp-right", "\xEE\xA4\x86"},
- {"on-ramp-sharp-left", "\xEE\xA4\x9B"},
- {"on-ramp-sharp-right", "\xEE\xA4\xA5"},
- {"on-ramp-slight-left", "\xEE\xA4\x87"},
- {"on-ramp-slight-right", "\xEE\xA4\x88"},
- {"on-ramp-straight", "\xEE\xA4\x84"},
- {"rotary", "\xEE\xA4\xA1"},
- {"rotary-left", "\xEE\xA4\xA2"},
- {"rotary-right", "\xEE\xA4\xA3"},
- {"rotary-sharp-left", "\xEE\xA4\xA4"},
- {"rotary-sharp-right", "\xEE\xA4\xA5"},
- {"rotary-slight-left", "\xEE\xA4\xA6"},
- {"rotary-slight-right", "\xEE\xA4\xA7"},
- {"rotary-straight", "\xEE\xA4\xA8"},
- {"roundabout", "\xEE\xA4\xA1"},
- {"roundabout-left", "\xEE\xA4\xA2"},
- {"roundabout-right", "\xEE\xA4\xA3"},
- {"roundabout-sharp-left", "\xEE\xA4\xA4"},
- {"roundabout-sharp-right", "\xEE\xA4\xA5"},
- {"roundabout-slight-left", "\xEE\xA4\xA6"},
- {"roundabout-slight-right", "\xEE\xA4\xA7"},
- {"roundabout-straight", "\xEE\xA4\xA8"},
- {"turn-left", "\xEE\xA4\x85"},
- {"turn-right", "\xEE\xA4\x86"},
- {"turn-sharp-left", "\xEE\xA4\x9B"},
- {"turn-sharp-right", "\xEE\xA4\xA5"},
- {"turn-slight-left", "\xEE\xA4\x87"},
- {"turn-slight-right", "\xEE\xA4\x88"},
- {"turn-straight", "\xEE\xA4\x84"},
- {"updown", "\xEE\xA4\xA9"},
- {"uturn", "\xEE\xA4\x89"},
- }};
-
- const char* iconForName(const std::string& icon) {
- for (auto iter : m_iconMap) {
- if (iter.first == icon) {
- return iter.second;
- }
- }
- return "\xEE\xA4\x90";
- }
-}
-
-/**
- * Navigation watchapp
- *
- */
-Navigation::Navigation(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::NavigationService& nav)
- : Screen(app), navService(nav) {
-
- imgFlag = lv_label_create(lv_scr_act(), nullptr);
- lv_obj_set_style_local_text_font(imgFlag, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_navi_80);
- lv_obj_set_style_local_text_color(imgFlag, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_CYAN);
- lv_label_set_text(imgFlag, iconForName("flag"));
- lv_obj_align(imgFlag, nullptr, LV_ALIGN_CENTER, 0, -60);
-
- txtNarrative = lv_label_create(lv_scr_act(), nullptr);
- lv_label_set_long_mode(txtNarrative, LV_LABEL_LONG_BREAK);
- lv_obj_set_width(txtNarrative, LV_HOR_RES);
- lv_label_set_text(txtNarrative, "Navigation");
- lv_label_set_align(txtNarrative, LV_LABEL_ALIGN_CENTER);
- lv_obj_align(txtNarrative, nullptr, LV_ALIGN_CENTER, 0, 10);
-
- txtManDist = lv_label_create(lv_scr_act(), nullptr);
- lv_label_set_long_mode(txtManDist, LV_LABEL_LONG_BREAK);
- lv_obj_set_style_local_text_color(txtManDist, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
- lv_obj_set_width(txtManDist, LV_HOR_RES);
- lv_label_set_text(txtManDist, "--M");
- lv_label_set_align(txtManDist, LV_LABEL_ALIGN_CENTER);
- lv_obj_align(txtManDist, nullptr, LV_ALIGN_CENTER, 0, 60);
-
- // Route Progress
- barProgress = lv_bar_create(lv_scr_act(), nullptr);
- lv_obj_set_size(barProgress, 200, 20);
- lv_obj_align(barProgress, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, -10);
- lv_obj_set_style_local_bg_color(barProgress, LV_BAR_PART_BG, LV_STATE_DEFAULT, lv_color_hex(0x222222));
- lv_obj_set_style_local_bg_color(barProgress, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
- lv_bar_set_anim_time(barProgress, 500);
- lv_bar_set_range(barProgress, 0, 100);
- lv_bar_set_value(barProgress, 0, LV_ANIM_OFF);
-
- taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
-}
-
-Navigation::~Navigation() {
- lv_task_del(taskRefresh);
- lv_obj_clean(lv_scr_act());
-}
-
-void Navigation::Refresh() {
- if (flag != navService.getFlag()) {
- flag = navService.getFlag();
- lv_label_set_text(imgFlag, iconForName(flag));
- }
-
- if (narrative != navService.getNarrative()) {
- narrative = navService.getNarrative();
- lv_label_set_text(txtNarrative, narrative.data());
- }
-
- if (manDist != navService.getManDist()) {
- manDist = navService.getManDist();
- lv_label_set_text(txtManDist, manDist.data());
- }
-
- if (progress != navService.getProgress()) {
- progress = navService.getProgress();
- lv_bar_set_value(barProgress, progress, LV_ANIM_OFF);
- if (progress > 90) {
- lv_obj_set_style_local_bg_color(barProgress, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED);
- } else {
- lv_obj_set_style_local_bg_color(barProgress, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
- }
- }
-}
diff --git a/src/displayapp/screens/Navigation.h b/src/displayapp/screens/Navigation.h
deleted file mode 100644
index 07674ef..0000000
--- a/src/displayapp/screens/Navigation.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/* Copyright (C) 2021 Adam Pigg
-
- This file is part of InfiniTime.
-
- InfiniTime is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- InfiniTime is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include <FreeRTOS.h>
-#include <lvgl/src/lv_core/lv_obj.h>
-#include <string>
-#include "displayapp/screens/Screen.h"
-#include <array>
-
-namespace Pinetime {
- namespace Controllers {
- class NavigationService;
- }
-
- namespace Applications {
- namespace Screens {
- class Navigation : public Screen {
- public:
- Navigation(DisplayApp* app, Pinetime::Controllers::NavigationService& nav);
- ~Navigation() override;
-
- void Refresh() override;
-
- private:
- lv_obj_t* imgFlag;
- lv_obj_t* txtNarrative;
- lv_obj_t* txtManDist;
- lv_obj_t* barProgress;
-
- Pinetime::Controllers::NavigationService& navService;
-
- std::string flag;
- std::string narrative;
- std::string manDist;
- int progress;
-
- lv_task_t* taskRefresh;
- };
- }
- }
-}
diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp
index f9afd8c..c10a60d 100644
--- a/src/displayapp/screens/Notifications.cpp
+++ b/src/displayapp/screens/Notifications.cpp
@@ -1,6 +1,5 @@
#include "displayapp/screens/Notifications.h"
#include "displayapp/DisplayApp.h"
-#include "components/ble/MusicService.h"
#include "components/ble/AlertNotificationService.h"
#include "displayapp/screens/Symbols.h"
diff --git a/src/displayapp/screens/Twos.cpp b/src/displayapp/screens/Twos.cpp
deleted file mode 100644
index 6d67585..0000000
--- a/src/displayapp/screens/Twos.cpp
+++ /dev/null
@@ -1,296 +0,0 @@
-#include "displayapp/screens/Twos.h"
-#include <array>
-#include <cstdio>
-#include <cstdlib>
-#include <lvgl/lvgl.h>
-#include <utility>
-#include <vector>
-
-using namespace Pinetime::Applications::Screens;
-
-Twos::Twos(Pinetime::Applications::DisplayApp* app) : Screen(app) {
-
- // create styles to apply to different valued tiles
- lv_style_init(&style_cell1);
- lv_style_init(&style_cell2);
- lv_style_init(&style_cell3);
- lv_style_init(&style_cell4);
- lv_style_init(&style_cell5);
-
- lv_style_set_border_color(&style_cell1, LV_STATE_DEFAULT, lv_color_hex(0xbbada0));
- lv_style_set_border_width(&style_cell1, LV_STATE_DEFAULT, 3);
- lv_style_set_bg_opa(&style_cell1, LV_STATE_DEFAULT, LV_OPA_COVER);
- lv_style_set_bg_color(&style_cell1, LV_STATE_DEFAULT, lv_color_hex(0xcdc0b4));
- lv_style_set_pad_top(&style_cell1, LV_STATE_DEFAULT, 25);
- lv_style_set_text_color(&style_cell1, LV_STATE_DEFAULT, LV_COLOR_BLACK);
-
- lv_style_set_border_color(&style_cell2, LV_STATE_DEFAULT, lv_color_hex(0xbbada0));
- lv_style_set_border_width(&style_cell2, LV_STATE_DEFAULT, 3);
- lv_style_set_bg_opa(&style_cell2, LV_STATE_DEFAULT, LV_OPA_COVER);
- lv_style_set_bg_color(&style_cell2, LV_STATE_DEFAULT, lv_color_hex(0xefdfc6));
- lv_style_set_pad_top(&style_cell2, LV_STATE_DEFAULT, 25);
- lv_style_set_text_color(&style_cell2, LV_STATE_DEFAULT, LV_COLOR_BLACK);
-
- lv_style_set_border_color(&style_cell3, LV_STATE_DEFAULT, lv_color_hex(0xbbada0));
- lv_style_set_border_width(&style_cell3, LV_STATE_DEFAULT, 3);
- lv_style_set_bg_opa(&style_cell3, LV_STATE_DEFAULT, LV_OPA_COVER);
- lv_style_set_bg_color(&style_cell3, LV_STATE_DEFAULT, lv_color_hex(0xef9263));
- lv_style_set_pad_top(&style_cell3, LV_STATE_DEFAULT, 25);
-
- lv_style_set_border_color(&style_cell4, LV_STATE_DEFAULT, lv_color_hex(0xbbada0));
- lv_style_set_border_width(&style_cell4, LV_STATE_DEFAULT, 3);
- lv_style_set_bg_opa(&style_cell4, LV_STATE_DEFAULT, LV_OPA_COVER);
- lv_style_set_bg_color(&style_cell4, LV_STATE_DEFAULT, lv_color_hex(0xf76142));
- lv_style_set_pad_top(&style_cell4, LV_STATE_DEFAULT, 25);
-
- lv_style_set_border_color(&style_cell5, LV_STATE_DEFAULT, lv_color_hex(0xbbada0));
- lv_style_set_border_width(&style_cell5, LV_STATE_DEFAULT, 3);
- lv_style_set_bg_opa(&style_cell5, LV_STATE_DEFAULT, LV_OPA_COVER);
- lv_style_set_bg_color(&style_cell5, LV_STATE_DEFAULT, lv_color_hex(0x007dc5));
- lv_style_set_pad_top(&style_cell5, LV_STATE_DEFAULT, 25);
-
- // format grid display
-
- gridDisplay = lv_table_create(lv_scr_act(), nullptr);
- lv_obj_add_style(gridDisplay, LV_TABLE_PART_CELL1, &style_cell1);
- lv_obj_add_style(gridDisplay, LV_TABLE_PART_CELL2, &style_cell2);
- lv_obj_add_style(gridDisplay, LV_TABLE_PART_CELL3, &style_cell3);
- lv_obj_add_style(gridDisplay, LV_TABLE_PART_CELL4, &style_cell4);
- lv_obj_add_style(gridDisplay, LV_TABLE_PART_CELL4 + 1, &style_cell5);
- lv_table_set_col_cnt(gridDisplay, 4);
- lv_table_set_row_cnt(gridDisplay, 4);
- lv_table_set_col_width(gridDisplay, 0, LV_HOR_RES / 4);
- lv_table_set_col_width(gridDisplay, 1, LV_HOR_RES / 4);
- lv_table_set_col_width(gridDisplay, 2, LV_HOR_RES / 4);
- lv_table_set_col_width(gridDisplay, 3, LV_HOR_RES / 4);
- lv_obj_align(gridDisplay, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
-
- lv_obj_clean_style_list(gridDisplay, LV_TABLE_PART_BG);
-
- // initialize grid
- for (int row = 0; row < 4; row++) {
- for (int col = 0; col < 4; col++) {
- grid[row][col].value = 0;
- lv_table_set_cell_type(gridDisplay, row, col, 1);
- lv_table_set_cell_align(gridDisplay, row, col, LV_LABEL_ALIGN_CENTER);
- }
- }
- placeNewTile();
- placeNewTile();
-
- // format score text
- scoreText = lv_label_create(lv_scr_act(), nullptr);
- lv_obj_set_width(scoreText, LV_HOR_RES);
- lv_label_set_align(scoreText, LV_ALIGN_IN_LEFT_MID);
- lv_obj_align(scoreText, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 10);
- lv_label_set_recolor(scoreText, true);
- lv_label_set_text_fmt(scoreText, "Score #FFFF00 %i#", score);
-
- lv_obj_t* backgroundLabel = lv_label_create(lv_scr_act(), nullptr);
- lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP);
- lv_obj_set_size(backgroundLabel, 240, 240);
- lv_obj_set_pos(backgroundLabel, 0, 0);
- lv_label_set_text(backgroundLabel, "");
-}
-
-Twos::~Twos() {
- lv_style_reset(&style_cell1);
- lv_style_reset(&style_cell2);
- lv_style_reset(&style_cell3);
- lv_style_reset(&style_cell4);
- lv_style_reset(&style_cell5);
- lv_obj_clean(lv_scr_act());
-}
-
-bool Twos::placeNewTile() {
- std::vector<std::pair<int, int>> availableCells;
- for (int row = 0; row < 4; row++) {
- for (int col = 0; col < 4; col++) {
- if (!grid[row][col].value) {
- availableCells.push_back(std::make_pair(row, col));
- }
- }
- }
-
- if (availableCells.size() == 0) {
- return false; // game lost
- }
-
- auto it = availableCells.cbegin();
- int random = rand() % availableCells.size();
- std::advance(it, random);
- std::pair<int, int> newCell = *it;
-
- if ((rand() % 100) < 90)
- grid[newCell.first][newCell.second].value = 2;
- else
- grid[newCell.first][newCell.second].value = 4;
- updateGridDisplay(grid);
- return true;
-}
-
-bool Twos::tryMerge(TwosTile grid[][4], int& newRow, int& newCol, int oldRow, int oldCol) {
- if (grid[newRow][newCol].value == grid[oldRow][oldCol].value) {
- if ((newCol != oldCol) || (newRow != oldRow)) {
- if (!grid[newRow][newCol].merged) {
- unsigned int newVal = grid[oldRow][oldCol].value *= 2;
- grid[newRow][newCol].value = newVal;
- score += newVal;
- lv_label_set_text_fmt(scoreText, "Score #FFFF00 %i#", score);
- grid[oldRow][oldCol].value = 0;
- grid[newRow][newCol].merged = true;
- return true;
- }
- }
- }
- return false;
-}
-
-bool Twos::tryMove(TwosTile grid[][4], int newRow, int newCol, int oldRow, int oldCol) {
- if (((newCol >= 0) && (newCol != oldCol)) || ((newRow >= 0) && (newRow != oldRow))) {
- grid[newRow][newCol].value = grid[oldRow][oldCol].value;
- grid[oldRow][oldCol].value = 0;
- return true;
- }
- return false;
-}
-
-bool Twos::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
- bool validMove = false;
- for (int row = 0; row < 4; row++) {
- for (int col = 0; col < 4; col++) {
- grid[row][col].merged = false; // reinitialize merge state
- }
- }
- switch (event) {
- case TouchEvents::SwipeLeft:
- for (int col = 1; col < 4; col++) { // ignore tiles already on far left
- for (int row = 0; row < 4; row++) {
- if (grid[row][col].value) {
- int newCol = -1;
- for (int potentialNewCol = col - 1; potentialNewCol >= 0; potentialNewCol--) {
- if (!grid[row][potentialNewCol].value) {
- newCol = potentialNewCol;
- } else { // blocked by another tile
- if (tryMerge(grid, row, potentialNewCol, row, col))
- validMove = true;
- break;
- }
- }
- if (tryMove(grid, row, newCol, row, col))
- validMove = true;
- }
- }
- }
- if (validMove) {
- placeNewTile();
- }
- return true;
- case TouchEvents::SwipeRight:
- for (int col = 2; col >= 0; col--) { // ignore tiles already on far right
- for (int row = 0; row < 4; row++) {
- if (grid[row][col].value) {
- int newCol = -1;
- for (int potentialNewCol = col + 1; potentialNewCol < 4; potentialNewCol++) {
- if (!grid[row][potentialNewCol].value) {
- newCol = potentialNewCol;
- } else { // blocked by another tile
- if (tryMerge(grid, row, potentialNewCol, row, col))
- validMove = true;
- break;
- }
- }
- if (tryMove(grid, row, newCol, row, col))
- validMove = true;
- }
- }
- }
- if (validMove) {
- placeNewTile();
- }
- return true;
- case TouchEvents::SwipeUp:
- for (int row = 1; row < 4; row++) { // ignore tiles already on top
- for (int col = 0; col < 4; col++) {
- if (grid[row][col].value) {
- int newRow = -1;
- for (int potentialNewRow = row - 1; potentialNewRow >= 0; potentialNewRow--) {
- if (!grid[potentialNewRow][col].value) {
- newRow = potentialNewRow;
- } else { // blocked by another tile
- if (tryMerge(grid, potentialNewRow, col, row, col))
- validMove = true;
- break;
- }
- }
- if (tryMove(grid, newRow, col, row, col))
- validMove = true;
- }
- }
- }
- if (validMove) {
- placeNewTile();
- }
- return true;
- case TouchEvents::SwipeDown:
- for (int row = 2; row >= 0; row--) { // ignore tiles already on bottom
- for (int col = 0; col < 4; col++) {
- if (grid[row][col].value) {
- int newRow = -1;
- for (int potentialNewRow = row + 1; potentialNewRow < 4; potentialNewRow++) {
- if (!grid[potentialNewRow][col].value) {
- newRow = potentialNewRow;
- } else { // blocked by another tile
- if (tryMerge(grid, potentialNewRow, col, row, col))
- validMove = true;
- break;
- }
- }
- if (tryMove(grid, newRow, col, row, col))
- validMove = true;
- }
- }
- }
- if (validMove) {
- placeNewTile();
- }
- return true;
- default:
- return false;
- }
- return false;
-}
-
-void Twos::updateGridDisplay(TwosTile grid[][4]) {
- for (int row = 0; row < 4; row++) {
- for (int col = 0; col < 4; col++) {
- if (grid[row][col].value) {
- char buffer[7];
- sprintf(buffer, "%d", grid[row][col].value);
- lv_table_set_cell_value(gridDisplay, row, col, buffer);
- } else {
- lv_table_set_cell_value(gridDisplay, row, col, "");
- }
- switch (grid[row][col].value) {
- case 0:
- lv_table_set_cell_type(gridDisplay, row, col, 1);
- break;
- case 2:
- case 4:
- lv_table_set_cell_type(gridDisplay, row, col, 2);
- break;
- case 8:
- case 16:
- lv_table_set_cell_type(gridDisplay, row, col, 3);
- break;
- case 32:
- case 64:
- lv_table_set_cell_type(gridDisplay, row, col, 4);
- break;
- default:
- lv_table_set_cell_type(gridDisplay, row, col, 5);
- break;
- }
- }
- }
-}
diff --git a/src/displayapp/screens/Twos.h b/src/displayapp/screens/Twos.h
deleted file mode 100644
index 5a0c435..0000000
--- a/src/displayapp/screens/Twos.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#pragma once
-
-#include <lvgl/src/lv_core/lv_obj.h>
-#include "displayapp/screens/Screen.h"
-
-namespace Pinetime {
- namespace Applications {
- struct TwosTile {
- bool merged = false;
- unsigned int value = 0;
- };
- namespace Screens {
- class Twos : public Screen {
- public:
- Twos(DisplayApp* app);
- ~Twos() override;
-
- bool OnTouchEvent(TouchEvents event) override;
-
- private:
- lv_style_t style_cell1;
- lv_style_t style_cell2;
- lv_style_t style_cell3;
- lv_style_t style_cell4;
- lv_style_t style_cell5;
-
- lv_obj_t* scoreText;
- lv_obj_t* gridDisplay;
- TwosTile grid[4][4];
- unsigned int score = 0;
- void updateGridDisplay(TwosTile grid[][4]);
- bool tryMerge(TwosTile grid[][4], int& newRow, int& newCol, int oldRow, int oldCol);
- bool tryMove(TwosTile grid[][4], int newRow, int newCol, int oldRow, int oldCol);
- bool placeNewTile();
- };
- }
- }
-}