Compare commits

..

39 commits

Author SHA1 Message Date
D. Scott Boggs cfd1ac4567 Add spell-check exception
Some checks failed
CI / build-firmware (push) Has been cancelled
CI / build-simulator (push) Has been cancelled
CI / get-base-ref-size (push) Has been cancelled
CI / Compare build size (push) Has been cancelled
2024-10-19 06:21:18 -04:00
D. Scott Boggs 6a9d13fe77 Bump version to 1.15.1
Some checks failed
CI / build-firmware (push) Has been cancelled
CI / build-simulator (push) Has been cancelled
CI / get-base-ref-size (push) Has been cancelled
CI / Compare build size (push) Has been cancelled
2024-09-15 12:00:38 -04:00
Davis Mosenkovs d689e5e874 Improve timer vibration
Some checks are pending
CI / build-firmware (push) Waiting to run
CI / build-simulator (push) Waiting to run
CI / get-base-ref-size (push) Waiting to run
CI / Compare build size (push) Blocked by required conditions
2024-09-15 11:57:35 -04:00
D. Scott Boggs 8abe9d428b Update flake for v1.15.0 2024-09-15 11:57:10 -04:00
D. Scott Boggs b7cf42156c bump version
Some checks are pending
CI / build-firmware (push) Waiting to run
CI / build-simulator (push) Waiting to run
CI / get-base-ref-size (push) Waiting to run
CI / Compare build size (push) Blocked by required conditions
2024-09-15 09:30:15 -04:00
D. Scott Boggs 7d8e58d863 Merge branch 'heartrate-measurements-in-background'
Some checks are pending
CI / build-firmware (push) Waiting to run
CI / build-simulator (push) Waiting to run
CI / get-base-ref-size (push) Waiting to run
CI / Compare build size (push) Blocked by required conditions
2024-09-15 09:07:20 -04:00
D. Scott Boggs fd15fd238d bump settings version 2024-09-15 08:43:08 -04:00
Dom Rodriguez a9a36793ad
feat: Introduce Flake for development and builds
Some checks are pending
CI / build-firmware (push) Waiting to run
CI / build-simulator (push) Waiting to run
CI / get-base-ref-size (push) Waiting to run
CI / Compare build size (push) Blocked by required conditions
This PR introduces a Nix flake, allowing for InfiniTime to be built as a
Flake, including a FHS development environment.

It's derived from #1850 and
c57c57f3c6.

We also introduce `flake-compat`, allowing for non-Flake Nix mahcines to
use the project as-is, both for building (`default.nix`), and
development (`shell.nix`).

Additionally, we introduce `.envrc`, meaning that with `direnv`, the Nix
Flake is activated automatically.

Fixes #1850.

Signed-off-by: Dom Rodriguez <shymega@shymega.org.uk>
2024-09-14 14:27:43 +01:00
Patric Gruber 7df39994ab integrate code review 2024-08-31 20:49:19 +02:00
Patric Gruber 9501d36060 use better state names 2024-08-31 00:54:05 +02:00
Patric Gruber b846547f2f remove unnecessary file 2024-08-31 00:42:51 +02:00
Patric Gruber 71b31c78fb use switch case 2024-08-31 00:40:58 +02:00
Patric Gruber 0978964b7d Merge branch 'heartrate-measurements-in-background' of github.com:patricgruber/InfiniTime into heartrate-measurements-in-background 2024-08-31 00:40:10 +02:00
Patric Gruber cedca795e2 use switch case 2024-08-31 00:39:13 +02:00
Patric Gruber 78af44eafe
keep measuring when transitioning to background
Co-authored-by: Simon Effenberg <savar@schuldeigen.de>
2024-07-17 20:18:31 +02:00
Patric Gruber e6f0a89202 reduce RAM size 2024-07-11 15:53:18 +02:00
Patric Gruber 616926345e refactor heartrate task (switch cases, comments with explanation) 2024-07-11 15:06:27 +02:00
Patric Gruber 6a0276f164 fix settings screen 2024-07-11 15:06:27 +02:00
Patric Gruber 7cf4f6e1ec fix bug where settings open pair pin screen 2024-07-11 15:06:27 +02:00
Patric Gruber ffc5f96d9a bump settings version 2024-07-11 15:06:27 +02:00
Patric Gruber 3b432cd310 fix issues after rebase on main 2024-07-11 15:06:27 +02:00
Patric Gruber d78f26201b fix DisplayApp.cpp 2024-07-11 15:06:27 +02:00
Patric Gruber 4ed4d2cfcd use pdMS_TO_TICKS correctly, format using clang-format 2024-07-11 15:06:27 +02:00
Patric Gruber 50d88bbe84 bump settings version, fix types 2024-07-11 15:06:27 +02:00
Patric Gruber 520e50901a fix rebase mistakes 2024-07-11 15:06:27 +02:00
Patric Gruber 04ed068ff9 add settings screen to choose heartrate measurement background 2024-07-11 15:06:27 +02:00
Patric Gruber 69578a679a properly format using clang-format 2024-07-11 15:06:27 +02:00
Patric Gruber eeaf5374d4 stop background after 30s of no data from the heart rate sensor 2024-07-11 15:06:22 +02:00
Patric Gruber f94c074064 rebase on main 2024-07-11 15:06:09 +02:00
Patric Gruber a2edd931ec add heart rate measurments in the background 2024-07-11 15:05:59 +02:00
Patric Gruber d376a856b7 use enum instead of uint32_t for heartrater interval setting 2024-07-11 15:05:59 +02:00
Patric Gruber be1a519098 use different style for the heartrate settings and fix issues with settings file 2024-07-11 15:05:59 +02:00
Patric Gruber 27ee1eb2c8 add settings screen to choose heartrate measurement background 2024-07-11 15:05:59 +02:00
Patric Gruber 5dbe1f77b5 properly format using clang-format 2024-07-11 15:05:59 +02:00
Patric Gruber 7ae790bcdb stop background after 30s of no data from the heart rate sensor 2024-07-11 15:05:50 +02:00
Patric Gruber a5db54af27 rebase on main 2024-07-11 15:05:37 +02:00
Patric Gruber 0370e3cd65 remove background start timestamp reset on sleep 2024-07-11 15:05:37 +02:00
Patric Gruber 58c507ee45 increase task delay when waiting in the background to 10s 2024-07-11 15:05:02 +02:00
Patric Gruber f7b1111e05 add heart rate measurments in the background 2024-07-11 15:05:02 +02:00
128 changed files with 1142 additions and 2203 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

8
.gitattributes vendored
View file

@ -1,9 +1,8 @@
# Set the default behavior, in case people don't have core.autocrlf set.
# Prevent build errors on non lf systems (like Windows), we need files with lf as newlines.
* text=auto eol=lf
* text=auto
# Explicitly declare text files you want to always be normalized and converted
# to lf line endings on checkout.
# to native line endings on checkout.
*.c text
*.cpp text
*.h text
@ -14,6 +13,3 @@
*.bin binary
*.jpg binary
*.jpeg binary
# Declare (Unix-style) files that will always have LF line endings on checkout.
*.sh text eol=lf

5
.gitconfig Normal file
View file

@ -0,0 +1,5 @@
[core]
whitespace = blank-at-eol,blank-at-eof,space-before-tab
autocrlf = input
[apply]
whitespace = fix

View file

@ -29,7 +29,7 @@ jobs:
run: tests/test-format.sh
- name: Upload patches
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v3
if: failure()
with:
name: Patches

View file

@ -22,8 +22,6 @@ jobs:
text_size: ${{ steps.output-sizes.outputs.text_size }}
data_size: ${{ steps.output-sizes.outputs.data_size }}
bss_size: ${{ steps.output-sizes.outputs.bss_size }}
firmware_artifact: ${{ steps.upload-firmware.outputs.artifact-id }}
resources_artifact: ${{ steps.upload-resources.outputs.artifact-id }}
env:
# InfiniTime sources are downloaded to the current directory.
# Override SOURCES_DIR in build.sh
@ -39,44 +37,34 @@ jobs:
apt-get -y install --no-install-recommends python3-pil
- name: Build
shell: bash
run: |
git config --global --add safe.directory /__w/InfiniTime/InfiniTime
/opt/build.sh all
run: /opt/build.sh all
- name: Output build size
id: output-sizes
shell: bash
run: |
. /opt/build.sh
.github/workflows/getSize.sh "$BUILD_DIR"/src/pinetime-app-*.out >> $GITHUB_OUTPUT
# Unzip the package because Upload Artifact will zip up the files
- name: Unzip DFU package
run: unzip ./build/output/pinetime-mcuboot-app-dfu-*.zip -d ./build/output/pinetime-mcuboot-app-dfu
- name: Set ref_name, but replace slashes with dashes.
shell: bash
env:
ref_name: ${{ github.head_ref || github.ref_name }}
run: echo "REF_NAME=${ref_name//\//-}" >> $GITHUB_ENV
- name: Upload DFU artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v3
with:
name: InfiniTime DFU ${{ env.REF_NAME }}
name: InfiniTime DFU ${{ github.head_ref }}
path: ./build/output/pinetime-mcuboot-app-dfu/*
- name: Upload MCUBoot image artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v3
with:
name: InfiniTime MCUBoot image ${{ env.REF_NAME }}
name: InfiniTime MCUBoot image ${{ github.head_ref }}
path: ./build/output/pinetime-mcuboot-app-image-*.bin
- name: Upload standalone ELF artifacts
uses: actions/upload-artifact@v4
id: upload-firmware
uses: actions/upload-artifact@v3
with:
name: InfiniTime image ${{ env.REF_NAME }}
name: InfiniTime image ${{ github.head_ref }}
path: ./build/output/src/pinetime-app-*.out
- name: Upload resources artifacts
uses: actions/upload-artifact@v4
id: upload-resources
uses: actions/upload-artifact@v3
with:
name: InfiniTime resources ${{ env.REF_NAME }}
name: InfiniTime resources ${{ github.head_ref }}
path: ./build/output/infinitime-resources-*.zip
build-simulator:
@ -115,9 +103,9 @@ jobs:
cmake --build build_lv_sim
- name: Upload simulator executable
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v3
with:
name: infinisim-${{ env.REF_NAME }}
name: infinisim-${{ github.head_ref }}
path: build_lv_sim/infinisim
get-base-ref-size:
@ -162,7 +150,6 @@ jobs:
- name: Output build size
id: output-sizes
shell: bash
run: |
. /opt/build.sh
.github/workflows/getSize.sh "$BUILD_DIR"/src/pinetime-app-*.out >> $GITHUB_OUTPUT
@ -213,12 +200,10 @@ jobs:
| text | ${{ needs.build-firmware.outputs.text_size }}B | ${{ steps.output-sizes-diff.outputs.text_diff }}B |
| data | ${{ needs.build-firmware.outputs.data_size }}B | ${{ steps.output-sizes-diff.outputs.data_diff }}B |
| bss | ${{ needs.build-firmware.outputs.bss_size }}B | ${{ steps.output-sizes-diff.outputs.bss_diff }}B |
[Run in InfiniEmu](https://infiniemu.pipe01.net/?firmware=artifact://${{ github.repository }}/${{ needs.build-firmware.outputs.firmware_artifact }}&resources=artifact://${{ github.repository }}/${{ needs.build-firmware.outputs.resources_artifact }})
EOF
- name: Upload comment
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v3
with:
name: comment
path: comment

5
.gitignore vendored
View file

@ -50,8 +50,3 @@ src/arm-none-eabi
# clangd
.cache/
# npm files
node_modules
package.json
package-lock.json

3
.gitmodules vendored
View file

@ -4,6 +4,9 @@
[submodule "src/libs/littlefs"]
path = src/libs/littlefs
url = https://github.com/littlefs-project/littlefs.git
[submodule "src/libs/QCBOR"]
path = src/libs/QCBOR
url = https://github.com/laurencelundblade/QCBOR.git
[submodule "src/libs/arduinoFFT"]
path = src/libs/arduinoFFT
url = https://github.com/kosme/arduinoFFT.git

View file

@ -66,5 +66,8 @@
"streambuf": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp"
}
},
"cSpell.words": [
"Pinetime"
]
}

View file

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose Debug or Release")
project(pinetime VERSION 1.15.0 LANGUAGES C CXX ASM)
project(pinetime VERSION 1.15.1 LANGUAGES C CXX ASM)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 20)

View file

@ -1,24 +1,8 @@
<div align="center">
# [InfiniTime](https://github.com/InfiniTimeOrg/InfiniTime)
![Header Image](doc/logo/watchface_collage.png)
![InfiniTime logo](doc/logo/infinitime-logo-small.jpg "InfiniTime Logo")
<br>
[![GitHub tag](https://img.shields.io/github/tag/InfiniTimeOrg/InfiniTime?include_prereleases=&sort=semver&color=blue)](https://github.com/InfiniTimeOrg/InfiniTime/releases)
[![GitHub License](https://img.shields.io/github/license/InfiniTimeOrg/InfiniTime)](https://github.com/InfiniTimeOrg/InfiniLink/blob/main/LICENSE)
[![Issues - InfiniTime](https://img.shields.io/github/issues/InfiniTimeOrg/InfiniTime)](https://github.com/InfiniTimeOrg/InfiniTime/issues)
[![Pull Requests - InfiniTime](https://img.shields.io/github/issues-pr/InfiniTimeOrg/InfiniTime)](https://github.com/InfiniTimeOrg/InfiniTime/pulls)
[![Downloads - InfiniTime](https://img.shields.io/github/downloads/InfiniTimeOrg/InfiniTime/total)](https://github.com/InfiniTimeOrg/InfiniTime)
[![Stars - InfiniTime](https://img.shields.io/github/stars/InfiniTimeOrg/InfiniTime?style=social)](https://github.com/InfiniTimeOrg/InfiniTime/stargazers)
[![Forks - InfiniTime](https://img.shields.io/github/forks/InfiniTimeOrg/InfiniTime?style=social)](https://github.com/InfiniTimeOrg/InfiniTime/network/members)
# InfiniTime
*Fast open-source firmware for the [PineTime smartwatch](https://pine64.org/devices/pinetime/) with many features, written in modern C++.*
<br>
</div>
Fast open-source firmware for the [PineTime smartwatch](https://pine64.org/devices/pinetime/) with many features, written in modern C++.
## New to InfiniTime?
@ -33,18 +17,13 @@
### Companion apps
- [Gadgetbridge](https://gadgetbridge.org/) (Android)
- [Amazfish](https://github.com/piggz/harbour-amazfish/) ([SailfishOS](https://sailfishos-chum.github.io/apps/harbour-amazfish/), [Ubuntu Touch](https://open-store.io/app/uk.co.piggz.amazfish), [Flatpak](https://flathub.org/apps/uk.co.piggz.amazfish))
- [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)
- [InfiniTimeExplorer](https://infinitimeexplorer.netlify.app) (Web)
<br>
> *InfiniTimeExplorer is only compatible with web browsers that support Web BLE. Current fully supported browsers include Chrome and Microsoft Edge.*
>
> *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/).*
***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

10
default.nix Normal file
View file

@ -0,0 +1,10 @@
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).defaultNix

View file

@ -5,7 +5,7 @@
To build this project, you'll need:
- A cross-compiler : [ARM-GCC (10.3-2021.10)](https://developer.arm.com/downloads/-/gnu-rm)
- The NRF52 SDK 15.3.0 : [nRF-SDK v15.3.0](https://nsscprodmedia.blob.core.windows.net/prod/software-and-other-downloads/sdks/nrf5/binaries/nrf5sdk153059ac345.zip)
- The NRF52 SDK 15.3.0 : [nRF-SDK v15.3.0](https://developer.nordicsemi.com/nRF5_SDK/nRF5_SDK_v15.x.x/nRF5_SDK_15.3.0_59ac345.zip)
- The Python 3 modules `cbor`, `intelhex`, `click` and `cryptography` modules for the `mcuboot` tool (see [requirements.txt](../tools/mcuboot/requirements.txt))
- To keep the system clean, you can install python modules into a python virtual environment (`venv`)
```sh
@ -66,7 +66,7 @@ DFU files are the files you'll need to install your build of InfiniTime using OT
#### CMake command
```
cmake -DARM_NONE_EABI_TOOLCHAIN_PATH=... -DNRF5_SDK_PATH=... -S ..
cmake -DARM_NONE_EABI_TOOLCHAIN_PATH=... -DNRF5_SDK_PATH=...
```
### Build the project

View file

@ -124,7 +124,7 @@ MyApp.h:
```cpp
#pragma once
#include "displayapp/apps/Apps.h"
#include "displayapp/Apps.h"
#include "displayapp/screens/Screen.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 846 KiB

View file

@ -33,7 +33,7 @@ RUN apt-get update -qq \
libpixman-1-dev \
libcairo2-dev \
libpango-1.0-0 \
libpango1.0-dev \
ibpango1.0-dev \
libpangocairo-1.0-0 \
&& rm -rf /var/cache/apt/* /var/lib/apt/lists/*;
@ -64,9 +64,6 @@ RUN bash -c "source /opt/build.sh; GetMcuBoot;"
# Add the infinitime user for connecting devcontainer
RUN adduser infinitime
# Configure Git to accept the /sources directory as safe
RUN git config --global --add safe.directory /sources
ENV SOURCES_DIR /sources
CMD ["/opt/build.sh"]

View file

@ -18,10 +18,6 @@ export npm_config_cache="${NPM_DIR}"
export BUILD_TYPE=${BUILD_TYPE:=Release}
export GCC_ARM_VER=${GCC_ARM_VER:="10.3-2021.10"}
export NRF_SDK_VER=${NRF_SDK_VER:="nRF5_SDK_15.3.0_59ac345"}
# convert to lower case and remove _ and . character
# the download URL uses the SLUG, but the extracted folder is named like the original value
NRF_SDK_VER_SLUG=${NRF_SDK_VER,,}
export NRF_SDK_VER_SLUG=${NRF_SDK_VER_SLUG//[_.]/}
MACHINE="$(uname -m)"
[ "$MACHINE" = "arm64" ] && MACHINE="aarch64"
@ -51,29 +47,17 @@ main() {
GetGcc() {
wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/$GCC_ARM_VER/$GCC_ARM_PATH-$MACHINE-linux.tar.bz2 -O - | tar -xj -C $TOOLS_DIR/
if [ ! -d "$TOOLS_DIR/$GCC_ARM_PATH" ]; then
echo "missing GCC path: $TOOLS_DIR/$GCC_ARM_PATH"
return 1
fi
}
GetMcuBoot() {
git clone https://github.com/mcu-tools/mcuboot.git "$TOOLS_DIR/mcuboot"
pip3 install -r "$TOOLS_DIR/mcuboot/scripts/requirements.txt"
if [ ! -d "$TOOLS_DIR/mcuboot" ]; then
echo "missing mcuboot path: $TOOLS_DIR/mcuboot"
return 1
fi
}
GetNrfSdk() {
wget -q "https://nsscprodmedia.blob.core.windows.net/prod/software-and-other-downloads/sdks/nrf5/binaries/$NRF_SDK_VER_SLUG.zip" -O /tmp/$NRF_SDK_VER
wget -q "https://developer.nordicsemi.com/nRF5_SDK/nRF5_SDK_v15.x.x/$NRF_SDK_VER.zip" -O /tmp/$NRF_SDK_VER
unzip -q /tmp/$NRF_SDK_VER -d "$TOOLS_DIR/"
rm /tmp/$NRF_SDK_VER
if [ ! -d "$TOOLS_DIR/$NRF_SDK_VER" ]; then
echo "missing NRF_SDK path: $TOOLS_DIR/$NRF_SDK_VER"
return 1
fi
}
CmakeGenerate() {

42
flake.lock Normal file
View file

@ -0,0 +1,42 @@
{
"nodes": {
"flake-compat": {
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"revCount": 57,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.0.1/018afb31-abd1-7bff-a5e4-cff7e18efb7a/source.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1725634671,
"narHash": "sha256-v3rIhsJBOMLR8e/RNWxr828tB+WywYIoajrZKFM+0Gg=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "574d1eac1c200690e27b8eb4e24887f8df7ac27c",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

114
flake.nix Normal file
View file

@ -0,0 +1,114 @@
{
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
};
outputs = { self, ... }@inputs:
let
forAllSystems = function:
inputs.nixpkgs.lib.genAttrs [
"x86_64-linux"
"aarch64-linux"
]
(system: function (import inputs.nixpkgs {
inherit system;
config.allowUnfree = true;
}));
in
{
packages = forAllSystems (pkgs:
let
infinitime-nrf5-sdk = pkgs.nrf5-sdk.overrideAttrs (old: {
version = "15.3.0";
src = pkgs.fetchzip {
url = "https://nsscprodmedia.blob.core.windows.net/prod/software-and-other-downloads/sdks/nrf5/binaries/nrf5sdk153059ac345.zip";
sha256 = "sha256-pfmhbpgVv5x2ju489XcivguwpnofHbgVA7bFUJRTj08=";
};
});
in
with pkgs; {
default = stdenv.mkDerivation rec {
name = "infinitime";
src = fetchFromGitea {
domain = "git.techwork.zone";
owner = "scott";
repo = "InfiniTime";
rev = "1.15.1";
hash = "sha256-9cy7qYRZrg7qZZwQzYeMIZivGLZ5uGUoTyPgHEvdnZ8=";
fetchSubmodules = true;
};
nativeBuildInputs = [
cmake
nodePackages.lv_font_conv
python3
python3.pkgs.cbor
python3.pkgs.click
python3.pkgs.cryptography
python3.pkgs.intelhex
python3.pkgs.pillow
adafruit-nrfutil
patch
git
];
postPatch = ''
# /usr/bin/env is not available in the build sandbox
substituteInPlace src/displayapp/fonts/generate.py --replace "'/usr/bin/env', 'patch'" "'patch'"
substituteInPlace tools/mcuboot/imgtool.py --replace "/usr/bin/env python3" "${python3}/bin/python3"
'';
cmakeFlags = [
''-DARM_NONE_EABI_TOOLCHAIN_PATH=${gcc-arm-embedded-10}''
''-DNRF5_SDK_PATH=${infinitime-nrf5-sdk}/share/nRF5_SDK''
''-DBUILD_DFU=1''
''-DBUILD_RESOURCES=1''
''-DCMAKE_SOURCE_DIR=${src}''
];
installPhase = ''
SOURCES_DIR=${src} BUILD_DIR=. OUTPUT_DIR=$out ./post_build.sh
'';
};
});
devShells = forAllSystems (pkgs:
let
infinitime-nrf5-sdk = pkgs.nrf5-sdk.overrideAttrs (old: {
version = "15.3.0";
src = pkgs.fetchzip {
url = "https://nsscprodmedia.blob.core.windows.net/prod/software-and-other-downloads/sdks/nrf5/binaries/nrf5sdk153059ac345.zip";
sha256 = "sha256-pfmhbpgVv5x2ju489XcivguwpnofHbgVA7bFUJRTj08=";
};
});
in
{
default =
pkgs.buildFHSUserEnv {
name = "infinitime-devenv";
# build tools
targetPkgs = pkgs: (with pkgs; [
cmake
nodePackages.lv_font_conv
python3
python3.pkgs.cbor
python3.pkgs.click
python3.pkgs.cryptography
python3.pkgs.intelhex
adafruit-nrfutil
(pkgs.writeShellScriptBin "cmake_infinitime" ''
cmake -DARM_NONE_EABI_TOOLCHAIN_PATH="${pkgs.gcc-arm-embedded-10}" \
-DNRF5_SDK_PATH="${infinitime-nrf5-sdk}/share/nRF5_SDK" \
"$@"
'')
]);
};
});
};
}

10
shell.nix Normal file
View file

@ -0,0 +1,10 @@
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).shellNix

View file

@ -380,7 +380,6 @@ list(APPEND SOURCE_FILES
displayapp/screens/Metronome.cpp
displayapp/screens/Motion.cpp
displayapp/screens/Weather.cpp
displayapp/screens/Calculator.cpp
displayapp/screens/FirmwareValidation.cpp
displayapp/screens/ApplicationList.cpp
displayapp/screens/Notifications.cpp
@ -412,6 +411,7 @@ list(APPEND SOURCE_FILES
displayapp/screens/settings/SettingWeatherFormat.cpp
displayapp/screens/settings/SettingWakeUp.cpp
displayapp/screens/settings/SettingDisplay.cpp
displayapp/screens/settings/SettingHeartRate.cpp
displayapp/screens/settings/SettingSteps.cpp
displayapp/screens/settings/SettingSetDateTime.cpp
displayapp/screens/settings/SettingSetDate.cpp
@ -419,7 +419,6 @@ list(APPEND SOURCE_FILES
displayapp/screens/settings/SettingChimes.cpp
displayapp/screens/settings/SettingShakeThreshold.cpp
displayapp/screens/settings/SettingBluetooth.cpp
displayapp/screens/settings/SettingOTA.cpp
## Watch faces
displayapp/screens/WatchFaceAnalog.cpp
@ -428,7 +427,6 @@ list(APPEND SOURCE_FILES
displayapp/screens/WatchFaceTerminal.cpp
displayapp/screens/WatchFacePineTimeStyle.cpp
displayapp/screens/WatchFaceCasioStyleG7710.cpp
displayapp/screens/WatchFacePrideFlag.cpp
##
@ -481,7 +479,6 @@ list(APPEND SOURCE_FILES
systemtask/SystemTask.cpp
systemtask/SystemMonitor.cpp
systemtask/WakeLock.cpp
drivers/TwiMaster.cpp
heartratetask/HeartRateTask.cpp
@ -546,7 +543,6 @@ list(APPEND RECOVERY_SOURCE_FILES
systemtask/SystemTask.cpp
systemtask/SystemMonitor.cpp
systemtask/WakeLock.cpp
drivers/TwiMaster.cpp
components/rle/RleDecoder.cpp
components/heartrate/HeartRateController.cpp
@ -665,7 +661,6 @@ set(INCLUDE_FILES
displayapp/InfiniTimeTheme.h
systemtask/SystemTask.h
systemtask/SystemMonitor.h
systemtask/WakeLock.h
displayapp/screens/Symbols.h
drivers/TwiMaster.h
heartratetask/HeartRateTask.h
@ -791,10 +786,6 @@ add_definitions(-DFREERTOS)
add_definitions(-D__STACK_SIZE=1024)
add_definitions(-D__HEAP_SIZE=0)
add_definitions(-DMYNEWT_VAL_BLE_LL_RFMGMT_ENABLE_TIME=1500)
add_definitions(-DLFS_CONFIG=libs/lfs_config.h)
# _sbrk is purposefully not implemented so that builds fail when it is used
add_link_options(-Wl,-wrap=malloc -Wl,-wrap=free -Wl,-wrap=calloc -Wl,-wrap=realloc -Wl,-wrap=_malloc_r -Wl,-wrap=_sbrk)
# Note: Only use this for debugging
# Derive the low frequency clock from the main clock (SYNT)

View file

@ -60,6 +60,15 @@ task.h is included from an application file. */
/* Assumes 8bit bytes! */
#define heapBITS_PER_BYTE ( ( size_t ) 8 )
/* Allocate the memory for the heap. */
#if( configAPPLICATION_ALLOCATED_HEAP == 1 )
/* The application writer has already defined the array used for the RTOS
heap - probably so it can be placed in a special segment or address. */
extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
#else
static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
#endif /* configAPPLICATION_ALLOCATED_HEAP */
/* Define the linked list structure. This is used to link free blocks in order
of their memory address. */
typedef struct A_BLOCK_LINK
@ -104,8 +113,6 @@ application. When the bit is free the block is still part of the free heap
space. */
static size_t xBlockAllocatedBit = 0;
static size_t xHeapSize = 0;
/*-----------------------------------------------------------*/
void *pvPortMalloc( size_t xWantedSize )
@ -325,38 +332,27 @@ size_t xPortGetMinimumEverFreeHeapSize( void )
}
/*-----------------------------------------------------------*/
size_t xPortGetHeapSize( void )
{
return xHeapSize;
}
/*-----------------------------------------------------------*/
void vPortInitialiseBlocks( void )
{
/* This just exists to keep the linker quiet. */
}
/*-----------------------------------------------------------*/
extern uint8_t *__HeapLimit; // Defined by nrf_common.ld
static void prvHeapInit( void )
{
BlockLink_t *pxFirstFreeBlock;
uint8_t *pucAlignedHeap;
size_t uxAddress;
size_t xTotalHeapSize = ( size_t ) &__StackLimit - ( size_t ) &__HeapLimit;
uint8_t *pucHeap = ( uint8_t * ) &__HeapLimit;
xHeapSize = xTotalHeapSize;
size_t xTotalHeapSize = configTOTAL_HEAP_SIZE;
/* Ensure the heap starts on a correctly aligned boundary. */
uxAddress = ( size_t ) pucHeap;
uxAddress = ( size_t ) ucHeap;
if( ( uxAddress & portBYTE_ALIGNMENT_MASK ) != 0 )
{
uxAddress += ( portBYTE_ALIGNMENT - 1 );
uxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK );
xTotalHeapSize -= uxAddress - ( size_t ) pucHeap;
xTotalHeapSize -= uxAddress - ( size_t ) ucHeap;
}
pucAlignedHeap = ( uint8_t * ) uxAddress;

