diff --git a/README.md b/README.md index 8d612360..7a696936 100644 --- a/README.md +++ b/README.md @@ -1,88 +1,38 @@ -# [InfiniTime](https://github.com/InfiniTimeOrg/InfiniTime) +# TODO +## Completed +### Pending version -![InfiniTime logo](doc/logo/infinitime-logo-small.jpg "InfiniTime Logo") +### v1.13.1 +- [x] Make $s in terminal watch face green +- [x] Swipe left to access music control +- [x] Flashlight starts on +- [x] Calculator +- [x] Redo music control gestures + - [x] Swipe up toggles control mode and swipe down exits +- [x] Swipe left/right goes to watchface/another app +- [x] Rearrange quick acces and apps +- [x] Exponent button on calculator +- [x] Seconds on digital watchface +- [x] Add quick ring settings -Fast open-source firmware for the [PineTime smartwatch](https://www.pine64.org/pinetime/) with many features, written in modern C++. +## Pending merge -## New to InfiniTime? +## In progress +### Elijah +- [ ] Countdown timer presistant buzz -- [Getting started with InfiniTime](doc/gettingStarted/gettingStarted-1.0.md) -- [Updating the software](doc/gettingStarted/updating-software.md) -- [About the firmware and bootloader](doc/gettingStarted/about-software.md) -- [PineTimeStyle Watch face](https://wiki.pine64.org/wiki/PineTimeStyle) - - [Weather integration](https://wiki.pine64.org/wiki/Infinitime-Weather) +### Josh +- [ ] Smiley face watchface :) +- [ ] Remap button double click -### Companion apps +### Moses -- [Gadgetbridge](https://gadgetbridge.org/) (Android) -- [AmazFish](https://openrepos.net/content/piggz/amazfish/) (SailfishOS) -- [Siglo](https://github.com/alexr4535/siglo) (Linux) -- [InfiniLink](https://github.com/InfiniTimeOrg/InfiniLink) (iOS) -- [ITD](https://gitea.elara.ws/Elara6331/itd) (Linux) -- [WatchMate](https://github.com/azymohliad/watchmate) (Linux) -***Note**: We removed mentions to NRFConnect as this app is closed source and recent versions do not work anymore with InfiniTime (the last version known to work is 4.24.3). If you used NRFConnect in the past, we recommend you switch to [Gadgetbridge](https://gadgetbridge.org/).* -## Development +## Medium priority +- [ ] Battery on digital watchface +- [ ] More watchfaces! -- [InfiniTime Vision](doc/InfiniTimeVision.md) -- [Rough structure of the code](doc/code/Intro.md) -- [How to implement an application](doc/code/Apps.md) -- [Generate the fonts and symbols](src/displayapp/fonts/README.md) -- [Tips on designing an app UI](doc/ui_guidelines.md) -- [Bootloader, OTA and DFU](bootloader/README.md) -- [External resources](doc/ExternalResources.md) - -### Contributing - -- [How to contribute?](CONTRIBUTING.md) -- [Coding conventions](doc/coding-convention.md) - -### Build, flash and debug - -- [InfiniTime simulator](https://github.com/InfiniTimeOrg/InfiniSim) -- [Build the project](doc/buildAndProgram.md) -- [Build the project with Docker](doc/buildWithDocker.md) -- [Build the project with VSCode](doc/buildWithVScode.md) -- [Flash the firmware using OpenOCD and STLinkV2](doc/openOCD.md) -- [Flash the firmware using SWD interface](doc/SWD.md) -- [Flash the firmware using JLink](doc/jlink.md) -- [Flash the firmware using GDB](doc/gdb.md) -- [Stub using NRF52-DK](doc/PinetimeStubWithNrf52DK.md) - -### API - -- [BLE implementation and API](doc/ble.md) - -### Architecture and technical topics - -- [Memory analysis](doc/MemoryAnalysis.md) - -### Project management - -- [Maintainer's guide](doc/maintainer-guide.md) -- [Versioning](doc/versioning.md) -- [Project branches](doc/branches.md) -- [Files included in the release notes](doc/filesInReleaseNotes.md) -- [Files needed by the factory](doc/files-needed-by-factory.md) - -## Licenses - -This project is released under the GNU General Public License version 3 or, at your option, any later version. - -It integrates the following projects: - -- RTOS: **[FreeRTOS](https://freertos.org)** under the MIT license -- UI: **[LittleVGL/LVGL](https://lvgl.io/)** under the MIT license -- BLE stack: **[NimBLE](https://github.com/apache/mynewt-nimble)** under the Apache 2.0 license -- Font: **[Jetbrains Mono](https://www.jetbrains.com/fr-fr/lp/mono/)** under the Apache 2.0 license - -## Credits - -I’m not working alone on this project. First, many people create pull requests for this project. Then, there is the whole #pinetime community: a lot of people all around the world who are hacking, searching, experimenting and programming the Pinetime. We exchange our ideas, experiments and code in the chat rooms and forums. - -Here are some people I would like to highlight: - -- [Atc1441](https://github.com/atc1441/): He works on an Arduino based firmware for the Pinetime and many other smartwatches based on similar hardware. He was of great help when I was implementing support for the BMA421 motion sensor and I²C driver. -- [Koen](https://github.com/bosmoment): He’s working on a firmware based on RiotOS. He integrated similar libs as me: NimBLE, LittleVGL,… His help was invaluable too! -- [Lup Yuen Lee](https://github.com/lupyuen): He is everywhere: he works on a Rust firmware, builds a MCUBoot based bootloader for the Pinetime, designs a Flutter based companion app for smartphones and writes a lot of articles about the Pinetime! +## Lower priority +- [ ] Temp sensor w/ arduino +- [ ] Homeassistant control diff --git a/README_orig.md b/README_orig.md new file mode 100644 index 00000000..2d397818 --- /dev/null +++ b/README_orig.md @@ -0,0 +1,88 @@ +# [InfiniTime](https://github.com/InfiniTimeOrg/InfiniTime) + +![InfiniTime logo](doc/logo/infinitime-logo-small.jpg "InfiniTime Logo") + +Fast open-source firmware for the [PineTime smartwatch](https://www.pine64.org/pinetime/) with many features, written in modern C++. + +## New to InfiniTime? + +- [Getting started with InfiniTime](doc/gettingStarted/gettingStarted-1.0.md) +- [Updating the software](doc/gettingStarted/updating-software.md) +- [About the firmware and bootloader](doc/gettingStarted/about-software.md) +- [PineTimeStyle Watch face](https://wiki.pine64.org/wiki/PineTimeStyle) + - [Weather integration](https://wiki.pine64.org/wiki/Infinitime-Weather) + +### Companion apps + +- [Gadgetbridge](https://gadgetbridge.org/) (Android) +- [AmazFish](https://openrepos.net/content/piggz/amazfish/) (SailfishOS) +- [Siglo](https://github.com/alexr4535/siglo) (Linux) +- [InfiniLink](https://github.com/InfiniTimeOrg/InfiniLink) (iOS) **[Looking for a new maintainer]** +- [ITD](https://gitea.elara.ws/Elara6331/itd) (Linux) +- [WatchMate](https://github.com/azymohliad/watchmate) (Linux) + +***Note** : We removed mentions to NRFConnect as this app is closed source and recent versions do not work anymore with InfiniTime (the last version known to work is 4.24.3). If you used NRFConnect in the past, we recommend you switch to [Gadgetbridge](https://gadgetbridge.org/).* + +## Development + +- [InfiniTime Vision](doc/InfiniTimeVision.md) +- [Rough structure of the code](doc/code/Intro.md) +- [How to implement an application](doc/code/Apps.md) +- [Generate the fonts and symbols](src/displayapp/fonts/README.md) +- [Tips on designing an app UI](doc/ui_guidelines.md) +- [Bootloader, OTA and DFU](bootloader/README.md) +- [External resources](doc/ExternalResources.md) + +### Contributing + +- [How to contribute?](CONTRIBUTING.md) +- [Coding conventions](doc/coding-convention.md) + +### Build, flash and debug + +- [InfiniTime simulator](https://github.com/InfiniTimeOrg/InfiniSim) +- [Build the project](doc/buildAndProgram.md) +- [Build the project with Docker](doc/buildWithDocker.md) +- [Build the project with VSCode](doc/buildWithVScode.md) +- [Flash the firmware using OpenOCD and STLinkV2](doc/openOCD.md) +- [Flash the firmware using SWD interface](doc/SWD.md) +- [Flash the firmware using JLink](doc/jlink.md) +- [Flash the firmware using GDB](doc/gdb.md) +- [Stub using NRF52-DK](doc/PinetimeStubWithNrf52DK.md) + +### API + +- [BLE implementation and API](doc/ble.md) + +### Architecture and technical topics + +- [Memory analysis](doc/MemoryAnalysis.md) + +### Project management + +- [Maintainer's guide](doc/maintainer-guide.md) +- [Versioning](doc/versioning.md) +- [Project branches](doc/branches.md) +- [Files included in the release notes](doc/filesInReleaseNotes.md) +- [Files needed by the factory](doc/files-needed-by-factory.md) + +## Licenses + +This project is released under the GNU General Public License version 3 or, at your option, any later version. + +It integrates the following projects: + +- RTOS : **[FreeRTOS](https://freertos.org)** under the MIT license +- UI : **[LittleVGL/LVGL](https://lvgl.io/)** under the MIT license +- BLE stack : **[NimBLE](https://github.com/apache/mynewt-nimble)** under the Apache 2.0 license +- Font : **[Jetbrains Mono](https://www.jetbrains.com/fr-fr/lp/mono/)** under the Apache 2.0 license + +## Credits + +I’m not working alone on this project. First, many people create PR for this project. Then, there is the whole #pinetime community : a lot of people all around the world who are hacking, searching, experimenting and programming the Pinetime. We exchange our ideas, experiments and code in the chat rooms and forums. + +Here are some people I would like to highlight: + +- [Atc1441](https://github.com/atc1441/) : He works on an Arduino based firmware for the Pinetime and many other smartwatches based on similar hardware. He was of great help when I was implementing support for the BMA421 motion sensor and I²C driver. +- [Koen](https://github.com/bosmoment) : He’s working on a firmware based on RiotOS. He integrated similar libs as me : NimBLE, LittleVGL,… His help was invaluable too! +- [Lup Yuen Lee](https://github.com/lupyuen) : He is everywhere: he works on a Rust firmware, builds a MCUBoot based bootloader for the Pinetime, designs a Flutter based companion app for smartphones and writes a lot of articles about the Pinetime! diff --git a/doc/buildWithDocker.md b/doc/buildWithDocker.md index 670590a6..2907b3fa 100644 --- a/doc/buildWithDocker.md +++ b/doc/buildWithDocker.md @@ -33,7 +33,7 @@ For cloning the repo, see [these instructions](../doc/buildAndProgram.md#clone-t ```bash cd # e.g. cd ./work/Pinetime -docker run --rm -it -v ${PWD}:/sources --user $(id -u):$(id -g) infinitime-build +docker run --rm -it -v ${PWD}:/sources --user $(id -u):$(id -g) infinitime/infinitime-build ``` By default, the container runs as `root`, which is not convenient as all the files generated by the build will also belong to `root`. @@ -45,7 +45,7 @@ This means calling the script explicitly as it will override the `CMD`. Here's an example for `pinetime-app`: ```bash -docker run --rm -it -v ${PWD}:/sources --user $(id -u):$(id -g) infinitime-build /opt/build.sh pinetime-app +docker run --rm -it -v ${PWD}:/sources --user $(id -u):$(id -g) infinitime/infinitime-build /opt/build.sh pinetime-app ``` ## Using the image from Docker Hub diff --git a/enviroment_setup.md b/enviroment_setup.md new file mode 100755 index 00000000..1c06b908 --- /dev/null +++ b/enviroment_setup.md @@ -0,0 +1,94 @@ +## Clone repositories +1. Clone InfiniTime: +```bash +git clone https://github.com/InfiniTimeOrg/InfiniTime.git +cd InfiniTime +git submodule update --init +``` + +2. Clone InfiniSim: +```bash +cd .. #Ignore this line if you already cd'd into the diretory you want it cloned into +git clone --recursive https://github.com/InfiniTimeOrg/InfiniSim.git +``` + +## Install dependencies +### For building InfiniTime +1. Install Docker +2. Pull docker container (optional, container will be pulled when running the docker container if not pulled now). +```bash +sudo docker pull infinitime/infinitime-build +``` + +### For building InfiniSim +This was the most difficult part for me to get right since the steps on the github page are not entirely complete for my setup. If you encounter errors while building, it's probably because one of the dependencies are missing or have the wrong version installed. If you do have an error while building, check out the issues on github and see if you can find some help there: https://github.com/InfiniTimeOrg/InfiniSim/issues +1. The apt install part. This is almost exactly the same as what is on the github page except for npm. When I added npm in to here, I got an older version that didn't work. We'll install the correct version in step 2. +```bash +sudo apt install -y cmake libsdl2-dev g++ libpng-dev +``` + +2. Install the correct node version. (At least v14.0.0 is required). Commands from https://github.com/nodesource/distributions First, choose the node version by running one of these lines: +```bash +NODE_MAJOR=16 +NODE_MAJOR=18 +NODE_MAJOR=20 +``` +I'm not sure which is the best to use, I went with 16 since that is the closest to the version required by InfiniSim, but I doubt it makes much of a difference. Once you've done that, then install it with these commands: +```bash +sudo apt-get update +sudo apt-get install -y ca-certificates curl gnupg +sudo mkdir -p /etc/apt/keyrings +curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg + +NODE_MAJOR=20 +echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list + +sudo apt-get update +sudo apt-get install nodejs -y +``` + +3. Install npm packages +```bash +npm install lv_font_conv@1.5.2 -g +npm install ts-node@10.9.1 @swc/core@1.3.82 lv_img_conv@0.3.0 -g +``` + + +## Build InfiniSim +### Building with stock InfiniTime +Now to see if we did everything the way our computer wants it. First cd into the directory where InfinSim was cloned (`cd InfiniSim` if you are still in the directory you started in). Now you should be able to build InfiniSim with the InfiniTime version that was included with InfiniSim: +```bash +cmake -S . -B build +cmake --build build -j4 +``` + +If that didn't produce any error, now run it! +```bash +./build/infinisim +``` + +### Building with your own version of InfiniTime +To test your own modifications of InfiniTime: +```bash +cmake -S . -B build -DInfiniTime_DIR=../InfiniTime +cmake --build build -j4 +``` +Assuming that the git clone command was run in the same directory for both InfiniSim and InfiniTime. If not, replace `../InfiniTime` with the path to the directory where InfiniTime was cloned to. +And now run it if there were no errors! +```bash +./build/infinisim +``` + +## Build InfiniTime +Now is the fun part, building your own version of InfiniTime and flashing it to your watch! +First, cd into the directory into which InfiniTime cloned (`cd ~/InfiniTime` if you cloned from your home directory). Now run the docker container (for more info on this command, see https://github.com/InfiniTimeOrg/InfiniTime/blob/main/doc/buildWithDocker.md): +```bash +sudo docker run --rm -it -v ${PWD}:/sources --user $(id -u):$(id -g) infinitime/infinitime-build +``` + +If that doesn't have any errors, it will save the files to build/output/. The file you will want to flash to your watch is `pinetime-mcuboot-app-dfu-x.x.x.zip`. I found a pretty nice program called WatchMate that you can use to flash it from linux, but I think you can also use Gadgetbridge to flash the file. In WatchMate, just scroll down to the "Firmware Version" dropdown and click on "Upload from file" > +"Firmware" and select the zip file mentioned above. Once that's done, you may also want to send it the `infinitime-resources-x.x.x.zip` if some features are greyed out on the watch (for me it was a couple watch faces and the navigation app that were greyed out). In WatchMate, you'll want to use the "Resources" option instead of the "Firmware" option to upload this file. + +## Celebrate +There you go, you've just flashed your own custom os to your watch! If you got all this far without running into any error, you have something to celebrate about as it took me a couple of days to get to this point. If you did have some errors and figured them out, then great, you've got it all figured out now! +One final thing, I would recommend making use of git commits and branches so that you can revert if you totally mess something up and don't have to clone the entire repository and dependencies again like I had to do several times before I decided to start doing that. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8b27c19d..eee4197e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -383,6 +383,7 @@ list(APPEND SOURCE_FILES displayapp/screens/ApplicationList.cpp displayapp/screens/Notifications.cpp displayapp/screens/Twos.cpp + displayapp/screens/Calculator.cpp displayapp/screens/HeartRate.cpp displayapp/screens/FlashLight.cpp displayapp/screens/List.cpp @@ -415,6 +416,7 @@ list(APPEND SOURCE_FILES displayapp/screens/settings/SettingChimes.cpp displayapp/screens/settings/SettingShakeThreshold.cpp displayapp/screens/settings/SettingBluetooth.cpp + displayapp/screens/settings/SettingQuickR.cpp ## Watch faces displayapp/screens/WatchFaceAnalog.cpp @@ -423,6 +425,7 @@ list(APPEND SOURCE_FILES displayapp/screens/WatchFaceTerminal.cpp displayapp/screens/WatchFacePineTimeStyle.cpp displayapp/screens/WatchFaceCasioStyleG7710.cpp + displayapp/screens/WatchFaceFace.cpp ## diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index 4e392416..2bbd2a03 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -5,14 +5,58 @@ using namespace Pinetime::Controllers; +namespace { + TimerHandle_t vibTimer; + + void PatternStep(TimerHandle_t xTimer) { + /* Vibration pattern format: + * { + * durationOfVibration, + * durationOfPause, + * durationOfVibration, + * durationOfPause, + * ..., + * durationOfVibration, + * zeroTerminator + * } + * + * Patterns can be any length + * The pattern must end with a duration of vibration and a terminator. + */ + + static constexpr uint8_t vibrationPattern[] = {10, 100, 50, 200, 10, 0}; + + static size_t patternPosition = 0; + if (vibrationPattern[patternPosition] != 0 && xTimerChangePeriod(vibTimer, vibrationPattern[patternPosition] << 1, 0) == pdPASS && + xTimerStart(vibTimer, 0) == pdPASS) { + if (patternPosition % 2 == 0) { + nrf_gpio_pin_clear(Pinetime::PinMap::Motor); + } else { + nrf_gpio_pin_set(Pinetime::PinMap::Motor); + } + patternPosition++; + } else { + patternPosition = 0; + nrf_gpio_pin_set(Pinetime::PinMap::Motor); + auto* motorController = static_cast(pvTimerGetTimerID(xTimer)); + motorController->PatternFinished(); + } + } +} + void MotorController::Init() { nrf_gpio_cfg_output(PinMap::Motor); nrf_gpio_pin_set(PinMap::Motor); + vibTimer = xTimerCreate("vibration", 1, pdFALSE, this, PatternStep); shortVib = xTimerCreate("shortVib", 1, pdFALSE, nullptr, StopMotor); longVib = xTimerCreate("longVib", pdMS_TO_TICKS(1000), pdTRUE, this, Ring); } +void MotorController::PatternFinished() { + patternPlaying = false; +} + void MotorController::Ring(TimerHandle_t xTimer) { auto* motorController = static_cast(pvTimerGetTimerID(xTimer)); motorController->RunForDuration(50); @@ -24,6 +68,15 @@ void MotorController::RunForDuration(uint8_t motorDuration) { } } +bool MotorController::StartPattern() { + if (!patternPlaying) { + patternPlaying = true; + PatternStep(vibTimer); + return true; + } + return false; +} + void MotorController::StartRinging() { RunForDuration(50); xTimerStart(longVib, 0); diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index 6dea6d1f..2f6ca59b 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -15,10 +15,13 @@ namespace Pinetime { void RunForDuration(uint8_t motorDuration); void StartRinging(); void StopRinging(); + void PatternFinished(); + bool StartPattern(); private: static void Ring(TimerHandle_t xTimer); static void StopMotor(TimerHandle_t xTimer); + bool patternPlaying; TimerHandle_t shortVib; TimerHandle_t longVib; }; diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 06312077..0cd72ead 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -14,6 +14,7 @@ namespace Pinetime { enum class Notification : uint8_t { On, Off, Sleep }; enum class ChimesOption : uint8_t { None, Hours, HalfHours }; enum class WakeUpMode : uint8_t { SingleTap = 0, DoubleTap = 1, RaiseWrist = 2, Shake = 3, LowerWrist = 4 }; + enum class QuickApp : uint8_t { MusicPlayer = 0, Calculator = 1, Alarm = 2, Timer = 3, HeartRate = 4 }; //, Alarm = 5, Timer = 6, Stopwatch = 7 }; enum class Colors : uint8_t { White, Silver, @@ -253,6 +254,14 @@ namespace Pinetime { return getWakeUpModes()[static_cast(mode)]; } + + + + + + + + void SetBrightness(Controllers::BrightnessController::Levels level) { if (level != settings.brightLevel) { settingsChanged = true; @@ -283,6 +292,26 @@ namespace Pinetime { return bleRadioEnabled; }; + + + // New Settings + void SetQuickRModes(QuickApp App_now, bool enabled) { + if (enabled != isQuickROn(App_now)) { + settingsChanged = true; + } + settings.quickApp.set(static_cast(App_now), enabled); + }; + + std::bitset<5> getQuickRModes() const { + return settings.quickApp; + } + + bool isQuickROn(const QuickApp app_holder) const { + return getQuickRModes()[static_cast(app_holder)]; + } + + + private: Pinetime::Controllers::FS& fs; @@ -291,6 +320,7 @@ namespace Pinetime { struct SettingsData { uint32_t version = settingsVersion; uint32_t stepsGoal = 10000; + uint32_t setquickr = 10000; uint32_t screenTimeOut = 15000; ClockType clockType = ClockType::H24; @@ -305,6 +335,7 @@ namespace Pinetime { WatchFaceInfineat watchFaceInfineat; std::bitset<5> wakeUpMode {0}; + std::bitset<5> quickApp {0}; uint16_t shakeWakeThreshold = 150; Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium; diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h new file mode 100644 index 00000000..1e951938 --- /dev/null +++ b/src/displayapp/Apps.h @@ -0,0 +1,45 @@ +#pragma once + +namespace Pinetime { + namespace Applications { + enum class Apps { + None, + Launcher, + Clock, + SysInfo, + FirmwareUpdate, + FirmwareValidation, + NotificationsPreview, + Notifications, + Timer, + Alarm, + FlashLight, + BatteryInfo, + Music, + Paint, + Paddle, + Twos, + HeartRate, + Navigation, + StopWatch, + Metronome, + Motion, + Steps, + PassKey, + QuickSettings, + Settings, + SettingWatchFace, + SettingTimeFormat, + SettingDisplay, + SettingWakeUp, + SettingSteps, + SettingSetDateTime, + SettingChimes, + SettingShakeThreshold, + SettingBluetooth, + Error, + Calculator, + SettingQuickR + }; + } +} diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 938d1179..2e025207 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -28,6 +28,10 @@ #include "displayapp/screens/Steps.h" #include "displayapp/screens/PassKey.h" #include "displayapp/screens/Error.h" +#include "displayapp/screens/Weather.h" + +// My New Apps +#include "displayapp/screens/Calculator.h" #include "drivers/Cst816s.h" #include "drivers/St7789.h" @@ -47,6 +51,7 @@ #include "displayapp/screens/settings/SettingChimes.h" #include "displayapp/screens/settings/SettingShakeThreshold.h" #include "displayapp/screens/settings/SettingBluetooth.h" +#include "displayapp/screens/settings/SettingQuickR.h" #include "libs/lv_conf.h" #include "UserApps.h" @@ -307,17 +312,29 @@ void DisplayApp::Refresh() { return TouchEvents::SwipeLeft; } }; + if (!currentScreen->OnTouchEvent(gesture)) { - if (currentApp == Apps::Clock) { + if (currentApp == Apps::Clock || currentApp == Apps::QuickSettings || (currentApp == Apps::Music && quick_app[0]) || (currentApp == Apps::Calculator && quick_app[1]) || (currentApp == Apps::Alarm && quick_app[2]) || (currentApp == Apps::Timer && quick_app[3]) || (currentApp == Apps::HeartRate && quick_app[4])) { switch (gesture) { case TouchEvents::SwipeUp: - LoadNewScreen(Apps::Launcher, DisplayApp::FullRefreshDirections::Up); + if (currentApp == Apps::Clock) { + LoadNewScreen(Apps::Launcher, DisplayApp::FullRefreshDirections::Up); + } else if (currentApp == Apps::QuickSettings) { + LoadNewScreen(Apps::Settings, DisplayApp::FullRefreshDirections::Up); + } break; case TouchEvents::SwipeDown: - LoadNewScreen(Apps::Notifications, DisplayApp::FullRefreshDirections::Down); + if (currentApp == Apps::Clock) { + LoadNewScreen(Apps::Notifications, DisplayApp::FullRefreshDirections::Down); + } else if (currentApp == Apps::QuickSettings) { + LoadNewScreen(Apps::FlashLight, DisplayApp::FullRefreshDirections::Down); + } break; case TouchEvents::SwipeRight: - LoadNewScreen(Apps::QuickSettings, DisplayApp::FullRefreshDirections::RightAnim); + gotoquickapp(-1); + break; + case TouchEvents::SwipeLeft: + gotoquickapp(1); break; case TouchEvents::DoubleTap: PushMessageToSystemTask(System::Messages::GoToSleep); @@ -336,6 +353,7 @@ void DisplayApp::Refresh() { if (!currentScreen->OnButtonPushed()) { if (currentApp == Apps::Clock) { PushMessageToSystemTask(System::Messages::GoToSleep); + } else { LoadPreviousScreen(); } @@ -375,8 +393,19 @@ void DisplayApp::Refresh() { // What should happen here? break; case Messages::Chime: - LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::None); - motorController.RunForDuration(35); + + time_var = dateTimeController.Minutes(); + if (time_var == 30){ + //NRF_LOG_INFO("Short: %d", time_var); + motorController.StartPattern(); + } + else + { + //NRF_LOG_INFO("Long: %d", time_var); + motorController.RunForDuration(200); + } + //LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::None); + break; case Messages::OnChargingEvent: RestoreBrightness(); @@ -550,7 +579,42 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio currentScreen.reset(userWatchFaces[0].create(controllers)); } break; - } + case Apps::Twos: + currentScreen = std::make_unique(); + break; + case Apps::Paint: + currentScreen = std::make_unique(lvgl, motorController); + break; + case Apps::Paddle: + currentScreen = std::make_unique(lvgl); + break; + case Apps::Music: + currentScreen = std::make_unique(systemTask->nimble().music()); + break; + case Apps::Navigation: + currentScreen = std::make_unique(systemTask->nimble().navigation()); + break; + case Apps::HeartRate: + currentScreen = std::make_unique(heartRateController, *systemTask); + break; + case Apps::Metronome: + currentScreen = std::make_unique(motorController, *systemTask); + break; + /* Weather debug app + case Apps::Weather: + currentScreen = std::make_unique(this, systemTask->nimble().weather()); + break; + */ + case Apps::Steps: + currentScreen = std::make_unique(motionController, settingsController); + break; + // My Apps + case Apps::Calculator: + currentScreen = std::make_unique(); + break; + case Apps::SettingQuickR: + currentScreen = std::make_unique(settingsController); + break; } currentApp = app; } @@ -631,3 +695,84 @@ void DisplayApp::ApplyBrightness() { } brightnessController.Set(brightness); } + + void DisplayApp::gotoquickapp(int app_step){ + NRF_LOG_INFO("QuickRing Swiped"); + currentQ_app += app_step; + + quick_app = settingsController.getQuickRModes(); + + while(true) + { + if(currentQ_app > 7) + { + currentQ_app = 1; + } else if(currentQ_app < 1) + { + currentQ_app = 7; + } + + if(currentQ_app != 1 && currentQ_app != 2) + { + if(quick_app[currentQ_app-3]) + { + break; + } + else + { + currentQ_app += (app_step); + } + } + else + { + break; + } + } + + + int quickringtotal = 2; + for(int i = 0; i < 5; i++){ + quickringtotal += (quick_app[i] ? 1 : 0 ); + } + + + + NRF_LOG_INFO("case number current Q: %i", currentQ_app); + Apps app = Apps::Clock; + switch (currentQ_app) { + case 1: + app = Apps::QuickSettings; + break; + case 2: + app = Apps::Clock; + break; + case 3: + app = Apps::Music; + break; + case 4: + app = Apps::Calculator; + break; + case 5: + app = Apps::Alarm; + break; + case 6: + app = Apps::Timer; + break; + case 7: + app = Apps::HeartRate; + break; + default: + break; + } + + + if(app_step < 0){ + LoadNewScreen(app, DisplayApp::FullRefreshDirections::RightAnim); + } + else + { + LoadNewScreen(app, DisplayApp::FullRefreshDirections::LeftAnim); + } + //appStackDirections.Pop(); + //returnAppStack.Pop(); + } \ No newline at end of file diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index 96bce4dd..c510f451 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -124,6 +124,8 @@ namespace Pinetime { void LoadNewScreen(Apps app, DisplayApp::FullRefreshDirections direction); void LoadScreen(Apps app, DisplayApp::FullRefreshDirections direction); void PushMessageToSystemTask(Pinetime::System::Messages message); + void gotoquickapp(int app_step); + Apps nextApp = Apps::None; DisplayApp::FullRefreshDirections nextDirection; @@ -134,7 +136,10 @@ namespace Pinetime { Utility::StaticStack returnAppStack; Utility::StaticStack appStackDirections; + int time_var; bool isDimmed = false; + int currentQ_app = 2; + std::bitset<5> quick_app; }; } } diff --git a/src/displayapp/screens/Calculator.cpp b/src/displayapp/screens/Calculator.cpp new file mode 100644 index 00000000..2f77c5dd --- /dev/null +++ b/src/displayapp/screens/Calculator.cpp @@ -0,0 +1,442 @@ +#include +#include +#include +#include "Calculator.h" +#include "displayapp/InfiniTimeTheme.h" +#include "Symbols.h" + +using namespace Pinetime::Applications::Screens; + +static void eventHandler(lv_obj_t* obj, lv_event_t event) { + auto app = static_cast(obj->user_data); + app->OnButtonEvent(obj, event); +} + +Calculator::~Calculator() { + lv_obj_clean(lv_scr_act()); +} + +static const char* buttonMap[] = { + "7", "8", "9", "^", "\n", "4", "5", "6", "+ -", "\n", "1", "2", "3", "* /", "\n", "0", ".", "(-)", "=", ""}; + +Calculator::Calculator() { + resultLabel = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_long_mode(resultLabel, LV_LABEL_LONG_CROP); + lv_label_set_align(resultLabel, LV_LABEL_ALIGN_RIGHT); + lv_label_set_text_fmt(resultLabel, "%" PRId64, result); + lv_obj_set_size(resultLabel, 200, 20); + lv_obj_set_pos(resultLabel, -30, 5); + + valueLabel = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_long_mode(valueLabel, LV_LABEL_LONG_CROP); + lv_label_set_align(valueLabel, LV_LABEL_ALIGN_RIGHT); + lv_label_set_text_fmt(valueLabel, "%" PRId64, value); + lv_obj_set_size(valueLabel, 200, 20); + lv_obj_set_pos(valueLabel, -30, 35); + + buttonMatrix = lv_btnmatrix_create(lv_scr_act(), nullptr); + buttonMatrix->user_data = this; + lv_obj_set_event_cb(buttonMatrix, eventHandler); + lv_btnmatrix_set_map(buttonMatrix, buttonMap); + lv_btnmatrix_set_one_check(buttonMatrix, true); + lv_obj_set_size(buttonMatrix, 238, 180); + lv_obj_set_style_local_bg_color(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_DEFAULT, Colors::bgAlt); + lv_obj_set_style_local_pad_inner(buttonMatrix, LV_BTNMATRIX_PART_BG, LV_STATE_DEFAULT, 1); + lv_obj_set_style_local_pad_top(buttonMatrix, LV_BTNMATRIX_PART_BG, LV_STATE_DEFAULT, 1); + lv_obj_set_style_local_pad_bottom(buttonMatrix, LV_BTNMATRIX_PART_BG, LV_STATE_DEFAULT, 1); + lv_obj_set_style_local_pad_left(buttonMatrix, LV_BTNMATRIX_PART_BG, LV_STATE_DEFAULT, 1); + lv_obj_set_style_local_pad_right(buttonMatrix, LV_BTNMATRIX_PART_BG, LV_STATE_DEFAULT, 1); + lv_obj_align(buttonMatrix, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, 0); + + lv_obj_set_style_local_bg_opa(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, LV_OPA_COVER); + lv_obj_set_style_local_bg_grad_stop(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, 128); + lv_obj_set_style_local_bg_main_stop(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, 128); + + // BackSpace Button + + back = lv_btn_create(lv_scr_act(), nullptr); + back->user_data = this; + lv_obj_set_event_cb(back, eventHandler); + lv_obj_set_size(back, 59, 44); + lv_obj_align(back, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 179, 16); + txtback = lv_label_create(back, nullptr); + lv_obj_set_style_local_bg_color(back, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Colors::bgAlt); + lv_label_set_text_static(txtback, Symbols::backspace); +} + + + + + +void Calculator::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { + if ((obj == buttonMatrix) && (event == LV_EVENT_PRESSED)) { + HandleInput(); + } + + if (obj == back && event == LV_EVENT_PRESSED) { + if (value != 0) { + // delete one value digit + if (offset < FIXED_POINT_OFFSET) { + if (offset == 0) { + offset = 1; + } else { + offset *= 10; + } + } else { + value /= 10; + } + if (offset < FIXED_POINT_OFFSET) { + value -= value % (10 * offset); + } else { + value -= value % offset; + } + } else if (offset < FIXED_POINT_OFFSET) { + if (offset == 0) { + offset = 1; + } else { + offset *= 10; + } + } else { + // reset the result + result = 0; + } + operation = ' '; + UpdateOperation(); + UpdateValueLabel(); + UpdateResultLabel(); + } +} + +void Calculator::HandleInput() { + const char* buttonText = lv_btnmatrix_get_active_btn_text(buttonMatrix); + + + if (buttonText == nullptr) { + return; + } + + if ((equalSignPressed && (*buttonText != '=')) || (error != Error::None)) { + ResetInput(); + UpdateOperation(); + } + + // we only compare the first char because it is enough + switch (*buttonText) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': { + // *buttonText is the first char in buttonText + // "- '0'" results in the int value of the char + auto digit = (*buttonText) - '0'; + auto sign = (value < 0) ? -1 : 1; + + // if this is true, we already pressed the . button + if (offset < FIXED_POINT_OFFSET) { + value += sign * offset * digit; + offset /= 10; + } else if (value <= MAX_VALUE / 10) { + value *= 10; + value += sign * offset * digit; + } + + NRF_LOG_INFO(". offset: %" PRId64, offset); + NRF_LOG_INFO(". value: %" PRId64, value); + NRF_LOG_INFO(". result: %" PRId64, result); + } break; + + // unary minus + case '(': + value = -value; + + NRF_LOG_INFO(". offset: %" PRId64, offset); + NRF_LOG_INFO(". value: %" PRId64, value); + NRF_LOG_INFO(". result: %" PRId64, result); + + break; + + // Decimal + case '.': + if (offset == FIXED_POINT_OFFSET) { + offset /= 10; + } + + NRF_LOG_INFO(". offset: %" PRId64, offset); + NRF_LOG_INFO(". value: %" PRId64, value); + NRF_LOG_INFO(". result: %" PRId64, result); + break; + + // for every operator we: + // - eval the current operator if value > FIXED_POINT_OFFSET + // - then set the new operator + // - + and - as well as * and / cycle on the same button + case '^': + if (value != 0) { + Eval(); + ResetInput(); + } + switch (operation) { + case ' ': + operation = '^'; + break; + default: + operation = ' '; + break; + } + UpdateOperation(); + break; + + case '+': + if (value != 0) { + Eval(); + ResetInput(); + } + + switch (operation) { + case '+': + operation = '-'; + break; + case '-': + operation = ' '; + break; + default: + operation = '+'; + break; + } + UpdateOperation(); + break; + + case '*': + if (value != 0) { + Eval(); + ResetInput(); + } + + switch (operation) { + case '*': + operation = '/'; + break; + case '/': + operation = ' '; + break; + default: + operation = '*'; + break; + } + UpdateOperation(); + break; + + case '=': + equalSignPressed = true; + Eval(); + // If the operation is ' ' then we move the value to the result. + // We reset the input after this. + // This seems more convenient. + if (operation == ' ') { + ResetInput(); + } + + NRF_LOG_INFO(". offset: %" PRId64, offset); + NRF_LOG_INFO(". value: %" PRId64, value); + NRF_LOG_INFO(". result: %" PRId64, result); + + break; + } + NRF_LOG_INFO("Operation End: %c", operation); + UpdateValueLabel(); + UpdateResultLabel(); +} + +void Calculator::UpdateOperation() const { + switch (operation) { + case '+': + lv_obj_set_style_local_bg_grad_dir(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, LV_GRAD_DIR_HOR); + lv_obj_set_style_local_bg_color(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, Colors::deepOrange); + lv_obj_set_style_local_bg_grad_color(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, Colors::bgAlt); + lv_btnmatrix_set_btn_ctrl(buttonMatrix, 7, LV_BTNMATRIX_CTRL_CHECK_STATE); + break; + case '-': + lv_obj_set_style_local_bg_grad_dir(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, LV_GRAD_DIR_HOR); + lv_obj_set_style_local_bg_color(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, Colors::bgAlt); + lv_obj_set_style_local_bg_grad_color(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, Colors::deepOrange); + lv_btnmatrix_set_btn_ctrl(buttonMatrix, 7, LV_BTNMATRIX_CTRL_CHECK_STATE); + break; + case '*': + lv_obj_set_style_local_bg_grad_dir(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, LV_GRAD_DIR_HOR); + lv_obj_set_style_local_bg_color(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, Colors::deepOrange); + lv_obj_set_style_local_bg_grad_color(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, Colors::bgAlt); + lv_btnmatrix_set_btn_ctrl(buttonMatrix, 11, LV_BTNMATRIX_CTRL_CHECK_STATE); + break; + case '/': + lv_obj_set_style_local_bg_grad_dir(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, LV_GRAD_DIR_HOR); + lv_obj_set_style_local_bg_color(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, Colors::bgAlt); + lv_obj_set_style_local_bg_grad_color(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, Colors::deepOrange); + lv_btnmatrix_set_btn_ctrl(buttonMatrix, 11, LV_BTNMATRIX_CTRL_CHECK_STATE); + break; + case '^': + lv_obj_set_style_local_bg_grad_dir(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, LV_GRAD_DIR_HOR); + lv_obj_set_style_local_bg_color(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, Colors::deepOrange); + lv_obj_set_style_local_bg_grad_color(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, Colors::deepOrange); + lv_btnmatrix_set_btn_ctrl(buttonMatrix, 3, LV_BTNMATRIX_CTRL_CHECK_STATE); + break; + default: + lv_btnmatrix_clear_btn_ctrl_all(buttonMatrix, LV_BTNMATRIX_CTRL_CHECK_STATE); + break; + } +} + +void Calculator::ResetInput() { + value = 0; + offset = FIXED_POINT_OFFSET; + operation = ' '; + equalSignPressed = false; + error = Error::None; +} + +void Calculator::UpdateResultLabel() const { + int64_t integer = result / FIXED_POINT_OFFSET; + int64_t remainder = result % FIXED_POINT_OFFSET; + bool negative = (remainder < 0); + + if (remainder == 0) { + lv_label_set_text_fmt(resultLabel, "%" PRId64, integer); + return; + } + + if (remainder < 0) { + remainder = -remainder; + } + + uint8_t min_width = N_DECIMALS; + + // cut "0"-digits on the right + while ((remainder > 0) && (remainder % 10 == 0)) { + remainder /= 10; + min_width--; + } + + if ((integer == 0) && negative) { + lv_label_set_text_fmt(resultLabel, "-0.%0*" PRId64, min_width, remainder); + } else { + lv_label_set_text_fmt(resultLabel, "%" PRId64 ".%0*" PRId64, integer, min_width, remainder); + } +} + +void Calculator::UpdateValueLabel() { + switch (error) { + case Error::TooLarge: + lv_label_set_text_static(valueLabel, "too large"); + break; + case Error::ZeroDivision: + lv_label_set_text_static(valueLabel, "zero division"); + break; + case Error::None: + default: { + int64_t integer = value / FIXED_POINT_OFFSET; + int64_t remainder = value % FIXED_POINT_OFFSET; + bool negative = (remainder < 0); + + int64_t printRemainder = remainder < 0 ? -remainder : remainder; + + uint8_t min_width = 0; + int64_t tmp_offset = offset; + + // TODO there has to be a simpler way to do this + if (tmp_offset == 0) { + tmp_offset = 1; + min_width = 1; + } + while (tmp_offset < FIXED_POINT_OFFSET) { + tmp_offset *= 10; + min_width++; + } + min_width--; + + for (uint8_t i = min_width; i < N_DECIMALS; i++) { + printRemainder /= 10; + } + + if ((integer == 0) && negative) { + lv_label_set_text_fmt(valueLabel, "-0.%0*" PRId64, min_width, printRemainder); + } else if (offset == FIXED_POINT_OFFSET) { + lv_label_set_text_fmt(valueLabel, "%" PRId64, integer); + } else if ((offset == (FIXED_POINT_OFFSET / 10)) && (remainder == 0)) { + lv_label_set_text_fmt(valueLabel, "%" PRId64 ".", integer); + } else { + lv_label_set_text_fmt(valueLabel, "%" PRId64 ".%0*" PRId64, integer, min_width, printRemainder); + } + } break; + } +} + +// update the result based on value and operation +void Calculator::Eval() { + switch (operation) { + case ' ': + result = value; + break; + + case '+': + // check for overflow + if (((result > 0) && (value > (MAX_VALUE - result))) || ((result < 0) && (value < (MIN_VALUE - result)))) { + error = Error::TooLarge; + break; + } + + result += value; + break; + case '-': + // check for overflow + if (((result < 0) && (value > (MAX_VALUE + result))) || ((result > 0) && (value < (MIN_VALUE + result)))) { + error = Error::TooLarge; + break; + } + + result -= value; + break; + case '*': + // check for overflow + // while dividing we eliminate the fixed point offset + // therefore we have to multiply it again for the comparison with value + // we also assume here that MAX_VALUE == -MIN_VALUE + if ((result != 0) && (std::abs(value) > (FIXED_POINT_OFFSET * (MAX_VALUE / std::abs(result))))) { + error = Error::TooLarge; + break; + } + + result *= value; + // fixed point offset was multiplied too + result /= FIXED_POINT_OFFSET; + break; + case '/': + // check for zero division + if (value == 0) { + error = Error::ZeroDivision; + break; + } + + // fixed point offset will be divided too + result *= FIXED_POINT_OFFSET; + result /= value; + break; + case '^': + // check for zero division + if (value == 0) { + error = Error::ZeroDivision; + break; + } + place_holder = result; + place_holder /= FIXED_POINT_OFFSET; + result = pow(place_holder, (value*0.0001))*10000; + break; + + default: + break; + } +} diff --git a/src/displayapp/screens/Calculator.h b/src/displayapp/screens/Calculator.h new file mode 100644 index 00000000..4b03faf7 --- /dev/null +++ b/src/displayapp/screens/Calculator.h @@ -0,0 +1,71 @@ +#pragma once + +#include "Screen.h" + +namespace { + int64_t constexpr powi(int64_t base, uint8_t exponent) { + int64_t value = 1; + while (exponent) { + value *= base; + exponent--; + } + return value; + } +} + +namespace Pinetime { + namespace Applications { + namespace Screens { + class Calculator : public Screen { + public: + ~Calculator() override; + + Calculator(); + + void OnButtonEvent(lv_obj_t* obj, lv_event_t event); + + private: + lv_obj_t* buttonMatrix {}; + lv_obj_t* valueLabel {}; + lv_obj_t* resultLabel {}; + lv_obj_t* back; + lv_obj_t* txtback; + double place_holder; + + void Eval(); + void ResetInput(); + void HandleInput(); + void UpdateValueLabel(); + void UpdateResultLabel() const; + void UpdateOperation() const; + + // change this if you want to change the number of decimals + static constexpr uint8_t N_DECIMALS = 4; + // this is the constant default offset + static constexpr int64_t FIXED_POINT_OFFSET = powi(10, N_DECIMALS); + // this is the current offset, may wary after pressing '.' + int64_t offset = FIXED_POINT_OFFSET; + + // the screen can show 12 chars + // but two are needed for '.' and '-' + static constexpr uint8_t MAX_DIGITS = 15; + static constexpr int64_t MAX_VALUE = powi(10, MAX_DIGITS) - 1; + // this is assumed in the multiplication overflow! + static constexpr int64_t MIN_VALUE = -MAX_VALUE; + + int64_t value = 0; + int64_t result = 0; + char operation = ' '; + bool equalSignPressed = false; + + enum Error { + TooLarge, + ZeroDivision, + None, + }; + + Error error = Error::None; + }; + } + } +} diff --git a/src/displayapp/screens/FlashLight.cpp b/src/displayapp/screens/FlashLight.cpp index 1b7cf39c..f560fef7 100644 --- a/src/displayapp/screens/FlashLight.cpp +++ b/src/displayapp/screens/FlashLight.cpp @@ -2,6 +2,7 @@ #include "displayapp/DisplayApp.h" #include "displayapp/screens/Symbols.h" #include "displayapp/InfiniTimeTheme.h" +#include using namespace Pinetime::Applications::Screens; @@ -47,6 +48,8 @@ FlashLight::FlashLight(System::SystemTask& systemTask, Controllers::BrightnessCo lv_obj_set_event_cb(backgroundAction, EventHandler); systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping); + + Toggle(); } FlashLight::~FlashLight() { @@ -56,8 +59,17 @@ FlashLight::~FlashLight() { } void FlashLight::SetColors() { - lv_color_t bgColor = isOn ? LV_COLOR_WHITE : LV_COLOR_BLACK; - lv_color_t fgColor = isOn ? Colors::lightGray : LV_COLOR_WHITE; + lv_color_t bgColor = LV_COLOR_BLACK; + if(State_l == 0){ + bgColor = LV_COLOR_BLACK; + } else if (State_l == 1){ + bgColor = LV_COLOR_WHITE; + } + else { + bgColor = lv_color_hex(0xff0000); + } + + lv_color_t fgColor = State_l ? Colors::lightGray : LV_COLOR_WHITE; lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, bgColor); lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, fgColor); @@ -84,9 +96,11 @@ void FlashLight::SetIndicators() { } void FlashLight::Toggle() { - isOn = !isOn; + State_l++; + if(State_l > 2) + State_l = 0; SetColors(); - if (isOn) { + if (State_l) { brightnessController.Set(brightnessLevel); } else { brightnessController.Set(Controllers::BrightnessController::Levels::Low); @@ -97,7 +111,7 @@ bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) { using namespace Pinetime::Controllers; auto SetState = [this]() { - if (isOn) { + if (State_l) { brightnessController.Set(brightnessLevel); } SetIndicators(); @@ -125,4 +139,4 @@ bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) { } return false; -} +} \ No newline at end of file diff --git a/src/displayapp/screens/FlashLight.h b/src/displayapp/screens/FlashLight.h index 2b710ed5..4f5d4ac3 100644 --- a/src/displayapp/screens/FlashLight.h +++ b/src/displayapp/screens/FlashLight.h @@ -26,12 +26,13 @@ namespace Pinetime { Pinetime::System::SystemTask& systemTask; Controllers::BrightnessController& brightnessController; + Controllers::BrightnessController::Levels brightnessLevel = Controllers::BrightnessController::Levels::High; lv_obj_t* flashLight; lv_obj_t* backgroundAction; lv_obj_t* indicators[3]; - bool isOn = false; + int State_l = 0; }; } } diff --git a/src/displayapp/screens/Music.cpp b/src/displayapp/screens/Music.cpp index 0763da0f..806132c0 100644 --- a/src/displayapp/screens/Music.cpp +++ b/src/displayapp/screens/Music.cpp @@ -47,6 +47,8 @@ inline void lv_img_set_src_arr(lv_obj_t* img, const lv_img_dsc_t* src_img) { * * TODO: Investigate Apple Media Service and AVRCPv1.6 support for seamless integration */ + + Music::Music(Pinetime::Controllers::MusicService& music) : musicService(music) { lv_obj_t* label; @@ -250,6 +252,13 @@ void Music::OnObjectEvent(lv_obj_t* obj, lv_event_t event) { bool Music::OnTouchEvent(Pinetime::Applications::TouchEvents event) { switch (event) { + case TouchEvents::SwipeDown: { + 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; + } case TouchEvents::SwipeUp: { lv_obj_set_hidden(btnVolDown, false); lv_obj_set_hidden(btnVolUp, false); @@ -258,24 +267,6 @@ bool Music::OnTouchEvent(Pinetime::Applications::TouchEvents event) { 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 index 52253321..89037741 100644 --- a/src/displayapp/screens/Music.h +++ b/src/displayapp/screens/Music.h @@ -18,6 +18,7 @@ #pragma once #include +#include "displayapp/DisplayApp.h" #include #include #include "displayapp/screens/Screen.h" diff --git a/src/displayapp/screens/Symbols.h b/src/displayapp/screens/Symbols.h index 549ea04f..6dadcf13 100644 --- a/src/displayapp/screens/Symbols.h +++ b/src/displayapp/screens/Symbols.h @@ -37,6 +37,10 @@ namespace Pinetime { static constexpr const char* eye = "\xEF\x81\xAE"; static constexpr const char* home = "\xEF\x80\x95"; static constexpr const char* sleep = "\xEE\xBD\x84"; + static constexpr const char* calculator = "\xEF\x87\xAC"; + static constexpr const char* backspace = "\xEF\x95\x9A"; + + // fontawesome_weathericons.c // static constexpr const char* sun = "\xEF\x86\x85"; diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp index 72bfaaa3..565d0986 100644 --- a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp @@ -9,7 +9,6 @@ #include "components/battery/BatteryController.h" #include "components/ble/BleController.h" #include "components/ble/NotificationManager.h" -#include "components/heartrate/HeartRateController.h" #include "components/motion/MotionController.h" #include "components/settings/Settings.h" using namespace Pinetime::Applications::Screens; @@ -19,7 +18,6 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTi const Controllers::Ble& bleController, Controllers::NotificationManager& notificatioManager, Controllers::Settings& settingsController, - Controllers::HeartRateController& heartRateController, Controllers::MotionController& motionController, Controllers::FS& filesystem) : currentDateTime {{}}, @@ -29,7 +27,6 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTi bleController {bleController}, notificatioManager {notificatioManager}, settingsController {settingsController}, - heartRateController {heartRateController}, motionController {motionController} { lfs_file f = {}; @@ -148,25 +145,20 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTi lv_obj_set_pos(backgroundLabel, 0, 0); lv_label_set_text_static(backgroundLabel, ""); - heartbeatIcon = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(heartbeatIcon, Symbols::heartBeat); - lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); - lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 5, -2); - - heartbeatValue = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(heartbeatValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); - lv_label_set_text_static(heartbeatValue, ""); - lv_obj_align(heartbeatValue, heartbeatIcon, LV_ALIGN_OUT_RIGHT_MID, 5, 0); + stepIcon = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(stepIcon, Symbols::shoe); + lv_obj_set_style_local_text_color(stepIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); + lv_obj_align(stepIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 5, -2); stepValue = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); - lv_label_set_text_static(stepValue, "0"); - lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -5, -2); + lv_label_set_text_static(stepValue, ""); + lv_obj_align(stepValue, stepIcon, LV_ALIGN_OUT_RIGHT_MID, 5, 0); - stepIcon = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(stepIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); - lv_label_set_text_static(stepIcon, Symbols::shoe); - lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0); + label_seconds = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(label_seconds, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); + lv_label_set_text_static(label_seconds, "0"); + lv_obj_align(label_seconds, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -9, -2); taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); Refresh(); @@ -222,10 +214,11 @@ void WatchFaceCasioStyleG7710::Refresh() { lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(notificationState.Get())); } - currentDateTime = std::chrono::time_point_cast(dateTimeController.CurrentDateTime()); + currentDateTime = std::chrono::time_point_cast(dateTimeController.CurrentDateTime()); if (currentDateTime.IsUpdated()) { uint8_t hour = dateTimeController.Hours(); uint8_t minute = dateTimeController.Minutes(); + uint8_t second = dateTimeController.Seconds(); if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { char ampmChar[2] = "A"; @@ -244,6 +237,9 @@ void WatchFaceCasioStyleG7710::Refresh() { } lv_obj_realign(label_time); + lv_label_set_text_fmt(label_seconds, "%02d", second); + lv_obj_realign(label_seconds); + currentDate = std::chrono::time_point_cast(currentDateTime.Get()); if (currentDate.IsUpdated()) { const char* weekNumberFormat = "%V"; @@ -289,26 +285,11 @@ void WatchFaceCasioStyleG7710::Refresh() { } } - heartbeat = heartRateController.HeartRate(); - heartbeatRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped; - if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) { - if (heartbeatRunning.Get()) { - lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); - lv_label_set_text_fmt(heartbeatValue, "%d", heartbeat.Get()); - } else { - lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x1B1B1B)); - lv_label_set_text_static(heartbeatValue, ""); - } - - lv_obj_realign(heartbeatIcon); - lv_obj_realign(heartbeatValue); - } - stepCount = motionController.NbSteps(); if (stepCount.IsUpdated()) { lv_label_set_text_fmt(stepValue, "%lu", stepCount.Get()); lv_obj_realign(stepValue); - lv_obj_realign(stepIcon); + lv_obj_realign(stepValue); } } diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.h b/src/displayapp/screens/WatchFaceCasioStyleG7710.h index f10e931c..22b0f464 100644 --- a/src/displayapp/screens/WatchFaceCasioStyleG7710.h +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.h @@ -18,7 +18,6 @@ namespace Pinetime { class Battery; class Ble; class NotificationManager; - class HeartRateController; class MotionController; } @@ -32,7 +31,6 @@ namespace Pinetime { const Controllers::Ble& bleController, Controllers::NotificationManager& notificatioManager, Controllers::Settings& settingsController, - Controllers::HeartRateController& heartRateController, Controllers::MotionController& motionController, Controllers::FS& filesystem); ~WatchFaceCasioStyleG7710() override; @@ -46,10 +44,8 @@ namespace Pinetime { Utility::DirtyValue powerPresent {}; Utility::DirtyValue bleState {}; Utility::DirtyValue bleRadioEnabled {}; - Utility::DirtyValue> currentDateTime {}; + Utility::DirtyValue> currentDateTime {}; Utility::DirtyValue stepCount {}; - Utility::DirtyValue heartbeat {}; - Utility::DirtyValue heartbeatRunning {}; Utility::DirtyValue notificationState {}; using days = std::chrono::duration>; // TODO: days is standard in c++20 Utility::DirtyValue> currentDate; @@ -66,6 +62,7 @@ namespace Pinetime { lv_style_t style_border; lv_obj_t* label_time; + lv_obj_t* label_seconds; lv_obj_t* line_time; lv_obj_t* label_time_ampm; lv_obj_t* label_date; @@ -79,8 +76,6 @@ namespace Pinetime { lv_obj_t* bleIcon; lv_obj_t* batteryPlug; lv_obj_t* label_battery_value; - lv_obj_t* heartbeatIcon; - lv_obj_t* heartbeatValue; lv_obj_t* stepIcon; lv_obj_t* stepValue; lv_obj_t* notificationIcon; @@ -93,7 +88,6 @@ namespace Pinetime { const Controllers::Ble& bleController; Controllers::NotificationManager& notificatioManager; Controllers::Settings& settingsController; - Controllers::HeartRateController& heartRateController; Controllers::MotionController& motionController; lv_task_t* taskRefresh; diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index ca53691b..37b6f53a 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -34,7 +34,11 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController, lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_LIME); lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false)); lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); - + + label_seconds = lv_label_create(lv_scr_act(), nullptr); // for secs + lv_obj_align(label_seconds, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, -55); + lv_obj_set_style_local_text_color(label_seconds, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); + label_date = lv_label_create(lv_scr_act(), nullptr); lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60); lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); @@ -44,10 +48,6 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController, lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0); - label_time_ampm = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(label_time_ampm, ""); - lv_obj_align(label_time_ampm, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -30, -55); - heartbeatIcon = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_static(heartbeatIcon, Symbols::heartBeat); lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B)); @@ -85,29 +85,27 @@ void WatchFaceDigital::Refresh() { lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(notificationState.Get())); } - currentDateTime = std::chrono::time_point_cast(dateTimeController.CurrentDateTime()); + currentDateTime = std::chrono::time_point_cast(dateTimeController.CurrentDateTime()); if (currentDateTime.IsUpdated()) { uint8_t hour = dateTimeController.Hours(); uint8_t minute = dateTimeController.Minutes(); + uint8_t second = dateTimeController.Seconds(); if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { - char ampmChar[3] = "AM"; if (hour == 0) { hour = 12; - } else if (hour == 12) { - ampmChar[0] = 'P'; } else if (hour > 12) { hour = hour - 12; - ampmChar[0] = 'P'; } - lv_label_set_text(label_time_ampm, ampmChar); lv_label_set_text_fmt(label_time, "%2d:%02d", hour, minute); lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0); } else { lv_label_set_text_fmt(label_time, "%02d:%02d", hour, minute); lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); } + + lv_label_set_text_fmt(label_seconds, "%02d", second); // for secs currentDate = std::chrono::time_point_cast(currentDateTime.Get()); if (currentDate.IsUpdated()) { diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index a4664792..c8dc1cdf 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -45,7 +45,7 @@ namespace Pinetime { Utility::DirtyValue powerPresent {}; Utility::DirtyValue bleState {}; Utility::DirtyValue bleRadioEnabled {}; - Utility::DirtyValue> currentDateTime {}; + Utility::DirtyValue> currentDateTime {}; Utility::DirtyValue stepCount {}; Utility::DirtyValue heartbeat {}; Utility::DirtyValue heartbeatRunning {}; @@ -54,7 +54,8 @@ namespace Pinetime { Utility::DirtyValue> currentDate; lv_obj_t* label_time; - lv_obj_t* label_time_ampm; + lv_obj_t* label_seconds; //for secs + lv_obj_t* batteryValue; lv_obj_t* label_date; lv_obj_t* heartbeatIcon; lv_obj_t* heartbeatValue; diff --git a/src/displayapp/screens/WatchFaceFace.cpp b/src/displayapp/screens/WatchFaceFace.cpp new file mode 100644 index 00000000..502f7cb5 --- /dev/null +++ b/src/displayapp/screens/WatchFaceFace.cpp @@ -0,0 +1,274 @@ +#include "displayapp/screens/WatchFaceFace.h" +#include +#include +#include "displayapp/screens/BatteryIcon.h" +#include "displayapp/screens/BleIcon.h" +#include "displayapp/screens/Symbols.h" +#include "displayapp/screens/NotificationIcon.h" +#include "components/settings/Settings.h" +#include "displayapp/InfiniTimeTheme.h" + +using namespace Pinetime::Applications::Screens; + +namespace { + constexpr int16_t HourLength = 100; + constexpr int16_t MinuteLength = 90; + constexpr int16_t SecondLength = 110; + + // sin(90) = 1 so the value of _lv_trigo_sin(90) is the scaling factor + const auto LV_TRIG_SCALE = _lv_trigo_sin(90); + + int16_t Cosine(int16_t angle) { + return _lv_trigo_sin(angle + 90); + } + + int16_t Sine(int16_t angle) { + return _lv_trigo_sin(angle); + } + + int16_t CoordinateXRelocate(int16_t x) { + return (x + LV_HOR_RES / 2); + } + + int16_t CoordinateYRelocate(int16_t y) { + return std::abs(y - LV_HOR_RES / 2); + } + + lv_point_t CoordinateRelocate(int16_t radius, int16_t angle) { + return lv_point_t {.x = CoordinateXRelocate(radius * static_cast(Sine(angle)) / LV_TRIG_SCALE), + .y = CoordinateYRelocate(radius * static_cast(Cosine(angle)) / LV_TRIG_SCALE)}; + } + +} + +WatchFaceFace::WatchFaceFace(Controllers::DateTime& dateTimeController, + const Controllers::Battery& batteryController, + const Controllers::Ble& bleController, + Controllers::NotificationManager& notificationManager, + Controllers::Settings& settingsController) + : currentDateTime {{}}, + batteryIcon(true), + dateTimeController {dateTimeController}, + batteryController {batteryController}, + bleController {bleController}, + notificationManager {notificationManager}, + settingsController {settingsController} { + + sHour = 99; + sMinute = 99; + sSecond = 99; + + mouth = lv_arc_create(lv_scr_act(), nullptr); + lv_arc_set_angles(mouth, 30, 110); + lv_arc_set_bg_angles(mouth, 45, 135); + lv_obj_set_size(mouth, 130, 130); + lv_obj_align(mouth, nullptr, LV_ALIGN_CENTER, 0, 0); + + leye = lv_arc_create(lv_scr_act(), nullptr); + lv_arc_set_angles(leye, 0, 360); + lv_obj_set_size(leye, 30, 30); + lv_obj_align(leye, nullptr, LV_ALIGN_CENTER, -35, -35); + + reye = lv_arc_create(lv_scr_act(), nullptr); + lv_arc_set_angles(reye, 0, 360); + lv_obj_set_size(reye, 30, 30); + lv_obj_align(reye, nullptr, LV_ALIGN_CENTER, 35, -35); + + + minor_scales = lv_linemeter_create(lv_scr_act(), nullptr); + lv_linemeter_set_scale(minor_scales, 300, 51); + lv_linemeter_set_angle_offset(minor_scales, 180); + lv_obj_set_size(minor_scales, 240, 240); + lv_obj_align(minor_scales, nullptr, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_style_local_bg_opa(minor_scales, LV_LINEMETER_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); + lv_obj_set_style_local_scale_width(minor_scales, LV_LINEMETER_PART_MAIN, LV_STATE_DEFAULT, 4); + lv_obj_set_style_local_scale_end_line_width(minor_scales, LV_LINEMETER_PART_MAIN, LV_STATE_DEFAULT, 1); + lv_obj_set_style_local_scale_end_color(minor_scales, LV_LINEMETER_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); + + major_scales = lv_linemeter_create(lv_scr_act(), nullptr); + lv_linemeter_set_scale(major_scales, 300, 11); + lv_linemeter_set_angle_offset(major_scales, 180); + lv_obj_set_size(major_scales, 240, 240); + lv_obj_align(major_scales, nullptr, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_style_local_bg_opa(major_scales, LV_LINEMETER_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); + lv_obj_set_style_local_scale_width(major_scales, LV_LINEMETER_PART_MAIN, LV_STATE_DEFAULT, 6); + lv_obj_set_style_local_scale_end_line_width(major_scales, LV_LINEMETER_PART_MAIN, LV_STATE_DEFAULT, 4); + lv_obj_set_style_local_scale_end_color(major_scales, LV_LINEMETER_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + + large_scales = lv_linemeter_create(lv_scr_act(), nullptr); + lv_linemeter_set_scale(large_scales, 180, 3); + lv_linemeter_set_angle_offset(large_scales, 180); + lv_obj_set_size(large_scales, 240, 240); + lv_obj_align(large_scales, nullptr, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_style_local_bg_opa(large_scales, LV_LINEMETER_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); + lv_obj_set_style_local_scale_width(large_scales, LV_LINEMETER_PART_MAIN, LV_STATE_DEFAULT, 20); + lv_obj_set_style_local_scale_end_line_width(large_scales, LV_LINEMETER_PART_MAIN, LV_STATE_DEFAULT, 4); + lv_obj_set_style_local_scale_end_color(large_scales, LV_LINEMETER_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_AQUA); + + twelve = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_align(twelve, LV_LABEL_ALIGN_CENTER); + lv_label_set_text_static(twelve, "12"); + lv_obj_set_pos(twelve, 110, 10); + lv_obj_set_style_local_text_color(twelve, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_AQUA); + + batteryIcon.Create(lv_scr_act()); + lv_obj_align(batteryIcon.GetObject(), nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); + + plugIcon = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(plugIcon, Symbols::plug); + lv_obj_align(plugIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); + + bleIcon = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(bleIcon, ""); + lv_obj_align(bleIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, -30, 0); + + notificationIcon = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_LIME); + lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false)); + lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); + + // Date - Day / Week day + + label_date_day = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(label_date_day, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::orange); + lv_label_set_text_fmt(label_date_day, "%s\n%02i", dateTimeController.DayOfWeekShortToString(), dateTimeController.Day()); + lv_label_set_align(label_date_day, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label_date_day, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); + + minute_body = lv_line_create(lv_scr_act(), nullptr); + minute_body_trace = lv_line_create(lv_scr_act(), nullptr); + hour_body = lv_line_create(lv_scr_act(), nullptr); + hour_body_trace = lv_line_create(lv_scr_act(), nullptr); + second_body = lv_line_create(lv_scr_act(), nullptr); + + lv_style_init(&second_line_style); + lv_style_set_line_width(&second_line_style, LV_STATE_DEFAULT, 3); + lv_style_set_line_color(&second_line_style, LV_STATE_DEFAULT, LV_COLOR_RED); + lv_style_set_line_rounded(&second_line_style, LV_STATE_DEFAULT, true); + lv_obj_add_style(second_body, LV_LINE_PART_MAIN, &second_line_style); + + lv_style_init(&minute_line_style); + lv_style_set_line_width(&minute_line_style, LV_STATE_DEFAULT, 3); + lv_style_set_line_color(&minute_line_style, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_style_set_line_rounded(&minute_line_style, LV_STATE_DEFAULT, true); + lv_obj_add_style(minute_body, LV_LINE_PART_MAIN, &minute_line_style); + + lv_style_init(&minute_line_style_trace); + lv_style_set_line_width(&minute_line_style_trace, LV_STATE_DEFAULT, 3); + lv_style_set_line_color(&minute_line_style_trace, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_style_set_line_rounded(&minute_line_style_trace, LV_STATE_DEFAULT, false); + lv_obj_add_style(minute_body_trace, LV_LINE_PART_MAIN, &minute_line_style_trace); + + lv_style_init(&hour_line_style); + lv_style_set_line_width(&hour_line_style, LV_STATE_DEFAULT, 7); + lv_style_set_line_color(&hour_line_style, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_style_set_line_rounded(&hour_line_style, LV_STATE_DEFAULT, true); + lv_obj_add_style(hour_body, LV_LINE_PART_MAIN, &hour_line_style); + + lv_style_init(&hour_line_style_trace); + lv_style_set_line_width(&hour_line_style_trace, LV_STATE_DEFAULT, 3); + lv_style_set_line_color(&hour_line_style_trace, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_style_set_line_rounded(&hour_line_style_trace, LV_STATE_DEFAULT, false); + lv_obj_add_style(hour_body_trace, LV_LINE_PART_MAIN, &hour_line_style_trace); + + taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); + + Refresh(); +} + +WatchFaceFace::~WatchFaceFace() { + lv_task_del(taskRefresh); + + lv_style_reset(&hour_line_style); + lv_style_reset(&hour_line_style_trace); + lv_style_reset(&minute_line_style); + lv_style_reset(&minute_line_style_trace); + lv_style_reset(&second_line_style); + + lv_obj_clean(lv_scr_act()); +} + +void WatchFaceFace::UpdateClock() { + uint8_t hour = dateTimeController.Hours(); + uint8_t minute = dateTimeController.Minutes(); + uint8_t second = dateTimeController.Seconds(); + + if (sMinute != minute) { + auto const angle = minute * 6; + minute_point[0] = CoordinateRelocate(10, angle - 90); + minute_point[1] = CoordinateRelocate(MinuteLength, angle); + minute_point[2] = CoordinateRelocate(10, angle + 90); + + lv_line_set_points(minute_body, minute_point, 3); + } + + if (sHour != hour || sMinute != minute) { + sHour = hour; + sMinute = minute; + auto const angle = (hour * 30 + minute / 2); + + hour_point[0] = CoordinateRelocate(90, angle); + hour_point[1] = CoordinateRelocate(HourLength, angle); + + lv_line_set_points(hour_body, hour_point, 2); + } + + if (sSecond != second) { + sSecond = second; + auto const angle = second * 6; + + second_point[0] = CoordinateRelocate(105, angle); + second_point[1] = CoordinateRelocate(SecondLength, angle); + lv_line_set_points(second_body, second_point, 2); + }//TODO: redo seconds +} + +void WatchFaceFace::SetBatteryIcon() { + auto batteryPercent = batteryPercentRemaining.Get(); + batteryIcon.SetBatteryPercentage(batteryPercent); +} + +void WatchFaceFace::Refresh() { + isCharging = batteryController.IsCharging(); + if (isCharging.IsUpdated()) { + if (isCharging.Get()) { + lv_obj_set_hidden(batteryIcon.GetObject(), true); + lv_obj_set_hidden(plugIcon, false); + } else { + lv_obj_set_hidden(batteryIcon.GetObject(), false); + lv_obj_set_hidden(plugIcon, true); + SetBatteryIcon(); + } + } + if (!isCharging.Get()) { + batteryPercentRemaining = batteryController.PercentRemaining(); + if (batteryPercentRemaining.IsUpdated()) { + SetBatteryIcon(); + } + } + + bleState = bleController.IsConnected(); + if (bleState.IsUpdated()) { + if (bleState.Get()) { + lv_label_set_text_static(bleIcon, Symbols::bluetooth); + } else { + lv_label_set_text_static(bleIcon, ""); + } + } + + notificationState = notificationManager.AreNewNotificationsAvailable(); + + if (notificationState.IsUpdated()) { + lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(notificationState.Get())); + } + + currentDateTime = dateTimeController.CurrentDateTime(); + if (currentDateTime.IsUpdated()) { + UpdateClock(); + + currentDate = std::chrono::time_point_cast(currentDateTime.Get()); + if (currentDate.IsUpdated()) { + lv_label_set_text_fmt(label_date_day, "%s\n%02i", dateTimeController.DayOfWeekShortToString(), dateTimeController.Day()); + } + } +} diff --git a/src/displayapp/screens/WatchFaceFace.h b/src/displayapp/screens/WatchFaceFace.h new file mode 100644 index 00000000..448ef327 --- /dev/null +++ b/src/displayapp/screens/WatchFaceFace.h @@ -0,0 +1,95 @@ +#pragma once + +#include +#include +#include +#include +#include "displayapp/screens/Screen.h" +#include "components/datetime/DateTimeController.h" +#include "components/battery/BatteryController.h" +#include "components/ble/BleController.h" +#include "components/ble/NotificationManager.h" +#include "displayapp/screens/BatteryIcon.h" +#include "utility/DirtyValue.h" + +namespace Pinetime { + namespace Controllers { + class Settings; + class Battery; + class Ble; + class NotificationManager; + } + + namespace Applications { + namespace Screens { + + class WatchFaceFace : public Screen { + public: + WatchFaceFace(Controllers::DateTime& dateTimeController, + const Controllers::Battery& batteryController, + const Controllers::Ble& bleController, + Controllers::NotificationManager& notificationManager, + Controllers::Settings& settingsController); + + ~WatchFaceFace() override; + + void Refresh() override; + + private: + uint8_t sHour, sMinute, sSecond; + + Utility::DirtyValue batteryPercentRemaining {0}; + Utility::DirtyValue isCharging {}; + Utility::DirtyValue bleState {}; + Utility::DirtyValue> currentDateTime; + Utility::DirtyValue notificationState {false}; + using days = std::chrono::duration>; // TODO: days is standard in c++20 + Utility::DirtyValue> currentDate; + + lv_obj_t* minor_scales; + lv_obj_t* major_scales; + lv_obj_t* large_scales; + lv_obj_t* twelve; + + lv_obj_t* hour_body; + lv_obj_t* hour_body_trace; + lv_obj_t* minute_body; + lv_obj_t* minute_body_trace; + lv_obj_t* second_body; + + lv_point_t hour_point[2]; + lv_point_t minute_point[3]; + lv_point_t second_point[2]; + + lv_style_t hour_line_style; + lv_style_t hour_line_style_trace; + lv_style_t minute_line_style; + lv_style_t minute_line_style_trace; + lv_style_t second_line_style; + + lv_obj_t* label_date_day; + lv_obj_t* plugIcon; + lv_obj_t* notificationIcon; + lv_obj_t* bleIcon; + + lv_obj_t* mouth; + lv_obj_t* leye; + lv_obj_t* reye; + + + BatteryIcon batteryIcon; + + const Controllers::DateTime& dateTimeController; + const Controllers::Battery& batteryController; + const Controllers::Ble& bleController; + Controllers::NotificationManager& notificationManager; + Controllers::Settings& settingsController; + + void UpdateClock(); + void SetBatteryIcon(); + + lv_task_t* taskRefresh; + }; + } + } +} diff --git a/src/displayapp/screens/WatchFaceTerminal.cpp b/src/displayapp/screens/WatchFaceTerminal.cpp index 72383729..bd0a9f17 100644 --- a/src/displayapp/screens/WatchFaceTerminal.cpp +++ b/src/displayapp/screens/WatchFaceTerminal.cpp @@ -10,8 +10,11 @@ #include "components/motion/MotionController.h" #include "components/settings/Settings.h" + + using namespace Pinetime::Applications::Screens; + WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController, const Controllers::Battery& batteryController, const Controllers::Ble& bleController, @@ -43,12 +46,14 @@ WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController, lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -40); label_prompt_1 = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_recolor(label_prompt_1, true); lv_obj_align(label_prompt_1, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -80); - lv_label_set_text_static(label_prompt_1, "user@watch:~ $ now"); + lv_label_set_text_static(label_prompt_1, "user@watch:~ #00ff00 $# now"); label_prompt_2 = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_recolor(label_prompt_2, true); lv_obj_align(label_prompt_2, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 60); - lv_label_set_text_static(label_prompt_2, "user@watch:~ $"); + lv_label_set_text_static(label_prompt_2, "user@watch:~ #00ff00 $#"); label_time = lv_label_create(lv_scr_act(), nullptr); lv_label_set_recolor(label_time, true); @@ -143,6 +148,8 @@ void WatchFaceTerminal::Refresh() { lv_label_set_text_static(heartbeatValue, "[L_HR]#ee3311 ---#"); } } + + stepCount = motionController.NbSteps(); if (stepCount.IsUpdated()) { diff --git a/src/displayapp/screens/settings/SettingQuickR.cpp b/src/displayapp/screens/settings/SettingQuickR.cpp new file mode 100644 index 00000000..63bf13f9 --- /dev/null +++ b/src/displayapp/screens/settings/SettingQuickR.cpp @@ -0,0 +1,77 @@ +#include "displayapp/screens/settings/SettingQuickR.h" +#include +#include "displayapp/DisplayApp.h" +#include "displayapp/screens/Symbols.h" +#include "displayapp/InfiniTimeTheme.h" + +using namespace Pinetime::Applications::Screens; + +constexpr std::array SettingQuickR::options; + +namespace { + void event_handler(lv_obj_t* obj, lv_event_t event) { + auto* screen = static_cast(obj->user_data); + if (event == LV_EVENT_VALUE_CHANGED) { + screen->UpdateSelected(obj); + } + } +} + +SettingQuickR::SettingQuickR(Pinetime::Controllers::Settings& settingsController) : settingsController {settingsController} { + lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); + + lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); + lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); + lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); + lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); + + lv_obj_set_pos(container1, 10, 35); + lv_obj_set_width(container1, LV_HOR_RES - 20); + lv_obj_set_height(container1, LV_VER_RES - 20); + lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); + + lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(title, "Quick Ring"); + lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); + lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); + + lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); + lv_label_set_text_static(icon, Symbols::check); + lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); + lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); + + for (unsigned int i = 0; i < 5; i++) { + cbOption[i] = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text(cbOption[i], options[i].name); + if (settingsController.isQuickROn(static_cast(i))) { + lv_checkbox_set_checked(cbOption[i], true); + } + cbOption[i]->user_data = this; + lv_obj_set_event_cb(cbOption[i], event_handler); + } +} + +SettingQuickR::~SettingQuickR() { + lv_obj_clean(lv_scr_act()); + settingsController.SaveSettings(); +} + +void SettingQuickR::UpdateSelected(lv_obj_t* object) { + // Find the index of the checkbox that triggered the event + for (size_t i = 0; i < 5; i++) { + if (cbOption[i] == object) { + bool currentState = settingsController.isQuickROn(options[i].quickApp); + settingsController.SetQuickRModes(options[i].quickApp, !currentState); + break; + } + } + + // Update checkbox according to current wakeup modes. + // This is needed because we can have extra logic when setting or unsetting wakeup modes, + // for example, when setting SingleTap, DoubleTap is unset and vice versa. + auto modes = settingsController.getQuickRModes(); + for (size_t i = 0; i < 5; ++i) { + lv_checkbox_set_checked(cbOption[i], modes[i]); + } +} diff --git a/src/displayapp/screens/settings/SettingQuickR.h b/src/displayapp/screens/settings/SettingQuickR.h new file mode 100644 index 00000000..cf70d19e --- /dev/null +++ b/src/displayapp/screens/settings/SettingQuickR.h @@ -0,0 +1,39 @@ +#pragma once + +#include +#include +#include +#include "components/settings/Settings.h" +#include "displayapp/screens/Screen.h" + +namespace Pinetime { + + namespace Applications { + namespace Screens { + + class SettingQuickR : public Screen { + public: + SettingQuickR(Pinetime::Controllers::Settings& settingsController); + ~SettingQuickR() override; + void UpdateSelected(lv_obj_t* object); + + private: + struct Option { + Controllers::Settings::QuickApp quickApp; + const char* name; + }; + + static constexpr std::array options = {{ + {Controllers::Settings::QuickApp::MusicPlayer, "Music Player"}, + {Controllers::Settings::QuickApp::Calculator, "Calculator"}, + {Controllers::Settings::QuickApp::Alarm, "Alarms"}, + {Controllers::Settings::QuickApp::Timer, "Timer"}, + {Controllers::Settings::QuickApp::HeartRate, "Heart Rate"}, + }}; + + lv_obj_t* cbOption[5]; + Controllers::Settings& settingsController; + }; + } + } +} diff --git a/src/displayapp/screens/settings/SettingWatchFace.h b/src/displayapp/screens/settings/SettingWatchFace.h index 4c75b0ab..17046f04 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.h +++ b/src/displayapp/screens/settings/SettingWatchFace.h @@ -11,6 +11,7 @@ #include "displayapp/screens/CheckboxList.h" #include "displayapp/screens/WatchFaceInfineat.h" #include "displayapp/screens/WatchFaceCasioStyleG7710.h" +#include "displayapp/screens/WatchFaceFace.h" namespace Pinetime { diff --git a/src/displayapp/screens/settings/Settings.h b/src/displayapp/screens/settings/Settings.h index a21b4ccd..5c91117d 100644 --- a/src/displayapp/screens/settings/Settings.h +++ b/src/displayapp/screens/settings/Settings.h @@ -41,12 +41,15 @@ namespace Pinetime { {Symbols::clock, "Date&Time", Apps::SettingSetDateTime}, {Symbols::cloudSunRain, "Weather", Apps::SettingWeatherFormat}, {Symbols::batteryHalf, "Battery", Apps::BatteryInfo}, + {Symbols::check, "QuickRing", Apps::SettingQuickR}, + {Symbols::clock, "Chimes", Apps::SettingChimes}, {Symbols::tachometer, "Shake Calib.", Apps::SettingShakeThreshold}, {Symbols::check, "Firmware", Apps::FirmwareValidation}, {Symbols::bluetooth, "Bluetooth", Apps::SettingBluetooth}, + {Symbols::list, "About", Apps::SysInfo}, // {Symbols::none, "None", Apps::None},