joeycastillo / Sensor-Watch

A board replacement for the classic Casio F-91W wristwatch
Other
1.17k stars 234 forks source link

Face settings: A fairly easy way to store watch face data persistently #257

Open TheOnePerson opened 1 year ago

TheOnePerson commented 1 year ago

In this PR, I have put together a solution for persisting data of a watch face trying to keep the logic for storing and reading the data files as encapsulated as possible: file_settings.c & file_settings.h implementing two functions face_settings_init() and face_settings_save().

The implementation of persistent storage for the alarm face looks like this:

This PR also extends the following faces, so that they persist their settings:

Any comments welcome! Let me know if you consider this a feasible approach.

P.S.: I had to heavily alter filesystem.c, too, so that it now uses the browser's localStorage to save and load files. This is due to easier debugging and to get any persistence at all in the emulator.

TheOnePerson commented 1 year ago

Converted this to draft again: I feel like I should simplify the data structure for holding face’s settings details a little bit, thus saving 4 bytes per entry. Will take care of it over the next couple of days.

TheOnePerson commented 1 year ago

I had to make a small change to the preferences face. When the alarm face is present, too, I may happen that the preferences face restores movement's settings after the alarm face has restored its face settings, resulting in blanking out the alarm indicator erroneously. Tbh, the whole construct of persisting movement settings from the preferences face feels a bit dodgy. The cleaner approach would be to move the logic for saving and restoring the data right into movement.c. But I hesitated to change this very central piece of code without feedback from @joeycastillo.