Avatar for Matjaz

Matjaz

Member since Oct 2020 • Last active Apr 2024
  • 1 conversations
  • 4 comments

Most recent activity

  • in JavaScript
    Avatar for Matjaz

    When I reboot (long press BNT1 + BTN2) the state is lost.
    So I guess that during the hardware setup stage, the state of all registers is initialized to some defaults. As a consequence, my flag is set to 0.

  • in JavaScript
    Avatar for Matjaz

    I am now storing the widget state in the SAMPLER register, with these two functions (and not setting it to false on boot):

    function getAlertsStoredState() {
        var addr = 0x40012508;
        var val = peek8(addr);
        val = val & 1;
        return val == 1;
      }
      
      function setAlertsStoredState( state ) {
        var addr = 0x40012508;
        var val = peek8(addr) & 254;
        if( state == true )
        {
          val = val + 1;
        }
        poke8(addr,val);
      }
    

    So far it looks like it works the way I intended.
    I would be interested to know if there is a way to make some code run only on first boot, but not on bnt3 long presses, but otherwise it works as expected.

    Thanks for all the advice and replies.

  • in JavaScript
    Avatar for Matjaz

    Thanks for the info. I might do the saving on kill event.

    Is there any other way ? Like just writing something to some memory location (I need to store a bool), some function call, anything ?
    I wanted to check if I could just write something at some memory location at random.

    The experiment:

    1.st: I find some memory address that I could potentially use by:

    var testArray = new Int8Array(10);
    E.getAddressOf(testArray,true);
    

    Return is 536883628;

    Then I write some number to this address:

    var num = 1 + 4 + 16 + 64;
    testArray[0] = num;
    testArray[1] = num;
    

    And check the output

    peek8(536883628,1);
    

    The return is 85, as expected.

    Now I reload the watch (long press on btn3).
    And try again.
    This time I get a different number (120 instead of 85).
    So this tells me the memory was changed and
    I can't use this trick to store some number between reboots.
    Is there another way ? Like some other memory location,
    some function to set some parameter ?

    Do I understand this correctly: long-pressing button 3 (or using load) will completely reset the js interpreter, and read all .boot files and so on ?
    Would it be possible to use a saved state of the interpreter (saved with http://www.espruino.com/Reference#l__glo­bal_save) which gets loaded at the beginning of a .boot script and contains a Int8Array ?

    Or is there really no way to achieve this ?

  • in JavaScript
    Avatar for Matjaz

    Hi,
    I am fairly new to javascript and I just got my bangle.
    However I already made my first widget, which does exactly what I want and is useful. The device really made this easy. Thanks.

    I have the following problem, however:
    I would like to preserve a state (boolean variable) in the widget, so that when I long press BTN3,
    the variable is not reset.
    I tried many things, including adding the variable to the global namespace from the widget. however each time I long press BTN3 all variables are lost.
    Is this expected ?
    Q: Is there any other way to preserve a widget's state between long presses of BTN3,
    apart from writing to storage ?

    I am planning to switch this state many times, and would like to avoid writing to flash.

Actions