diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index c5f88a827b..a90f78d8e4 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -2,7 +2,7 @@ "env": { // TODO: This is a duplication of the configuration set in /docker/build.sh! "TOOLS_DIR": "/opt", - "GCC_ARM_PATH": "gcc-arm-none-eabi-10.3-2021.10" + "GCC_ARM_PATH": "arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-eabi" }, "configurations": [ { diff --git a/.vscode/launch.json b/.vscode/launch.json index 7d3f17a11c..afd37c9ead 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -53,7 +53,7 @@ "continue" ], // Only use armToolchainPath if your arm-none-eabi-gdb is not in your path (some GCC packages does not contain arm-none-eabi-gdb) - "armToolchainPath": "${workspaceRoot}/../gcc-arm-none-eabi-10.3-2021.10/bin", + "armToolchainPath": "${workspaceRoot}/../arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-eabi/bin", "svdFile": "${workspaceRoot}/nrf52.svd", "configFiles": [ "interface/stlink.cfg", @@ -68,7 +68,7 @@ "request": "launch", "servertype": "external", // FIXME: This is hardcoded. I have no idea how to use the values set in build.sh here - "gdbPath": "/opt/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gdb", + "gdbPath": "/opt/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb", // Connect to an already running OpenOCD instance "gdbTarget": "host.docker.internal:3333", "svdFile": "${workspaceRoot}/nrf52.svd", diff --git a/doc/buildAndProgram.md b/doc/buildAndProgram.md index 5d3af46ef0..8fb765a009 100644 --- a/doc/buildAndProgram.md +++ b/doc/buildAndProgram.md @@ -4,7 +4,7 @@ To build this project, you'll need: -- A cross-compiler : [ARM-GCC (10.3-2021.10)](https://developer.arm.com/downloads/-/gnu-rm) +- A cross-compiler : [ARM-GCC 15.2-Rel1 from December 17, 2025 (AArch32 bare-metal target (arm-none-eabi))](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads) - 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 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`) @@ -38,7 +38,7 @@ CMake configures the project according to variables you specify the command line Variable | Description | Example| ----------|-------------|--------| -**ARM_NONE_EABI_TOOLCHAIN_PATH**|path to the toolchain directory|`-DARM_NONE_EABI_TOOLCHAIN_PATH=/home/jf/nrf52/gcc-arm-none-eabi-10.3-2021.10/`| +**ARM_NONE_EABI_TOOLCHAIN_PATH**|path to the toolchain directory|`-DARM_NONE_EABI_TOOLCHAIN_PATH=/home/jf/nrf52/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-eabi/`| **NRF5_SDK_PATH**|path to the NRF52 SDK|`-DNRF5_SDK_PATH=/home/jf/nrf52/Pinetime/sdk`| **CMAKE_BUILD_TYPE (\*)**| Build type (Release or Debug). Release is applied by default if this variable is not specified.|`-DCMAKE_BUILD_TYPE=Debug` **BUILD_DFU (\*\*)**|Build DFU files while building (needs [adafruit-nrfutil](https://github.com/adafruit/Adafruit_nRF52_nrfutil)).|`-DBUILD_DFU=1` diff --git a/doc/buildWithVScode.md b/doc/buildWithVScode.md index 5f8724828a..9d9575356b 100644 --- a/doc/buildWithVScode.md +++ b/doc/buildWithVScode.md @@ -8,7 +8,7 @@ To support as many setups as possible the VS Code configuration files expect the Variable | Description | Example ----------|-------------|-------- -**ARM_NONE_EABI_TOOLCHAIN_PATH**|path to the toolchain directory|`export ARM_NONE_EABI_TOOLCHAIN_PATH=/opt/gcc-arm-none-eabi-10.3-2021.10` +**ARM_NONE_EABI_TOOLCHAIN_PATH**|path to the toolchain directory|`export ARM_NONE_EABI_TOOLCHAIN_PATH=/opt/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-eabi` **NRF5_SDK_PATH**|path to the NRF52 SDK|`export NRF5_SDK_PATH=/opt/nRF5_SDK_15.3.0_59ac345` ## VS Code Extensions diff --git a/doc/gettingStarted/Watchfaces.md b/doc/gettingStarted/Watchfaces.md index 9edff0bb51..a1e820f9ba 100644 --- a/doc/gettingStarted/Watchfaces.md +++ b/doc/gettingStarted/Watchfaces.md @@ -29,3 +29,7 @@ InfiniTime has 6 apps on the `main` branch at the time of writing. ### Casio G7710 ![Casio G7710 face](/doc/gettingStarted/Watchfaces/CasioG7710.png) + +### Pride Flag +![Pride flag face](/doc/gettingStarted/Watchfaces/Pride.png) + - You can long-press on the display to change flags. (Gay, Lesbian, Bi, Trans, Non-binary, Aromantic, Asexual, AroAce, Pansexual) \ No newline at end of file diff --git a/doc/gettingStarted/Watchfaces/Pride.png b/doc/gettingStarted/Watchfaces/Pride.png new file mode 100644 index 0000000000..7e97295cea Binary files /dev/null and b/doc/gettingStarted/Watchfaces/Pride.png differ diff --git a/docker/build.sh b/docker/build.sh index 04963ea0ab..d4470f2eb3 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -16,7 +16,7 @@ export NPM_DIR="$BUILD_DIR/npm" export npm_config_cache="${NPM_DIR}" export BUILD_TYPE=${BUILD_TYPE:=Release} -export GCC_ARM_VER=${GCC_ARM_VER:="10.3-2021.10"} +export GCC_ARM_VER=${GCC_ARM_VER:="15.2.rel1"} 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 @@ -26,7 +26,7 @@ export NRF_SDK_VER_SLUG=${NRF_SDK_VER_SLUG//[_.]/} MACHINE="$(uname -m)" [ "$MACHINE" = "arm64" ] && MACHINE="aarch64" -export GCC_ARM_PATH="gcc-arm-none-eabi-$GCC_ARM_VER" +export GCC_ARM_PATH="arm-gnu-toolchain-$GCC_ARM_VER-$MACHINE-arm-none-eabi" main() { local target="$1" @@ -50,7 +50,7 @@ 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/ + wget -q https://developer.arm.com/-/media/Files/downloads/gnu/$GCC_ARM_VER/binrel/$GCC_ARM_PATH.tar.xz -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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e4a354df64..faef4160da 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -930,7 +930,7 @@ target_compile_options(${EXECUTABLE_NAME} PUBLIC set_target_properties(${EXECUTABLE_NAME} PROPERTIES SUFFIX ".out" - LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT} --specs=nosys.specs -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Wl,--print-memory-usage --specs=nano.specs -Wl,-Map=${EXECUTABLE_FILE_NAME}.map" + LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Wl,--print-memory-usage --specs=nano.specs -Wl,-Map=${EXECUTABLE_FILE_NAME}.map" ) add_custom_command(TARGET ${EXECUTABLE_NAME} @@ -965,7 +965,7 @@ target_compile_options(${EXECUTABLE_MCUBOOT_NAME} PUBLIC set_target_properties(${EXECUTABLE_MCUBOOT_NAME} PROPERTIES SUFFIX ".out" - LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT_MCUBOOT} --specs=nosys.specs -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Wl,--print-memory-usage --specs=nano.specs -Wl,-Map=${EXECUTABLE_MCUBOOT_FILE_NAME}.map" + LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT_MCUBOOT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Wl,--print-memory-usage --specs=nano.specs -Wl,-Map=${EXECUTABLE_MCUBOOT_FILE_NAME}.map" ) add_custom_command(TARGET ${EXECUTABLE_MCUBOOT_NAME} @@ -1008,7 +1008,7 @@ target_compile_options(${EXECUTABLE_RECOVERY_NAME} PUBLIC set_target_properties(${EXECUTABLE_RECOVERY_NAME} PROPERTIES SUFFIX ".out" - LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT} --specs=nosys.specs -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Wl,--print-memory-usage --specs=nano.specs -Wl,-Map=${EXECUTABLE_RECOVERY_FILE_NAME}.map" + LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Wl,--print-memory-usage --specs=nano.specs -Wl,-Map=${EXECUTABLE_RECOVERY_FILE_NAME}.map" ) add_custom_command(TARGET ${EXECUTABLE_RECOVERY_NAME} @@ -1040,7 +1040,7 @@ target_compile_options(${EXECUTABLE_RECOVERY_MCUBOOT_NAME} PUBLIC set_target_properties(${EXECUTABLE_RECOVERY_MCUBOOT_NAME} PROPERTIES SUFFIX ".out" - LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT_MCUBOOT} --specs=nosys.specs -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Wl,--print-memory-usage --specs=nano.specs -Wl,-Map=${EXECUTABLE_GRAPHICS_FILE_NAME}.map" + LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT_MCUBOOT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Wl,--print-memory-usage --specs=nano.specs -Wl,-Map=${EXECUTABLE_GRAPHICS_FILE_NAME}.map" ) add_custom_command(TARGET ${EXECUTABLE_RECOVERY_MCUBOOT_NAME} @@ -1083,7 +1083,7 @@ add_dependencies(${EXECUTABLE_RECOVERYLOADER_NAME} ${EXECUTABLE_RECOVERY_MCUBOOT set_target_properties(${EXECUTABLE_RECOVERYLOADER_NAME} PROPERTIES SUFFIX ".out" - LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT} --specs=nosys.specs -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Wl,--print-memory-usage --specs=nano.specs -Wl,-Map=${EXECUTABLE_RECOVERYLOADER_FILE_NAME}.map" + LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Wl,--print-memory-usage --specs=nano.specs -Wl,-Map=${EXECUTABLE_RECOVERYLOADER_FILE_NAME}.map" ) add_custom_command(TARGET ${EXECUTABLE_RECOVERYLOADER_NAME} @@ -1118,7 +1118,7 @@ add_dependencies(${EXECUTABLE_MCUBOOT_RECOVERYLOADER_NAME} ${EXECUTABLE_RECOVERY set_target_properties(${EXECUTABLE_MCUBOOT_RECOVERYLOADER_NAME} PROPERTIES SUFFIX ".out" - LINK_FLAGS "-mthumb -mabi=aapcs -std=gnu++98 -std=c99 -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT_MCUBOOT} --specs=nosys.specs -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Wl,--print-memory-usage --specs=nano.specs -Wl,-Map=${EXECUTABLE_MCUBOOT_RECOVERYLOADER_FILE_NAME}.map" + LINK_FLAGS "-mthumb -mabi=aapcs -std=gnu++98 -std=c99 -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT_MCUBOOT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Wl,--print-memory-usage --specs=nano.specs -Wl,-Map=${EXECUTABLE_MCUBOOT_RECOVERYLOADER_FILE_NAME}.map" ) add_custom_command(TARGET ${EXECUTABLE_MCUBOOT_RECOVERYLOADER_NAME} diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 9133d3fea1..93b484336d 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -39,7 +39,7 @@ 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 PrideFlag : uint8_t { Gay, Trans, Bi, Lesbian, Nonbinary, Ace, Aro, AroAce, Pan }; enum class DfuAndFsMode : uint8_t { Disabled, Enabled, EnabledTillReboot }; struct PineTimeStyle { diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 84fa603622..6f33635e20 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -377,11 +377,10 @@ void DisplayApp::Refresh() { // Load timer app if not loaded if (currentApp != Apps::Timer) { LoadNewScreen(Apps::Timer, DisplayApp::FullRefreshDirections::Up); - } else { - // Set the timer to ringing mode if already loaded - auto* timerScreen = static_cast(currentScreen.get()); - timerScreen->SetTimerRinging(); } + // Set the timer to ringing mode + auto* timerScreen = static_cast(currentScreen.get()); + timerScreen->SetTimerRinging(); break; } case Messages::AlarmTriggered: diff --git a/src/displayapp/fonts/fonts.json b/src/displayapp/fonts/fonts.json index 3221c2f171..9c113f0fdb 100644 --- a/src/displayapp/fonts/fonts.json +++ b/src/displayapp/fonts/fonts.json @@ -28,7 +28,7 @@ "sources": [ { "file": "JetBrainsMono-Light.ttf", - "range": "0x25, 0x2D, 0x2F, 0x30-0x3a, 0x43, 0x46, 0xb0" + "range": "0x25, 0x2B, 0x2D, 0x2F, 0x30-0x3a, 0x43, 0x46, 0xb0" } ], "bpp": 1, diff --git a/src/displayapp/icons/music/disc.c b/src/displayapp/icons/music/disc.c deleted file mode 100644 index 0957873f87..0000000000 --- a/src/displayapp/icons/music/disc.c +++ /dev/null @@ -1,110 +0,0 @@ -/* Copyright (C) 2020 Avamander - - This file is part of InfiniTime. - - InfiniTime is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - InfiniTime is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -#pragma once - -#include "lvgl/lvgl.h" - -#ifndef LV_ATTRIBUTE_MEM_ALIGN -#define LV_ATTRIBUTE_MEM_ALIGN -#endif - -#ifndef LV_ATTRIBUTE_IMG_DISC -#define LV_ATTRIBUTE_IMG_DISC -#endif - -const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_IMG_DISC uint8_t disc_map[] = { - 0xbd, 0xc1, 0xbe, 0xff, /* Color of index 0: foreground */ - 0x00, 0x00, 0x00, 0x00, /* Color of index 1: background */ - - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xc0, 0x01, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xfc, 0x00, 0x00, 0x1f, 0xff, 0xff, - 0xff, 0xff, 0xf0, 0x0f, 0xf8, 0x07, 0xff, 0xff, - 0xff, 0xff, 0xc0, 0xff, 0xff, 0x81, 0xff, 0xff, - 0xff, 0xff, 0x07, 0xff, 0xff, 0xf0, 0x7f, 0xff, - 0xff, 0xfc, 0x1f, 0xff, 0xff, 0xfc, 0x1f, 0xff, - 0xff, 0xf8, 0x7f, 0xff, 0xff, 0xff, 0x0f, 0xff, - 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x87, 0xff, - 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xe3, 0xff, - 0xff, 0xc7, 0xff, 0xff, 0xff, 0xff, 0xf1, 0xff, - 0xff, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, - 0xff, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x7f, - 0xfe, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x3f, - 0xfc, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, - 0xfc, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, - 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, - 0xf9, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, - 0xf1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc7, - 0xf3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, - 0xe3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe3, - 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, - 0xc7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, - 0xc7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, - 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf9, - 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf9, - 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, - 0x8f, 0xff, 0xff, 0xf8, 0x0f, 0xff, 0xff, 0xf8, - 0x9f, 0xff, 0xff, 0xf0, 0x07, 0xff, 0xff, 0xfc, - 0x9f, 0xff, 0xff, 0xe3, 0xe3, 0xff, 0xff, 0xfc, - 0x9f, 0xff, 0xff, 0xe7, 0xf3, 0xff, 0xff, 0xfc, - 0x9f, 0xff, 0xff, 0xe7, 0xf3, 0xff, 0xff, 0xfc, - 0x9f, 0xff, 0xff, 0xe7, 0xf3, 0xff, 0xff, 0xfc, - 0x9f, 0xff, 0xff, 0xe7, 0xf3, 0xff, 0xff, 0xfc, - 0x9f, 0xff, 0xff, 0xe7, 0xf3, 0xff, 0xff, 0xfc, - 0x9f, 0xff, 0xff, 0xe3, 0xe3, 0xff, 0xff, 0xfc, - 0x9f, 0xff, 0xff, 0xf0, 0x07, 0xff, 0xff, 0xfc, - 0x8f, 0xff, 0xff, 0xf8, 0x0f, 0xff, 0xff, 0xf8, - 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, - 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf9, - 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf9, - 0xc7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, - 0xc7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, - 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, - 0xe3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe3, - 0xf3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, - 0xf1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc7, - 0xf9, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, - 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, - 0xfc, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, - 0xfc, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, - 0xfe, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x3f, - 0xff, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x7f, - 0xff, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, - 0xff, 0xc7, 0xff, 0xff, 0xff, 0xff, 0xf1, 0xff, - 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xe3, 0xff, - 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x87, 0xff, - 0xff, 0xf8, 0x7f, 0xff, 0xff, 0xff, 0x0f, 0xff, - 0xff, 0xfc, 0x1f, 0xff, 0xff, 0xfc, 0x1f, 0xff, - 0xff, 0xff, 0x07, 0xff, 0xff, 0xf0, 0x7f, 0xff, - 0xff, 0xff, 0xc0, 0xff, 0xff, 0x81, 0xff, 0xff, - 0xff, 0xff, 0xf0, 0x0f, 0xf8, 0x07, 0xff, 0xff, - 0xff, 0xff, 0xfc, 0x00, 0x00, 0x1f, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xc0, 0x01, 0xff, 0xff, 0xff, -}; - -const lv_img_dsc_t disc = { - { - LV_IMG_CF_INDEXED_1BIT, - 0, - 0, - 64, - 64 - }, - 520, - disc_map -}; \ No newline at end of file diff --git a/src/displayapp/icons/music/disc.png b/src/displayapp/icons/music/disc.png deleted file mode 100644 index 699734fb9c..0000000000 Binary files a/src/displayapp/icons/music/disc.png and /dev/null differ diff --git a/src/displayapp/icons/music/disc_f_1.c b/src/displayapp/icons/music/disc_f_1.c deleted file mode 100644 index 9b6b74177f..0000000000 --- a/src/displayapp/icons/music/disc_f_1.c +++ /dev/null @@ -1,79 +0,0 @@ -/* Copyright (C) 2020 Avamander - - This file is part of InfiniTime. - - InfiniTime is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - InfiniTime is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -#pragma once - -#include "lvgl/lvgl.h" - -#ifndef LV_ATTRIBUTE_MEM_ALIGN -#define LV_ATTRIBUTE_MEM_ALIGN -#endif - -#ifndef LV_ATTRIBUTE_IMG_DISC_F_1 -#define LV_ATTRIBUTE_IMG_DISC_F_1 -#endif - -const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_IMG_DISC_F_1 uint8_t disc_f_1_map[] = { - 0xbd, 0xc1, 0xbe, 0xff, /* Color of index 0: foreground */ - 0x00, 0x00, 0x00, 0x00, /* Color of index 1: background */ - - 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xc0, - 0xff, 0xff, 0xfc, 0x00, - 0xff, 0xff, 0xf0, 0x0f, - 0xff, 0xff, 0xc0, 0xff, - 0xff, 0xff, 0x07, 0xff, - 0xff, 0xfc, 0x1f, 0xff, - 0xff, 0xf8, 0x7f, 0xff, - 0xff, 0xf0, 0xff, 0xff, - 0xff, 0xe3, 0xff, 0xff, - 0xff, 0xc7, 0xf3, 0xff, - 0xff, 0x8f, 0xc3, 0xff, - 0xff, 0x1f, 0x87, 0xff, - 0xfe, 0x3f, 0x0f, 0xff, - 0xfc, 0x7e, 0x1f, 0xff, - 0xfc, 0x7c, 0x3f, 0xff, - 0xf8, 0xfc, 0x7f, 0xff, - 0xf9, 0xfc, 0xff, 0xff, - 0xf1, 0xff, 0xff, 0xff, - 0xf3, 0xff, 0xff, 0xff, - 0xe3, 0xff, 0xff, 0xff, - 0xe7, 0xff, 0xff, 0xff, - 0xc7, 0xff, 0xff, 0xff, - 0xc7, 0xff, 0xff, 0xff, - 0xcf, 0xff, 0xff, 0xff, - 0xcf, 0xff, 0xff, 0xff, - 0x8f, 0xff, 0xff, 0xff, - 0x8f, 0xff, 0xff, 0xf8, - 0x9f, 0xff, 0xff, 0xf0, - 0x9f, 0xff, 0xff, 0xe3, - 0x9f, 0xff, 0xff, 0xe7, - 0x9f, 0xff, 0xff, 0xe7, -}; - -const lv_img_dsc_t disc_f_1 = { - { - LV_IMG_CF_INDEXED_1BIT, - 0, - 0, - 32, - 32 - }, - 136, - disc_f_1_map -}; - diff --git a/src/displayapp/icons/music/disc_f_1.png b/src/displayapp/icons/music/disc_f_1.png deleted file mode 100644 index 946577344a..0000000000 Binary files a/src/displayapp/icons/music/disc_f_1.png and /dev/null differ diff --git a/src/displayapp/icons/music/disc_f_2.c b/src/displayapp/icons/music/disc_f_2.c deleted file mode 100644 index 3d2331d171..0000000000 --- a/src/displayapp/icons/music/disc_f_2.c +++ /dev/null @@ -1,79 +0,0 @@ -/* Copyright (C) 2020 Avamander - - This file is part of InfiniTime. - - InfiniTime is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - InfiniTime is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -#pragma once - -#include "lvgl/lvgl.h" - -#ifndef LV_ATTRIBUTE_MEM_ALIGN -#define LV_ATTRIBUTE_MEM_ALIGN -#endif - -#ifndef LV_ATTRIBUTE_IMG_DISC_F_2 -#define LV_ATTRIBUTE_IMG_DISC_F_2 -#endif - -const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_IMG_DISC_F_2 uint8_t disc_f_2_map[] = { - 0xbd, 0xc1, 0xbe, 0xff, /* Color of index 0: foreground */ - 0x00, 0x00, 0x00, 0x00, /* Color of index 1: background */ - - 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xc0, - 0xff, 0xff, 0xfc, 0x00, - 0xff, 0xff, 0xf0, 0x0f, - 0xff, 0xff, 0xc0, 0xff, - 0xff, 0xff, 0x07, 0xff, - 0xff, 0xfc, 0x1f, 0xff, - 0xff, 0xf8, 0x7f, 0xf1, - 0xff, 0xf0, 0xff, 0x00, - 0xff, 0xe3, 0xfc, 0x03, - 0xff, 0xc7, 0xf0, 0x3f, - 0xff, 0x8f, 0xf0, 0xff, - 0xff, 0x1f, 0xf3, 0xff, - 0xfe, 0x3f, 0xff, 0xff, - 0xfc, 0x7f, 0xff, 0xff, - 0xfc, 0x7f, 0xff, 0xff, - 0xf8, 0xff, 0xff, 0xff, - 0xf9, 0xff, 0xff, 0xff, - 0xf1, 0xff, 0xff, 0xff, - 0xf3, 0xff, 0xff, 0xff, - 0xe3, 0xff, 0xff, 0xff, - 0xe7, 0xff, 0xff, 0xff, - 0xc7, 0xff, 0xff, 0xff, - 0xc7, 0xff, 0xff, 0xff, - 0xcf, 0xff, 0xff, 0xff, - 0xcf, 0xff, 0xff, 0xff, - 0x8f, 0xff, 0xff, 0xff, - 0x8f, 0xff, 0xff, 0xf8, - 0x9f, 0xff, 0xff, 0xf0, - 0x9f, 0xff, 0xff, 0xe3, - 0x9f, 0xff, 0xff, 0xe7, - 0x9f, 0xff, 0xff, 0xe7, -}; - -const lv_img_dsc_t disc_f_2 = { - { - LV_IMG_CF_INDEXED_1BIT, - 0, - 0, - 32, - 32 - }, - 136, - disc_f_2_map -}; - diff --git a/src/displayapp/icons/music/disc_f_2.png b/src/displayapp/icons/music/disc_f_2.png deleted file mode 100644 index 4d9a4a388a..0000000000 Binary files a/src/displayapp/icons/music/disc_f_2.png and /dev/null differ diff --git a/src/displayapp/screens/Alarm.cpp b/src/displayapp/screens/Alarm.cpp index 4cf4392157..4fc1e142db 100644 --- a/src/displayapp/screens/Alarm.cpp +++ b/src/displayapp/screens/Alarm.cpp @@ -74,6 +74,14 @@ Alarm::Alarm(Controllers::AlarmController& alarmController, lv_label_set_text_static(colonLabel, ":"); lv_obj_align(colonLabel, lv_scr_act(), LV_ALIGN_CENTER, 0, -29); + progressStop = lv_bar_create(lv_scr_act(), nullptr); + lv_bar_set_range(progressStop, 0, progressBarSize); + lv_bar_set_value(progressStop, 0, LV_ANIM_OFF); + lv_obj_set_size(progressStop, progressBarSize, 10); + lv_obj_align(progressStop, nullptr, LV_ALIGN_IN_TOP_MID, 0, 0); + lv_obj_set_style_local_bg_color(progressStop, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_ORANGE); + lv_obj_set_hidden(progressStop, true); + btnStop = lv_btn_create(lv_scr_act(), nullptr); btnStop->user_data = this; lv_obj_set_event_cb(btnStop, btnEventHandler); @@ -122,12 +130,28 @@ Alarm::Alarm(Controllers::AlarmController& alarmController, } else { SetSwitchState(LV_ANIM_OFF); } + + taskRefresh = lv_task_create(RefreshTaskCallback, 50, LV_TASK_PRIO_MID, this); +} + +void Alarm::Refresh() { + if (stopBtnPressTime.has_value()) { + TickType_t elapsed = xTaskGetTickCount() - stopBtnPressTime.value(); + if (elapsed >= longPressTimeout) { + ResetStopProgress(); + StopAlerting(); + } else { + lv_coord_t stopPosition = (elapsed * progressBarSize) / longPressTimeout; + UpdateStopProgress(stopPosition); + } + } } Alarm::~Alarm() { if (alarmController.IsAlerting()) { StopAlerting(); } + lv_task_del(taskRefresh); lv_obj_clean(lv_scr_act()); alarmController.SaveAlarm(); } @@ -139,12 +163,32 @@ void Alarm::DisableAlarm() { } } +void Alarm::StopButtonPressed() { + stopBtnPressTime = xTaskGetTickCount(); + UpdateStopProgress(0); + lv_obj_set_hidden(progressStop, false); +} + +void Alarm::ResetStopProgress() { + stopBtnPressTime = std::nullopt; + lv_obj_set_hidden(progressStop, true); + UpdateStopProgress(0); +} + +void Alarm::UpdateStopProgress(lv_coord_t stopPosition) { + lv_bar_set_value(progressStop, progressBarSize - stopPosition, LV_ANIM_OFF); +} + void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { - if (event == LV_EVENT_CLICKED) { - if (obj == btnStop) { - StopAlerting(); - return; + if (obj == btnStop) { + if (event == LV_EVENT_PRESSED) { + StopButtonPressed(); + } else if (event == LV_EVENT_RELEASED || event == LV_EVENT_PRESS_LOST) { + ResetStopProgress(); } + return; + } + if (event == LV_EVENT_CLICKED) { if (obj == btnInfo) { ShowInfo(); return; diff --git a/src/displayapp/screens/Alarm.h b/src/displayapp/screens/Alarm.h index 2dde6e8754..a0aabd1ebf 100644 --- a/src/displayapp/screens/Alarm.h +++ b/src/displayapp/screens/Alarm.h @@ -24,6 +24,7 @@ #include "displayapp/Controllers.h" #include "systemtask/WakeLock.h" #include "Symbols.h" +#include namespace Pinetime { namespace Applications { @@ -35,12 +36,15 @@ namespace Pinetime { System::SystemTask& systemTask, Controllers::MotorController& motorController); ~Alarm() override; + void Refresh() override; void SetAlerting(); void OnButtonEvent(lv_obj_t* obj, lv_event_t event); bool OnButtonPushed() override; bool OnTouchEvent(TouchEvents event) override; void OnValueChanged(); void StopAlerting(); + void StopButtonPressed(); + void ResetStopProgress(); private: Controllers::AlarmController& alarmController; @@ -51,6 +55,7 @@ namespace Pinetime { lv_obj_t* lblampm = nullptr; lv_obj_t* txtMessage = nullptr; lv_obj_t* btnMessage = nullptr; + lv_task_t* taskRefresh = nullptr; lv_task_t* taskStopAlarm = nullptr; enum class EnableButtonState { On, Off, Alerting }; @@ -62,8 +67,14 @@ namespace Pinetime { void HideInfo(); void ToggleRecurrence(); void UpdateAlarmTime(); + void UpdateStopProgress(lv_coord_t stopPosition); Widgets::Counter hourCounter = Widgets::Counter(0, 23, jetbrains_mono_76); Widgets::Counter minuteCounter = Widgets::Counter(0, 59, jetbrains_mono_76); + + lv_obj_t* progressStop; + std::optional stopBtnPressTime; + static constexpr TickType_t longPressTimeout = pdMS_TO_TICKS(1000); + static constexpr lv_coord_t progressBarSize = 240; }; } diff --git a/src/displayapp/screens/Music.cpp b/src/displayapp/screens/Music.cpp index e1441460f7..0745c50e50 100644 --- a/src/displayapp/screens/Music.cpp +++ b/src/displayapp/screens/Music.cpp @@ -20,27 +20,27 @@ #include #include "displayapp/DisplayApp.h" #include "components/ble/MusicService.h" -#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" +#include "components/ble/BleController.h" using namespace Pinetime::Applications::Screens; -static void event_handler(lv_obj_t* obj, lv_event_t event) { - Music* screen = static_cast(obj->user_data); - screen->OnObjectEvent(obj, event); -} +namespace { + void EventHandler(lv_obj_t* obj, lv_event_t event) { + auto* screen = static_cast(obj->user_data); + screen->OnObjectEvent(obj, event); + } -/** - * Set the pixel array to display by the image - * This just calls lv_img_set_src but adds type safety - * - * @param img pointer to an image object - * @param data the image array - */ -inline void lv_img_set_src_arr(lv_obj_t* img, const lv_img_dsc_t* src_img) { - lv_img_set_src(img, src_img); + /** + * Set the pixel array to display by the image + * This just calls lv_img_set_src but adds type safety + * + * @param img pointer to an image object + * @param data the image array + */ + inline void lv_img_set_src_arr(lv_obj_t* img, const lv_img_dsc_t* src_img) { + lv_img_set_src(img, src_img); + } } /** @@ -48,8 +48,8 @@ inline void lv_img_set_src_arr(lv_obj_t* img, const lv_img_dsc_t* src_img) { * * TODO: Investigate Apple Media Service and AVRCPv1.6 support for seamless integration */ -Music::Music(Pinetime::Controllers::MusicService& music) : musicService(music) { - lv_obj_t* label; +Music::Music(Pinetime::Controllers::MusicService& music, const Controllers::Ble& bleController) + : musicService(music), bleController {bleController} { lv_style_init(&btn_style); lv_style_set_radius(&btn_style, LV_STATE_DEFAULT, 20); @@ -57,90 +57,94 @@ Music::Music(Pinetime::Controllers::MusicService& music) : musicService(music) { btnVolDown = lv_btn_create(lv_scr_act(), nullptr); btnVolDown->user_data = this; - lv_obj_set_event_cb(btnVolDown, event_handler); - lv_obj_set_size(btnVolDown, 76, 76); - lv_obj_align(btnVolDown, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 3, 0); + lv_obj_set_event_cb(btnVolDown, EventHandler); + lv_obj_set_size(btnVolDown, 117, 60); + lv_obj_align(btnVolDown, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); lv_obj_add_style(btnVolDown, LV_STATE_DEFAULT, &btn_style); - label = lv_label_create(btnVolDown, nullptr); - lv_label_set_text_static(label, Symbols::volumDown); - lv_obj_set_hidden(btnVolDown, true); + txtVolDown = lv_label_create(btnVolDown, nullptr); + lv_label_set_text_static(txtVolDown, Symbols::volumDown); btnVolUp = lv_btn_create(lv_scr_act(), nullptr); btnVolUp->user_data = this; - lv_obj_set_event_cb(btnVolUp, event_handler); - lv_obj_set_size(btnVolUp, 76, 76); - lv_obj_align(btnVolUp, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, -3, 0); + lv_obj_set_event_cb(btnVolUp, EventHandler); + lv_obj_set_size(btnVolUp, 117, 60); + lv_obj_align(btnVolUp, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); lv_obj_add_style(btnVolUp, LV_STATE_DEFAULT, &btn_style); - label = lv_label_create(btnVolUp, nullptr); - lv_label_set_text_static(label, Symbols::volumUp); - lv_obj_set_hidden(btnVolUp, true); + txtVolUp = lv_label_create(btnVolUp, nullptr); + lv_label_set_text_static(txtVolUp, Symbols::volumUp); btnPrev = lv_btn_create(lv_scr_act(), nullptr); btnPrev->user_data = this; - lv_obj_set_event_cb(btnPrev, event_handler); + lv_obj_set_event_cb(btnPrev, EventHandler); lv_obj_set_size(btnPrev, 76, 76); lv_obj_align(btnPrev, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 3, 0); lv_obj_add_style(btnPrev, LV_STATE_DEFAULT, &btn_style); - label = lv_label_create(btnPrev, nullptr); - lv_label_set_text_static(label, Symbols::stepBackward); + txtBtnPrev = lv_label_create(btnPrev, nullptr); + lv_label_set_text_static(txtBtnPrev, Symbols::stepBackward); btnNext = lv_btn_create(lv_scr_act(), nullptr); btnNext->user_data = this; - lv_obj_set_event_cb(btnNext, event_handler); + lv_obj_set_event_cb(btnNext, EventHandler); lv_obj_set_size(btnNext, 76, 76); lv_obj_align(btnNext, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, -3, 0); lv_obj_add_style(btnNext, LV_STATE_DEFAULT, &btn_style); - label = lv_label_create(btnNext, nullptr); - lv_label_set_text_static(label, Symbols::stepForward); + txtBtnNext = lv_label_create(btnNext, nullptr); + lv_label_set_text_static(txtBtnNext, Symbols::stepForward); btnPlayPause = lv_btn_create(lv_scr_act(), nullptr); btnPlayPause->user_data = this; - lv_obj_set_event_cb(btnPlayPause, event_handler); + lv_obj_set_event_cb(btnPlayPause, EventHandler); lv_obj_set_size(btnPlayPause, 76, 76); lv_obj_align(btnPlayPause, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, 0); lv_obj_add_style(btnPlayPause, LV_STATE_DEFAULT, &btn_style); txtPlayPause = lv_label_create(btnPlayPause, nullptr); lv_label_set_text_static(txtPlayPause, Symbols::play); - txtTrackDuration = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_long_mode(txtTrackDuration, LV_LABEL_LONG_SROLL); - lv_obj_align(txtTrackDuration, nullptr, LV_ALIGN_IN_TOP_LEFT, 12, 20); - lv_label_set_text_static(txtTrackDuration, "--:--/--:--"); - lv_label_set_align(txtTrackDuration, LV_ALIGN_IN_LEFT_MID); - lv_obj_set_width(txtTrackDuration, LV_HOR_RES); - - constexpr uint8_t FONT_HEIGHT = 12; - constexpr uint8_t LINE_PAD = 15; - constexpr int8_t MIDDLE_OFFSET = -25; - txtArtist = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_long_mode(txtArtist, LV_LABEL_LONG_SROLL_CIRC); - lv_obj_align(txtArtist, nullptr, LV_ALIGN_IN_LEFT_MID, 12, MIDDLE_OFFSET + 2 * FONT_HEIGHT + LINE_PAD); - 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); + // I'm using the txtTrack label as the top anchor for the whole lot + // of song, artist, progress bar and duration text (0:00 and -0:00) so + // its much easier to move that around and mess with the buttons separately + constexpr int16_t BASE_Y = -40; // -45 for buttons at the top 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, 0, BASE_Y); lv_label_set_align(txtTrack, LV_ALIGN_IN_LEFT_MID); - lv_obj_set_width(txtTrack, LV_HOR_RES - 12); + lv_obj_set_width(txtTrack, LV_HOR_RES); lv_label_set_text_static(txtTrack, ""); - pageIndicator.Create(); - - /** Init animation */ - imgDisc = lv_img_create(lv_scr_act(), nullptr); - lv_img_set_src_arr(imgDisc, &disc); - lv_obj_align(imgDisc, nullptr, LV_ALIGN_IN_TOP_RIGHT, -15, 15); - - imgDiscAnim = lv_img_create(lv_scr_act(), nullptr); - lv_img_set_src_arr(imgDiscAnim, &disc_f_1); - lv_obj_align(imgDiscAnim, nullptr, LV_ALIGN_IN_TOP_RIGHT, -15 - 32, 15); + txtArtist = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_long_mode(txtArtist, LV_LABEL_LONG_SROLL_CIRC); + lv_obj_align(txtArtist, txtTrack, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); + lv_label_set_align(txtArtist, LV_ALIGN_IN_LEFT_MID); + lv_obj_set_width(txtArtist, LV_HOR_RES); + lv_label_set_text_static(txtArtist, ""); + lv_obj_set_style_local_text_color(txtArtist, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); - frameB = false; + barTrackDuration = lv_bar_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_bg_color(barTrackDuration, LV_BAR_PART_BG, LV_STATE_DEFAULT, Colors::bgAlt); + lv_obj_set_style_local_bg_color(barTrackDuration, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, Colors::lightGray); + lv_obj_set_style_local_bg_opa(barTrackDuration, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_OPA_100); + lv_obj_set_style_local_radius(barTrackDuration, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); + lv_obj_set_size(barTrackDuration, 240, 10); + lv_obj_align(barTrackDuration, txtArtist, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); + lv_bar_set_range(barTrackDuration, 0, 1000); + lv_bar_set_value(barTrackDuration, 0, LV_ANIM_OFF); + + txtCurrentPosition = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_long_mode(txtCurrentPosition, LV_LABEL_LONG_SROLL); + lv_obj_align(txtCurrentPosition, barTrackDuration, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); + lv_label_set_text_static(txtCurrentPosition, "--:--"); + lv_label_set_align(txtCurrentPosition, LV_ALIGN_IN_LEFT_MID); + lv_obj_set_width(txtCurrentPosition, LV_HOR_RES); + lv_obj_set_style_local_text_color(txtCurrentPosition, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); - musicService.event(Controllers::MusicService::EVENT_MUSIC_OPEN); + txtTrackDuration = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_long_mode(txtTrackDuration, LV_LABEL_LONG_SROLL); + lv_obj_align(txtTrackDuration, barTrackDuration, LV_ALIGN_OUT_BOTTOM_RIGHT, -13, 0); + lv_label_set_text_static(txtTrackDuration, "--:--"); + lv_label_set_align(txtTrackDuration, LV_ALIGN_IN_RIGHT_MID); + lv_obj_set_width(txtTrackDuration, LV_HOR_RES); + lv_obj_set_style_local_text_color(txtTrackDuration, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); } @@ -152,22 +156,71 @@ Music::~Music() { } void Music::Refresh() { - if (artist != musicService.getArtist()) { - artist = musicService.getArtist(); - lv_label_set_text(txtArtist, artist.data()); + bleState = bleController.IsConnected(); + + if (bleState.IsUpdated()) { + const bool connected = bleState.Get(); + + if (!connected) { + SetDisconnectedUI(); + return; + } + musicService.event(Controllers::MusicService::EVENT_MUSIC_OPEN); + SetConnectedUI(); + RefreshTrackInfo(); + return; + } + + if (bleState.Get()) { + RefreshTrackInfo(); + } +} + +void Music::SetDisconnectedUI() { + lv_label_set_text_static(txtArtist, "Disconnected"); + lv_label_set_text_static(txtTrack, ""); + + for (auto* btn : GetButtons()) { + lv_obj_set_style_local_bg_color(btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Colors::bgDark); } - if (track != musicService.getTrack()) { - track = musicService.getTrack(); - lv_label_set_text(txtTrack, track.data()); + for (auto* lbl : GetButtonLabels()) { + lv_obj_set_style_local_text_color(lbl, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::bgAlt); + } + + lv_label_set_text_static(txtCurrentPosition, "--:--"); + lv_label_set_text_static(txtTrackDuration, "--:--"); + lv_bar_set_range(barTrackDuration, 0, 1000); + lv_bar_set_value(barTrackDuration, 0, LV_ANIM_OFF); + + artist = ""; + track = ""; +} + +void Music::SetConnectedUI() { + for (auto* btn : GetButtons()) { + lv_obj_set_style_local_bg_color(btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Colors::bgAlt); } - if (album != musicService.getAlbum()) { - album = musicService.getAlbum(); + for (auto* lbl : GetButtonLabels()) { + lv_obj_set_style_local_text_color(lbl, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); } +} +void Music::RefreshTrackInfo() { if (playing != musicService.isPlaying()) { playing = musicService.isPlaying(); + lv_label_set_text_static(txtPlayPause, playing ? Symbols::pause : Symbols::play); + } + + artist = musicService.getArtist(); + if (artist.IsUpdated()) { + lv_label_set_text(txtArtist, artist.Get().data()); + } + + track = musicService.getTrack(); + if (track.IsUpdated()) { + lv_label_set_text(txtTrack, track.Get().data()); } if (currentPosition != musicService.getProgress()) { @@ -179,47 +232,25 @@ void Music::Refresh() { totalLength = musicService.getTrackLength(); UpdateLength(); } - - if (playing) { - lv_label_set_text_static(txtPlayPause, Symbols::pause); - if (xTaskGetTickCount() - 1024 >= lastIncrement) { - - if (frameB) { - lv_img_set_src(imgDiscAnim, &disc_f_1); - } else { - lv_img_set_src(imgDiscAnim, &disc_f_2); - } - frameB = !frameB; - - if (currentPosition >= totalLength) { - // Let's assume the getTrack finished, paused when the timer ends - // and there's no new getTrack being sent to us - playing = false; - } - lastIncrement = xTaskGetTickCount(); - } - } else { - lv_label_set_text_static(txtPlayPause, Symbols::play); - } } void Music::UpdateLength() { + int remaining = std::max(totalLength - currentPosition, 0); + int range = std::min(totalLength > 0 ? totalLength : 1, static_cast(std::numeric_limits::max())); + if (totalLength > (99 * 60 * 60)) { - lv_label_set_text_static(txtTrackDuration, "Inf/Inf"); + lv_label_set_text_static(txtCurrentPosition, "Inf"); + lv_label_set_text_static(txtTrackDuration, "Inf"); } else if (totalLength > (99 * 60)) { - lv_label_set_text_fmt(txtTrackDuration, - "%02d:%02d/%02d:%02d", - (currentPosition / (60 * 60)) % 100, - ((currentPosition % (60 * 60)) / 60) % 100, - (totalLength / (60 * 60)) % 100, - ((totalLength % (60 * 60)) / 60) % 100); + lv_label_set_text_fmt(txtCurrentPosition, "%d:%02d", (currentPosition / (60 * 60)) % 100, ((currentPosition % (60 * 60)) / 60) % 100); + lv_label_set_text_fmt(txtTrackDuration, "-%d:%02d", (remaining / (60 * 60)) % 100, ((remaining % (60 * 60)) / 60) % 100); + lv_bar_set_range(barTrackDuration, 0, range); + lv_bar_set_value(barTrackDuration, std::min(currentPosition, range), LV_ANIM_OFF); } else { - lv_label_set_text_fmt(txtTrackDuration, - "%02d:%02d/%02d:%02d", - (currentPosition / 60) % 100, - (currentPosition % 60) % 100, - (totalLength / 60) % 100, - (totalLength % 60) % 100); + lv_label_set_text_fmt(txtCurrentPosition, "%d:%02d", (currentPosition / 60) % 100, (currentPosition % 60) % 100); + lv_label_set_text_fmt(txtTrackDuration, "-%d:%02d", (remaining / 60) % 100, (remaining % 60) % 100); + lv_bar_set_range(barTrackDuration, 0, range); + lv_bar_set_value(barTrackDuration, std::min(currentPosition, range), LV_ANIM_OFF); } } @@ -232,18 +263,14 @@ void Music::OnObjectEvent(lv_obj_t* obj, lv_event_t event) { } else if (obj == btnPrev) { musicService.event(Controllers::MusicService::EVENT_MUSIC_PREV); } else if (obj == btnPlayPause) { - if (playing == Pinetime::Controllers::MusicService::MusicStatus::Playing) { + if (playing) { musicService.event(Controllers::MusicService::EVENT_MUSIC_PAUSE); - - // Let's assume it stops playing instantly - playing = Controllers::MusicService::NotPlaying; } else { musicService.event(Controllers::MusicService::EVENT_MUSIC_PLAY); - - // Let's assume it starts playing instantly - // TODO: In the future should check for BT connection for better UX - playing = Controllers::MusicService::Playing; } + // Let's assume it stops/starts playing instantly + // TODO: In the future should check for BT connection for better UX + playing = !playing; } else if (obj == btnNext) { musicService.event(Controllers::MusicService::EVENT_MUSIC_NEXT); } @@ -252,25 +279,6 @@ void Music::OnObjectEvent(lv_obj_t* obj, lv_event_t event) { bool Music::OnTouchEvent(Pinetime::Applications::TouchEvents event) { switch (event) { - case TouchEvents::SwipeUp: { - lv_obj_set_hidden(btnVolDown, false); - lv_obj_set_hidden(btnVolUp, false); - lv_obj_set_hidden(btnNext, true); - lv_obj_set_hidden(btnPrev, true); - pageIndicator.SetPageIndicatorPosition(1); - return true; - } - case TouchEvents::SwipeDown: { - if (lv_obj_get_hidden(btnNext)) { - lv_obj_set_hidden(btnNext, false); - lv_obj_set_hidden(btnPrev, false); - lv_obj_set_hidden(btnVolDown, true); - lv_obj_set_hidden(btnVolUp, true); - pageIndicator.SetPageIndicatorPosition(0); - return true; - } - return false; - } case TouchEvents::SwipeLeft: { musicService.event(Controllers::MusicService::EVENT_MUSIC_NEXT); return true; diff --git a/src/displayapp/screens/Music.h b/src/displayapp/screens/Music.h index 3c371b85eb..5487c1f900 100644 --- a/src/displayapp/screens/Music.h +++ b/src/displayapp/screens/Music.h @@ -19,12 +19,14 @@ #include #include +#include #include #include "displayapp/screens/Screen.h" -#include "displayapp/widgets/PageIndicator.h" #include "displayapp/apps/Apps.h" #include "displayapp/Controllers.h" #include "Symbols.h" +#include "components/ble/BleController.h" +#include "utility/DirtyValue.h" namespace Pinetime { namespace Controllers { @@ -35,7 +37,7 @@ namespace Pinetime { namespace Screens { class Music : public Screen { public: - Music(Pinetime::Controllers::MusicService& music); + Music(Pinetime::Controllers::MusicService& music, const Controllers::Ble& bleController); ~Music() override; @@ -48,42 +50,57 @@ namespace Pinetime { void UpdateLength(); + void RefreshTrackInfo(); + + void SetDisconnectedUI(); + + void SetConnectedUI(); + lv_obj_t* btnPrev; lv_obj_t* btnPlayPause; lv_obj_t* btnNext; lv_obj_t* btnVolDown; lv_obj_t* btnVolUp; + + std::array GetButtons() { + return {btnPrev, btnPlayPause, btnNext, btnVolDown, btnVolUp}; + } + + lv_obj_t* txtBtnPrev; + lv_obj_t* txtPlayPause; + lv_obj_t* txtBtnNext; + lv_obj_t* txtVolDown; + lv_obj_t* txtVolUp; + + std::array GetButtonLabels() { + return {txtBtnPrev, txtPlayPause, txtBtnNext, txtVolDown, txtVolUp}; + } + lv_obj_t* txtArtist; lv_obj_t* txtTrack; - lv_obj_t* txtPlayPause; - lv_obj_t* imgDisc; - lv_obj_t* imgDiscAnim; lv_obj_t* txtTrackDuration; + lv_obj_t* txtCurrentPosition; + lv_obj_t* barTrackDuration; lv_style_t btn_style; - /** For the spinning disc animation */ - bool frameB; - Pinetime::Controllers::MusicService& musicService; + const Controllers::Ble& bleController; - std::string artist; - std::string album; - std::string track; + Utility::DirtyValue artist; + Utility::DirtyValue track; /** Total length in seconds */ int totalLength = 0; /** Current position in seconds */ int currentPosition; - /** Last time an animation update or timer was incremented */ - TickType_t lastIncrement = 0; bool playing; lv_task_t* taskRefresh; - Widgets::PageIndicator pageIndicator = Widgets::PageIndicator(0, 2); + Utility::DirtyValue bleState; /** Watchapp */ }; @@ -95,7 +112,7 @@ namespace Pinetime { static constexpr const char* icon = Screens::Symbols::music; static Screens::Screen* Create(AppControllers& controllers) { - return new Screens::Music(*controllers.musicService); + return new Screens::Music(*controllers.musicService, controllers.bleController); }; static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) { diff --git a/src/displayapp/screens/Timer.cpp b/src/displayapp/screens/Timer.cpp index 749d985933..1cee62ae52 100644 --- a/src/displayapp/screens/Timer.cpp +++ b/src/displayapp/screens/Timer.cpp @@ -6,9 +6,14 @@ using namespace Pinetime::Applications::Screens; +// Initialize static member with default timer durations (5min, 10min, 15min) +uint32_t Timer::timerDurations[Timer::numRecentTimers] = {300000, 600000, 900000}; + static void btnEventHandler(lv_obj_t* obj, lv_event_t event) { auto* screen = static_cast(obj->user_data); - if (event == LV_EVENT_PRESSED) { + if (screen->launcherMode && event == LV_EVENT_CLICKED) { + screen->OnLauncherButtonClicked(obj); + } else if (event == LV_EVENT_PRESSED) { screen->ButtonPressed(); } else if (event == LV_EVENT_RELEASED || event == LV_EVENT_PRESS_LOST) { screen->MaskReset(); @@ -20,57 +25,17 @@ static void btnEventHandler(lv_obj_t* obj, lv_event_t event) { Timer::Timer(Controllers::Timer& timerController, Controllers::MotorController& motorController, System::SystemTask& systemTask) : timer {timerController}, motorController {motorController}, wakeLock(systemTask) { - lv_obj_t* colonLabel = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_font(colonLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76); - lv_obj_set_style_local_text_color(colonLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); - lv_label_set_text_static(colonLabel, ":"); - lv_obj_align(colonLabel, lv_scr_act(), LV_ALIGN_CENTER, 0, -29); - - minuteCounter.Create(); - secondCounter.Create(); - lv_obj_align(minuteCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); - lv_obj_align(secondCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); - - highlightObjectMask = lv_objmask_create(lv_scr_act(), nullptr); - lv_obj_set_size(highlightObjectMask, 240, 50); - lv_obj_align(highlightObjectMask, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); - - lv_draw_mask_line_param_t tmpMaskLine; - - lv_draw_mask_line_points_init(&tmpMaskLine, 0, 0, 0, 240, LV_DRAW_MASK_LINE_SIDE_LEFT); - highlightMask = lv_objmask_add_mask(highlightObjectMask, &tmpMaskLine); - - lv_obj_t* btnHighlight = lv_obj_create(highlightObjectMask, nullptr); - lv_obj_set_style_local_radius(btnHighlight, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_obj_set_style_local_bg_color(btnHighlight, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); - lv_obj_set_size(btnHighlight, LV_HOR_RES, 50); - lv_obj_align(btnHighlight, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); - - btnObjectMask = lv_objmask_create(lv_scr_act(), nullptr); - lv_obj_set_size(btnObjectMask, 240, 50); - lv_obj_align(btnObjectMask, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); - - lv_draw_mask_line_points_init(&tmpMaskLine, 0, 0, 0, 240, LV_DRAW_MASK_LINE_SIDE_RIGHT); - btnMask = lv_objmask_add_mask(btnObjectMask, &tmpMaskLine); - - btnPlayPause = lv_btn_create(btnObjectMask, nullptr); - btnPlayPause->user_data = this; - lv_obj_set_style_local_radius(btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_obj_set_style_local_bg_color(btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Colors::bgAlt); - 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); - auto timerStatus = timer.GetTimerState(); if (timerStatus && timerStatus->expired) { - SetTimerRinging(); + // If timer has expired, go directly to timer UI with 0 duration + CreateTimerUI(0, false); } else if (timer.IsRunning()) { - SetTimerRunning(); + // If timer is already running, skip launcher and go directly to timer UI + uint32_t durationMs = GetTimerDuration(0); + CreateTimerUI(durationMs, false); } else { - SetTimerStopped(); + CreateLauncherUI(); } taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); @@ -86,6 +51,10 @@ Timer::~Timer() { timer.ResetExpiredTime(); } + if (launcherMode) { + lv_style_reset(&btnStyle); + } + lv_obj_clean(lv_scr_act()); } @@ -116,6 +85,18 @@ void Timer::UpdateMask() { } void Timer::Refresh() { + // Don't try to update timer display if we're in launcher mode + if (launcherMode) { + // If timer starts while in launcher, transition to timer UI + if (timer.IsRunning()) { + uint32_t durationMs = GetTimerDuration(0); + lv_style_reset(&btnStyle); + lv_obj_clean(lv_scr_act()); + CreateTimerUI(durationMs, false); + } + return; + } + auto timerStatus = timer.GetTimerState(); if (timerStatus && timerStatus->expired) { @@ -156,6 +137,9 @@ void Timer::DisplayTime() { } void Timer::SetTimerRunning() { + if (launcherMode) { + return; + } minuteCounter.HideControls(); secondCounter.HideControls(); lv_label_set_text_static(txtPlayPause, "Pause"); @@ -163,6 +147,9 @@ void Timer::SetTimerRunning() { } void Timer::SetTimerStopped() { + if (launcherMode) { + return; + } minuteCounter.ShowControls(); secondCounter.ShowControls(); lv_label_set_text_static(txtPlayPause, "Start"); @@ -170,6 +157,10 @@ void Timer::SetTimerStopped() { } void Timer::SetTimerRinging() { + if (launcherMode) { + // Timer expired while in launcher mode - transition will happen in Refresh() + return; + } motorController.StartRinging(); wakeLock.Lock(); minuteCounter.HideControls(); @@ -190,6 +181,11 @@ void Timer::ToggleRunning() { } else if (secondCounter.GetValue() + minuteCounter.GetValue() > 0) { auto timerDuration = std::chrono::minutes(minuteCounter.GetValue()) + std::chrono::seconds(secondCounter.GetValue()); timer.StartTimer(timerDuration); + + // Add the timer duration to MRU list + uint32_t durationMs = (minuteCounter.GetValue() * 60 + secondCounter.GetValue()) * 1000; + AddTimerDuration(durationMs); + Refresh(); SetTimerRunning(); } @@ -200,3 +196,195 @@ void Timer::Reset() { DisplayTime(); SetTimerStopped(); } + +void Timer::AddTimerDuration(uint32_t duration) { + // If already at front, nothing to do + if (duration == timerDurations[0]) { + return; + } + + // Shift elements down, stopping after we find the duration + uint32_t prev = timerDurations[0]; + for (int i = 1; i < numRecentTimers; i++) { + uint32_t temp = timerDurations[i]; + timerDurations[i] = prev; + prev = temp; + if (temp == duration) { + // Found it - stop after this shift + break; + } + } + + // Insert duration at front + timerDurations[0] = duration; +} + +uint32_t Timer::GetTimerDuration(uint8_t index) const { + if (index >= numRecentTimers) { + return timerDurations[0]; + } + return timerDurations[index]; +} + +void Timer::CreateLauncherUI() { + static constexpr uint8_t innerDistance = 10; + static constexpr uint8_t buttonHeight = (LV_VER_RES_MAX - innerDistance) / 2; + static constexpr uint8_t buttonWidth = (LV_HOR_RES_MAX - innerDistance) / 2; + + lv_style_init(&btnStyle); + lv_style_set_radius(&btnStyle, LV_STATE_DEFAULT, buttonHeight / 4); + lv_style_set_bg_color(&btnStyle, LV_STATE_DEFAULT, Colors::bgAlt); + + // Layout positions for the 3 recent timer buttons + static constexpr lv_align_t buttonAlignments[numRecentTimers] = { + LV_ALIGN_IN_TOP_LEFT, // Button 0: Top-left + LV_ALIGN_IN_TOP_RIGHT, // Button 1: Top-right + LV_ALIGN_IN_BOTTOM_LEFT // Button 2: Bottom-left + }; + + // Create each of the recent timer buttons + for (int i = 0; i < numRecentTimers; i++) { + btnRecent[i] = lv_btn_create(lv_scr_act(), nullptr); + btnRecent[i]->user_data = this; + lv_obj_set_event_cb(btnRecent[i], btnEventHandler); + lv_obj_add_style(btnRecent[i], LV_BTN_PART_MAIN, &btnStyle); + lv_obj_set_size(btnRecent[i], buttonWidth, buttonHeight); + lv_obj_align(btnRecent[i], nullptr, buttonAlignments[i], 0, 0); + + uint32_t duration = GetTimerDuration(i); + uint32_t minutes = duration / 60000; + uint32_t seconds = (duration % 60000) / 1000; + + labelRecent[i] = lv_label_create(btnRecent[i], nullptr); + lv_obj_t* labelIcon = lv_label_create(btnRecent[i], nullptr); + + // Show the minutes + lv_obj_set_style_local_text_font(labelRecent[i], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76); + lv_label_set_text_fmt(labelRecent[i], "%lu", minutes); + lv_obj_align(labelRecent[i], btnRecent[i], LV_ALIGN_CENTER, 0, -20); + + // Show the seconds, or "min" below + lv_obj_set_style_local_text_font(labelIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20); + if (seconds == 0) { + lv_label_set_text_static(labelIcon, "min"); + } else { + lv_label_set_text_fmt(labelIcon, ":%02lu", seconds); + } + lv_obj_align(labelIcon, btnRecent[i], LV_ALIGN_CENTER, 0, 20); + } + + // Bottom-right: New timer + btnCustom = lv_btn_create(lv_scr_act(), nullptr); + btnCustom->user_data = this; + lv_obj_set_event_cb(btnCustom, btnEventHandler); + lv_obj_add_style(btnCustom, LV_BTN_PART_MAIN, &btnStyle); + lv_obj_set_size(btnCustom, buttonWidth, buttonHeight); + lv_obj_align(btnCustom, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); + + labelCustom = lv_label_create(btnCustom, nullptr); + lv_obj_set_style_local_text_font(labelCustom, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76); + lv_label_set_text_static(labelCustom, "+"); +} + +void Timer::CreateTimerUI(uint32_t startDurationMs, bool autoStart) { + launcherMode = false; + + lv_obj_t* colonLabel = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_font(colonLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76); + lv_obj_set_style_local_text_color(colonLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_label_set_text_static(colonLabel, ":"); + lv_obj_align(colonLabel, lv_scr_act(), LV_ALIGN_CENTER, 0, -29); + + minuteCounter.Create(); + secondCounter.Create(); + lv_obj_align(minuteCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); + lv_obj_align(secondCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); + + highlightObjectMask = lv_objmask_create(lv_scr_act(), nullptr); + lv_obj_set_size(highlightObjectMask, 240, 50); + lv_obj_align(highlightObjectMask, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); + + lv_draw_mask_line_param_t tmpMaskLine; + + lv_draw_mask_line_points_init(&tmpMaskLine, 0, 0, 0, 240, LV_DRAW_MASK_LINE_SIDE_LEFT); + highlightMask = lv_objmask_add_mask(highlightObjectMask, &tmpMaskLine); + + lv_obj_t* btnHighlight = lv_obj_create(highlightObjectMask, nullptr); + lv_obj_set_style_local_radius(btnHighlight, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); + lv_obj_set_style_local_bg_color(btnHighlight, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); + lv_obj_set_size(btnHighlight, LV_HOR_RES, 50); + lv_obj_align(btnHighlight, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); + + btnObjectMask = lv_objmask_create(lv_scr_act(), nullptr); + lv_obj_set_size(btnObjectMask, 240, 50); + lv_obj_align(btnObjectMask, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); + + lv_draw_mask_line_points_init(&tmpMaskLine, 0, 0, 0, 240, LV_DRAW_MASK_LINE_SIDE_RIGHT); + btnMask = lv_objmask_add_mask(btnObjectMask, &tmpMaskLine); + + btnPlayPause = lv_btn_create(btnObjectMask, nullptr); + btnPlayPause->user_data = this; + lv_obj_set_style_local_radius(btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); + lv_obj_set_style_local_bg_color(btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Colors::bgAlt); + 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); + + // Reset button press state + buttonPressing = false; + pressTime = 0; + + if (timer.IsRunning()) { + SetTimerRunning(); + DisplayTime(); + } else if (autoStart) { + auto timerDuration = std::chrono::milliseconds(startDurationMs); + timer.StartTimer(timerDuration); + AddTimerDuration(startDurationMs); + SetTimerRunning(); + DisplayTime(); + } else { + // Set the initial duration only when timer is stopped + uint32_t minutes = startDurationMs / 60000; + uint32_t seconds = (startDurationMs % 60000) / 1000; + minuteCounter.SetValue(minutes); + secondCounter.SetValue(seconds); + SetTimerStopped(); + } +} + +void Timer::OnLauncherButtonClicked(lv_obj_t* obj) { + uint32_t durationMs; + bool autoStart; + + // Check if it's one of the recent timer buttons + bool found = false; + for (int i = 0; i < numRecentTimers; i++) { + if (obj == btnRecent[i]) { + durationMs = GetTimerDuration(i); + autoStart = true; + found = true; + break; + } + } + + // Check if it's the custom timer button + if (!found) { + if (obj == btnCustom) { + durationMs = 0; + autoStart = false; + } else { + return; + } + } + + lv_style_reset(&btnStyle); + lv_obj_clean(lv_scr_act()); + + CreateTimerUI(durationMs, autoStart); + + // Wait for button release to prevent the press state from carrying over to the new UI + lv_indev_wait_release(lv_indev_get_act()); +} diff --git a/src/displayapp/screens/Timer.h b/src/displayapp/screens/Timer.h index 651c7f0d57..25199c5e2a 100644 --- a/src/displayapp/screens/Timer.h +++ b/src/displayapp/screens/Timer.h @@ -24,16 +24,32 @@ namespace Pinetime::Applications { void ButtonPressed(); void MaskReset(); void SetTimerRinging(); + void OnLauncherButtonClicked(lv_obj_t* obj); + + bool launcherMode = true; private: void SetTimerRunning(); void SetTimerStopped(); void UpdateMask(); void DisplayTime(); + void CreateLauncherUI(); + void CreateTimerUI(uint32_t startDurationMs, bool autoStart); + void AddTimerDuration(uint32_t duration); + uint32_t GetTimerDuration(uint8_t index) const; + Pinetime::Controllers::Timer& timer; Pinetime::Controllers::MotorController& motorController; Pinetime::System::WakeLock wakeLock; + // Launcher UI elements + static constexpr int numRecentTimers = 3; + static uint32_t timerDurations[numRecentTimers]; + lv_obj_t* btnRecent[numRecentTimers] = {nullptr}; + lv_obj_t* btnCustom = nullptr; + lv_obj_t* labelRecent[numRecentTimers] = {nullptr}; + lv_obj_t* labelCustom = nullptr; + lv_style_t btnStyle; lv_obj_t* btnPlayPause; lv_obj_t* txtPlayPause; diff --git a/src/displayapp/screens/WatchFacePrideFlag.cpp b/src/displayapp/screens/WatchFacePrideFlag.cpp index e029c076f4..d035337444 100644 --- a/src/displayapp/screens/WatchFacePrideFlag.cpp +++ b/src/displayapp/screens/WatchFacePrideFlag.cpp @@ -3,6 +3,7 @@ #include "components/battery/BatteryController.h" #include "components/ble/BleController.h" #include "displayapp/screens/Symbols.h" +#include "lvgl/src/lv_misc/lv_color.h" using namespace Pinetime::Applications::Screens; @@ -15,7 +16,7 @@ namespace { Pinetime::Controllers::Settings::PrideFlag GetNext(Pinetime::Controllers::Settings::PrideFlag prideFlag) { const auto prideFlagAsInt = static_cast(prideFlag); Pinetime::Controllers::Settings::PrideFlag nextFlag; - if (prideFlagAsInt < 3) { + if (prideFlagAsInt < 8) { nextFlag = static_cast(prideFlagAsInt + 1); } else { nextFlag = static_cast(0); @@ -29,7 +30,7 @@ namespace { if (prideFlagAsInt > 0) { prevFlag = static_cast(prideFlagAsInt - 1); } else { - prevFlag = static_cast(3); + prevFlag = static_cast(8); } return prevFlag; } @@ -62,6 +63,8 @@ namespace { 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 sunOrange = LV_COLOR_MAKE(0xe2, 0x8c, 0x00); + constexpr lv_color_t brightYellow = LV_COLOR_MAKE(0xec, 0xcd, 0x00); 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); @@ -71,14 +74,29 @@ namespace { 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 lv_color_t skyBlue = LV_COLOR_MAKE(0x4a, 0x91, 0xe8); constexpr std::array gayColours {darkGreen, cyan, lightGreen, LV_COLOR_WHITE, lightBlue, indigo, steelBlue}; constexpr std::array transColours {lightBlue, lightPink, LV_COLOR_WHITE, lightPink, lightBlue}; constexpr std::array biColours {hotPink, hotPink, grayPurple, darkBlue, darkBlue}; constexpr std::array lesbianColours {LV_COLOR_RED, orange, lightOrange, LV_COLOR_WHITE, lightPurple, darkPurple, magenta}; + constexpr std::array nonbinaryColours {LV_COLOR_YELLOW, LV_COLOR_WHITE, LV_COLOR_PURPLE, LV_COLOR_BLACK}; + constexpr std::array aceColours {LV_COLOR_BLACK, LV_COLOR_GRAY, LV_COLOR_WHITE, LV_COLOR_PURPLE}; + constexpr std::array aroColours {LV_COLOR_GREEN, lightGreen, LV_COLOR_WHITE, LV_COLOR_GRAY, LV_COLOR_BLACK}; + constexpr std::array aroaceColours {sunOrange, + brightYellow, + LV_COLOR_WHITE, + LV_COLOR_MAKE(0x62, 0xae, 0xdc), + LV_COLOR_MAKE(0x20, 0x38, 0x56)}; + constexpr std::array panColours {hotPink, LV_COLOR_YELLOW, skyBlue}; 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); + constexpr PrideFlagData nonbinaryFlagData(nonbinaryColours, LV_COLOR_BLACK, LV_COLOR_BLACK, LV_COLOR_WHITE); + constexpr PrideFlagData aceFlagData(aceColours, LV_COLOR_WHITE, LV_COLOR_BLACK, LV_COLOR_BLACK); + constexpr PrideFlagData aroFlagData(aroColours, LV_COLOR_WHITE, LV_COLOR_BLACK, LV_COLOR_WHITE); + constexpr PrideFlagData aroaceFlagData(aroaceColours, LV_COLOR_WHITE, LV_COLOR_BLACK, LV_COLOR_WHITE); + constexpr PrideFlagData panFlagData(panColours, LV_COLOR_BLACK, LV_COLOR_BLACK, LV_COLOR_BLACK); } WatchFacePrideFlag::WatchFacePrideFlag(Controllers::DateTime& dateTimeController, @@ -333,5 +351,20 @@ void WatchFacePrideFlag::UpdateScreen(const Pinetime::Controllers::Settings::Pri case Pinetime::Controllers::Settings::PrideFlag::Lesbian: UseFlagData(lesbianFlagData); break; + case Pinetime::Controllers::Settings::PrideFlag::Nonbinary: + UseFlagData(nonbinaryFlagData); + break; + case Pinetime::Controllers::Settings::PrideFlag::Ace: + UseFlagData(aceFlagData); + break; + case Pinetime::Controllers::Settings::PrideFlag::Aro: + UseFlagData(aroFlagData); + break; + case Pinetime::Controllers::Settings::PrideFlag::AroAce: + UseFlagData(aroaceFlagData); + break; + case Pinetime::Controllers::Settings::PrideFlag::Pan: + UseFlagData(panFlagData); + break; } } diff --git a/src/displayapp/screens/Weather.cpp b/src/displayapp/screens/Weather.cpp index de32a1538b..ddc52a774c 100644 --- a/src/displayapp/screens/Weather.cpp +++ b/src/displayapp/screens/Weather.cpp @@ -24,16 +24,22 @@ namespace { } } -Weather::Weather(Controllers::Settings& settingsController, Controllers::SimpleWeatherService& weatherService) - : settingsController {settingsController}, weatherService {weatherService} { +Weather::Weather(Controllers::Settings& settingsController, + Controllers::SimpleWeatherService& weatherService, + Controllers::DateTime& dateTimeController) + : settingsController {settingsController}, weatherService {weatherService}, dateTimeController {dateTimeController} { temperature = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_obj_set_style_local_text_font(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text(temperature, "---"); - lv_obj_align(temperature, nullptr, LV_ALIGN_CENTER, 0, -30); + lv_obj_align(temperature, nullptr, LV_ALIGN_CENTER, 0, -32); lv_obj_set_auto_realign(temperature, true); + lastUpdated = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(lastUpdated, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::bg); + lv_label_set_text(lastUpdated, ""); + minTemperature = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(minTemperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::bg); lv_label_set_text(minTemperature, ""); @@ -123,10 +129,41 @@ void Weather::Refresh() { 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); + + auto secondsSinceEpoch = std::chrono::duration_cast(dateTimeController.CurrentDateTime().time_since_epoch()); + int32_t secondsSinceWeatherUpdate = secondsSinceEpoch.count() - optCurrentWeather->timestamp; + int8_t minutesSinceWeatherUpdate = secondsSinceWeatherUpdate / 60; + int8_t hoursSinceWeatherUpdate = secondsSinceWeatherUpdate / 3600; + + constexpr uint8_t Y_POSITION = 108; + constexpr uint8_t X_SINGLE_DIGIT_POSITION = 90; + constexpr uint8_t X_TWO_DIGIT_POSITION = 78; + constexpr uint8_t X_NOW_POSITION = 102; + + lv_obj_set_pos(lastUpdated, X_SINGLE_DIGIT_POSITION, Y_POSITION); + + if (hoursSinceWeatherUpdate > 0) { + if (hoursSinceWeatherUpdate > 9) { + lv_obj_set_pos(lastUpdated, X_TWO_DIGIT_POSITION, Y_POSITION); + } + lv_label_set_text_fmt(lastUpdated, "%dh ago", hoursSinceWeatherUpdate); + } else if (minutesSinceWeatherUpdate > 0) { + if (minutesSinceWeatherUpdate > 9) { + lv_obj_set_pos(lastUpdated, X_TWO_DIGIT_POSITION, Y_POSITION); + } + lv_label_set_text_fmt(lastUpdated, "%dm ago", minutesSinceWeatherUpdate); + } else if (secondsSinceWeatherUpdate > 30) { + lv_obj_set_pos(lastUpdated, X_TWO_DIGIT_POSITION, Y_POSITION); + lv_label_set_text_fmt(lastUpdated, "%ds ago", secondsSinceWeatherUpdate); + } else if (secondsSinceWeatherUpdate < 31) { + lv_obj_set_pos(lastUpdated, X_NOW_POSITION, Y_POSITION); + lv_label_set_text_fmt(lastUpdated, "Now", secondsSinceWeatherUpdate); + } } else { lv_label_set_text(icon, ""); lv_label_set_text(condition, ""); lv_label_set_text(temperature, "---"); + lv_label_set_text(lastUpdated, ""); lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_label_set_text(minTemperature, ""); lv_label_set_text(maxTemperature, ""); diff --git a/src/displayapp/screens/Weather.h b/src/displayapp/screens/Weather.h index 03266be105..aa6288fcce 100644 --- a/src/displayapp/screens/Weather.h +++ b/src/displayapp/screens/Weather.h @@ -4,6 +4,7 @@ #include #include "displayapp/screens/Screen.h" #include "components/ble/SimpleWeatherService.h" +#include "components/datetime/DateTimeController.h" #include "displayapp/apps/Apps.h" #include "displayapp/Controllers.h" #include "Symbols.h" @@ -20,7 +21,9 @@ namespace Pinetime { class Weather : public Screen { public: - Weather(Controllers::Settings& settingsController, Controllers::SimpleWeatherService& weatherService); + Weather(Controllers::Settings& settingsController, + Controllers::SimpleWeatherService& weatherService, + Controllers::DateTime& dateTimeController); ~Weather() override; void Refresh() override; @@ -28,6 +31,7 @@ namespace Pinetime { private: Controllers::Settings& settingsController; Controllers::SimpleWeatherService& weatherService; + Controllers::DateTime& dateTimeController; Utility::DirtyValue> currentWeather {}; Utility::DirtyValue> currentForecast {}; @@ -35,6 +39,7 @@ namespace Pinetime { lv_obj_t* icon; lv_obj_t* condition; lv_obj_t* temperature; + lv_obj_t* lastUpdated; lv_obj_t* minTemperature; lv_obj_t* maxTemperature; lv_obj_t* forecast; @@ -49,7 +54,7 @@ namespace Pinetime { static constexpr const char* icon = Screens::Symbols::cloudSunRain; static Screens::Screen* Create(AppControllers& controllers) { - return new Screens::Weather(controllers.settingsController, *controllers.weatherController); + return new Screens::Weather(controllers.settingsController, *controllers.weatherController, controllers.dateTimeController); }; static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) { diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp index c5c3071aef..66231453c4 100644 --- a/src/displayapp/screens/settings/QuickSettings.cpp +++ b/src/displayapp/screens/settings/QuickSettings.cpp @@ -119,7 +119,7 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app, lv_obj_set_style_local_text_font(lbl_btn, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48); lv_label_set_text_static(lbl_btn, Symbols::settings); - taskUpdate = lv_task_create(lv_update_task, 5000, LV_TASK_PRIO_MID, this); + taskUpdate = lv_task_create(lv_update_task, 100, LV_TASK_PRIO_MID, this); UpdateScreen(); } diff --git a/src/displayapp/screens/settings/SettingWatchFace.cpp b/src/displayapp/screens/settings/SettingWatchFace.cpp index 0d5168d26f..3c7ee1b817 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.cpp +++ b/src/displayapp/screens/settings/SettingWatchFace.cpp @@ -57,7 +57,10 @@ SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, : watchfaceItems {std::move(watchfaceItems)}, settingsController {settingsController}, filesystem {filesystem}, - screens {app, 0, CreateScreenList(), Screens::ScreenListModes::UpDown} { + screens {app, + static_cast(static_cast(settingsController.GetWatchFace()) / 4), + CreateScreenList(), + Screens::ScreenListModes::UpDown} { } SettingWatchFace::~SettingWatchFace() { diff --git a/src/drivers/SpiMaster.cpp b/src/drivers/SpiMaster.cpp index 19422ef3c3..5002ea37d0 100644 --- a/src/drivers/SpiMaster.cpp +++ b/src/drivers/SpiMaster.cpp @@ -161,6 +161,7 @@ void SpiMaster::OnStartedEvent() { } void SpiMaster::PrepareTx(const uint32_t bufferAddress, const size_t size) { + ASSERT(size < 256); spiBaseAddress->TXD.PTR = bufferAddress; spiBaseAddress->TXD.MAXCNT = size; spiBaseAddress->TXD.LIST = 0; @@ -171,6 +172,7 @@ void SpiMaster::PrepareTx(const uint32_t bufferAddress, const size_t size) { } void SpiMaster::PrepareRx(const uint32_t bufferAddress, const size_t size) { + ASSERT(size < 256); spiBaseAddress->TXD.PTR = 0; spiBaseAddress->TXD.MAXCNT = 0; spiBaseAddress->TXD.LIST = 0; @@ -240,12 +242,17 @@ bool SpiMaster::Read(uint8_t pinCsn, uint8_t* cmd, size_t cmdSize, uint8_t* data spiBaseAddress->TASKS_START = 1; while (spiBaseAddress->EVENTS_END == 0) ; + while (dataSize > 0) { + size_t readSize = std::min(dataSize, 255U); + PrepareRx((uint32_t) data, readSize); + spiBaseAddress->TASKS_START = 1; - PrepareRx((uint32_t) data, dataSize); - spiBaseAddress->TASKS_START = 1; - - while (spiBaseAddress->EVENTS_END == 0) - ; + while (spiBaseAddress->EVENTS_END == 0) { + ; + } + data += readSize; + dataSize -= readSize; + } nrf_gpio_pin_set(this->pinCsn); xSemaphoreGive(mutex); diff --git a/src/libs/lfs_config.h b/src/libs/lfs_config.h index eaeede0e63..8e283579fd 100644 --- a/src/libs/lfs_config.h +++ b/src/libs/lfs_config.h @@ -2,25 +2,25 @@ #include -#ifndef LFS_TRACE -#ifdef LFS_YES_TRACE -#define LFS_TRACE_(fmt, ...) \ - NRF_LOG_DEBUG("[LFS] %s:%d:trace: " fmt "%s\n", __FILE__, __LINE__, __VA_ARGS__) -#define LFS_TRACE(...) LFS_TRACE_(__VA_ARGS__, "") -#else -#define LFS_TRACE(...) -#endif -#endif +//#ifndef LFS_TRACE +//#ifdef LFS_YES_TRACE +//#define LFS_TRACE_(fmt, ...) \ +// NRF_LOG_DEBUG("[LFS] %s:%d:trace: " fmt "%s\n", __FILE__, __LINE__, __VA_ARGS__) +//#define LFS_TRACE(...) LFS_TRACE_(__VA_ARGS__, "") +//#else +//#define LFS_TRACE(...) +//#endif +//#endif -#ifndef LFS_DEBUG -#ifndef LFS_NO_DEBUG -#define LFS_DEBUG_(fmt, ...) \ - NRF_LOG_DEBUG("[LFS] %s:%d:debug: " fmt "%s\n", __FILE__, __LINE__, __VA_ARGS__) -#define LFS_DEBUG(...) LFS_DEBUG_(__VA_ARGS__, "") -#else -#define LFS_DEBUG(...) -#endif -#endif +//#ifndef LFS_DEBUG +//#ifndef LFS_NO_DEBUG +//#define LFS_DEBUG_(fmt, ...) \ +// NRF_LOG_DEBUG("[LFS] %s:%d:debug: " fmt "%s\n", __FILE__, __LINE__, __VA_ARGS__) +//#define LFS_DEBUG(...) LFS_DEBUG_(__VA_ARGS__, "") +//#else +//#define LFS_DEBUG(...) +//#endif +//#endif #ifndef LFS_WARN #ifndef LFS_NO_WARN diff --git a/src/stdlib.c b/src/stdlib.c index 21b506a843..18884c4893 100644 --- a/src/stdlib.c +++ b/src/stdlib.c @@ -1,6 +1,8 @@ #include #include #include +#include +#include // Override malloc() and free() to use the memory manager from FreeRTOS. // According to the documentation of libc, we also need to override @@ -29,7 +31,7 @@ void __wrap_free(void* ptr) { } void* calloc(size_t num, size_t size) { - void *ptr = malloc(num * size); + void* ptr = malloc(num * size); if (ptr) { memset(ptr, 0, num * size); } @@ -49,3 +51,58 @@ void* realloc(void* ptr, size_t newSize) { void* __wrap_realloc(void* ptr, size_t newSize) { return realloc(ptr, newSize); } + +// Implement functions required by libc as stubs +// These functions aren't linked into the final binary + +__attribute__((error("stub"))) void _close(int fp) { + __builtin_trap(); + (void) fp; +} + +__attribute__((error("stub"))) void _fstat(int fildes, struct stat* buf) { + __builtin_trap(); + (void) fildes; + (void) buf; +} + +__attribute__((error("stub"))) pid_t _getpid() { + __builtin_trap(); +} + +__attribute__((error("stub"))) int _isatty(int fd) { + __builtin_trap(); + (void) fd; +} + +__attribute__((error("stub"))) int _kill(pid_t pid, int sig) { + __builtin_trap(); + (void) pid; + (void) sig; +} + +__attribute__((error("stub"))) off_t _lseek(int fd, off_t offset, int whence) { + __builtin_trap(); + (void) fd; + (void) offset; + (void) whence; +} + +__attribute__((error("stub"))) ssize_t _read(int fd, void* buf, size_t count) { + __builtin_trap(); + (void) fd; + (void) buf; + (void) count; +} + +__attribute__((error("stub"))) ssize_t _write(int fd, void* buf, size_t count) { + __builtin_trap(); + (void) fd; + (void) buf; + (void) count; +} + +__attribute__((error("stub"))) void _exit(int status) { + __builtin_trap(); + (void) status; +}