View file

@ -180,7 +180,6 @@ __STATIC_INLINE uint32_t ulPortRaiseBASEPRI( void )
/*-----------------------------------------------------------*/
size_t xPortGetHeapSize(void);
#ifdef __cplusplus
}

View file

@ -62,6 +62,7 @@
#define configTICK_RATE_HZ 1024
#define configMAX_PRIORITIES (3)
#define configMINIMAL_STACK_SIZE (120)
#define configTOTAL_HEAP_SIZE (1024 * 40)
#define configMAX_TASK_NAME_LEN (4)
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
@ -73,7 +74,7 @@
#define configUSE_QUEUE_SETS 0
#define configUSE_TIME_SLICING 0
#define configUSE_NEWLIB_REENTRANT 0
#define configENABLE_BACKWARD_COMPATIBILITY 0
#define configENABLE_BACKWARD_COMPATIBILITY 1
#define configUSE_TASK_NOTIFICATIONS 0
/* Hook function related definitions. */

View file

@ -19,13 +19,11 @@
#include "systemtask/SystemTask.h"
#include "task.h"
#include <chrono>
#include <libraries/log/nrf_log.h>
using namespace Pinetime::Controllers;
using namespace std::chrono_literals;
AlarmController::AlarmController(Controllers::DateTime& dateTimeController, Controllers::FS& fs)
: dateTimeController {dateTimeController}, fs {fs} {
AlarmController::AlarmController(Controllers::DateTime& dateTimeController) : dateTimeController {dateTimeController} {
}
namespace {
@ -38,28 +36,11 @@ namespace {
void AlarmController::Init(System::SystemTask* systemTask) {
this->systemTask = systemTask;
alarmTimer = xTimerCreate("Alarm", 1, pdFALSE, this, SetOffAlarm);
LoadSettingsFromFile();
if (alarm.isEnabled) {
NRF_LOG_INFO("[AlarmController] Loaded alarm was enabled, scheduling");
ScheduleAlarm();
}
}
void AlarmController::SaveAlarm() {
// verify if it is necessary to save
if (alarmChanged) {
SaveSettingsToFile();
}
alarmChanged = false;
}
void AlarmController::SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin) {
if (alarm.hours == alarmHr && alarm.minutes == alarmMin) {
return;
}
alarm.hours = alarmHr;
alarm.minutes = alarmMin;
alarmChanged = true;
hours = alarmHr;
minutes = alarmMin;
}
void AlarmController::ScheduleAlarm() {
@ -72,19 +53,18 @@ void AlarmController::ScheduleAlarm() {
tm* tmAlarmTime = std::localtime(&ttAlarmTime);
// If the time being set has already passed today,the alarm should be set for tomorrow
if (alarm.hours < dateTimeController.Hours() ||
(alarm.hours == dateTimeController.Hours() && alarm.minutes <= dateTimeController.Minutes())) {
if (hours < dateTimeController.Hours() || (hours == dateTimeController.Hours() && minutes <= dateTimeController.Minutes())) {
tmAlarmTime->tm_mday += 1;
// tm_wday doesn't update automatically
tmAlarmTime->tm_wday = (tmAlarmTime->tm_wday + 1) % 7;
}
tmAlarmTime->tm_hour = alarm.hours;
tmAlarmTime->tm_min = alarm.minutes;
tmAlarmTime->tm_hour = hours;
tmAlarmTime->tm_min = minutes;
tmAlarmTime->tm_sec = 0;
// if alarm is in weekday-only mode, make sure it shifts to the next weekday
if (alarm.recurrence == RecurType::Weekdays) {
if (recurrence == RecurType::Weekdays) {
if (tmAlarmTime->tm_wday == 0) { // Sunday, shift 1 day
tmAlarmTime->tm_mday += 1;
} else if (tmAlarmTime->tm_wday == 6) { // Saturday, shift 2 days
@ -99,10 +79,7 @@ void AlarmController::ScheduleAlarm() {
xTimerChangePeriod(alarmTimer, secondsToAlarm * configTICK_RATE_HZ, 0);
xTimerStart(alarmTimer, 0);
if (!alarm.isEnabled) {
alarm.isEnabled = true;
alarmChanged = true;
}
state = AlarmState::Set;
}
uint32_t AlarmController::SecondsToAlarm() const {
@ -111,71 +88,20 @@ uint32_t AlarmController::SecondsToAlarm() const {
void AlarmController::DisableAlarm() {
xTimerStop(alarmTimer, 0);
if (alarm.isEnabled) {
alarm.isEnabled = false;
alarmChanged = true;
}
state = AlarmState::Not_Set;
}
void AlarmController::SetOffAlarmNow() {
isAlerting = true;
state = AlarmState::Alerting;
systemTask->PushMessage(System::Messages::SetOffAlarm);
}
void AlarmController::StopAlerting() {
isAlerting = false;
// Disable alarm unless it is recurring
if (alarm.recurrence == RecurType::None) {
alarm.isEnabled = false;
alarmChanged = true;
// Alarm state is off unless this is a recurring alarm
if (recurrence == RecurType::None) {
state = AlarmState::Not_Set;
} else {
// set next instance
ScheduleAlarm();
}
}
void AlarmController::SetRecurrence(RecurType recurrence) {
if (alarm.recurrence != recurrence) {
alarm.recurrence = recurrence;
alarmChanged = true;
}
}
void AlarmController::LoadSettingsFromFile() {
lfs_file_t alarmFile;
AlarmSettings alarmBuffer;
if (fs.FileOpen(&alarmFile, "/.system/alarm.dat", LFS_O_RDONLY) != LFS_ERR_OK) {
NRF_LOG_WARNING("[AlarmController] Failed to open alarm data file");
return;
}
fs.FileRead(&alarmFile, reinterpret_cast<uint8_t*>(&alarmBuffer), sizeof(alarmBuffer));
fs.FileClose(&alarmFile);
if (alarmBuffer.version != alarmFormatVersion) {
NRF_LOG_WARNING("[AlarmController] Loaded alarm settings has version %u instead of %u, discarding",
alarmBuffer.version,
alarmFormatVersion);
return;
}
alarm = alarmBuffer;
NRF_LOG_INFO("[AlarmController] Loaded alarm settings from file");
}
void AlarmController::SaveSettingsToFile() const {
lfs_dir systemDir;
if (fs.DirOpen("/.system", &systemDir) != LFS_ERR_OK) {
fs.DirCreate("/.system");
}
fs.DirClose(&systemDir);
lfs_file_t alarmFile;
if (fs.FileOpen(&alarmFile, "/.system/alarm.dat", LFS_O_WRONLY | LFS_O_CREAT) != LFS_ERR_OK) {
NRF_LOG_WARNING("[AlarmController] Failed to open alarm data file for saving");
return;
}
fs.FileWrite(&alarmFile, reinterpret_cast<const uint8_t*>(&alarm), sizeof(alarm));
fs.FileClose(&alarmFile);
NRF_LOG_INFO("[AlarmController] Saved alarm settings with format version %u to file", alarm.version);
}

View file

@ -30,65 +30,47 @@ namespace Pinetime {
namespace Controllers {
class AlarmController {
public:
AlarmController(Controllers::DateTime& dateTimeController, Controllers::FS& fs);
AlarmController(Controllers::DateTime& dateTimeController);
void Init(System::SystemTask* systemTask);
void SaveAlarm();
void SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin);
void ScheduleAlarm();
void DisableAlarm();
void SetOffAlarmNow();
uint32_t SecondsToAlarm() const;
void StopAlerting();
enum class AlarmState { Not_Set, Set, Alerting };
enum class RecurType { None, Daily, Weekdays };
uint8_t Hours() const {
return alarm.hours;
return hours;
}
uint8_t Minutes() const {
return alarm.minutes;
return minutes;
}
bool IsAlerting() const {
return isAlerting;
}
bool IsEnabled() const {
return alarm.isEnabled;
AlarmState State() const {
return state;
}
RecurType Recurrence() const {
return alarm.recurrence;
return recurrence;
}
void SetRecurrence(RecurType recurrence);
void SetRecurrence(RecurType recurType) {
recurrence = recurType;
}
private:
// Versions 255 is reserved for now, so the version field can be made
// bigger, should it ever be needed.
static constexpr uint8_t alarmFormatVersion = 1;
struct AlarmSettings {
uint8_t version = alarmFormatVersion;
uint8_t hours = 7;
uint8_t minutes = 0;
RecurType recurrence = RecurType::None;
bool isEnabled = false;
};
bool isAlerting = false;
bool alarmChanged = false;
Controllers::DateTime& dateTimeController;
Controllers::FS& fs;
System::SystemTask* systemTask = nullptr;
TimerHandle_t alarmTimer;
AlarmSettings alarm;
uint8_t hours = 7;
uint8_t minutes = 0;
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> alarmTime;
void LoadSettingsFromFile();
void SaveSettingsToFile() const;
AlarmState state = AlarmState::Not_Set;
RecurType recurrence = RecurType::None;
};
}
}

View file

@ -1,8 +1,6 @@
#include "components/ble/DfuService.h"
#include <cstring>
#include "components/ble/BleController.h"
#include "components/ble/NotificationManager.h"
#include "components/settings/Settings.h"
#include "drivers/SpiNorFlash.h"
#include "systemtask/SystemTask.h"
#include <nrf_log.h>
@ -80,18 +78,6 @@ void DfuService::Init() {
}
int DfuService::OnServiceData(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context) {
#ifndef PINETIME_IS_RECOVERY
if (systemTask.GetSettings().GetDfuAndFsMode() == Pinetime::Controllers::Settings::DfuAndFsMode::Disabled) {
Pinetime::Controllers::NotificationManager::Notification notif;
memcpy(notif.message.data(), denyAlert, denyAlertLength);
notif.size = denyAlertLength;
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
systemTask.GetNotificationManager().Push(std::move(notif));
systemTask.PushMessage(Pinetime::System::Messages::OnNewNotification);
return BLE_ATT_ERR_INSUFFICIENT_AUTHOR;
}
#endif
if (bleController.IsFirmwareUpdating()) {
xTimerStart(timeoutTimer, 0);
}
@ -138,11 +124,9 @@ int DfuService::WritePacketHandler(uint16_t connectionHandle, os_mbuf* om) {
bootloaderSize,
applicationSize);
// Wait until SystemTask has disabled sleeping
// This isn't quite correct, as we don't actually know
// if BleFirmwareUpdateStarted has been received yet
while (!systemTask.IsSleepDisabled()) {
vTaskDelay(pdMS_TO_TICKS(5));
// wait until SystemTask has finished waking up all devices
while (systemTask.IsSleeping()) {
vTaskDelay(50); // 50ms
}
dfuImage.Erase();

View file

@ -20,8 +20,6 @@ namespace Pinetime {
namespace Controllers {
class Ble;
class Settings;
class NotificationManager;
class DfuService {
public:
@ -89,9 +87,6 @@ namespace Pinetime {
DfuImage dfuImage;
NotificationManager notificationManager;
static constexpr const char denyAlert[] = "InfiniTime\0Firmware update attempted, but disabled in settings.";
static constexpr const uint8_t denyAlertLength = sizeof(denyAlert); // for this to work denyAlert MUST be array
static constexpr uint16_t dfuServiceId {0x1530};
static constexpr uint16_t packetCharacteristicId {0x1532};
static constexpr uint16_t controlPointCharacteristicId {0x1531};

View file

@ -1,8 +1,6 @@
#include <nrf_log.h>
#include "FSService.h"
#include "components/ble/BleController.h"
#include "components/ble/NotificationManager.h"
#include "components/settings/Settings.h"
#include "systemtask/SystemTask.h"
using namespace Pinetime::Controllers;
@ -51,18 +49,6 @@ void FSService::Init() {
}
int FSService::OnFSServiceRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context) {
#ifndef PINETIME_IS_RECOVERY
if (systemTask.GetSettings().GetDfuAndFsMode() == Pinetime::Controllers::Settings::DfuAndFsMode::Disabled) {
Pinetime::Controllers::NotificationManager::Notification notif;
memcpy(notif.message.data(), denyAlert, denyAlertLength);
notif.size = denyAlertLength;
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
systemTask.GetNotificationManager().Push(std::move(notif));
systemTask.PushMessage(Pinetime::System::Messages::OnNewNotification);
return BLE_ATT_ERR_INSUFFICIENT_AUTHOR;
}
#endif
if (attributeHandle == versionCharacteristicHandle) {
NRF_LOG_INFO("FS_S : handle = %d", versionCharacteristicHandle);
int res = os_mbuf_append(context->om, &fsVersion, sizeof(fsVersion));

View file

@ -14,8 +14,6 @@ namespace Pinetime {
namespace Controllers {
class Ble;
class Settings;
class NotificationManager;
class FSService {
public:
@ -28,10 +26,6 @@ namespace Pinetime {
private:
Pinetime::System::SystemTask& systemTask;
Pinetime::Controllers::FS& fs;
static constexpr const char denyAlert[] = "InfiniTime\0File access attempted, but disabled in settings.";
static constexpr const uint8_t denyAlertLength = sizeof(denyAlert); // for this to work denyAlert MUST be array
static constexpr uint16_t FSServiceId {0xFEBB};
static constexpr uint16_t fsVersionId {0x0100};
static constexpr uint16_t fsTransferId {0x0200};

View file

@ -18,8 +18,6 @@
#include "components/ble/MusicService.h"
#include "components/ble/NimbleController.h"
#include <cstring>
#include <FreeRTOS.h>
#include <task.h>
namespace {
// 0000yyxx-78fc-48fe-8e23-433b3a1942d0

View file

@ -25,7 +25,6 @@
#include <host/ble_uuid.h>
#undef max
#undef min
#include <FreeRTOS.h>
namespace Pinetime {
namespace Controllers {
@ -71,9 +70,9 @@ namespace Pinetime {
uint16_t eventHandle {};
std::string trackName;
std::string albumName;
std::string artistName {"Not Playing"};
std::string artistName {"Waiting for"};
std::string albumName {};
std::string trackName {"track information.."};
bool playing {false};

View file

@ -454,15 +454,9 @@ void NimbleController::PersistBond(struct ble_gap_conn_desc& desc) {
/* Wakeup Spi and SpiNorFlash before accessing the file system
* This should be fixed in the FS driver
*/
systemTask.PushMessage(Pinetime::System::Messages::GoToRunning);
systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping);
// This isn't quite correct
// SystemTask could receive EnableSleeping right after passing this check
// We need some guarantee that the SystemTask has processed the above message
// before we can continue
while (!systemTask.IsSleepDisabled()) {
vTaskDelay(pdMS_TO_TICKS(5));
}
vTaskDelay(10);
lfs_file_t file_p;

View file

@ -28,7 +28,7 @@ namespace Pinetime {
using Id = uint8_t;
using Idx = uint8_t;
std::array<char, MessageSize + 1> message{};
std::array<char, MessageSize + 1> message;
uint8_t size;
Categories category = Categories::Unknown;
Id id = 0;

View file

@ -42,9 +42,9 @@ namespace {
std::memcpy(cityName.data(), &dataBuffer[16], 32);
cityName[32] = '\0';
return SimpleWeatherService::CurrentWeather(ToUInt64(&dataBuffer[2]),
SimpleWeatherService::Temperature(ToInt16(&dataBuffer[10])),
SimpleWeatherService::Temperature(ToInt16(&dataBuffer[12])),
SimpleWeatherService::Temperature(ToInt16(&dataBuffer[14])),
ToInt16(&dataBuffer[10]),
ToInt16(&dataBuffer[12]),
ToInt16(&dataBuffer[14]),
SimpleWeatherService::Icons {dataBuffer[16 + 32]},
std::move(cityName));
}
@ -52,12 +52,12 @@ namespace {
SimpleWeatherService::Forecast CreateForecast(const uint8_t* dataBuffer) {
auto timestamp = static_cast<uint64_t>(ToUInt64(&dataBuffer[2]));
std::array<std::optional<SimpleWeatherService::Forecast::Day>, SimpleWeatherService::MaxNbForecastDays> days;
std::array<SimpleWeatherService::Forecast::Day, SimpleWeatherService::MaxNbForecastDays> days;
const uint8_t nbDaysInBuffer = dataBuffer[10];
const uint8_t nbDays = std::min(SimpleWeatherService::MaxNbForecastDays, nbDaysInBuffer);
for (int i = 0; i < nbDays; i++) {
days[i] = SimpleWeatherService::Forecast::Day {SimpleWeatherService::Temperature(ToInt16(&dataBuffer[11 + (i * 5)])),
SimpleWeatherService::Temperature(ToInt16(&dataBuffer[13 + (i * 5)])),
days[i] = SimpleWeatherService::Forecast::Day {ToInt16(&dataBuffer[11 + (i * 5)]),
ToInt16(&dataBuffer[13 + (i * 5)]),
SimpleWeatherService::Icons {dataBuffer[15 + (i * 5)]}};
}
return SimpleWeatherService::Forecast {timestamp, nbDays, days};
@ -98,9 +98,9 @@ int SimpleWeatherService::OnCommand(struct ble_gatt_access_ctxt* ctxt) {
currentWeather = CreateCurrentWeather(dataBuffer);
NRF_LOG_INFO("Current weather :\n\tTimestamp : %d\n\tTemperature:%d\n\tMin:%d\n\tMax:%d\n\tIcon:%d\n\tLocation:%s",
currentWeather->timestamp,
currentWeather->temperature.PreciseCelsius(),
currentWeather->minTemperature.PreciseCelsius(),
currentWeather->maxTemperature.PreciseCelsius(),
currentWeather->temperature,
currentWeather->minTemperature,
currentWeather->maxTemperature,
currentWeather->iconId,
currentWeather->location.data());
}
@ -112,9 +112,9 @@ int SimpleWeatherService::OnCommand(struct ble_gatt_access_ctxt* ctxt) {
for (int i = 0; i < 5; i++) {
NRF_LOG_INFO("\t[%d] Min: %d - Max : %d - Icon : %d",
i,
forecast->days[i]->minTemperature.PreciseCelsius(),
forecast->days[i]->maxTemperature.PreciseCelsius(),
forecast->days[i]->iconId);
forecast->days[i].minTemperature,
forecast->days[i].maxTemperature,
forecast->days[i].iconId);
}
}
break;

View file

@ -19,7 +19,7 @@
#include <cstdint>
#include <string>
#include <array>
#include <vector>
#include <memory>
#define min // workaround: nimble's min/max macros conflict with libstdc++
@ -61,42 +61,13 @@ namespace Pinetime {
Unknown = 255
};
class Temperature {
public:
explicit Temperature(int16_t raw) : raw {raw} {
}
[[nodiscard]] int16_t PreciseCelsius() const {
return raw;
}
[[nodiscard]] int16_t PreciseFahrenheit() const {
return raw * 9 / 5 + 3200;
}
[[nodiscard]] int16_t Celsius() const {
return (PreciseCelsius() + 50) / 100;
}
[[nodiscard]] int16_t Fahrenheit() const {
return (PreciseFahrenheit() + 50) / 100;
}
bool operator==(const Temperature& other) const {
return raw == other.raw;
}
private:
int16_t raw;
};
using Location = std::array<char, 33>; // 32 char + \0 (end of string)
struct CurrentWeather {
CurrentWeather(uint64_t timestamp,
Temperature temperature,
Temperature minTemperature,
Temperature maxTemperature,
int16_t temperature,
int16_t minTemperature,
int16_t maxTemperature,
Icons iconId,
Location&& location)
: timestamp {timestamp},
@ -108,9 +79,9 @@ namespace Pinetime {
}
uint64_t timestamp;
Temperature temperature;
Temperature minTemperature;
Temperature maxTemperature;
int16_t temperature;
int16_t minTemperature;
int16_t maxTemperature;
Icons iconId;
Location location;
@ -122,14 +93,14 @@ namespace Pinetime {
uint8_t nbDays;
struct Day {
Temperature minTemperature;
Temperature maxTemperature;
int16_t minTemperature;
int16_t maxTemperature;
Icons iconId;
bool operator==(const Day& other) const;
};
std::array<std::optional<Day>, MaxNbForecastDays> days;
std::array<Day, MaxNbForecastDays> days;
bool operator==(const Forecast& other) const;
};
@ -137,6 +108,10 @@ namespace Pinetime {
std::optional<CurrentWeather> Current() const;
std::optional<Forecast> GetForecast() const;
static int16_t CelsiusToFahrenheit(int16_t celsius) {
return celsius * 9 / 5 + 3200;
}
private:
// 00050000-78fc-48fe-8e23-433b3a1942d0
static constexpr ble_uuid128_t BaseUuid() {

View file

@ -7,31 +7,16 @@
using namespace Pinetime::Controllers;
namespace {
constexpr const char* const DaysStringShort[] = {"--", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
constexpr const char* const DaysStringShortLow[] = {"--", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
constexpr const char* const DaysString[] = {"--", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"};
constexpr const char* const DaysStringLow[] = {"--", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
constexpr const char* const MonthsString[] = {"--", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
constexpr const char* const MonthsStringLow[] =
{"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
constexpr int compileTimeAtoi(const char* str) {
int result = 0;
while (*str >= '0' && *str <= '9') {
result = result * 10 + *str - '0';
str++;
}
return result;
}
char const* DaysStringShort[] = {"--", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
char const* DaysStringShortLow[] = {"--", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
char const* MonthsString[] = {"--", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
char const* MonthsStringLow[] = {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
}
DateTime::DateTime(Controllers::Settings& settingsController) : settingsController {settingsController} {
mutex = xSemaphoreCreateMutex();
ASSERT(mutex != nullptr);
xSemaphoreGive(mutex);
// __DATE__ is a string of the format "MMM DD YYYY", so an offset of 7 gives the start of the year
SetTime(compileTimeAtoi(&__DATE__[7]), 1, 1, 0, 0, 0);
}
void DateTime::SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t) {
@ -61,9 +46,7 @@ void DateTime::SetTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour,
UpdateTime(previousSystickCounter, true);
xSemaphoreGive(mutex);
if (systemTask != nullptr) {
systemTask->PushMessage(System::Messages::OnNewTime);
}
systemTask->PushMessage(System::Messages::OnNewTime);
}
void DateTime::SetTimeZone(int8_t timezone, int8_t dst) {
@ -146,10 +129,6 @@ const char* DateTime::DayOfWeekShortToString() const {
return DaysStringShort[static_cast<uint8_t>(DayOfWeek())];
}
const char* DateTime::DayOfWeekToString() const {
return DaysString[static_cast<uint8_t>(DayOfWeek())];
}
const char* DateTime::MonthShortToStringLow(Months month) {
return MonthsStringLow[static_cast<uint8_t>(month)];
}
@ -158,10 +137,6 @@ const char* DateTime::DayOfWeekShortToStringLow(Days day) {
return DaysStringShortLow[static_cast<uint8_t>(day)];
}
const char* DateTime::DayOfWeekToStringLow(Days day) {
return DaysStringLow[static_cast<uint8_t>(day)];
}
void DateTime::Register(Pinetime::System::SystemTask* systemTask) {
this->systemTask = systemTask;
}

View file

@ -41,7 +41,7 @@ namespace Pinetime {
*
* used to update difference between utc and local time (see UtcOffset())
*
* parameters are in quarters of an hour. Following the BLE CTS specification,
* parameters are in quarters of an our. Following the BLE CTS specification,
* timezone is expected to be constant over DST which will be reported in
* dst field.
*/
@ -121,10 +121,8 @@ namespace Pinetime {
const char* MonthShortToString() const;
const char* DayOfWeekShortToString() const;
const char* DayOfWeekToString() const;
static const char* MonthShortToStringLow(Months month);
static const char* DayOfWeekShortToStringLow(Days day);
static const char* DayOfWeekToStringLow(Days day);
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> CurrentDateTime();

View file

@ -142,7 +142,7 @@ Ppg::Ppg() {
spectrum.fill(0.0f);
}
int8_t Ppg::Preprocess(uint16_t hrs, uint16_t als) {
int8_t Ppg::Preprocess(uint32_t hrs, uint32_t als) {
if (dataIndex < dataLength) {
dataHRS[dataIndex++] = hrs;
}

View file

@ -14,7 +14,7 @@ namespace Pinetime {
class Ppg {
public:
Ppg();
int8_t Preprocess(uint16_t hrs, uint16_t als);
int8_t Preprocess(uint32_t hrs, uint32_t als);
int HeartRate();
void Reset(bool resetDaqBuffer);
static constexpr int deltaTms = 100;

View file

@ -8,13 +8,11 @@ Settings::Settings(Pinetime::Controllers::FS& fs) : fs {fs} {
}
void Settings::Init() {
// Load default settings from Flash
LoadSettingsFromFile();
}
void Settings::SaveSettings() {
// verify if is necessary to save
if (settingsChanged) {
SaveSettingsToFile();

View file

@ -4,7 +4,6 @@
#include "components/brightness/BrightnessController.h"
#include "components/fs/FS.h"
#include "displayapp/apps/Apps.h"
#include <nrf_log.h>
namespace Pinetime {
namespace Controllers {
@ -37,8 +36,6 @@ namespace Pinetime {
};
enum class PTSGaugeStyle : uint8_t { Full, Half, Numeric };
enum class PTSWeather : uint8_t { On, Off };
enum class PrideFlag : uint8_t { Gay, Trans, Bi, Lesbian };
enum class DfuAndFsMode : uint8_t { Disabled, Enabled, EnabledTillReboot };
struct PineTimeStyle {
Colors ColorTime = Colors::Teal;
@ -53,6 +50,17 @@ namespace Pinetime {
int colorIndex = 0;
};
enum class HeartRateBackgroundMeasurementInterval : uint8_t {
Off,
Continuous,
TenSeconds,
ThirtySeconds,
OneMinute,
FiveMinutes,
TenMinutes,
ThirtyMinutes,
};
Settings(Pinetime::Controllers::FS& fs);
Settings(const Settings&) = delete;
@ -157,16 +165,6 @@ namespace Pinetime {
return settings.PTS.weatherEnable;
};
void SetPrideFlag(PrideFlag prideFlag) {
if (prideFlag != settings.prideFlag)
settingsChanged = true;
settings.prideFlag = prideFlag;
};
PrideFlag GetPrideFlag() const {
return settings.prideFlag;
};
void SetAppMenu(uint8_t menu) {
appMenu = menu;
};
@ -311,28 +309,16 @@ namespace Pinetime {
return bleRadioEnabled;
};
void SetDfuAndFsMode(DfuAndFsMode mode) {
if (mode == GetDfuAndFsMode()) {
return;
}
if (mode == DfuAndFsMode::Enabled || GetDfuAndFsMode() == DfuAndFsMode::Enabled) {
HeartRateBackgroundMeasurementInterval GetHeartRateBackgroundMeasurementInterval() const {
return settings.heartRateBackgroundMeasurementInterval;
}
void SetHeartRateBackgroundMeasurementInterval(HeartRateBackgroundMeasurementInterval newHeartRateBackgroundMeasurementInterval) {
if (newHeartRateBackgroundMeasurementInterval != settings.heartRateBackgroundMeasurementInterval) {
settingsChanged = true;
}
settings.dfuAndFsEnabledOnBoot = (mode == DfuAndFsMode::Enabled);
dfuAndFsEnabledTillReboot = (mode == DfuAndFsMode::EnabledTillReboot);
};
DfuAndFsMode GetDfuAndFsMode() {
if (dfuAndFsEnabledTillReboot) {
if (settings.dfuAndFsEnabledOnBoot) { // ensure both variables are in consistent state
settingsChanged = true;
settings.dfuAndFsEnabledOnBoot = false;
NRF_LOG_ERROR("Settings: DfuAndFsMode data corrupted");
}
return DfuAndFsMode::EnabledTillReboot;
}
return (settings.dfuAndFsEnabledOnBoot ? DfuAndFsMode::Enabled : DfuAndFsMode::Disabled);
};
settings.heartRateBackgroundMeasurementInterval = newHeartRateBackgroundMeasurementInterval;
}
private:
Pinetime::Controllers::FS& fs;
@ -355,8 +341,6 @@ namespace Pinetime {
PineTimeStyle PTS;
PrideFlag prideFlag = PrideFlag::Gay;
WatchFaceInfineat watchFaceInfineat;
std::bitset<5> wakeUpMode {0};
@ -364,7 +348,7 @@ namespace Pinetime {
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
bool dfuAndFsEnabledOnBoot = false;
HeartRateBackgroundMeasurementInterval heartRateBackgroundMeasurementInterval = HeartRateBackgroundMeasurementInterval::Off;
};
SettingsData settings;
@ -377,7 +361,6 @@ namespace Pinetime {
* to off (false) on every boot because we always want ble to be enabled on startup
*/
bool bleRadioEnabled = true;
bool dfuAndFsEnabledTillReboot = false;
void LoadSettingsFromFile();
void SaveSettingsToFile();

View file

@ -30,7 +30,6 @@
#include "displayapp/screens/Weather.h"
#include "displayapp/screens/PassKey.h"
#include "displayapp/screens/Error.h"
#include "displayapp/screens/Calculator.h"
#include "drivers/Cst816s.h"
#include "drivers/St7789.h"
@ -48,15 +47,13 @@
#include "displayapp/screens/settings/SettingSteps.h"
#include "displayapp/screens/settings/SettingSetDateTime.h"
#include "displayapp/screens/settings/SettingChimes.h"
#include "displayapp/screens/settings/SettingHeartRate.h"
#include "displayapp/screens/settings/SettingShakeThreshold.h"
#include "displayapp/screens/settings/SettingBluetooth.h"
#include "displayapp/screens/settings/SettingOTA.h"
#include "libs/lv_conf.h"
#include "UserApps.h"
#include <algorithm>
using namespace Pinetime::Applications;
using namespace Pinetime::Applications::Display;
@ -130,6 +127,15 @@ void DisplayApp::Start(System::BootErrors error) {
bootError = error;
lvgl.Init();
motorController.Init();
if (error == System::BootErrors::TouchController) {
LoadNewScreen(Apps::Error, DisplayApp::FullRefreshDirections::None);
} else {
LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::None);
}
if (pdPASS != xTaskCreate(DisplayApp::Process, "displayapp", 800, this, 0, &taskHandle)) {
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
}
@ -138,42 +144,26 @@ void DisplayApp::Start(System::BootErrors error) {
void DisplayApp::Process(void* instance) {
auto* app = static_cast<DisplayApp*>(instance);
NRF_LOG_INFO("displayapp task started!");
app->Init();
if (app->bootError == System::BootErrors::TouchController) {
app->LoadNewScreen(Apps::Error, DisplayApp::FullRefreshDirections::None);
} else {
app->LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::None);
}
app->InitHw();
while (true) {
app->Refresh();
}
}
void DisplayApp::Init() {
lcd.Init();
motorController.Init();
void DisplayApp::InitHw() {
brightnessController.Init();
ApplyBrightness();
lvgl.Init();
lcd.Init();
}
TickType_t DisplayApp::CalculateSleepTime() {
// Calculates how many system ticks DisplayApp should sleep before rendering the next AOD frame
// Next frame time is frame count * refresh period (ms) * tick rate
auto RoundedDiv = [](uint32_t a, uint32_t b) {
return ((a + (b / 2)) / b);
};
// RoundedDiv overflows when numerator + (denominator floordiv 2) > uint32 max
// in this case around 9 hours (=overflow frame count / always on refresh period)
constexpr TickType_t overflowFrameCount = (UINT32_MAX - (1000 / 16)) / ((configTICK_RATE_HZ / 8) * alwaysOnRefreshPeriod);
TickType_t ticksElapsed = xTaskGetTickCount() - alwaysOnStartTime;
// Divide both the numerator and denominator by 8 (=GCD(1000,1024))
// to increase the number of ticks (frames) before the overflow tick is reached
TickType_t targetRenderTick = RoundedDiv((configTICK_RATE_HZ / 8) * alwaysOnFrameCount * alwaysOnRefreshPeriod, 1000 / 8);
// Divide both the numerator and denominator by 8 to increase the number of ticks (frames) before the overflow tick is reached
TickType_t elapsedTarget = ROUNDED_DIV((configTICK_RATE_HZ / 8) * alwaysOnTickCount * alwaysOnRefreshPeriod, 1000 / 8);
// ROUNDED_DIV overflows when numerator + (denominator floordiv 2) > uint32 max
// in this case around 9 hours
constexpr TickType_t overflowTick = (UINT32_MAX - (1000 / 16)) / ((configTICK_RATE_HZ / 8) * alwaysOnRefreshPeriod);
// Assumptions
@ -181,17 +171,17 @@ TickType_t DisplayApp::CalculateSleepTime() {
// Needed for division trick above
static_assert(configTICK_RATE_HZ % 8 == 0);
// Frame count must always wraparound more often than the system tick count does
// Local tick count must always wraparound before the system tick count does
// As a static assert we can use 64 bit ints and therefore dodge overflows
// Always on overflow time (ms) < system tick overflow time (ms)
// Using 64bit ints here to avoid overflow
static_assert((uint64_t) overflowFrameCount * (uint64_t) alwaysOnRefreshPeriod < (uint64_t) UINT32_MAX * 1000ULL / configTICK_RATE_HZ);
static_assert((uint64_t) overflowTick * (uint64_t) alwaysOnRefreshPeriod < (uint64_t) UINT32_MAX * 1000ULL / configTICK_RATE_HZ);
if (alwaysOnFrameCount == overflowFrameCount) {
alwaysOnFrameCount = 0;
if (alwaysOnTickCount == overflowTick) {
alwaysOnTickCount = 0;
alwaysOnStartTime = xTaskGetTickCount();
}
if (targetRenderTick > ticksElapsed) {
return targetRenderTick - ticksElapsed;
if (elapsedTarget > ticksElapsed) {
return elapsedTarget - ticksElapsed;
} else {
return 0;
}
@ -231,27 +221,28 @@ void DisplayApp::Refresh() {
TickType_t queueTimeout;
switch (state) {
case States::Idle:
queueTimeout = portMAX_DELAY;
break;
case States::AOD:
if (!currentScreen->IsRunning()) {
LoadPreviousScreen();
}
// Check we've slept long enough
// Might not be true if the loop received an event
// If not true, then wait that amount of time
queueTimeout = CalculateSleepTime();
if (queueTimeout == 0) {
// Only advance the tick count when LVGL is done
// Otherwise keep running the task handler while it still has things to draw
// Note: under high graphics load, LVGL will always have more work to do
if (lv_task_handler() > 0) {
// Drop frames that we've missed if drawing/event handling took way longer than expected
while (queueTimeout == 0) {
alwaysOnFrameCount += 1;
queueTimeout = CalculateSleepTime();
}
if (settingsController.GetAlwaysOnDisplay()) {
if (!currentScreen->IsRunning()) {
LoadPreviousScreen();
}
// Check we've slept long enough
// Might not be true if the loop received an event
// If not true, then wait that amount of time
queueTimeout = CalculateSleepTime();
if (queueTimeout == 0) {
// Only advance the tick count when LVGL is done
// Otherwise keep running the task handler while it still has things to draw
// Note: under high graphics load, LVGL will always have more work to do
if (lv_task_handler() > 0) {
// Drop frames that we've missed if drawing/event handling took way longer than expected
while (queueTimeout == 0) {
alwaysOnTickCount += 1;
queueTimeout = CalculateSleepTime();
}
};
}
} else {
queueTimeout = portMAX_DELAY;
}
break;
case States::Running:
@ -265,20 +256,9 @@ void DisplayApp::Refresh() {
isDimmed = true;
brightnessController.Set(Controllers::BrightnessController::Levels::Low);
}
if (IsPastSleepTime() && uxQueueMessagesWaiting(msgQueue) == 0) {
PushMessageToSystemTask(System::Messages::GoToSleep);
// Can't set state to Idle here, something may send
// DisableSleeping before this GoToSleep arrives
// Instead we check we have no messages queued before sending GoToSleep
// This works as the SystemTask is higher priority than DisplayApp
// As soon as we send GoToSleep, SystemTask pre-empts DisplayApp
// Whenever DisplayApp is running again, it is guaranteed that
// SystemTask has handled the message
// If it responded, we will have a GoToSleep waiting in the queue
// By checking that there are no messages in the queue, we avoid
// resending GoToSleep when we already have a response
// SystemTask is resilient to duplicate messages, this is an
// optimisation to reduce pressure on the message queues
if (IsPastSleepTime()) {
systemTask->PushMessage(System::Messages::GoToSleep);
state = States::Idle;
}
} else if (isDimmed) {
isDimmed = false;
@ -294,22 +274,12 @@ void DisplayApp::Refresh() {
if (xQueueReceive(msgQueue, &msg, queueTimeout) == pdTRUE) {
switch (msg) {
case Messages::GoToSleep:
case Messages::GoToAOD:
// Checking if SystemTask is sleeping is purely an optimisation.
// If it's no longer sleeping since it sent GoToSleep, it has
// cancelled the sleep and transitioned directly from
// GoingToSleep->Running, so we are about to receive GoToRunning
// and can ignore this message. If it wasn't ignored, DisplayApp
// would go to sleep and then immediately re-wake
if (state != States::Running || !systemTask->IsSleeping()) {
break;
}
while (brightnessController.Level() != Controllers::BrightnessController::Levels::Low) {
brightnessController.Lower();
vTaskDelay(100);
}
// Turn brightness down (or set to AlwaysOn mode)
if (msg == Messages::GoToAOD) {
if (settingsController.GetAlwaysOnDisplay()) {
brightnessController.Set(Controllers::BrightnessController::Levels::AlwaysOn);
} else {
brightnessController.Set(Controllers::BrightnessController::Levels::Off);
@ -322,34 +292,23 @@ void DisplayApp::Refresh() {
while (!lv_task_handler()) {
};
}
// Clear any ongoing touch pressed events
// Without this LVGL gets stuck in the pressed state and will keep refreshing the
// display activity timer causing the screen to never sleep after timeout
lvgl.ClearTouchState();
if (msg == Messages::GoToAOD) {
// Turn LCD display off (or set to low power for AlwaysOn mode)
if (settingsController.GetAlwaysOnDisplay()) {
lcd.LowPowerOn();
// Record idle entry time
alwaysOnFrameCount = 0;
alwaysOnTickCount = 0;
alwaysOnStartTime = xTaskGetTickCount();
PushMessageToSystemTask(Pinetime::System::Messages::OnDisplayTaskAOD);
state = States::AOD;
} else {
lcd.Sleep();
PushMessageToSystemTask(Pinetime::System::Messages::OnDisplayTaskSleeping);
state = States::Idle;
}
PushMessageToSystemTask(Pinetime::System::Messages::OnDisplayTaskSleeping);
state = States::Idle;
break;
case Messages::NotifyDeviceActivity:
lv_disp_trig_activity(nullptr);
break;
case Messages::GoToRunning:
// If SystemTask is sleeping, the GoToRunning message is old
// and must be ignored. Otherwise DisplayApp will use SPI
// that is powered down and cause bad behaviour
if (state == States::Running || systemTask->IsSleeping()) {
break;
}
if (state == States::AOD) {
if (settingsController.GetAlwaysOnDisplay()) {
lcd.LowPowerOff();
} else {
lcd.Wakeup();
@ -375,7 +334,7 @@ void DisplayApp::Refresh() {
} else {
LoadNewScreen(Apps::Timer, DisplayApp::FullRefreshDirections::Up);
}
motorController.RunForDuration(35);
motorController.StartRinging();
break;
case Messages::AlarmTriggered:
if (currentApp == Apps::Alarm) {
@ -478,10 +437,13 @@ void DisplayApp::Refresh() {
LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::None);
motorController.RunForDuration(35);
break;
case Messages::OnChargingEvent:
motorController.RunForDuration(15);
break;
}
}
if (state == States::Running && touchHandler.IsTouching()) {
if (touchHandler.IsTouching()) {
currentScreen->OnTouchEvent(touchHandler.GetX(), touchHandler.GetY());
}
@ -518,25 +480,26 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
switch (app) {
case Apps::Launcher: {
std::array<Screens::Tile::Applications, UserAppTypes::Count> apps;
std::ranges::transform(userApps, apps.begin(), [this](const auto& userApp) {
return Screens::Tile::Applications {userApp.icon, userApp.app, userApp.isAvailable(controllers.filesystem)};
});
int i = 0;
for (const auto& userApp : userApps) {
apps[i++] = Screens::Tile::Applications {userApp.icon, userApp.app, true};
}
currentScreen = std::make_unique<Screens::ApplicationList>(this,
settingsController,
batteryController,
bleController,
alarmController,
dateTimeController,
filesystem,
std::move(apps));
} break;
case Apps::Clock: {
const auto* watchFace = std::ranges::find_if(userWatchFaces, [this](const WatchFaceDescription& watchfaceDescription) {
return watchfaceDescription.watchFace == settingsController.GetWatchFace();
});
if (watchFace != userWatchFaces.end()) {
const auto* watchFace =
std::find_if(userWatchFaces.begin(), userWatchFaces.end(), [this](const WatchFaceDescription& watchfaceDescription) {
return watchfaceDescription.watchFace == settingsController.GetWatchFace();
});
if (watchFace != userWatchFaces.end())
currentScreen.reset(watchFace->create(controllers));
} else {
else {
currentScreen.reset(userWatchFaces[0].create(controllers));
}
settingsController.SetAppMenu(0);
@ -579,19 +542,18 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
brightnessController,
motorController,
settingsController,
bleController,
alarmController);
bleController);
break;
case Apps::Settings:
currentScreen = std::make_unique<Screens::Settings>(this, settingsController);
break;
case Apps::SettingWatchFace: {
std::array<Screens::SettingWatchFace::Item, UserWatchFaceTypes::Count> items;
std::ranges::transform(userWatchFaces, items.begin(), [this](const WatchFaceDescription& userWatchFace) {
return Screens::SettingWatchFace::Item {userWatchFace.name,
userWatchFace.watchFace,
userWatchFace.isAvailable(controllers.filesystem)};
});
int i = 0;
for (const auto& userWatchFace : userWatchFaces) {
items[i++] =
Screens::SettingWatchFace::Item {userWatchFace.name, userWatchFace.watchFace, userWatchFace.isAvailable(controllers.filesystem)};
}
currentScreen = std::make_unique<Screens::SettingWatchFace>(this, std::move(items), settingsController, filesystem);
} break;
case Apps::SettingTimeFormat:
@ -603,8 +565,11 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
case Apps::SettingWakeUp:
currentScreen = std::make_unique<Screens::SettingWakeUp>(settingsController);
break;
case Apps::SettingHeartRate:
currentScreen = std::make_unique<Screens::SettingHeartRate>(settingsController);
break;
case Apps::SettingDisplay:
currentScreen = std::make_unique<Screens::SettingDisplay>(settingsController);
currentScreen = std::make_unique<Screens::SettingDisplay>(this, settingsController);
break;
case Apps::SettingSteps:
currentScreen = std::make_unique<Screens::SettingSteps>(settingsController);
@ -621,9 +586,6 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
case Apps::SettingBluetooth:
currentScreen = std::make_unique<Screens::SettingBluetooth>(this, settingsController);
break;
case Apps::SettingOTA:
currentScreen = std::make_unique<Screens::SettingOTA>(this, settingsController);
break;
case Apps::BatteryInfo:
currentScreen = std::make_unique<Screens::BatteryInfo>(batteryController);
break;
@ -642,7 +604,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
currentScreen = std::make_unique<Screens::FlashLight>(*systemTask, brightnessController);
break;
default: {
const auto* d = std::ranges::find_if(userApps, [app](const AppDescription& appDescription) {
const auto* d = std::find_if(userApps.begin(), userApps.end(), [app](const AppDescription& appDescription) {
return appDescription.app == app;
});
if (d != userApps.end()) {

View file

@ -49,7 +49,7 @@ namespace Pinetime {
namespace Applications {
class DisplayApp {
public:
enum class States { Idle, Running, AOD };
enum class States { Idle, Running };
enum class FullRefreshDirections { None, Up, Down, Left, Right, LeftAnim, RightAnim };
DisplayApp(Drivers::St7789& lcd,
@ -121,7 +121,7 @@ namespace Pinetime {
TouchEvents GetGesture();
static void Process(void* instance);
void Init();
void InitHw();
void Refresh();
void LoadNewScreen(Apps app, DisplayApp::FullRefreshDirections direction);
void LoadScreen(Apps app, DisplayApp::FullRefreshDirections direction);
@ -139,7 +139,7 @@ namespace Pinetime {
bool isDimmed = false;
TickType_t CalculateSleepTime();
TickType_t alwaysOnFrameCount;
TickType_t alwaysOnTickCount;
TickType_t alwaysOnStartTime;
// If this is to be changed, make sure the actual always on refresh rate is changed
// by configuring the LCD refresh timings

View file

@ -248,8 +248,6 @@ void LittleVgl::SetNewTouchPoint(int16_t x, int16_t y, bool contact) {
}
}
// Cancel an ongoing tap
// Signifies that LVGL should not handle the current tap
void LittleVgl::CancelTap() {
if (tapped) {
isCancelled = true;
@ -257,13 +255,6 @@ void LittleVgl::CancelTap() {
}
}
// Clear the current tapped state
// Signifies that touch input processing is suspended
void LittleVgl::ClearTouchState() {
touchPoint = {-1, -1};
tapped = false;
}
bool LittleVgl::GetTouchPadInfo(lv_indev_data_t* ptr) {
ptr->point.x = touchPoint.x;
ptr->point.y = touchPoint.y;

View file

@ -26,7 +26,6 @@ namespace Pinetime {
void SetFullRefresh(FullRefreshDirections direction);
void SetNewTouchPoint(int16_t x, int16_t y, bool contact);
void CancelTap();
void ClearTouchState();
bool GetFullRefresh() {
bool returnValue = fullRefresh;

View file

@ -6,7 +6,6 @@ namespace Pinetime {
namespace Display {
enum class Messages : uint8_t {
GoToSleep,
GoToAOD,
GoToRunning,
UpdateBleConnection,
TouchEvent,
@ -24,6 +23,7 @@ namespace Pinetime {
AlarmTriggered,
Chime,
BleRadioEnableToggle,
OnChargingEvent,
};
}
}

View file

@ -14,7 +14,6 @@
#include "displayapp/screens/WatchFaceInfineat.h"
#include "displayapp/screens/WatchFacePineTimeStyle.h"
#include "displayapp/screens/WatchFaceTerminal.h"
#include "displayapp/screens/WatchFacePrideFlag.h"
namespace Pinetime {
namespace Applications {
@ -26,7 +25,6 @@ namespace Pinetime {
Apps app;
const char* icon;
Screens::Screen* (*create)(AppControllers& controllers);
bool (*isAvailable)(Controllers::FS& fileSystem);
};
struct WatchFaceDescription {
@ -38,7 +36,7 @@ namespace Pinetime {
template <Apps t>
consteval AppDescription CreateAppDescription() {
return {AppTraits<t>::app, AppTraits<t>::icon, &AppTraits<t>::Create, &AppTraits<t>::IsAvailable};
return {AppTraits<t>::app, AppTraits<t>::icon, &AppTraits<t>::Create};
}
template <WatchFace t>

View file

@ -26,7 +26,6 @@ namespace Pinetime {
StopWatch,
Metronome,
Motion,
Calculator,
Steps,
Dice,
Weather,
@ -36,6 +35,7 @@ namespace Pinetime {
SettingWatchFace,
SettingTimeFormat,
SettingWeatherFormat,
SettingHeartRate,
SettingDisplay,
SettingWakeUp,
SettingSteps,
@ -43,7 +43,6 @@ namespace Pinetime {
SettingChimes,
SettingShakeThreshold,
SettingBluetooth,
SettingOTA,
Error
};
@ -54,7 +53,6 @@ namespace Pinetime {
Terminal,
Infineat,
CasioStyleG7710,
PrideFlag,
};
template <Apps>

View file

@ -13,7 +13,6 @@ else ()
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Dice")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Metronome")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Navigation")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Calculator")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Weather")
#set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Motion")
set(USERAPP_TYPES "${DEFAULT_USER_APP_TYPES}" CACHE STRING "List of user apps to build into the firmware")
@ -28,7 +27,6 @@ else()
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::Terminal")
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::Infineat")
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::CasioStyleG7710")
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::PrideFlag")
set(WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}" CACHE STRING "List of watch faces to build into the firmware")
endif()

View file

@ -11,7 +11,6 @@ configure_file(${CMAKE_CURRENT_LIST_DIR}/jetbrains_mono_bold_20.c_M.patch
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12)
# FindPython3 module introduces with CMake 3.12
# https://cmake.org/cmake/help/latest/module/FindPython3.html
set(Python3_FIND_STRATEGY LOCATION) # https://discourse.cmake.org/t/find-package-python3-is-not-finding-the-correct-python/10563
find_package(Python3 REQUIRED)
else()
set(Python3_EXECUTABLE "python")

View file

@ -7,7 +7,7 @@
},
{
"file": "FontAwesome5-Solid+Brands+Regular.woff",
"range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c, 0xf0f3, 0xf522, 0xf743, 0xf1ec, 0xf55a, 0xf3ed"
"range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c, 0xf0f3, 0xf522, 0xf743"
}
],
"bpp": 1,

View file

@ -48,7 +48,7 @@ Alarm::Alarm(Controllers::AlarmController& alarmController,
Controllers::Settings::ClockType clockType,
System::SystemTask& systemTask,
Controllers::MotorController& motorController)
: alarmController {alarmController}, wakeLock(systemTask), motorController {motorController} {
: alarmController {alarmController}, systemTask {systemTask}, motorController {motorController} {
hourCounter.Create();
lv_obj_align(hourCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
@ -77,7 +77,7 @@ Alarm::Alarm(Controllers::AlarmController& alarmController,
btnStop = lv_btn_create(lv_scr_act(), nullptr);
btnStop->user_data = this;
lv_obj_set_event_cb(btnStop, btnEventHandler);
lv_obj_set_size(btnStop, 240, 70);
lv_obj_set_size(btnStop, 115, 50);
lv_obj_align(btnStop, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
lv_obj_set_style_local_bg_color(btnStop, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
txtStop = lv_label_create(btnStop, nullptr);
@ -117,7 +117,7 @@ Alarm::Alarm(Controllers::AlarmController& alarmController,
UpdateAlarmTime();
if (alarmController.IsAlerting()) {
if (alarmController.State() == Controllers::AlarmController::AlarmState::Alerting) {
SetAlerting();
} else {
SetSwitchState(LV_ANIM_OFF);
@ -125,15 +125,14 @@ Alarm::Alarm(Controllers::AlarmController& alarmController,
}
Alarm::~Alarm() {
if (alarmController.IsAlerting()) {
if (alarmController.State() == AlarmController::AlarmState::Alerting) {
StopAlerting();
}
lv_obj_clean(lv_scr_act());
alarmController.SaveAlarm();
}
void Alarm::DisableAlarm() {
if (alarmController.IsEnabled()) {
if (alarmController.State() == AlarmController::AlarmState::Set) {
alarmController.DisableAlarm();
lv_switch_off(enableSwitch, LV_ANIM_ON);
}
@ -173,7 +172,7 @@ bool Alarm::OnButtonPushed() {
HideInfo();
return true;
}
if (alarmController.IsAlerting()) {
if (alarmController.State() == AlarmController::AlarmState::Alerting) {
StopAlerting();
return true;
}
@ -182,7 +181,7 @@ bool Alarm::OnButtonPushed() {
bool Alarm::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
// Don't allow closing the screen by swiping while the alarm is alerting
return alarmController.IsAlerting() && event == TouchEvents::SwipeDown;
return alarmController.State() == AlarmController::AlarmState::Alerting && event == TouchEvents::SwipeDown;
}
void Alarm::OnValueChanged() {
@ -203,14 +202,10 @@ void Alarm::UpdateAlarmTime() {
void Alarm::SetAlerting() {
lv_obj_set_hidden(enableSwitch, true);
lv_obj_set_hidden(btnRecur, true);
lv_obj_set_hidden(btnInfo, true);
hourCounter.HideControls();
minuteCounter.HideControls();
lv_obj_set_hidden(btnStop, false);
taskStopAlarm = lv_task_create(StopAlarmTaskCallback, pdMS_TO_TICKS(60 * 1000), LV_TASK_PRIO_MID, this);
motorController.StartRinging();
wakeLock.Lock();
systemTask.PushMessage(System::Messages::DisableSleeping);
}
void Alarm::StopAlerting() {
@ -221,20 +216,21 @@ void Alarm::StopAlerting() {
lv_task_del(taskStopAlarm);
taskStopAlarm = nullptr;
}
wakeLock.Release();
lv_obj_set_hidden(btnStop, true);
hourCounter.ShowControls();
minuteCounter.ShowControls();
lv_obj_set_hidden(btnInfo, false);
lv_obj_set_hidden(btnRecur, false);
systemTask.PushMessage(System::Messages::EnableSleeping);
lv_obj_set_hidden(enableSwitch, false);
lv_obj_set_hidden(btnStop, true);
}
void Alarm::SetSwitchState(lv_anim_enable_t anim) {
if (alarmController.IsEnabled()) {
lv_switch_on(enableSwitch, anim);
} else {
lv_switch_off(enableSwitch, anim);
switch (alarmController.State()) {
case AlarmController::AlarmState::Set:
lv_switch_on(enableSwitch, anim);
break;
case AlarmController::AlarmState::Not_Set:
lv_switch_off(enableSwitch, anim);
break;
default:
break;
}
}
@ -251,7 +247,7 @@ void Alarm::ShowInfo() {
txtMessage = lv_label_create(btnMessage, nullptr);
lv_obj_set_style_local_bg_color(btnMessage, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_NAVY);
if (alarmController.IsEnabled()) {
if (alarmController.State() == AlarmController::AlarmState::Set) {
auto timeToAlarm = alarmController.SecondsToAlarm();
auto daysToAlarm = timeToAlarm / 86400;

View file

@ -22,7 +22,6 @@
#include "displayapp/screens/Screen.h"
#include "displayapp/widgets/Counter.h"
#include "displayapp/Controllers.h"
#include "systemtask/WakeLock.h"
#include "Symbols.h"
namespace Pinetime {
@ -44,7 +43,7 @@ namespace Pinetime {
private:
Controllers::AlarmController& alarmController;
System::WakeLock wakeLock;
System::SystemTask& systemTask;
Controllers::MotorController& motorController;
lv_obj_t *btnStop, *txtStop, *btnRecur, *txtRecur, *btnInfo, *enableSwitch;
@ -78,10 +77,6 @@ namespace Pinetime {
*controllers.systemTask,
controllers.motorController);
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
};
};
}
}

View file

@ -21,7 +21,6 @@ ApplicationList::ApplicationList(DisplayApp* app,
Pinetime::Controllers::Settings& settingsController,
const Pinetime::Controllers::Battery& batteryController,
const Pinetime::Controllers::Ble& bleController,
const Pinetime::Controllers::AlarmController& alarmController,
Controllers::DateTime& dateTimeController,
Pinetime::Controllers::FS& filesystem,
std::array<Tile::Applications, UserAppTypes::Count>&& apps)
@ -29,7 +28,6 @@ ApplicationList::ApplicationList(DisplayApp* app,
settingsController {settingsController},
batteryController {batteryController},
bleController {bleController},
alarmController {alarmController},
dateTimeController {dateTimeController},
filesystem {filesystem},
apps {std::move(apps)},
@ -61,7 +59,6 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen(unsigned int screenNum) co
settingsController,
batteryController,
bleController,
alarmController,
dateTimeController,
pageApps);
}

View file

@ -18,7 +18,6 @@ namespace Pinetime {
Pinetime::Controllers::Settings& settingsController,
const Pinetime::Controllers::Battery& batteryController,
const Pinetime::Controllers::Ble& bleController,
const Pinetime::Controllers::AlarmController& alarmController,
Controllers::DateTime& dateTimeController,
Pinetime::Controllers::FS& filesystem,
std::array<Tile::Applications, UserAppTypes::Count>&& apps);
@ -33,7 +32,6 @@ namespace Pinetime {
Controllers::Settings& settingsController;
const Pinetime::Controllers::Battery& batteryController;
const Pinetime::Controllers::Ble& bleController;
const Pinetime::Controllers::AlarmController& alarmController;
Controllers::DateTime& dateTimeController;
Pinetime::Controllers::FS& filesystem;
std::array<Tile::Applications, UserAppTypes::Count> apps;

View file

@ -10,35 +10,33 @@ BatteryInfo::BatteryInfo(const Pinetime::Controllers::Battery& batteryController
batteryPercent = batteryController.PercentRemaining();
batteryVoltage = batteryController.Voltage();
chargingArc = lv_arc_create(lv_scr_act(), nullptr);
lv_arc_set_rotation(chargingArc, 270);
lv_arc_set_bg_angles(chargingArc, 0, 360);
lv_arc_set_adjustable(chargingArc, false);
lv_obj_set_size(chargingArc, 180, 180);
lv_obj_align(chargingArc, nullptr, LV_ALIGN_CENTER, 0, -30);
lv_arc_set_value(chargingArc, batteryPercent);
lv_obj_set_style_local_bg_opa(chargingArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, LV_OPA_0);
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, Colors::bgAlt);
lv_obj_set_style_local_border_width(chargingArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, 2);
lv_obj_set_style_local_radius(chargingArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, 0);
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_LIME);
charging_bar = lv_bar_create(lv_scr_act(), nullptr);
lv_obj_set_size(charging_bar, 200, 15);
lv_bar_set_range(charging_bar, 0, 100);
lv_obj_align(charging_bar, nullptr, LV_ALIGN_CENTER, 0, 10);
lv_bar_set_anim_time(charging_bar, 1000);
lv_obj_set_style_local_radius(charging_bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, Colors::bgAlt);
lv_obj_set_style_local_bg_opa(charging_bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_OPA_100);
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED);
lv_bar_set_value(charging_bar, batteryPercent, LV_ANIM_ON);
status = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(status, "Reading Battery status");
lv_label_set_align(status, LV_LABEL_ALIGN_CENTER);
lv_obj_align(status, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, -17);
lv_obj_align(status, charging_bar, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);
percent = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(percent, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
lv_label_set_text_fmt(percent, "%i%%", batteryPercent);
lv_obj_set_style_local_text_font(percent, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
lv_label_set_text_fmt(percent, "%02i%%", batteryPercent);
lv_label_set_align(percent, LV_LABEL_ALIGN_LEFT);
lv_obj_align(percent, chargingArc, LV_ALIGN_CENTER, 0, 0);
lv_obj_align(percent, nullptr, LV_ALIGN_CENTER, 0, -60);
voltage = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(voltage, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::orange);
lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltage / 1000, batteryVoltage % 1000 / 10);
lv_label_set_align(voltage, LV_LABEL_ALIGN_CENTER);
lv_obj_align(voltage, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, -7);
lv_obj_align(voltage, nullptr, LV_ALIGN_CENTER, 0, 95);
taskRefresh = lv_task_create(RefreshTaskCallback, 5000, LV_TASK_PRIO_MID, this);
Refresh();
@ -55,26 +53,22 @@ void BatteryInfo::Refresh() {
batteryVoltage = batteryController.Voltage();
if (batteryController.IsCharging()) {
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_LIME);
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED);
lv_label_set_text_static(status, "Charging");
} else if (batteryPercent == 100) {
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_BLUE);
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_BLUE);
lv_label_set_text_static(status, "Fully charged");
} else if (batteryPercent > 15) {
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_GREEN);
lv_label_set_text_static(status, "Discharging");
} else if (batteryPercent > 5) {
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
} else if (batteryPercent < 10) {
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
lv_label_set_text_static(status, "Battery low");
} else {
lv_obj_set_style_local_line_color(chargingArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, Colors::deepOrange);
lv_label_set_text_static(status, "Battery critical");
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, Colors::highlight);
lv_label_set_text_static(status, "Discharging");
}
lv_label_set_text_fmt(percent, "%i%%", batteryPercent);
lv_obj_align(percent, chargingArc, LV_ALIGN_CENTER, 0, 0);
lv_label_set_text_fmt(percent, "%02i%%", batteryPercent);
lv_obj_align(status, voltage, LV_ALIGN_IN_BOTTOM_MID, 0, -27);
lv_obj_align(status, charging_bar, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);
lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltage / 1000, batteryVoltage % 1000 / 10);
lv_arc_set_value(chargingArc, batteryPercent);
lv_bar_set_value(charging_bar, batteryPercent, LV_ANIM_ON);
}

View file

@ -24,7 +24,7 @@ namespace Pinetime {
lv_obj_t* voltage;
lv_obj_t* percent;
lv_obj_t* chargingArc;
lv_obj_t* charging_bar;
lv_obj_t* status;
lv_task_t* taskRefresh;

View file

@ -1,375 +0,0 @@
#include <cmath>
#include <cinttypes>
#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<Calculator*>(obj->user_data);
app->OnButtonEvent(obj, event);
}
Calculator::~Calculator() {
lv_obj_clean(lv_scr_act());
}
constexpr const char* const buttonMap[] = {
"7", "8", "9", Symbols::backspace, "\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, 10, 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, 10, 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, const_cast<const char**>(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);
}
void Calculator::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
if ((obj == buttonMatrix) && (event == LV_EVENT_PRESSED)) {
HandleInput();
}
}
void Calculator::HandleInput() {
const char* buttonText = lv_btnmatrix_get_active_btn_text(buttonMatrix);
if (buttonText == nullptr) {
return;
}
if ((equalSignPressedBefore && (*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
uint8_t digit = (*buttonText) - '0';
int8_t 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;
}
} break;
// unary minus
case '(':
value = -value;
break;
case '.':
if (offset == FIXED_POINT_OFFSET) {
offset /= 10;
}
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;
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;
// this is a little hacky because it matches only the first char
case Symbols::backspace[0]:
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;
}
if (value == 0) {
operation = ' ';
UpdateOperation();
}
break;
case '=':
equalSignPressedBefore = 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();
}
break;
}
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;
default:
lv_btnmatrix_clear_btn_ctrl_all(buttonMatrix, LV_BTNMATRIX_CTRL_CHECK_STATE);
break;
}
}
void Calculator::ResetInput() {
value = 0;
offset = FIXED_POINT_OFFSET;
operation = ' ';
equalSignPressedBefore = 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 minWidth = N_DECIMALS;
// cut "0"-digits on the right
while ((remainder > 0) && (remainder % 10 == 0)) {
remainder /= 10;
minWidth--;
}
if ((integer == 0) && negative) {
lv_label_set_text_fmt(resultLabel, "-0.%0*" PRId64, minWidth, remainder);
} else {
lv_label_set_text_fmt(resultLabel, "%" PRId64 ".%0*" PRId64, integer, minWidth, 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 minWidth = 0;
int64_t tmpOffset = offset;
if (tmpOffset == 0) {
tmpOffset = 1;
minWidth = 1;
}
while (tmpOffset < FIXED_POINT_OFFSET) {
tmpOffset *= 10;
minWidth++;
}
minWidth--;
for (uint8_t i = minWidth; i < N_DECIMALS; i++) {
printRemainder /= 10;
}
if ((integer == 0) && negative) {
lv_label_set_text_fmt(valueLabel, "-0.%0*" PRId64, minWidth, 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, minWidth, 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;
default:
break;
}
}

View file

@ -1,87 +0,0 @@
#pragma once
#include "displayapp/screens/Screen.h"
#include "displayapp/apps/Apps.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"
namespace {
constexpr int64_t 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 {};
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
// keep in mind, that we only have 12 digits in total (see MAX_DIGITS)
// due to the fixed point implementation
static constexpr uint8_t N_DECIMALS = 3;
// this is the constant default offset
static constexpr int64_t FIXED_POINT_OFFSET = powi(10, N_DECIMALS);
// this is the current offset, may vary 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 = 12;
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 equalSignPressedBefore = false;
enum Error {
TooLarge,
ZeroDivision,
None,
};
Error error = Error::None;
};
}
template <>
struct AppTraits<Apps::Calculator> {
static constexpr Apps app = Apps::Calculator;
static constexpr const char* icon = Screens::Symbols::calculator;
static Screens::Screen* Create(AppControllers& /* controllers */) {
return new Screens::Calculator();
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
};
};
}
}

View file

@ -56,10 +56,6 @@ namespace Pinetime {
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::Dice(controllers.motionController, controllers.motorController, controllers.settingsController);
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
};
};
}
}

View file

@ -2,7 +2,6 @@
#include <lvgl/lvgl.h>
#include "components/ble/BleController.h"
#include "displayapp/DisplayApp.h"
#include "displayapp/InfiniTimeTheme.h"
using namespace Pinetime::Applications::Screens;
@ -13,9 +12,6 @@ FirmwareUpdate::FirmwareUpdate(const Pinetime::Controllers::Ble& bleController)
lv_obj_align(titleLabel, nullptr, LV_ALIGN_IN_TOP_MID, 0, 50);
bar1 = lv_bar_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_bg_color(bar1, LV_BAR_PART_BG, LV_STATE_DEFAULT, Colors::bgAlt);
lv_obj_set_style_local_bg_opa(bar1, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_OPA_100);
lv_obj_set_style_local_radius(bar1, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
lv_obj_set_size(bar1, 200, 30);
lv_obj_align(bar1, nullptr, LV_ALIGN_CENTER, 0, 0);
lv_bar_set_range(bar1, 0, 1000);
@ -79,7 +75,7 @@ void FirmwareUpdate::DisplayProgression() const {
const uint32_t total = bleController.FirmwareUpdateTotalBytes();
const int16_t permille = current / (total / 1000);
lv_label_set_text_fmt(percentLabel, "%d%%", permille / 10);
lv_label_set_text_fmt(percentLabel, "%d %%", permille / 10);
lv_bar_set_value(bar1, permille, LV_ANIM_OFF);
}

View file

@ -15,7 +15,7 @@ namespace {
}
FlashLight::FlashLight(System::SystemTask& systemTask, Controllers::BrightnessController& brightnessController)
: wakeLock(systemTask), brightnessController {brightnessController} {
: systemTask {systemTask}, brightnessController {brightnessController} {
previousBrightnessLevel = brightnessController.Level();
brightnessController.Set(Controllers::BrightnessController::Levels::Low);
@ -47,13 +47,14 @@ FlashLight::FlashLight(System::SystemTask& systemTask, Controllers::BrightnessCo
backgroundAction->user_data = this;
lv_obj_set_event_cb(backgroundAction, EventHandler);
wakeLock.Lock();
systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping);
}
FlashLight::~FlashLight() {
lv_obj_clean(lv_scr_act());
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
brightnessController.Set(previousBrightnessLevel);
systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
}
void FlashLight::SetColors() {

View file

@ -3,7 +3,6 @@
#include "displayapp/screens/Screen.h"
#include "components/brightness/BrightnessController.h"
#include "systemtask/SystemTask.h"
#include "systemtask/WakeLock.h"
#include <cstdint>
#include <lvgl/lvgl.h>
@ -24,7 +23,7 @@ namespace Pinetime {
void SetIndicators();
void SetColors();
Pinetime::System::WakeLock wakeLock;
Pinetime::System::SystemTask& systemTask;
Controllers::BrightnessController& brightnessController;
Controllers::BrightnessController::Levels brightnessLevel = Controllers::BrightnessController::Levels::High;

View file

@ -29,7 +29,7 @@ namespace {
}
HeartRate::HeartRate(Controllers::HeartRateController& heartRateController, System::SystemTask& systemTask)
: heartRateController {heartRateController}, wakeLock(systemTask) {
: heartRateController {heartRateController}, systemTask {systemTask} {
bool isHrRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped;
label_hr = lv_label_create(lv_scr_act(), nullptr);
@ -63,7 +63,7 @@ HeartRate::HeartRate(Controllers::HeartRateController& heartRateController, Syst
label_startStop = lv_label_create(btn_startStop, nullptr);
UpdateStartStopButton(isHrRunning);
if (isHrRunning) {
wakeLock.Lock();
systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping);
}
taskRefresh = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this);
@ -72,6 +72,7 @@ HeartRate::HeartRate(Controllers::HeartRateController& heartRateController, Syst
HeartRate::~HeartRate() {
lv_task_del(taskRefresh);
lv_obj_clean(lv_scr_act());
systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
}
void HeartRate::Refresh() {
@ -100,12 +101,12 @@ void HeartRate::OnStartStopEvent(lv_event_t event) {
if (heartRateController.State() == Controllers::HeartRateController::States::Stopped) {
heartRateController.Start();
UpdateStartStopButton(heartRateController.State() != Controllers::HeartRateController::States::Stopped);
wakeLock.Lock();
systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping);
lv_obj_set_style_local_text_color(label_hr, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::highlight);
} else {
heartRateController.Stop();
UpdateStartStopButton(heartRateController.State() != Controllers::HeartRateController::States::Stopped);
wakeLock.Release();
systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
lv_obj_set_style_local_text_color(label_hr, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
}
}

View file

@ -4,7 +4,6 @@
#include <chrono>
#include "displayapp/screens/Screen.h"
#include "systemtask/SystemTask.h"
#include "systemtask/WakeLock.h"
#include "Symbols.h"
#include <lvgl/src/lv_core/lv_style.h>
#include <lvgl/src/lv_core/lv_obj.h>
@ -28,7 +27,7 @@ namespace Pinetime {
private:
Controllers::HeartRateController& heartRateController;
Pinetime::System::WakeLock wakeLock;
Pinetime::System::SystemTask& systemTask;
void UpdateStartStopButton(bool isRunning);
lv_obj_t* label_hr;
lv_obj_t* label_bpm;
@ -48,10 +47,6 @@ namespace Pinetime {
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::HeartRate(controllers.heartRateController, *controllers.systemTask);
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
};
};
}
}

View file

@ -47,10 +47,6 @@ namespace Pinetime {
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::InfiniPaint(controllers.lvgl, controllers.motorController);
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
};
};
}
}

View file

@ -22,7 +22,7 @@ namespace {
}
Metronome::Metronome(Controllers::MotorController& motorController, System::SystemTask& systemTask)
: motorController {motorController}, wakeLock(systemTask) {
: motorController {motorController}, systemTask {systemTask} {
bpmArc = lv_arc_create(lv_scr_act(), nullptr);
bpmArc->user_data = this;
@ -72,6 +72,7 @@ Metronome::Metronome(Controllers::MotorController& motorController, System::Syst
Metronome::~Metronome() {
lv_task_del(taskRefresh);
systemTask.PushMessage(System::Messages::EnableSleeping);
lv_obj_clean(lv_scr_act());
}
@ -127,12 +128,12 @@ void Metronome::OnEvent(lv_obj_t* obj, lv_event_t event) {
metronomeStarted = !metronomeStarted;
if (metronomeStarted) {
lv_label_set_text_static(lblPlayPause, Symbols::pause);
wakeLock.Lock();
systemTask.PushMessage(System::Messages::DisableSleeping);
startTime = xTaskGetTickCount();
counter = 1;
} else {
lv_label_set_text_static(lblPlayPause, Symbols::play);
wakeLock.Release();
systemTask.PushMessage(System::Messages::EnableSleeping);
}
}
break;

View file

@ -1,7 +1,6 @@
#pragma once
#include "systemtask/SystemTask.h"
#include "systemtask/WakeLock.h"
#include "components/motor/MotorController.h"
#include "displayapp/screens/Screen.h"
#include "Symbols.h"
@ -22,7 +21,7 @@ namespace Pinetime {
TickType_t startTime = 0;
TickType_t tappedTime = 0;
Controllers::MotorController& motorController;
System::WakeLock wakeLock;
System::SystemTask& systemTask;
int16_t bpm = 120;
uint8_t bpb = 4;
uint8_t counter = 1;
@ -47,10 +46,6 @@ namespace Pinetime {
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::Metronome(controllers.motorController, *controllers.systemTask);
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
};
};
}
}

View file

@ -41,10 +41,6 @@ namespace Pinetime {
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::Motion(controllers.motionController);
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
};
};
}
}

View file

@ -23,7 +23,6 @@
#include "displayapp/icons/music/disc.c"
#include "displayapp/icons/music/disc_f_1.c"
#include "displayapp/icons/music/disc_f_2.c"
#include "displayapp/InfiniTimeTheme.h"
using namespace Pinetime::Applications::Screens;
@ -53,7 +52,8 @@ Music::Music(Pinetime::Controllers::MusicService& music) : musicService(music) {
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, Colors::bgAlt);
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_50);
btnVolDown = lv_btn_create(lv_scr_act(), nullptr);
btnVolDown->user_data = this;
@ -114,18 +114,18 @@ Music::Music(Pinetime::Controllers::MusicService& music) : musicService(music) {
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 + 2 * FONT_HEIGHT + LINE_PAD);
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_static(txtArtist, "");
lv_obj_set_style_local_text_color(txtArtist, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
lv_label_set_text_static(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 + 1 * FONT_HEIGHT);
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_static(txtTrack, "");
lv_label_set_text_static(txtTrack, "This is a very long getTrack name");
/** Init animation */
imgDisc = lv_img_create(lv_scr_act(), nullptr);

View file

@ -94,10 +94,6 @@ namespace Pinetime {
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::Music(*controllers.musicService);
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
};
};
}
}

View file

@ -67,10 +67,6 @@ namespace Pinetime {
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::Navigation(*controllers.navigationService);
};
static bool IsAvailable(Pinetime::Controllers::FS& filesystem) {
return Screens::Navigation::IsAvailable(filesystem);
};
};
}
}

View file

@ -20,7 +20,7 @@ Notifications::Notifications(DisplayApp* app,
notificationManager {notificationManager},
alertNotificationService {alertNotificationService},
motorController {motorController},
wakeLock(systemTask),
systemTask {systemTask},
mode {mode} {
notificationManager.ClearNewNotificationFlag();
@ -40,7 +40,7 @@ Notifications::Notifications(DisplayApp* app,
validDisplay = false;
}
if (mode == Modes::Preview) {
wakeLock.Lock();
systemTask.PushMessage(System::Messages::DisableSleeping);
if (notification.category == Controllers::NotificationManager::Categories::IncomingCall) {
motorController.StartRinging();
} else {
@ -65,6 +65,7 @@ Notifications::~Notifications() {
lv_task_del(taskRefresh);
// make sure we stop any vibrations before exiting
motorController.StopRinging();
systemTask.PushMessage(System::Messages::EnableSleeping);
lv_obj_clean(lv_scr_act());
}
@ -81,6 +82,7 @@ void Notifications::Refresh() {
} else if (mode == Modes::Preview && dismissingNotification) {
running = false;
currentItem = std::make_unique<NotificationItem>(alertNotificationService, motorController);
} else if (dismissingNotification) {
dismissingNotification = false;
@ -111,15 +113,15 @@ void Notifications::Refresh() {
alertNotificationService,
motorController);
} else {
running = false;
currentItem = std::make_unique<NotificationItem>(alertNotificationService, motorController);
}
}
running = running && currentItem->IsRunning();
running = currentItem->IsRunning() && running;
}
void Notifications::OnPreviewInteraction() {
wakeLock.Release();
systemTask.PushMessage(System::Messages::EnableSleeping);
motorController.StopRinging();
if (timeoutLine != nullptr) {
lv_obj_del(timeoutLine);
@ -171,9 +173,7 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
} else if (nextMessage.valid) {
currentId = nextMessage.id;
} else {
// don't update id, notification manager will try to fetch
// but not find it. Refresh will try to load latest message
// or dismiss to watchface
// don't update id, won't be found be refresh and try to load latest message or no message box
}
DismissToBlack();
return true;
@ -246,8 +246,8 @@ namespace {
Notifications::NotificationItem::NotificationItem(Pinetime::Controllers::AlertNotificationService& alertNotificationService,
Pinetime::Controllers::MotorController& motorController)
: NotificationItem("Notifications",
"No notifications to display",
: NotificationItem("Notification",
"No notification to display",
0,
Controllers::NotificationManager::Categories::Unknown,
0,

View file

@ -8,7 +8,6 @@
#include "components/ble/NotificationManager.h"
#include "components/motor/MotorController.h"
#include "systemtask/SystemTask.h"
#include "systemtask/WakeLock.h"
namespace Pinetime {
namespace Controllers {
@ -74,7 +73,7 @@ namespace Pinetime {
Pinetime::Controllers::NotificationManager& notificationManager;
Pinetime::Controllers::AlertNotificationService& alertNotificationService;
Pinetime::Controllers::MotorController& motorController;
System::WakeLock wakeLock;
System::SystemTask& systemTask;
Modes mode = Modes::Normal;
std::unique_ptr<NotificationItem> currentItem;
Pinetime::Controllers::NotificationManager::Notification::Id currentId;

View file

@ -57,10 +57,6 @@ namespace Pinetime {
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::Paddle(controllers.lvgl);
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
};
};
}
}

View file

@ -51,10 +51,6 @@ namespace Pinetime {
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::Steps(controllers.motionController, controllers.settingsController);
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
};
};
}
}

View file

@ -34,7 +34,7 @@ namespace {
constexpr TickType_t blinkInterval = pdMS_TO_TICKS(1000);
}
StopWatch::StopWatch(System::SystemTask& systemTask) : wakeLock(systemTask) {
StopWatch::StopWatch(System::SystemTask& systemTask) : systemTask {systemTask} {
static constexpr uint8_t btnWidth = 115;
static constexpr uint8_t btnHeight = 80;
btnPlayPause = lv_btn_create(lv_scr_act(), nullptr);
@ -79,6 +79,7 @@ StopWatch::StopWatch(System::SystemTask& systemTask) : wakeLock(systemTask) {
StopWatch::~StopWatch() {
lv_task_del(taskRefresh);
systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
lv_obj_clean(lv_scr_act());
}
@ -134,7 +135,7 @@ void StopWatch::Start() {
SetInterfaceRunning();
startTime = xTaskGetTickCount();
currentState = States::Running;
wakeLock.Lock();
systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping);
}
void StopWatch::Pause() {
@ -144,7 +145,7 @@ void StopWatch::Pause() {
oldTimeElapsed = laps[lapsDone];
blinkTime = xTaskGetTickCount() + blinkInterval;
currentState = States::Halted;
wakeLock.Release();
systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
}
void StopWatch::Refresh() {

View file

@ -7,7 +7,6 @@
#include "portmacro_cmsis.h"
#include "systemtask/SystemTask.h"
#include "systemtask/WakeLock.h"
#include "displayapp/apps/Apps.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"
@ -44,7 +43,7 @@ namespace Pinetime {
void Start();
void Pause();
Pinetime::System::WakeLock wakeLock;
Pinetime::System::SystemTask& systemTask;
States currentState = States::Init;
TickType_t startTime;
TickType_t oldTimeElapsed = 0;
@ -69,10 +68,6 @@ namespace Pinetime {
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::StopWatch(*controllers.systemTask);
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
};
};
}
}

View file

@ -8,7 +8,6 @@ namespace Pinetime {
static constexpr const char* batteryHalf = "\xEF\x89\x82";
static constexpr const char* heartBeat = "\xEF\x88\x9E";
static constexpr const char* bluetooth = "\xEF\x8A\x94";
static constexpr const char* shieldAlt = "\xEF\x8F\xAD";
static constexpr const char* plug = "\xEF\x87\xA6";
static constexpr const char* shoe = "\xEF\x95\x8B";
static constexpr const char* clock = "\xEF\x80\x97";
@ -40,8 +39,6 @@ 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";

View file

@ -40,7 +40,8 @@ SystemInfo::SystemInfo(Pinetime::Applications::DisplayApp* app,
Pinetime::Controllers::MotionController& motionController,
const Pinetime::Drivers::Cst816S& touchPanel,
const Pinetime::Drivers::SpiNorFlash& spiNorFlash)
: dateTimeController {dateTimeController},
: app {app},
dateTimeController {dateTimeController},
batteryController {batteryController},
brightnessController {brightnessController},
bleController {bleController},
@ -195,10 +196,10 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen3() {
"#808080 SPI Flash# %02x-%02x-%02x\n"
"\n"
"#808080 Memory heap#\n"
" #808080 Free# %d/%d\n"
" #808080 Free# %d\n"
" #808080 Min free# %d\n"
" #808080 Alloc err# %d\n"
" #808080 Ovrfl err# %d",
" #808080 Ovrfl err# %d\n",
bleAddr[5],
bleAddr[4],
bleAddr[3],
@ -209,7 +210,6 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen3() {
spiFlashId.type,
spiFlashId.density,
xPortGetFreeHeapSize(),
xPortGetHeapSize(),
xPortGetMinimumEverFreeHeapSize(),
mallocFailedCount,
stackOverflowCount);
@ -241,12 +241,7 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen4() {
lv_table_set_col_width(infoTask, 3, 90);
auto nb = uxTaskGetSystemState(tasksStatus, maxTaskCount, nullptr);
// g++ emits a spurious warning (and thus error because we compile with -Werror)
// due to the way std::sort is implemented
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
std::sort(tasksStatus, tasksStatus + nb, sortById);
#pragma GCC diagnostic pop
for (uint8_t i = 0; i < nb && i < maxTaskCount; i++) {
char buffer[11] = {0};

View file

@ -35,6 +35,7 @@ namespace Pinetime {
bool OnTouchEvent(TouchEvents event) override;
private:
DisplayApp* app;
Pinetime::Controllers::DateTime& dateTimeController;
const Pinetime::Controllers::Battery& batteryController;
Pinetime::Controllers::BrightnessController& brightnessController;

View file

@ -29,13 +29,9 @@ Tile::Tile(uint8_t screenID,
Controllers::Settings& settingsController,
const Controllers::Battery& batteryController,
const Controllers::Ble& bleController,
const Controllers::AlarmController& alarmController,
Controllers::DateTime& dateTimeController,
std::array<Applications, 6>& applications)
: app {app},
dateTimeController {dateTimeController},
pageIndicator(screenID, numScreens),
statusIcons(batteryController, bleController, alarmController) {
: app {app}, dateTimeController {dateTimeController}, pageIndicator(screenID, numScreens), statusIcons(batteryController, bleController) {
settingsController.SetAppMenu(screenID);
@ -70,7 +66,8 @@ Tile::Tile(uint8_t screenID,
lv_obj_align(btnm1, nullptr, LV_ALIGN_CENTER, 0, 10);
lv_obj_set_style_local_radius(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DEFAULT, 20);
lv_obj_set_style_local_bg_color(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DEFAULT, Colors::bgAlt);
lv_obj_set_style_local_bg_opa(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DEFAULT, LV_OPA_50);
lv_obj_set_style_local_bg_color(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DEFAULT, LV_COLOR_AQUA);
lv_obj_set_style_local_bg_opa(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DISABLED, LV_OPA_50);
lv_obj_set_style_local_bg_color(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DISABLED, Colors::bgDark);
lv_obj_set_style_local_pad_all(btnm1, LV_BTNMATRIX_PART_BG, LV_STATE_DEFAULT, 0);

View file

@ -28,7 +28,6 @@ namespace Pinetime {
Controllers::Settings& settingsController,
const Controllers::Battery& batteryController,
const Controllers::Ble& bleController,
const Controllers::AlarmController& alarmController,
Controllers::DateTime& dateTimeController,
std::array<Applications, 6>& applications);

View file

@ -59,8 +59,8 @@ Timer::Timer(Controllers::Timer& timerController) : timer {timerController} {
lv_obj_set_event_cb(btnPlayPause, btnEventHandler);
lv_obj_set_size(btnPlayPause, LV_HOR_RES, 50);
// Create the label as a child of the button so it stays centered by default
txtPlayPause = lv_label_create(btnPlayPause, nullptr);
txtPlayPause = lv_label_create(lv_scr_act(), nullptr);
lv_obj_align(txtPlayPause, btnPlayPause, LV_ALIGN_CENTER, 0, 0);
if (timer.IsRunning()) {
SetTimerRunning();

View file

@ -1,6 +1,7 @@
#pragma once
#include "displayapp/screens/Screen.h"
#include "components/datetime/DateTimeController.h"
#include "systemtask/SystemTask.h"
#include "displayapp/LittleVgl.h"
#include "displayapp/widgets/Counter.h"
@ -56,9 +57,5 @@ namespace Pinetime::Applications {
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::Timer(controllers.timer);
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
};
};
}

View file

@ -45,10 +45,6 @@ namespace Pinetime {
static Screens::Screen* Create(AppControllers& /*controllers*/) {
return new Screens::Twos();
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
};
};
}
}

View file

@ -1,6 +1,5 @@
#include "displayapp/screens/WatchFaceAnalog.h"
#include <cmath>
#include <limits>
#include <lvgl/lvgl.h>
#include "displayapp/screens/BatteryIcon.h"
#include "displayapp/screens/BleIcon.h"
@ -16,10 +15,8 @@ namespace {
constexpr int16_t MinuteLength = 90;
constexpr int16_t SecondLength = 110;
// LVGL sin isn't constexpr (though it could be if it were C++) so fix size here
// All the types are hardcoded anyway and would need changing if the size changed
// sin(90) = 1 so the value of _lv_trigo_sin(90) is the scaling factor
constexpr int16_t LV_TRIG_SCALE = std::numeric_limits<int16_t>::max(); // = _lv_trigo_sin(90)
const auto LV_TRIG_SCALE = _lv_trigo_sin(90);
int16_t Cosine(int16_t angle) {
return _lv_trigo_sin(angle + 90);

View file

@ -2,7 +2,6 @@
#include <lvgl/lvgl.h>
#include <cstdio>
#include "displayapp/screens/NotificationIcon.h"
#include "displayapp/screens/Symbols.h"
#include "displayapp/screens/WeatherSymbols.h"
@ -19,7 +18,6 @@ using namespace Pinetime::Applications::Screens;
WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController,
const Controllers::Battery& batteryController,
const Controllers::Ble& bleController,
const Controllers::AlarmController& alarmController,
Controllers::NotificationManager& notificationManager,
Controllers::Settings& settingsController,
Controllers::HeartRateController& heartRateController,
@ -32,7 +30,7 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController,
heartRateController {heartRateController},
motionController {motionController},
weatherService {weatherService},
statusIcons(batteryController, bleController, alarmController) {
statusIcons(batteryController, bleController) {
statusIcons.Create();
@ -176,12 +174,13 @@ void WatchFaceDigital::Refresh() {
if (currentWeather.IsUpdated()) {
auto optCurrentWeather = currentWeather.Get();
if (optCurrentWeather) {
int16_t temp = optCurrentWeather->temperature.Celsius();
int16_t temp = optCurrentWeather->temperature;
char tempUnit = 'C';
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
temp = optCurrentWeather->temperature.Fahrenheit();
temp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(temp);
tempUnit = 'F';
}
temp = temp / 100 + (temp % 100 >= 50 ? 1 : 0);
lv_label_set_text_fmt(temperature, "%d°%c", temp, tempUnit);
lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId));
} else {

View file

@ -17,7 +17,6 @@ namespace Pinetime {
class Settings;
class Battery;
class Ble;
class AlarmController;
class NotificationManager;
class HeartRateController;
class MotionController;
@ -31,7 +30,6 @@ namespace Pinetime {
WatchFaceDigital(Controllers::DateTime& dateTimeController,
const Controllers::Battery& batteryController,
const Controllers::Ble& bleController,
const Controllers::AlarmController& alarmController,
Controllers::NotificationManager& notificationManager,
Controllers::Settings& settingsController,
Controllers::HeartRateController& heartRateController,
@ -86,7 +84,6 @@ namespace Pinetime {
return new Screens::WatchFaceDigital(controllers.dateTimeController,
controllers.batteryController,
controllers.bleController,
controllers.alarmController,
controllers.notificationManager,
controllers.settingsController,
controllers.heartRateController,

View file

@ -316,7 +316,7 @@ WatchFaceInfineat::~WatchFaceInfineat() {
bool WatchFaceInfineat::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
if ((event == Pinetime::Applications::TouchEvents::LongTap) && lv_obj_get_hidden(btnSettings)) {
lv_obj_set_hidden(btnSettings, false);
savedTick = xTaskGetTickCount();
savedTick = lv_tick_get();
return true;
}
// Prevent screen from sleeping when double tapping with settings on
@ -434,15 +434,12 @@ void WatchFaceInfineat::Refresh() {
batteryPercentRemaining = batteryController.PercentRemaining();
isCharging = batteryController.IsCharging();
// Charging battery animation
if (batteryController.IsCharging() && (xTaskGetTickCount() - chargingAnimationTick > pdMS_TO_TICKS(150))) {
// Dividing 100 by the height gives the battery percentage required to shift the animation by 1 pixel
chargingBatteryPercent += 100 / lv_obj_get_height(logoPine);
if (batteryController.IsCharging()) { // Charging battery animation
chargingBatteryPercent += 1;
if (chargingBatteryPercent > 100) {
chargingBatteryPercent = batteryPercentRemaining.Get();
}
SetBatteryLevel(chargingBatteryPercent);
chargingAnimationTick = xTaskGetTickCount();
} else if (isCharging.IsUpdated() || batteryPercentRemaining.IsUpdated()) {
chargingBatteryPercent = batteryPercentRemaining.Get();
SetBatteryLevel(chargingBatteryPercent);
@ -463,7 +460,7 @@ void WatchFaceInfineat::Refresh() {
}
if (!lv_obj_get_hidden(btnSettings)) {
if ((savedTick > 0) && (xTaskGetTickCount() - savedTick > pdMS_TO_TICKS(3000))) {
if ((savedTick > 0) && (lv_tick_get() - savedTick > 3000)) {
lv_obj_set_hidden(btnSettings, true);
savedTick = 0;
}

View file

@ -45,9 +45,8 @@ namespace Pinetime {
static bool IsAvailable(Pinetime::Controllers::FS& filesystem);
private:
uint32_t savedTick = 0;
uint8_t chargingBatteryPercent = 101; // not a mistake ;)
TickType_t savedTick = 0;
TickType_t chargingAnimationTick = 0;
Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
Utility::DirtyValue<bool> isCharging {};

View file

@ -22,7 +22,7 @@
#include "displayapp/screens/WatchFacePineTimeStyle.h"
#include <lvgl/lvgl.h>
#include <cstdio>
#include "displayapp/Colors.h"
#include <displayapp/Colors.h>
#include "displayapp/screens/BatteryIcon.h"
#include "displayapp/screens/BleIcon.h"
#include "displayapp/screens/NotificationIcon.h"
@ -407,7 +407,7 @@ bool WatchFacePineTimeStyle::OnTouchEvent(Pinetime::Applications::TouchEvents ev
if ((event == Pinetime::Applications::TouchEvents::LongTap) && lv_obj_get_hidden(btnClose)) {
lv_obj_set_hidden(btnSetColor, false);
lv_obj_set_hidden(btnSetOpts, false);
savedTick = xTaskGetTickCount();
savedTick = lv_tick_get();
return true;
}
if ((event == Pinetime::Applications::TouchEvents::DoubleTap) && (lv_obj_get_hidden(btnClose) == false)) {
@ -543,10 +543,11 @@ void WatchFacePineTimeStyle::Refresh() {
if (currentWeather.IsUpdated()) {
auto optCurrentWeather = currentWeather.Get();
if (optCurrentWeather) {
int16_t temp = optCurrentWeather->temperature.Celsius();
int16_t temp = optCurrentWeather->temperature;
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
temp = optCurrentWeather->temperature.Fahrenheit();
temp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(temp);
}
temp = temp / 100 + (temp % 100 >= 50 ? 1 : 0);
lv_label_set_text_fmt(temperature, "%d°", temp);
lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId));
} else {
@ -558,7 +559,7 @@ void WatchFacePineTimeStyle::Refresh() {
}
if (!lv_obj_get_hidden(btnSetColor)) {
if ((savedTick > 0) && (xTaskGetTickCount() - savedTick > pdMS_TO_TICKS(3000))) {
if ((savedTick > 0) && (lv_tick_get() - savedTick > 3000)) {
lv_obj_set_hidden(btnSetColor, true);
lv_obj_set_hidden(btnSetOpts, true);
savedTick = 0;

View file

@ -52,7 +52,7 @@ namespace Pinetime {
Controllers::DateTime::Months currentMonth = Pinetime::Controllers::DateTime::Months::Unknown;
Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
uint8_t currentDay = 0;
TickType_t savedTick = 0;
uint32_t savedTick = 0;
Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
Utility::DirtyValue<bool> isCharging {};

View file

@ -1,337 +0,0 @@
#include "displayapp/screens/WatchFacePrideFlag.h"
#include <lvgl/lvgl.h>
#include "components/battery/BatteryController.h"
#include "components/ble/BleController.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<WatchFacePrideFlag*>(obj->user_data);
screen->UpdateSelected(obj, event);
}
Pinetime::Controllers::Settings::PrideFlag GetNext(Pinetime::Controllers::Settings::PrideFlag prideFlag) {
const auto prideFlagAsInt = static_cast<uint8_t>(prideFlag);
Pinetime::Controllers::Settings::PrideFlag nextFlag;
if (prideFlagAsInt < 3) {
nextFlag = static_cast<Pinetime::Controllers::Settings::PrideFlag>(prideFlagAsInt + 1);
} else {
nextFlag = static_cast<Pinetime::Controllers::Settings::PrideFlag>(0);
}
return nextFlag;
}
Pinetime::Controllers::Settings::PrideFlag GetPrevious(Pinetime::Controllers::Settings::PrideFlag prideFlag) {
const auto prideFlagAsInt = static_cast<uint8_t>(prideFlag);
Pinetime::Controllers::Settings::PrideFlag prevFlag;
if (prideFlagAsInt > 0) {
prevFlag = static_cast<Pinetime::Controllers::Settings::PrideFlag>(prideFlagAsInt - 1);
} else {
prevFlag = static_cast<Pinetime::Controllers::Settings::PrideFlag>(3);
}
return prevFlag;
}
template <std::size_t N>
class PrideFlagData {
public:
constexpr PrideFlagData(const std::array<lv_color_t, N>& sectionColours,
lv_color_t defaultTopLabelColour,
lv_color_t labelTimeColour,
lv_color_t defaultBottomLabelColour)
: sectionColours {sectionColours},
defaultTopLabelColour {defaultTopLabelColour},
labelTimeColour {labelTimeColour},
defaultBottomLabelColour {defaultBottomLabelColour} {
// Space between adjacent text values calculated according to the following equation
spacing = static_cast<uint8_t>(1.5f * static_cast<float>(N) + 40.5f);
}
std::array<lv_color_t, N> sectionColours;
lv_color_t defaultTopLabelColour;
lv_color_t labelTimeColour;
lv_color_t defaultBottomLabelColour;
uint8_t spacing;
};
constexpr lv_color_t lightBlue = LV_COLOR_MAKE(0x00, 0xbf, 0xf3);
constexpr lv_color_t lightPink = LV_COLOR_MAKE(0xf4, 0x9a, 0xc1);
constexpr lv_color_t hotPink = LV_COLOR_MAKE(0xd6, 0x02, 0x70);
constexpr lv_color_t grayPurple = LV_COLOR_MAKE(0x9b, 0x4f, 0x96);
constexpr lv_color_t darkBlue = LV_COLOR_MAKE(0x00, 0x38, 0xa8);
constexpr lv_color_t orange = LV_COLOR_MAKE(0xef, 0x76, 0x27);
constexpr lv_color_t lightOrange = LV_COLOR_MAKE(0xff, 0x9b, 0x55);
constexpr lv_color_t lightPurple = LV_COLOR_MAKE(0xd4, 0x61, 0xa6);
constexpr lv_color_t darkPurple = LV_COLOR_MAKE(0xb5, 0x56, 0x90);
constexpr lv_color_t magenta = LV_COLOR_MAKE(0xa5, 0x00, 0x62);
constexpr lv_color_t darkGreen = LV_COLOR_MAKE(0x07, 0x8d, 0x70);
constexpr lv_color_t cyan = LV_COLOR_MAKE(0x26, 0xce, 0xaa);
constexpr lv_color_t lightGreen = LV_COLOR_MAKE(0x98, 0xe8, 0xc1);
constexpr lv_color_t indigo = LV_COLOR_MAKE(0x50, 0x49, 0xcc);
constexpr lv_color_t steelBlue = LV_COLOR_MAKE(0x3d, 0x1a, 0x78);
constexpr std::array<lv_color_t, 7> gayColours {darkGreen, cyan, lightGreen, LV_COLOR_WHITE, lightBlue, indigo, steelBlue};
constexpr std::array<lv_color_t, 5> transColours {lightBlue, lightPink, LV_COLOR_WHITE, lightPink, lightBlue};
constexpr std::array<lv_color_t, 5> biColours {hotPink, hotPink, grayPurple, darkBlue, darkBlue};
constexpr std::array<lv_color_t, 7> lesbianColours {LV_COLOR_RED, orange, lightOrange, LV_COLOR_WHITE, lightPurple, darkPurple, magenta};
constexpr PrideFlagData gayFlagData(gayColours, LV_COLOR_BLACK, LV_COLOR_BLACK, LV_COLOR_WHITE);
constexpr PrideFlagData transFlagData(transColours, LV_COLOR_WHITE, LV_COLOR_BLACK, LV_COLOR_WHITE);
constexpr PrideFlagData biFlagData(biColours, LV_COLOR_BLACK, LV_COLOR_WHITE, LV_COLOR_BLACK);
constexpr PrideFlagData lesbianFlagData(lesbianColours, LV_COLOR_WHITE, LV_COLOR_BLACK, LV_COLOR_WHITE);
}
WatchFacePrideFlag::WatchFacePrideFlag(Controllers::DateTime& dateTimeController,
const Controllers::Battery& batteryController,
const Controllers::Ble& bleController,
Controllers::NotificationManager& notificationManager,
Controllers::Settings& settingsController,
Controllers::MotionController& motionController)
: currentDateTime {{}},
dateTimeController {dateTimeController},
batteryController {batteryController},
bleController {bleController},
notificationManager {notificationManager},
settingsController {settingsController},
motionController {motionController} {
bluetoothStatus = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(bluetoothStatus, "");
lv_obj_align(bluetoothStatus, nullptr, LV_ALIGN_IN_TOP_RIGHT, -16, 0);
batteryValue = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_recolor(batteryValue, true);
lv_label_set_align(batteryValue, LV_LABEL_ALIGN_CENTER);
lv_obj_set_auto_realign(batteryValue, true);
notificationText = lv_label_create(lv_scr_act(), nullptr);
lv_obj_align(notificationText, nullptr, LV_ALIGN_IN_LEFT_MID, 0, -110);
lv_obj_set_style_local_text_color(notificationText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
btnClose = lv_btn_create(lv_scr_act(), nullptr);
btnClose->user_data = this;
lv_obj_set_size(btnClose, 60, 60);
lv_obj_align(btnClose, lv_scr_act(), LV_ALIGN_CENTER, 0, -80);
lv_obj_set_style_local_bg_opa(btnClose, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_50);
lv_obj_t* lblClose = lv_label_create(btnClose, nullptr);
lv_label_set_text_static(lblClose, "X");
lv_obj_set_event_cb(btnClose, EventHandler);
lv_obj_set_hidden(btnClose, true);
btnNextFlag = lv_btn_create(lv_scr_act(), nullptr);
btnNextFlag->user_data = this;
lv_obj_set_size(btnNextFlag, 60, 60);
lv_obj_align(btnNextFlag, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -15, 80);
lv_obj_set_style_local_bg_opa(btnNextFlag, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_50);
lv_obj_t* lblNextBG = lv_label_create(btnNextFlag, nullptr);
lv_label_set_text_static(lblNextBG, ">");
lv_obj_set_event_cb(btnNextFlag, EventHandler);
lv_obj_set_hidden(btnNextFlag, true);
btnPrevFlag = lv_btn_create(lv_scr_act(), nullptr);
btnPrevFlag->user_data = this;
lv_obj_set_size(btnPrevFlag, 60, 60);
lv_obj_align(btnPrevFlag, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 15, 80);
lv_obj_set_style_local_bg_opa(btnPrevFlag, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_50);
lv_obj_t* lblPrevFlag = lv_label_create(btnPrevFlag, nullptr);
lv_label_set_text_static(lblPrevFlag, "<");
lv_obj_set_event_cb(btnPrevFlag, EventHandler);
lv_obj_set_hidden(btnPrevFlag, true);
labelDate = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_recolor(labelDate, true);
lv_label_set_align(labelDate, LV_LABEL_ALIGN_CENTER);
lv_obj_set_auto_realign(labelDate, true);
labelTime = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_recolor(labelTime, true);
lv_obj_align(labelTime, lv_scr_act(), LV_ALIGN_CENTER, 0, -1);
lv_label_set_align(labelTime, LV_LABEL_ALIGN_CENTER);
lv_obj_set_style_local_text_font(labelTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
lv_obj_set_auto_realign(labelTime, true);
labelDay = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_recolor(labelDay, true);
lv_label_set_align(labelDay, LV_LABEL_ALIGN_CENTER);
lv_obj_set_auto_realign(labelDay, true);
stepValue = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_recolor(stepValue, true);
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, 96);
lv_label_set_align(stepValue, LV_LABEL_ALIGN_CENTER);
lv_obj_set_auto_realign(stepValue, true);
UpdateScreen(settingsController.GetPrideFlag());
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
Refresh();
}
WatchFacePrideFlag::~WatchFacePrideFlag() {
lv_task_del(taskRefresh);
lv_obj_clean(lv_scr_act());
}
bool WatchFacePrideFlag::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
if ((event == Pinetime::Applications::TouchEvents::LongTap) && lv_obj_get_hidden(btnClose)) {
lv_obj_set_hidden(btnPrevFlag, false);
lv_obj_set_hidden(btnNextFlag, false);
lv_obj_set_hidden(btnClose, false);
savedTick = xTaskGetTickCount();
return true;
}
if ((event == Pinetime::Applications::TouchEvents::DoubleTap) && !lv_obj_get_hidden(btnClose)) {
return true;
}
return false;
}
void WatchFacePrideFlag::CloseMenu() {
settingsController.SaveSettings();
lv_obj_set_hidden(btnClose, true);
lv_obj_set_hidden(btnNextFlag, true);
lv_obj_set_hidden(btnPrevFlag, true);
}
void WatchFacePrideFlag::Refresh() {
powerPresent = batteryController.IsPowerPresent();
bleState = bleController.IsConnected();
batteryPercentRemaining = batteryController.PercentRemaining();
if (batteryPercentRemaining.IsUpdated() || powerPresent.IsUpdated() || themeChanged) {
lv_label_set_text_fmt(batteryValue, "%d%%", batteryPercentRemaining.Get());
if (batteryController.IsPowerPresent()) {
lv_label_ins_text(batteryValue, LV_LABEL_POS_LAST, " Charging");
}
}
if (bleState.IsUpdated()) {
if (bleState.Get()) {
lv_label_set_text_static(bluetoothStatus, Symbols::bluetooth);
} else {
lv_label_set_text_static(bluetoothStatus, "");
}
}
notificationState = notificationManager.AreNewNotificationsAvailable();
if (notificationState.IsUpdated()) {
if (notificationState.Get()) {
lv_label_set_text_static(notificationText, "You have\nmail!");
} else {
lv_label_set_text_static(notificationText, "");
}
}
currentDateTime = std::chrono::time_point_cast<std::chrono::seconds>(dateTimeController.CurrentDateTime());
if (currentDateTime.IsUpdated() || themeChanged) {
uint8_t hour = dateTimeController.Hours();
const uint8_t minute = dateTimeController.Minutes();
const uint8_t second = dateTimeController.Seconds();
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
if (hour == 0) {
ampmChar = "AM";
hour = 12;
} else if (hour == 12) {
ampmChar = "PM";
} else if (hour > 12) {
hour = hour - 12;
ampmChar = "PM";
}
}
lv_label_set_text_fmt(labelTime, "%02d:%02d:%02d", hour, minute, second);
currentDate = std::chrono::time_point_cast<std::chrono::days>(currentDateTime.Get());
if (currentDate.IsUpdated() || ampmChar.IsUpdated() || themeChanged) {
const uint16_t year = dateTimeController.Year();
const Controllers::DateTime::Months month = dateTimeController.Month();
const uint8_t day = dateTimeController.Day();
const Controllers::DateTime::Days dayOfWeek = dateTimeController.DayOfWeek();
lv_label_set_text_fmt(labelDate, "%02d-%02d-%04d", day, static_cast<uint8_t>(month), year);
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
lv_label_set_text_fmt(labelDay, "%s %s", dateTimeController.DayOfWeekToStringLow(dayOfWeek), ampmChar);
} else {
lv_label_set_text_fmt(labelDay, "%s", dateTimeController.DayOfWeekToStringLow(dayOfWeek));
}
}
}
stepCount = motionController.NbSteps();
if (stepCount.IsUpdated() || themeChanged) {
lv_label_set_text_fmt(stepValue, "%lu steps", stepCount.Get());
}
if (themeChanged) {
themeChanged = false;
}
}
void WatchFacePrideFlag::UpdateSelected(lv_obj_t* object, lv_event_t event) {
if (event == LV_EVENT_CLICKED) {
auto valueFlag = settingsController.GetPrideFlag();
bool flagChanged = false;
if (object == btnClose) {
CloseMenu();
}
if (object == btnNextFlag) {
valueFlag = GetNext(valueFlag);
flagChanged = true;
}
if (object == btnPrevFlag) {
valueFlag = GetPrevious(valueFlag);
flagChanged = true;
}
settingsController.SetPrideFlag(valueFlag);
if (flagChanged) {
UpdateScreen(valueFlag);
}
}
}
bool WatchFacePrideFlag::OnButtonPushed() {
if (!lv_obj_get_hidden(btnClose)) {
CloseMenu();
return true;
}
return false;
}
void WatchFacePrideFlag::UpdateScreen(const Pinetime::Controllers::Settings::PrideFlag prideFlag) {
auto UseFlagData = [this]<size_t N>(PrideFlagData<N> flagData) {
backgroundSections.reserve(N);
for (size_t i = 0; i < N; i++) {
backgroundSections.push_back(lv_obj_create(lv_scr_act(), nullptr));
lv_obj_set_style_local_bg_color(backgroundSections[i], LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, flagData.sectionColours[i]);
lv_obj_set_size(backgroundSections[i], LV_HOR_RES, (LV_VER_RES / N) + 1);
lv_obj_set_pos(backgroundSections[i], 0, i * LV_VER_RES / N);
lv_obj_set_style_local_radius(backgroundSections[i], LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 0);
lv_obj_move_background(backgroundSections[i]);
}
lv_obj_set_style_local_text_color(labelTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, flagData.labelTimeColour);
lv_obj_set_style_local_text_color(batteryValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, flagData.defaultTopLabelColour);
lv_obj_set_style_local_text_color(labelDate, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, flagData.defaultTopLabelColour);
lv_obj_set_style_local_text_color(labelDay, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, flagData.defaultBottomLabelColour);
lv_obj_set_style_local_text_color(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, flagData.defaultBottomLabelColour);
lv_obj_align(batteryValue, lv_scr_act(), LV_ALIGN_CENTER, 0, -2 * flagData.spacing);
lv_obj_align(labelDate, lv_scr_act(), LV_ALIGN_CENTER, 0, -1 * flagData.spacing);
lv_obj_align(labelDay, lv_scr_act(), LV_ALIGN_CENTER, 0, flagData.spacing);
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, 2 * flagData.spacing);
};
themeChanged = true;
for (lv_obj_t* backgroundSection : backgroundSections) {
lv_obj_del(backgroundSection);
}
backgroundSections.clear();
switch (prideFlag) {
case Pinetime::Controllers::Settings::PrideFlag::Gay:
UseFlagData(gayFlagData);
break;
case Pinetime::Controllers::Settings::PrideFlag::Trans:
UseFlagData(transFlagData);
break;
case Pinetime::Controllers::Settings::PrideFlag::Bi:
UseFlagData(biFlagData);
break;
case Pinetime::Controllers::Settings::PrideFlag::Lesbian:
UseFlagData(lesbianFlagData);
break;
}
}

View file

@ -1,102 +0,0 @@
#pragma once
#include <lvgl/src/lv_core/lv_obj.h>
#include <chrono>
#include <vector>
#include <cstdint>
#include <array>
#include <FreeRTOS.h>
#include "displayapp/screens/Screen.h"
#include "utility/DirtyValue.h"
#include "components/settings/Settings.h"
#include "components/battery/BatteryController.h"
namespace Pinetime {
namespace Controllers {
class Settings;
class Battery;
class Ble;
class NotificationManager;
class MotionController;
}
namespace Applications {
namespace Screens {
class WatchFacePrideFlag : public Screen {
public:
WatchFacePrideFlag(Controllers::DateTime& dateTimeController,
const Controllers::Battery& batteryController,
const Controllers::Ble& bleController,
Controllers::NotificationManager& notificationManager,
Controllers::Settings& settingsController,
Controllers::MotionController& motionController);
~WatchFacePrideFlag() override;
bool OnTouchEvent(TouchEvents event) override;
bool OnButtonPushed() override;
void Refresh() override;
void UpdateSelected(lv_obj_t* object, lv_event_t event);
private:
void UpdateScreen(Pinetime::Controllers::Settings::PrideFlag);
Utility::DirtyValue<uint8_t> batteryPercentRemaining;
Utility::DirtyValue<bool> powerPresent;
Utility::DirtyValue<bool> bleState;
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds>> currentDateTime;
Utility::DirtyValue<uint32_t> stepCount;
Utility::DirtyValue<bool> notificationState;
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::days>> currentDate;
// Must be wrapped in a dirty value, since it is displayed in the day but is updated twice a day
Utility::DirtyValue<const char*> ampmChar {"AM"};
TickType_t savedTick = 0;
std::vector<lv_obj_t*> backgroundSections;
bool themeChanged = false;
lv_obj_t* bluetoothStatus;
lv_obj_t* labelTime;
lv_obj_t* labelDate;
lv_obj_t* labelDay;
lv_obj_t* batteryValue;
lv_obj_t* stepValue;
lv_obj_t* notificationText;
lv_obj_t* btnClose;
lv_obj_t* btnNextFlag;
lv_obj_t* btnPrevFlag;
Controllers::DateTime& dateTimeController;
const Controllers::Battery& batteryController;
const Controllers::Ble& bleController;
Controllers::NotificationManager& notificationManager;
Controllers::Settings& settingsController;
Controllers::MotionController& motionController;
lv_task_t* taskRefresh;
void CloseMenu();
};
}
template <>
struct WatchFaceTraits<WatchFace::PrideFlag> {
static constexpr WatchFace watchFace = WatchFace::PrideFlag;
static constexpr const char* name = "Pride Flag";
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::WatchFacePrideFlag(controllers.dateTimeController,
controllers.batteryController,
controllers.bleController,
controllers.notificationManager,
controllers.settingsController,
controllers.motionController);
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
}
};
}
}

View file

@ -1,7 +1,5 @@
#include "displayapp/screens/Weather.h"
#include <lvgl/lvgl.h>
#include "components/ble/SimpleWeatherService.h"
#include "components/datetime/DateTimeController.h"
#include "components/settings/Settings.h"
@ -12,27 +10,31 @@
using namespace Pinetime::Applications::Screens;
namespace {
lv_color_t TemperatureColor(Pinetime::Controllers::SimpleWeatherService::Temperature temp) {
if (temp.Celsius() <= 0) { // freezing
lv_color_t TemperatureColor(int16_t temperature) {
if (temperature <= 0) { // freezing
return Colors::blue;
} else if (temp.Celsius() <= 4) { // ice
} else if (temperature <= 400) { // ice
return LV_COLOR_CYAN;
} else if (temp.Celsius() >= 27) { // hot
} else if (temperature >= 2700) { // hot
return Colors::deepOrange;
}
return Colors::orange; // normal
}
uint8_t TemperatureStyle(Pinetime::Controllers::SimpleWeatherService::Temperature temp) {
if (temp.Celsius() <= 0) { // freezing
uint8_t TemperatureStyle(int16_t temperature) {
if (temperature <= 0) { // freezing
return LV_TABLE_PART_CELL3;
} else if (temp.Celsius() <= 4) { // ice
} else if (temperature <= 400) { // ice
return LV_TABLE_PART_CELL4;
} else if (temp.Celsius() >= 27) { // hot
} else if (temperature >= 2700) { // hot
return LV_TABLE_PART_CELL6;
}
return LV_TABLE_PART_CELL5; // normal
}
int16_t RoundTemperature(int16_t temp) {
return temp = temp / 100 + (temp % 100 >= 50 ? 1 : 0);
}
}
Weather::Weather(Controllers::Settings& settingsController, Controllers::SimpleWeatherService& weatherService)
@ -118,25 +120,22 @@ void Weather::Refresh() {
if (currentWeather.IsUpdated()) {
auto optCurrentWeather = currentWeather.Get();
if (optCurrentWeather) {
int16_t temp = optCurrentWeather->temperature.Celsius();
int16_t minTemp = optCurrentWeather->minTemperature.Celsius();
int16_t maxTemp = optCurrentWeather->maxTemperature.Celsius();
int16_t temp = optCurrentWeather->temperature;
int16_t minTemp = optCurrentWeather->minTemperature;
int16_t maxTemp = optCurrentWeather->maxTemperature;
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, TemperatureColor(temp));
char tempUnit = 'C';
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
temp = optCurrentWeather->temperature.Fahrenheit();
minTemp = optCurrentWeather->minTemperature.Fahrenheit();
maxTemp = optCurrentWeather->maxTemperature.Fahrenheit();
temp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(temp);
minTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(minTemp);
maxTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(maxTemp);
tempUnit = 'F';
}
lv_obj_set_style_local_text_color(temperature,
LV_LABEL_PART_MAIN,
LV_STATE_DEFAULT,
TemperatureColor(optCurrentWeather->temperature));
lv_label_set_text(icon, Symbols::GetSymbol(optCurrentWeather->iconId));
lv_label_set_text(condition, Symbols::GetCondition(optCurrentWeather->iconId));
lv_label_set_text_fmt(temperature, "%d°%c", temp, tempUnit);
lv_label_set_text_fmt(minTemperature, "%d°", minTemp);
lv_label_set_text_fmt(maxTemperature, "%d°", maxTemp);
lv_label_set_text_fmt(temperature, "%d°%c", RoundTemperature(temp), tempUnit);
lv_label_set_text_fmt(minTemperature, "%d°", RoundTemperature(minTemp));
lv_label_set_text_fmt(maxTemperature, "%d°", RoundTemperature(maxTemp));
} else {
lv_label_set_text(icon, "");
lv_label_set_text(condition, "");
@ -153,22 +152,24 @@ void Weather::Refresh() {
if (optCurrentForecast) {
std::tm localTime = *std::localtime(reinterpret_cast<const time_t*>(&optCurrentForecast->timestamp));
for (int i = 0; i < optCurrentForecast->nbDays; i++) {
int16_t maxTemp = optCurrentForecast->days[i]->maxTemperature.Celsius();
int16_t minTemp = optCurrentForecast->days[i]->minTemperature.Celsius();
for (int i = 0; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) {
int16_t maxTemp = optCurrentForecast->days[i].maxTemperature;
int16_t minTemp = optCurrentForecast->days[i].minTemperature;
lv_table_set_cell_type(forecast, 2, i, TemperatureStyle(maxTemp));
lv_table_set_cell_type(forecast, 3, i, TemperatureStyle(minTemp));
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
maxTemp = optCurrentForecast->days[i]->maxTemperature.Fahrenheit();
minTemp = optCurrentForecast->days[i]->minTemperature.Fahrenheit();
maxTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(maxTemp);
minTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(minTemp);
}
lv_table_set_cell_type(forecast, 2, i, TemperatureStyle(optCurrentForecast->days[i]->maxTemperature));
lv_table_set_cell_type(forecast, 3, i, TemperatureStyle(optCurrentForecast->days[i]->minTemperature));
uint8_t wday = localTime.tm_wday + i + 1;
if (wday > 7) {
wday -= 7;
}
maxTemp = RoundTemperature(maxTemp);
minTemp = RoundTemperature(minTemp);
const char* dayOfWeek = Controllers::DateTime::DayOfWeekShortToStringLow(static_cast<Controllers::DateTime::Days>(wday));
lv_table_set_cell_value(forecast, 0, i, dayOfWeek);
lv_table_set_cell_value(forecast, 1, i, Symbols::GetSymbol(optCurrentForecast->days[i]->iconId));
lv_table_set_cell_value(forecast, 1, i, Symbols::GetSymbol(optCurrentForecast->days[i].iconId));
// Pad cells based on the largest number of digits on each column
char maxPadding[3] = " ";
char minPadding[3] = " ";

View file

@ -51,10 +51,6 @@ namespace Pinetime {
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::Weather(controllers.settingsController, *controllers.weatherController);
};
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {
return true;
};
};
}
}

View file

@ -33,14 +33,13 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app,
Controllers::BrightnessController& brightness,
Controllers::MotorController& motorController,
Pinetime::Controllers::Settings& settingsController,
const Controllers::Ble& bleController,
const Controllers::AlarmController& alarmController)
const Controllers::Ble& bleController)
: app {app},
dateTimeController {dateTimeController},
brightness {brightness},
motorController {motorController},
settingsController {settingsController},
statusIcons(batteryController, bleController, alarmController) {
statusIcons(batteryController, bleController) {
statusIcons.Create();

View file

@ -23,8 +23,7 @@ namespace Pinetime {
Controllers::BrightnessController& brightness,
Controllers::MotorController& motorController,
Pinetime::Controllers::Settings& settingsController,
const Controllers::Ble& bleController,
const Controllers::AlarmController& alarmController);
const Controllers::Ble& bleController);
~QuickSettings() override;

View file

@ -24,7 +24,8 @@ namespace {
constexpr std::array<uint16_t, 6> SettingDisplay::options;
SettingDisplay::SettingDisplay(Pinetime::Controllers::Settings& settingsController) : settingsController {settingsController} {
SettingDisplay::SettingDisplay(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
: app {app}, settingsController {settingsController} {
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr);

Some files were not shown because too many files have changed in this diff Show more