• Hi,

    I am developing a timer widget.
    As this only counts the seconds when it is loaded, I am storing the current seconds to flash.
    This way it can pick up where it left when the widget is loaded again.

    const storage = require('Storage');
    storage.write('chronowid.json', settings);
    

    Currently I am doing this every second, but could this hurt the flash memory?

    Thanks

  • Tue 2020.04.14

    'but could this hurt the flash memory'

    Eventually, especially as there are 86,400 seconds in a day!

    page 19 spec max ratings:   https://infocenter.nordicsemi.com/pdf/nR­F52832_PS_v1.1.pdf


    'This way it can pick up where it left when the widget is loaded again'

    Maybe the usage logic is a bit off? As the widget is used say once a day, why the need to save every second? Just archive when idle, or before the widget is dismissed.

  • Eventually, especially as there are 86,400 seconds in a day!

    I am only storing once a second as long as the timer is active. When the timer is not active, the widget is loaded, but not shown.

    Just archive when idle, or before the widget is dismissed.

    Yeah, that would be better. But how can I detect that widget is being dismissed?

  • There isn't enough detail here on what and how the widget works, or how the user interacts with it. So can only guess. One idea might be to build a watchdog using setTimeout() and reset the watchdog every time the user interacts, (moves, presses button, etc) otherwise, save file (storage) and dismiss.

  • It is a widget counting down and displaying time.
    Each second 1000 ms are substracted from the counter.
    The counter (time left) is written to a file each second, to not lose progress.

    The user interaction is done via an app to set hours, minutes, seconds and to activate the timer. When activated, the widget is shown.

  • Yeah, that would be better. But how can I detect that widget is being dismissed?

    Would the the E.on('kill',...) event work? (see https://github.com/espruino/BangleApps/b­lob/master/README.md#misc-notes)

  • Bangle Reference

    https://banglejs.com/reference#l_E_kill

    This event is called just before the device shuts down for commands such as reset(), load(), save(), E.reboot() or Bangle.off()

    Still having difficulty grasping why the need to use flash as often, as presumeably the user will be monitoring the timer, as they wouldn't have set it otherwise? Under that condition, the timer will always be running in the seconds duration update interval. This explains the design usage of the Storage module by Gordon himself:

    post #9 Moar space for code

  • When I open an app which does not show widgets, the timer progress is lost.
    And the kill event is not triggered then, I think. But I will try this anyway.

  • Currently I am doing this every second, but could this hurt the flash memory?

    It's definitely not something I'd recommend. Eventually it'll fill flash memory and that'll have to be cleared. Using the kill event would be infinitely better.

    When I open an app which does not show widgets... the kill event is not triggered then,

    The kill event is built into the firmware, so should always be fired (apart from in the case where you hard-reboot using BTN1+BTN2, which should be amazingly rare)

  • The kill event is built into the firmware, so should always be fired

    Ah, I just tried it and it should work.
    I thought the event would only be triggered when the watch itself is 'killed', but it is already triggered when the widget is 'killed'.

    Of course it makes sense to only write the timer progress to the file on the kill event, not every second (or even regularly without need).

    Thanks.

  • An other approach would be to save the time when the timer was started, and calculate elapsed time from (current time - start time) when the widget is loaded. That would allow the timer to keep track of the elapsed time even when the widget is not loaded.

  • I completely rewrote the widget and it is now based on a target time.
    This time is written to the file once from the config app. No need to write regularly.

    Thanks for the suggestion.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

[Solved] How frequently to write to flash without damage?

Posted by Avatar for Purple-Tentacle @Purple-Tentacle

Actions