Skip to content
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

Alarm persist to flash #1367

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

NeroBurner
Copy link
Contributor

rebase of #1333 with additional SaveAlarm() function as described below


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
or a firmware update

Introduce SaveAlarm() member function which saves to file only if the
alarm setting is changed.
The alarmChanged boolean flag mimics the behavior of settingsChanged
flag from Settings.h

Also mark the SaveAlarmToFile() function const, as it doesn't change
anything in the AlarmController object.


This PR needs InfiniTimeOrg/InfiniSim#67 to work on InfiniSim

@NeroBurner NeroBurner added this to the 1.11.0 milestone Oct 12, 2022
@NeroBurner NeroBurner changed the title Alarm persist to flash neroburner Alarm persist to flash Oct 12, 2022
@NeroBurner NeroBurner modified the milestones: 1.11.0, 1.12.0 Oct 16, 2022
src/components/alarm/AlarmController.h Show resolved Hide resolved
src/components/alarm/AlarmController.h Outdated Show resolved Hide resolved
ght and others added 3 commits October 27, 2022 22:17
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.
Introduce `SaveAlarm()` member function which saves to file only if the
alarm setting is changed.
The `alarmChanged` boolean flag mimics the behavior of `settingsChanged`
flag from `Settings.h`

Also mark the `SaveAlarmToFile()` function const, as it doesn't change
anything in the `AlarmController` object.
@NeroBurner NeroBurner force-pushed the alarm-persist-to-flash-neroburner branch from ac410fa to 3969a4a Compare October 27, 2022 22:01
lfs_file_t alarmFile;
AlarmData alarmBuffer;

if (fs.FileOpen(&alarmFile, "/alarm.dat", LFS_O_RDONLY) != LFS_ERR_OK) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we add features that allow users to access the filesystem, we need to decide if the root of the filesystem will be generally accessible for the user, or if there'll be a "home directory". If the root will be accessible, system files must be placed in a directory.

I think the current structure used for the resources isn't really optimal if the root will be generally accessible. I think I'd prefer creating a safe "home directory" and limit general access to under that directory, which wouldn't require changes in this PR necessarily.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the filesystem is used to store

  • user settings
  • BLE bonding info
  • external resources since 1.11

The end users are not supposed to access those files directly : infinitime manages the settings/bonding data and the resources are uploaded following a specified procedure. But, they can, for example, customize the external resources if they want to (and if they know what they are doing).

What do you mean by "generally accessible" ? I don't think the users will ever need to create and manage their own file on the FS. This is at least not the case for now. Which files would you put in the "home directory"?

I'm OK to define a folder structure to keep the FS clean & tidy. For example:

  • system : settings + bonding info
  • resources : external resources (with subdir for fonts, pictures,...)
  • apps : config and data files specific for each application that need persistance

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine users would need to be able to access the filesystem to install apps, translations, files for viewing with a gallery app, maybe customization patches, it could be anything.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I guess those files will have to be stored at the exact location where InfiniTime and the apps will look for them, the users won't be able to upload those file anywhere they want in their home directory. For example, InfiniTime will look for translations in a specific folder and the gallery app will look for pictures in another specific folder.

So how will we specify which file must be stored in /home rather than in another "system" folder?

Copy link
Contributor

@Riksu9000 Riksu9000 Jan 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's getting a bit off topic, but I think we should never place anything in the user directory, so only user uploaded files would be there. The thing I'm concerned with here is the user having to navigate among system files. Only giving access to a user directory (by default) would be my preferred way to resolve the issue. If we instead allow root access by default, then I think there should be no files directly at root.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want the user to encounter system files.

Let's imagine adding files to the filesystem. On my phone there are directories to put your music, pictures, etc.. On the PineTime with root access, you would see alarm.dat, settings.dat, etc., which doesn't seem right to me.

There are two solutions to the problem, and we can even implement both.

One is not placing any files in the root and making sure the user doesn't mistakingly enter system directories.

Second is not allowing access to the root in the first place. I suppose this would be done by restricting the BLE FS API, but I'm thinking about the issue more conceptually.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Ok, I understand. Currently, the users never interact directly with the FS. It's possible for them to replace a resource with a custom one if they want to, but that's not expected. But yes, in the future, with apps like the Gallery, they'll probably have more opportunities to use the filesystem.

Our current BLE FS API doesn't prevent anyone from accessing any file in the FS, and I don't think we should restrict the BLEFSAPI to a specific folder. Companion apps might want to provide an easy way to edit the settings, the alarm or even the bond info (or clear them). They also need to access the FS to upload the resources.

So yes, we can create folders for specific folders like I say in a previous comment (with an additional home folder for user customizable files, maybe), but I don't think we'll be able to prevent the users from accessing other folder than the home folder.
It is also possible for companion apps to implement UIs specific to some apps/files so that the user does not have to manually upload and update the file, this will be implemented by the companion app.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we prepended all system directories with a dot and asked companion apps to hide directories beginning with a dot by default? I propose moving the alarm file to .system/alarm.dat.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually a good idea! Yep, I approve :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should we do about the existing files and directories? @JF002

@JF002 JF002 removed this from the 1.12.0 milestone Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants