summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/launch.json20
l---------[-rw-r--r--]CONTRIBUTING.md34
-rw-r--r--doc/contribute.md57
-rw-r--r--src/components/motor/MotorController.cpp37
-rw-r--r--src/components/motor/MotorController.h7
-rw-r--r--src/displayapp/DisplayApp.cpp5
-rw-r--r--src/displayapp/screens/Metronome.cpp119
-rw-r--r--src/displayapp/screens/Metronome.h48
-rw-r--r--src/displayapp/screens/Notifications.cpp85
-rw-r--r--src/displayapp/screens/Notifications.h13
-rw-r--r--src/displayapp/screens/settings/QuickSettings.cpp2
-rw-r--r--src/main.cpp15
-rw-r--r--src/systemtask/SystemTask.cpp5
13 files changed, 228 insertions, 219 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 7cf3acd1..3d9aa789 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -40,7 +40,25 @@
"break main",
"continue"
]
+ },
+ {
+ "cwd": "${workspaceRoot}",
+ // TODO: find better way to get latest build filename
+ "executable": "./build/src/pinetime-app-1.3.0.out",
+ "name": "Debug OpenOCD ST-LINK pinetime-app-1.3.0.out",
+ "request": "launch",
+ "type": "cortex-debug",
+ "showDevDebugOutput": false,
+ "servertype": "openocd",
+ "runToMain": true,
+ // 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-9-2020-q2-update/bin",
+ "svdFile": "${workspaceRoot}/nrf52.svd",
+ "configFiles": [
+ "interface/stlink.cfg",
+ "target/nrf52.cfg"
+ ],
}
]
-} \ No newline at end of file
+}
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index a6fa6828..15e2c684 100644..120000
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,33 +1 @@
-This contribution guide is in progress, improvements are welcome.
-
-### Code style
-
-Any C++ code PRs should aim to follow the style of existing code in the project.
-
-Using an autoformatter is heavily recommended, but make sure it's configured properly.
-
-There's currently preconfigured autoformatter rules for:
-
- * CLion (IntelliJ) in .idea/codeStyles/Project.xml
-
-You can use those to configure your own IDE if it's not already on the list.
-
-#### Linting errors and compiler warnings
-
-Try to avoid any currently enabled warnings and try to reduce the amount of linter errors.
-
-#### Spelling
-
-Make sure you spellcheck your code before commiting it.
-
-#### TODO, FIXME
-
-Check before commiting that you haven't forgotten anything, preferably don't leave these in your commits.
-
-#### Licence headers
-
-You should add your name to the comma-space separated list of contributors if there's a license header.
-
-### License
-
-By contributing you agree to licence your code under the repository's general license (which is currently GPL-v3+).
+doc/contribute.md \ No newline at end of file
diff --git a/doc/contribute.md b/doc/contribute.md
index 9f4c2154..0c34e2a5 100644
--- a/doc/contribute.md
+++ b/doc/contribute.md
@@ -1,68 +1,89 @@
# How to contribute?
+
## Report bugs
-You use your Pinetime and find a bug in the firmware? [Create an issue on Github](https://github.com/JF002/InfiniTime/issues) explaining the bug, how to reproduce it, the version of the firmware you use...
+
+Have you found a bug in the firmware? [Create an issue on Github](https://github.com/JF002/InfiniTime/issues) explaining the bug, how to reproduce it, the version of the firmware you use...
+
## Write and improve documentation
+
Documentation might be incomplete, or not clear enough, and it is always possible to improve it with better wording, pictures, photo, video,...
As the documentation is part of the source code, you can submit your improvements to the documentation by submitting a pull request (see below).
+
## Fix bugs, add functionalities and improve the code
+
You want to fix a bug, add a cool new functionality or improve the code? See *How to submit a pull request below*.
+
## Spread the word
-The Pinetime is a cool open source project that deserves to be known. Talk about it around you, on social networks, on your blog,... and let people know that we are working on an open-source firmware for a smartwatch!
+
+The Pinetime is a cool open source project that deserves to be known. Talk about it around you, on social networks, on your blog,... and let people know that we are working on an open source firmware for a smartwatch!
# How to submit a pull request ?
## TL;DR
+
- Create a branch from develop;
- Work on a single subject in this branch. Create multiple branches/pulls-requests if you want to work on multiple subjects (bugs, features,...);
- Test your modifications on the actual hardware;
- Check the code formatting against our coding conventions and [clang-format](../.clang-format) and [clang-tidy](../.clang-tidy);
- Clean your code and remove files that are not needed;
- - Write documentation related to your new feature is applicable;
- - Create the pull-request and write a great description about it : what does your PR do, why, how,... Add pictures and video if possible;
+ - Write documentation related to your new feature if applicable;
+ - Create a pull request and write a great description about it : what does your PR do, why, how,... Add pictures and video if possible;
- Wait for someone to review your PR and take part in the review process;
- Your PR will eventually be merged :)
-Your contribution is more than welcome!
+Your contributions are more than welcome!
-If you want to fix a bug, add a functionality or improve the code, you'll first need to create a branch from the **develop** branch (see [this page about the branching model](./branches.md)). This branch is called a feature branch, and you should choose a name that explains what you are working on (ex: "add-doc-about-contributions"). In this branch, **focus on only one topic, bug or feature**. For example, if you created this branch to work on the UI of a specific application, do not commit modifications about the SPI driver. If you want to work on multiple topics, create one branch per topic.
+If you want to fix a bug, add functionality or improve the code, you'll first need to create a branch from the **develop** branch (see [this page about the branching model](./branches.md)). This branch is called a feature branch, and you should choose a name that explains what you are working on (ex: "add-doc-about-contributions"). In this branch, **focus on only one topic, bug or feature**. For example, if you created this branch to work on the UI of a specific application, do not commit modifications about the SPI driver. If you want to work on multiple topics, create one branch for each topic.
When your feature branch is ready, **make sure it actually works** and **do not forget to write documentation** about it if it's relevant.
-I **strongly discourage to create a PR containing modifications that haven't been tested**. If, for any reason, you cannot test your modifications but want to publish them anyway, **please mention it in the description**. This way, other contributors might be willing to test it and provide feedback about your code.
+**Creating a pull request containing modifications that haven't been tested is strongly discouraged.** If, for any reason, you cannot test your modifications but want to publish them anyway, **please mention it in the description**. This way, other contributors might be willing to test it and provide feedback about your code.
Also, before submitting your PR, check the coding style of your code against the **coding conventions** detailed below. This project also provides [clang-format](../.clang-format) and [clang-tidy](../.clang-tidy) configuration files. You can use them to ensure correct formatting of your code.
-Do not forget to check the files you are going to commit and remove those who are not necessary (config files from your IDE, for example). Remove old comments, commented code,...
+Don't forget to check the files you are going to commit and remove those which aren't necessary (config files from your IDE, for example). Remove old comments, commented code,...
-Then, you can submit a pull-request for review. Try to **describe your pull request as much as possible**: what did you do in this branch, how does it work, how is it designed, are there any limitations,... This will help the contributors to understand and review your code easily. You can add pictures and video to the description so that contributors will have a quick overview of your work.
+Then, you can submit a pull request for review. Try to **describe your pull request as much as possible**: what did you do in this branch, how does it work, how it is designed, are there any limitations,... This will help the contributors to understand and review your code easily. You can add pictures and video to the description so that contributors will have a quick overview of your work.
Other contributors can post comments about the pull request, maybe ask for more info or adjustments in the code.
-Once the pull request is reviewed and accepted, it'll be merge in **develop** and will be released in the next release version of the firmware.
+Once the pull request is reviewed and accepted, it'll be merged into **develop** and will be released in the next version of the firmware.
## Why all these rules?
-Reviewing pull-requests is a **very time consuming task** for the creator of this project ([JF002](https://github.com/JF002)) and for other contributors who take the time to review them. Every little thing you do to make their lives easier will **increase the chances your PR will be merge quickly**.
-When reviewing PR, the author and contributors will first look at the **description**. If it's easy to understand what the PR does, why the modification is needed or interesting and how it's done, a good part of the work is already done : we understand the PR and its context.
+Reviewing pull requests is a **very time consuming task** for the creator of this project ([JF002](https://github.com/JF002)) and for other contributors who take the time to review them. Everything you do to make reviewing easier will **get your PR merged faster**.
-Then, reviewing **a few files that were modified for a single purpose** is a lot more easier than to review 30 files modified for many reasons (bug fix, UI improvements, typos in doc,...), even if all these changes make sense. Also, it's possible that we agree on some modification but not on some other, and we won't be able to merge the PR because of the changes that are not accepted.
+When reviewing PRs, the author and contributors will first look at the **description**. If it's easy to understand what the PR does, why the modification is needed or interesting and how it's done, a good part of the work is already done : we understand the PR and its context.
-We do our best to keep the code as consistent as possible, and that means we pay attention to the **formatting** of the code. If the code formatting is not consistent with our code base, we'll ask you to review it, which will take more time.
+Then, reviewing **a few files that were modified for a single purpose** is a lot more easier than to review 30 files modified for many reasons (bug fix, UI improvements, typos in doc,...), even if all these changes make sense. Also, it's possible that we agree on some modification but not on some other, so we won't be able to merge the PR because of the changes that are not accepted.
-The last step of the review consists in **testing** the modification. If it doesn't work out of the box, we'll ask your to review your code and to ensure that it works as expected.
+We do our best to keep the code as consistent as possible. If the formatting of the code in your PR is not consistent with our code base, we'll ask you to review it, which will take more time.
-It's totally normal for a PR to need some more work even after it was created, that's why we review them. But every round trip takes time, and it's good practice to try to reduce them as much as possible by following those simple rules.
+The last step of the review consists of **testing** the modification. If it doesn't work out of the box, we'll ask your to review your code and to ensure that it works as expected.
+
+It's totally normal for a PR to need some more work even after it was created, that's why we review them. But every round trip takes time, so it's good practice to try to reduce them as much as possible by following those simple rules.
# Coding convention
+
## Language
-The language of this project is **C++**, and all new code must be written in C++. (Modern) C++ provides a lot of useful tools and functionalities that are beneficial for embedded software development like `constexpr`, `template` and anything that provides zero-cost abstraction.
-It's OK to include C code if this code comes from another library like FreeRTOS, NimBLE, LVGL or the NRF-SDK.
+The language of this project is **C++**, and all new code must be written in C++. (Modern) C++ provides a lot of useful tools and functionalities that are beneficial for embedded software development like `constexpr`, `template` and anything that provides zero-cost abstraction.
+
+C code is accepted if it comes from another library like FreeRTOS, NimBLE, LVGL or the NRF-SDK.
## Coding style
+
The most important rule to follow is to try to keep the code as easy to read and maintain as possible.
+Using an autoformatter is highly recommended, but make sure it's configured properly.
+
+There are preconfigured autoformatter rules for:
+
+ * CLion (IntelliJ) in .idea/codeStyles/Project.xml
+
+If there are no preconfigured rules for your IDE, you can use one of the existing ones to configure your IDE.
+
- **Indentation** : 2 spaces, no tabulation
- **Opening brace** at the end of the line
- **Naming** : Choose self-describing variable name
diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp
index 3afa0ced..b25e6bc8 100644
--- a/src/components/motor/MotorController.cpp
+++ b/src/components/motor/MotorController.cpp
@@ -3,7 +3,8 @@
#include "systemtask/SystemTask.h"
#include "app_timer.h"
-APP_TIMER_DEF(vibTimer);
+APP_TIMER_DEF(shortVibTimer);
+APP_TIMER_DEF(longVibTimer);
using namespace Pinetime::Controllers;
@@ -13,19 +14,39 @@ MotorController::MotorController(Controllers::Settings& settingsController) : se
void MotorController::Init() {
nrf_gpio_cfg_output(pinMotor);
nrf_gpio_pin_set(pinMotor);
- app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate);
+ app_timer_init();
+
+ app_timer_create(&shortVibTimer, APP_TIMER_MODE_SINGLE_SHOT, StopMotor);
+ app_timer_create(&longVibTimer, APP_TIMER_MODE_REPEATED, Ring);
}
-void MotorController::SetDuration(uint8_t motorDuration) {
+void MotorController::Ring(void* p_context) {
+ auto* motorController = static_cast<MotorController*>(p_context);
+ motorController->RunForDuration(50);
+}
- if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF)
+void MotorController::RunForDuration(uint8_t motorDuration) {
+ if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF) {
return;
+ }
nrf_gpio_pin_clear(pinMotor);
- /* Start timer for motorDuration miliseconds and timer triggers vibrate() when it finishes*/
- app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL);
+ app_timer_start(shortVibTimer, APP_TIMER_TICKS(motorDuration), nullptr);
+}
+
+void MotorController::StartRinging() {
+ if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF) {
+ return;
+ }
+ Ring(this);
+ app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this);
}
-void MotorController::vibrate(void* p_context) {
+void MotorController::StopRinging() {
+ app_timer_stop(longVibTimer);
nrf_gpio_pin_set(pinMotor);
-} \ No newline at end of file
+}
+
+void MotorController::StopMotor(void* p_context) {
+ nrf_gpio_pin_set(pinMotor);
+}
diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h
index df61af78..d2c9fe5f 100644
--- a/src/components/motor/MotorController.h
+++ b/src/components/motor/MotorController.h
@@ -12,11 +12,14 @@ namespace Pinetime {
public:
MotorController(Controllers::Settings& settingsController);
void Init();
- void SetDuration(uint8_t motorDuration);
+ void RunForDuration(uint8_t motorDuration);
+ void StartRinging();
+ static void StopRinging();
private:
+ static void Ring(void* p_context);
Controllers::Settings& settingsController;
- static void vibrate(void* p_context);
+ static void StopMotor(void* p_context);
};
}
}
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp
index c6e94668..2c09f5d0 100644
--- a/src/displayapp/DisplayApp.cpp
+++ b/src/displayapp/DisplayApp.cpp
@@ -333,12 +333,12 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
case Apps::Notifications:
currentScreen = std::make_unique<Screens::Notifications>(
- this, notificationManager, systemTask->nimble().alertService(), Screens::Notifications::Modes::Normal);
+ this, notificationManager, systemTask->nimble().alertService(), motorController, Screens::Notifications::Modes::Normal);
ReturnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp);
break;
case Apps::NotificationsPreview:
currentScreen = std::make_unique<Screens::Notifications>(
- this, notificationManager, systemTask->nimble().alertService(), Screens::Notifications::Modes::Preview);
+ this, notificationManager, systemTask->nimble().alertService(), motorController, Screens::Notifications::Modes::Preview);
ReturnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp);
break;
case Apps::Timer:
@@ -411,6 +411,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
break;
case Apps::Metronome:
currentScreen = std::make_unique<Screens::Metronome>(this, motorController, *systemTask);
+ ReturnApp(Apps::Launcher, FullRefreshDirections::Down, TouchEvents::None);
break;
case Apps::Motion:
currentScreen = std::make_unique<Screens::Motion>(this, motionController);
diff --git a/src/displayapp/screens/Metronome.cpp b/src/displayapp/screens/Metronome.cpp
index 7bfbccb7..66f8f621 100644
--- a/src/displayapp/screens/Metronome.cpp
+++ b/src/displayapp/screens/Metronome.cpp
@@ -1,35 +1,15 @@
#include "Metronome.h"
-
-#include "Screen.h"
#include "Symbols.h"
-#include "lvgl/lvgl.h"
-#include "FreeRTOSConfig.h"
-#include "task.h"
-
-#include <string>
-#include <tuple>
using namespace Pinetime::Applications::Screens;
namespace {
- float calculateDelta(const TickType_t startTime, const TickType_t currentTime) {
- TickType_t delta = 0;
- // Take care of overflow
- if (startTime > currentTime) {
- delta = 0xffffffff - startTime;
- delta += (currentTime + 1);
- } else {
- delta = currentTime - startTime;
- }
- return static_cast<float>(delta) / static_cast<float>(configTICK_RATE_HZ);
- }
-
- static void eventHandler(lv_obj_t* obj, lv_event_t event) {
- Metronome* screen = static_cast<Metronome*>(obj->user_data);
+ void eventHandler(lv_obj_t* obj, lv_event_t event) {
+ auto* screen = static_cast<Metronome*>(obj->user_data);
screen->OnEvent(obj, event);
}
- lv_obj_t* createLabel(const char* name, lv_obj_t* reference, lv_align_t align, lv_font_t* font, uint8_t x = 0, uint8_t y = 0) {
+ lv_obj_t* createLabel(const char* name, lv_obj_t* reference, lv_align_t align, lv_font_t* font, uint8_t x, uint8_t y) {
lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font);
lv_obj_set_style_local_text_color(label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
@@ -41,7 +21,7 @@ namespace {
}
Metronome::Metronome(DisplayApp* app, Controllers::MotorController& motorController, System::SystemTask& systemTask)
- : Screen(app), running {true}, currentState {States::Stopped}, startTime {}, motorController {motorController}, systemTask {systemTask} {
+ : Screen(app), motorController {motorController}, systemTask {systemTask} {
bpmArc = lv_arc_create(lv_scr_act(), nullptr);
bpmArc->user_data = this;
@@ -52,10 +32,10 @@ Metronome::Metronome(DisplayApp* app, Controllers::MotorController& motorControl
lv_arc_set_value(bpmArc, bpm);
lv_obj_set_size(bpmArc, 210, 210);
lv_arc_set_adjustable(bpmArc, true);
- lv_obj_align(bpmArc, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 7);
+ lv_obj_align(bpmArc, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0);
- bpmValue = createLabel(std::to_string(lv_arc_get_value(bpmArc)).c_str(), bpmArc, LV_ALIGN_IN_TOP_MID, &jetbrains_mono_76, 0, 55);
- bpmLegend = createLabel("bpm", bpmValue, LV_ALIGN_OUT_BOTTOM_MID, &jetbrains_mono_bold_20, 0, 0);
+ bpmValue = createLabel("120", bpmArc, LV_ALIGN_IN_TOP_MID, &jetbrains_mono_76, 0, 55);
+ createLabel("bpm", bpmValue, LV_ALIGN_OUT_BOTTOM_MID, &jetbrains_mono_bold_20, 0, 0);
bpmTap = lv_btn_create(lv_scr_act(), nullptr);
bpmTap->user_data = this;
@@ -69,20 +49,23 @@ Metronome::Metronome(DisplayApp* app, Controllers::MotorController& motorControl
lv_obj_set_event_cb(bpbDropdown, eventHandler);
lv_obj_set_style_local_pad_left(bpbDropdown, LV_DROPDOWN_PART_MAIN, LV_STATE_DEFAULT, 20);
lv_obj_set_style_local_pad_left(bpbDropdown, LV_DROPDOWN_PART_LIST, LV_STATE_DEFAULT, 20);
- lv_obj_align(bpbDropdown, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 15, -4);
+ lv_obj_set_size(bpbDropdown, 115, 50);
+ lv_obj_align(bpbDropdown, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
lv_dropdown_set_options(bpbDropdown, "1\n2\n3\n4\n5\n6\n7\n8\n9");
lv_dropdown_set_selected(bpbDropdown, bpb - 1);
- bpbLegend = lv_label_create(bpbDropdown, nullptr);
- lv_label_set_text(bpbLegend, "bpb");
- lv_obj_align(bpbLegend, bpbDropdown, LV_ALIGN_IN_RIGHT_MID, -15, 0);
+ lv_dropdown_set_show_selected(bpbDropdown, false);
+ lv_dropdown_set_text(bpbDropdown, "");
+
+ currentBpbText = lv_label_create(bpbDropdown, nullptr);
+ lv_label_set_text_fmt(currentBpbText, "%d bpb", bpb);
+ lv_obj_align(currentBpbText, bpbDropdown, LV_ALIGN_CENTER, 0, 0);
playPause = lv_btn_create(lv_scr_act(), nullptr);
playPause->user_data = this;
lv_obj_set_event_cb(playPause, eventHandler);
- lv_obj_align(playPause, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -15, -10);
- lv_obj_set_height(playPause, 39);
- playPauseLabel = lv_label_create(playPause, nullptr);
- lv_label_set_text(playPauseLabel, Symbols::play);
+ lv_obj_set_size(playPause, 115, 50);
+ lv_obj_align(playPause, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
+ lv_obj_set_style_local_value_str(playPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Symbols::play);
app->SetTouchMode(DisplayApp::TouchModes::Polling);
}
@@ -93,28 +76,17 @@ Metronome::~Metronome() {
lv_obj_clean(lv_scr_act());
}
-bool Metronome::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
- return true;
-}
-
bool Metronome::Refresh() {
- switch (currentState) {
- case States::Stopped: {
- break;
- }
- case States::Running: {
- if (calculateDelta(startTime, xTaskGetTickCount()) >= (60.0 / bpm)) {
- counter--;
- startTime -= 60.0 / bpm;
- startTime = xTaskGetTickCount();
- if (counter == 0) {
- counter = bpb;
- motorController.SetDuration(90);
- } else {
- motorController.SetDuration(30);
- }
+ if (metronomeStarted) {
+ if (xTaskGetTickCount() - startTime > 60 * configTICK_RATE_HZ / bpm) {
+ startTime += 60 * configTICK_RATE_HZ / bpm;
+ counter--;
+ if (counter == 0) {
+ counter = bpb;
+ motorController.RunForDuration(90);
+ } else {
+ motorController.RunForDuration(30);
}
- break;
}
}
return running;
@@ -128,42 +100,39 @@ void Metronome::OnEvent(lv_obj_t* obj, lv_event_t event) {
lv_label_set_text_fmt(bpmValue, "%03d", bpm);
} else if (obj == bpbDropdown) {
bpb = lv_dropdown_get_selected(obj) + 1;
+ lv_label_set_text_fmt(currentBpbText, "%d bpb", bpb);
+ lv_obj_realign(currentBpbText);
}
break;
}
case LV_EVENT_PRESSED: {
if (obj == bpmTap) {
- float timeDelta = calculateDelta(tappedTime, xTaskGetTickCount());
- if (tappedTime == 0 || timeDelta > 3) {
- tappedTime = xTaskGetTickCount();
- } else {
- bpm = ceil(60.0 / timeDelta);
+ TickType_t delta = xTaskGetTickCount() - tappedTime;
+ if (tappedTime != 0 && delta < configTICK_RATE_HZ * 3) {
+ bpm = configTICK_RATE_HZ * 60 / delta;
lv_arc_set_value(bpmArc, bpm);
lv_label_set_text_fmt(bpmValue, "%03d", bpm);
- tappedTime = xTaskGetTickCount();
}
+ tappedTime = xTaskGetTickCount();
}
break;
}
case LV_EVENT_CLICKED: {
if (obj == playPause) {
- currentState = (currentState == States::Stopped ? States::Running : States::Stopped);
- switch (currentState) {
- case States::Stopped: {
- lv_label_set_text(playPauseLabel, Symbols::play);
- systemTask.PushMessage(System::Messages::EnableSleeping);
- break;
- }
- case States::Running: {
- lv_label_set_text(playPauseLabel, Symbols::pause);
- systemTask.PushMessage(System::Messages::DisableSleeping);
- startTime = xTaskGetTickCount();
- counter = 1;
- break;
- }
+ metronomeStarted = !metronomeStarted;
+ if (metronomeStarted) {
+ lv_obj_set_style_local_value_str(playPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Symbols::pause);
+ systemTask.PushMessage(System::Messages::DisableSleeping);
+ startTime = xTaskGetTickCount();
+ counter = 1;
+ } else {
+ lv_obj_set_style_local_value_str(playPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Symbols::play);
+ systemTask.PushMessage(System::Messages::EnableSleeping);
}
}
break;
}
+ default:
+ break;
}
}
diff --git a/src/displayapp/screens/Metronome.h b/src/displayapp/screens/Metronome.h
index 3a1f1084..a4baa096 100644
--- a/src/displayapp/screens/Metronome.h
+++ b/src/displayapp/screens/Metronome.h
@@ -3,32 +3,32 @@
#include "systemtask/SystemTask.h"
#include "components/motor/MotorController.h"
-#include <array>
+namespace Pinetime {
+ namespace Applications {
+ namespace Screens {
-namespace Pinetime::Applications::Screens {
+ class Metronome : public Screen {
+ public:
+ Metronome(DisplayApp* app, Controllers::MotorController& motorController, System::SystemTask& systemTask);
+ ~Metronome() override;
+ bool Refresh() override;
+ void OnEvent(lv_obj_t* obj, lv_event_t event);
- class Metronome : public Screen {
- public:
- Metronome(DisplayApp* app, Controllers::MotorController& motorController, System::SystemTask& systemTask);
- ~Metronome() override;
- bool Refresh() override;
- bool OnTouchEvent(TouchEvents event) override;
- void OnEvent(lv_obj_t* obj, lv_event_t event);
- enum class States { Running, Stopped };
+ private:
+ TickType_t startTime = 0;
+ TickType_t tappedTime = 0;
+ Controllers::MotorController& motorController;
+ System::SystemTask& systemTask;
+ int16_t bpm = 120;
+ uint8_t bpb = 4;
+ uint8_t counter = 1;
- private:
- bool running;
- States currentState;
- TickType_t startTime;
- TickType_t tappedTime = 0;
- Controllers::MotorController& motorController;
- System::SystemTask& systemTask;
- uint16_t bpm = 120;
- uint8_t bpb = 4;
- uint8_t counter = 1;
+ bool metronomeStarted = false;
- lv_obj_t *bpmArc, *bpmTap, *bpmValue, *bpmLegend;
- lv_obj_t *bpbDropdown, *bpbLegend;
- lv_obj_t *playPause, *playPauseLabel;
- };
+ lv_obj_t *bpmArc, *bpmTap, *bpmValue;
+ lv_obj_t *bpbDropdown, *currentBpbText;
+ lv_obj_t *playPause;
+ };
+ }
+ }
}
diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp
index 5c23ed1f..c061c146 100644
--- a/src/displayapp/screens/Notifications.cpp
+++ b/src/displayapp/screens/Notifications.cpp
@@ -11,6 +11,7 @@ extern lv_font_t jetbrains_mono_bold_20;
Notifications::Notifications(DisplayApp* app,
Pinetime::Controllers::NotificationManager& notificationManager,
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
+ Pinetime::Controllers::MotorController& motorController,
Modes mode)
: Screen(app), notificationManager {notificationManager}, alertNotificationService {alertNotificationService}, mode {mode} {
notificationManager.ClearNewNotificationFlag();
@@ -36,25 +37,31 @@ Notifications::Notifications(DisplayApp* app,
}
if (mode == Modes::Preview) {
-
- timeoutLine = lv_line_create(lv_scr_act(), nullptr);
-
- lv_obj_set_style_local_line_width(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
- lv_obj_set_style_local_line_color(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
- lv_obj_set_style_local_line_rounded(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true);
-
- lv_line_set_points(timeoutLine, timeoutLinePoints, 2);
- timeoutTickCountStart = xTaskGetTickCount();
- timeoutTickCountEnd = timeoutTickCountStart + (5 * 1024);
+ if (notification.category == Controllers::NotificationManager::Categories::IncomingCall) {
+ motorController.StartRinging();
+ } else {
+ motorController.RunForDuration(35);
+ timeoutLine = lv_line_create(lv_scr_act(), nullptr);
+
+ lv_obj_set_style_local_line_width(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
+ lv_obj_set_style_local_line_color(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
+ lv_obj_set_style_local_line_rounded(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true);
+
+ lv_line_set_points(timeoutLine, timeoutLinePoints, 2);
+ timeoutTickCountStart = xTaskGetTickCount();
+ timeoutTickCountEnd = timeoutTickCountStart + (5 * 1024);
+ }
}
}
Notifications::~Notifications() {
+ // make sure we stop any vibrations before exiting
+ Controllers::MotorController::StopRinging();
lv_obj_clean(lv_scr_act());
}
bool Notifications::Refresh() {
- if (mode == Modes::Preview) {
+ if (mode == Modes::Preview && timeoutLine != nullptr) {
auto tick = xTaskGetTickCount();
int32_t pos = 240 - ((tick - timeoutTickCountStart) / ((timeoutTickCountEnd - timeoutTickCountStart) / 240));
if (pos < 0)
@@ -63,13 +70,13 @@ bool Notifications::Refresh() {
timeoutLinePoints[1].x = pos;
lv_line_set_points(timeoutLine, timeoutLinePoints, 2);
}
-
- return running;
+ return running && currentItem->IsRunning();
}
bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
- if (mode != Modes::Normal)
- return true;
+ if (mode != Modes::Normal) {
+ return false;
+ }
switch (event) {
case Pinetime::Applications::TouchEvents::SwipeDown: {
@@ -130,19 +137,9 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
}
namespace {
- static void AcceptIncomingCallEventHandler(lv_obj_t* obj, lv_event_t event) {
- auto* item = static_cast<Notifications::NotificationItem*>(obj->user_data);
- item->OnAcceptIncomingCall(event);
- }
-
- static void MuteIncomingCallEventHandler(lv_obj_t* obj, lv_event_t event) {
+ void CallEventHandler(lv_obj_t* obj, lv_event_t event) {
auto* item = static_cast<Notifications::NotificationItem*>(obj->user_data);
- item->OnMuteIncomingCall(event);
- }
-
- static void RejectIncomingCallEventHandler(lv_obj_t* obj, lv_event_t event) {
- auto* item = static_cast<Notifications::NotificationItem*>(obj->user_data);
- item->OnRejectIncomingCall(event);
+ item->OnCallButtonEvent(obj, event);
}
}
@@ -154,7 +151,6 @@ Notifications::NotificationItem::NotificationItem(const char* title,
Modes mode,
Pinetime::Controllers::AlertNotificationService& alertNotificationService)
: notifNr {notifNr}, notifNb {notifNb}, mode {mode}, alertNotificationService {alertNotificationService} {
-
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), NULL);
lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x222222));
@@ -212,7 +208,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
bt_accept = lv_btn_create(lv_scr_act(), nullptr);
bt_accept->user_data = this;
- lv_obj_set_event_cb(bt_accept, AcceptIncomingCallEventHandler);
+ lv_obj_set_event_cb(bt_accept, CallEventHandler);
lv_obj_set_size(bt_accept, 76, 76);
lv_obj_align(bt_accept, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
label_accept = lv_label_create(bt_accept, nullptr);
@@ -221,7 +217,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
bt_reject = lv_btn_create(lv_scr_act(), nullptr);
bt_reject->user_data = this;
- lv_obj_set_event_cb(bt_reject, RejectIncomingCallEventHandler);
+ lv_obj_set_event_cb(bt_reject, CallEventHandler);
lv_obj_set_size(bt_reject, 76, 76);
lv_obj_align(bt_reject, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
label_reject = lv_label_create(bt_reject, nullptr);
@@ -230,7 +226,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
bt_mute = lv_btn_create(lv_scr_act(), nullptr);
bt_mute->user_data = this;
- lv_obj_set_event_cb(bt_mute, MuteIncomingCallEventHandler);
+ lv_obj_set_event_cb(bt_mute, CallEventHandler);
lv_obj_set_size(bt_mute, 76, 76);
lv_obj_align(bt_mute, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
label_mute = lv_label_create(bt_mute, nullptr);
@@ -246,25 +242,22 @@ Notifications::NotificationItem::NotificationItem(const char* title,
lv_label_set_text(backgroundLabel, "");
}
-void Notifications::NotificationItem::OnAcceptIncomingCall(lv_event_t event) {
- if (event != LV_EVENT_CLICKED)
- return;
-
- alertNotificationService.AcceptIncomingCall();
-}
-
-void Notifications::NotificationItem::OnMuteIncomingCall(lv_event_t event) {
- if (event != LV_EVENT_CLICKED)
+void Notifications::NotificationItem::OnCallButtonEvent(lv_obj_t* obj, lv_event_t event) {
+ if (event != LV_EVENT_CLICKED) {
return;
+ }
- alertNotificationService.MuteIncomingCall();
-}
+ Controllers::MotorController::StopRinging();
-void Notifications::NotificationItem::OnRejectIncomingCall(lv_event_t event) {
- if (event != LV_EVENT_CLICKED)
- return;
+ if (obj == bt_accept) {
+ alertNotificationService.AcceptIncomingCall();
+ } else if (obj == bt_reject) {
+ alertNotificationService.RejectIncomingCall();
+ } else if (obj == bt_mute) {
+ alertNotificationService.MuteIncomingCall();
+ }
- alertNotificationService.RejectIncomingCall();
+ running = false;
}
Notifications::NotificationItem::~NotificationItem() {
diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h
index 51ca81da..a02d9b46 100644
--- a/src/displayapp/screens/Notifications.h
+++ b/src/displayapp/screens/Notifications.h
@@ -5,6 +5,7 @@
#include <memory>
#include "Screen.h"
#include "components/ble/NotificationManager.h"
+#include "components/motor/MotorController.h"
namespace Pinetime {
namespace Controllers {
@@ -19,6 +20,7 @@ namespace Pinetime {
explicit Notifications(DisplayApp* app,
Pinetime::Controllers::NotificationManager& notificationManager,
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
+ Pinetime::Controllers::MotorController& motorController,
Modes mode);
~Notifications() override;
@@ -35,12 +37,10 @@ namespace Pinetime {
Modes mode,
Pinetime::Controllers::AlertNotificationService& alertNotificationService);
~NotificationItem();
- bool Refresh() {
- return false;
+ bool IsRunning() const {
+ return running;
}
- void OnAcceptIncomingCall(lv_event_t event);
- void OnMuteIncomingCall(lv_event_t event);
- void OnRejectIncomingCall(lv_event_t event);
+ void OnCallButtonEvent(lv_obj_t*, lv_event_t event);
private:
uint8_t notifNr = 0;
@@ -60,6 +60,7 @@ namespace Pinetime {
lv_obj_t* bottomPlaceholder;
Modes mode;
Pinetime::Controllers::AlertNotificationService& alertNotificationService;
+ bool running = true;
};
private:
@@ -75,7 +76,7 @@ namespace Pinetime {
bool validDisplay = false;
lv_point_t timeoutLinePoints[2] {{0, 1}, {239, 1}};
- lv_obj_t* timeoutLine;
+ lv_obj_t* timeoutLine = nullptr;
uint32_t timeoutTickCountStart;
uint32_t timeoutTickCountEnd;
};
diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp
index 2cd24876..0421d103 100644
--- a/src/displayapp/screens/settings/QuickSettings.cpp
+++ b/src/displayapp/screens/settings/QuickSettings.cpp
@@ -140,7 +140,7 @@ void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
if (lv_obj_get_state(btn3, LV_BTN_PART_MAIN) & LV_STATE_CHECKED) {
settingsController.SetVibrationStatus(Controllers::Settings::Vibration::ON);
- motorController.SetDuration(35);
+ motorController.RunForDuration(35);
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOn);
} else {
settingsController.SetVibrationStatus(Controllers::Settings::Vibration::OFF);
diff --git a/src/main.cpp b/src/main.cpp
index ffbba5e7..d301be67 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -5,6 +5,7 @@
#include <libraries/gpiote/app_gpiote.h>
#include <libraries/timer/app_timer.h>
#include <softdevice/common/nrf_sdh.h>
+#include <nrf_delay.h>
// nimble
#define min // workaround: nimble's min/max macros conflict with libstdc++
@@ -300,6 +301,20 @@ int main(void) {
nrf_drv_clock_init();
+ // Unblock i2c?
+ nrf_gpio_cfg(pinTwiScl,
+ NRF_GPIO_PIN_DIR_OUTPUT,
+ NRF_GPIO_PIN_INPUT_DISCONNECT,
+ NRF_GPIO_PIN_NOPULL,
+ NRF_GPIO_PIN_S0D1,
+ NRF_GPIO_PIN_NOSENSE);
+ nrf_gpio_pin_set(pinTwiScl);
+ for (uint8_t i = 0; i < 16; i++) {
+ nrf_gpio_pin_toggle(pinTwiScl);
+ nrf_delay_us(5);
+ }
+ nrf_gpio_cfg_default(pinTwiScl);
+
debounceTimer = xTimerCreate("debounceTimer", 200, pdFALSE, (void*) 0, DebounceTimerCallback);
debounceChargeTimer = xTimerCreate("debounceTimerCharge", 200, pdFALSE, (void*) 0, DebounceTimerChargeCallback);
diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp
index 7ef6fc61..00932f63 100644
--- a/src/systemtask/SystemTask.cpp
+++ b/src/systemtask/SystemTask.cpp
@@ -266,14 +266,13 @@ void SystemTask::Work() {
if (isSleeping && !isWakingUp) {
GoToRunning();
}
- motorController.SetDuration(35);
displayApp.PushMessage(Pinetime::Applications::Display::Messages::NewNotification);
break;
case Messages::OnTimerDone:
if (isSleeping && !isWakingUp) {
GoToRunning();
}
- motorController.SetDuration(35);
+ motorController.RunForDuration(35);
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TimerDone);
break;
case Messages::BleConnected:
@@ -327,7 +326,7 @@ void SystemTask::Work() {
break;
case Messages::OnChargingEvent:
batteryController.Update();
- motorController.SetDuration(15);
+ motorController.RunForDuration(15);
break;
case Messages::MeasureBatteryTimerExpired:
sendBatteryNotification = true;