-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
AlarmController: Add saving alarm time to file #1333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
872c719 to
d2341c1
Compare
Save the set alarm time to the SPI NOR flash, so it does not reset to the default value when the watch resets, e.g. due to watchdog timeout. Size impact: +204 (400332 -> 400536)
d2341c1 to
9574ea5
Compare
|
👍 for implementing this so fast. Did you test it? Should be easy to reboot once and check. |
|
Yes, both in the simulator and on the PineTime (that's when I caught the typo fixed in the first force-push). I assumed it was mandatory for a PR (that is not marked as draft) to be tested :) If you want to test it too, do not forget to verify the firmware before you reboot. I might have had to flash twice… |
Lol, this makes it quite dangerous to test those kind of features, right? At least, you are not tinkering with Bluetooth. |
|
Since this was an issue in another issue: did you see my comments specific lines? If not, tldr: you can use the data array for everything and omit the attributes. Also, pack activation and recurrence status also in the data struct because the are important to recover an active alarm. |
|
Also, #1278 gets rid of log-functions. I assume that you should follow that. |
30fb6d4 to
2af96ce
Compare
Not sure what you mean by dangerous. All that happened was that I first forgot to verify before I rebooted the watch, so the bootloader dutifully reverted to the previous firmware and I had to wait another 10 minutes while flashing again (via BLE DFU) for the next try.
Did you comment on the commit somewhere? I didn't get any notifications besides the ones for your comments in this thread and can't find any comments elsewhere, sorry.
Good point, not sure how I missed that on the first version. I now added saving the recurrence and the enabled state along with the alarm time. The saved alarm is properly scheduled again after being loaded after boot if it was enabled
IMHO that is the wrong way to go and I commented there. Should there be consensus to merge that PR however, I will remove the logging in this PR. |
Rebooting to the last verified image is a nice fallback, when something goes wrong. But when testing features requires a reboot one has to verify the test firmware and loses that fallback.
Apparently I used that feature wrong. Sorry for the confusion. |
|
@minacode Verifying a firmware you're currently testing isn't as dangerous as it sounds at first. This is because if there is some issue with it, you can press and hold the button to reboot until you see the pinecone turn blue. This will rollback to the good now-secondary firmware even after you have validated the bad firmware. Source: about-software.md |
|
Adding the enabled state to persistence has made dismissing an alarm glitchy, I'll investigate more and fix later when I'm at my PC. Persistence works, but when the alarm rings, you have to exit the alarm app by long pressing the button as a workaround, as swiping down hangs the app. |
Also reverts the attempt at deferring saving the alarm data for reduced
flash writes, in order to reduce complexity.
Split `AlarmController.State()` into `.IsAlerting()` and `.IsEnabled()`,
since the two properties are conceptually independent and it makes code
much cleaner:
```diff
- if (alarmController.State() == Controllers::AlarmController::AlarmState::Alerting) { ...
+ if (alarmController.IsAlerting()) { ...
- if (alarmController.State() == AlarmController::AlarmState::Set) { ...
+ if (alarmController.IsEnabled()) { ...
```
See the removed `switch` for another example.
Size impact: +44 (400536 -> 400580)
2af96ce to
6fed68a
Compare
|
The problems dismissing the ringing alarm should be fixed now; I'll mark the tasks in the first post as done once the fix is tested and confirmed working. |
Support for InfiniTimeOrg/InfiniTime#1333 by @ght The PR adds saving and restoring alarm state to the SPI NOR flash. So the AlarmController needs the FileSystem-controller to work.
NeroBurner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the persistent Alarm implementation, thanks for the PR
This avoids writing the time to flash for every single change. Size impact: +16 (400580 -> 400596)
|
The idea about saving only on toggle and on changes didn't let me go. So I implemented the behavior and tested the firmware sizes to see the impact of my changes. It surprised me, but my desired behavior didn't increase the size anymore Opened a PR to make it easy to get those changes into your branch: ght#1 @ght please review |
|
@NeroBurner Thanks for trying it out! Cool to see that it does not necessarily increase binary size. This approach however has an API change I don't like: now the AlarmController no longer saves the alarm when data could be lost otherwise, but has to be told to do so explicitly by the caller. And not even consistently: in case of This gives me hope that it's doable without a size increase while keeping a clean API though. I'll look into it again too. I really do not want the caller to have to remember to save. But the alternative is that the caller has to remember not to save unnecessarily, to avoid wearing out the flash. What do you think of adding a timer to the alarm controller? Instead of committing every change to flash immediately, the timer is set to count down e.g. 10s or even just 5s and writing to flash only happens when the timer fires. That way it doesn't matter if the alarm app calls |
|
What real-life problem do you want to solve? The app saving once in the destructor should be enough for everything except when the app is never left.
Persistence is a feature that will come for more and more apps. And this behavior should be as standardized as possible or every app will tinker on basically the same problem. |
|
The
|
|
Ok, I like this behavior. We just have to keep in mind that every value change has to disable the alarm. Maybe this should be documented somewhere. |
Support for InfiniTimeOrg/InfiniTime#1333 by @ght The PR adds saving and restoring alarm state to the SPI NOR flash. So the AlarmController needs the FileSystem-controller to work.
|
Opened a rebased PR #1367 with simplified No need to work around bugs in the same firmware with saving the alarm. Instead such bugs should be fixed. This lets us keep the remaining code more simple |
|
@ght I hope it is ok I hijack your PR, trying to champion your idea to get it into the firmware as soon as possible |
|
@NeroBurner Ok to merge this? I think those changes require changes in InfiniSim too ? |
… to file Support for InfiniTimeOrg/InfiniTime#1367 which is a rebase/improvement of InfiniTimeOrg/InfiniTime#1333 by @ght The PR adds saving and restoring alarm state to the SPI NOR flash. So the AlarmController needs the FileSystem-controller to work. To support both the current `main` branch and the "save-alarm-to-file" PR pass the Filesystem controller conditionally, only if `Controller::FS` is mentioned in the `AlarmController.h` file
… to file Support for InfiniTimeOrg/InfiniTime#1367 which is a rebase/improvement of InfiniTimeOrg/InfiniTime#1333 by @ght The PR adds saving and restoring alarm state to the SPI NOR flash. So the AlarmController needs the FileSystem-controller to work. To support both the current `main` branch and the "save-alarm-to-file" PR pass the Filesystem controller conditionally, only if `Controller::FS` is mentioned in the `AlarmController.h` file
|
closing in favor of #1367 |
Save the set alarm time to the SPI NOR flash, so it does not reset to the default value when the watch resets, e.g. due to watchdog timeout.
Fixes #1330
Size impact: +248 (400332 -> 400580)