• Testing robustness of SWBtn's .disable() method

    Copy SWBtn and test code at the bottom of this post into edit pane and send it to Espruino.

    Basically, there will be intervals with enabled and disabled SWBtn. During and straddling those intervals you will perform press sequences.

    Be prepared to timely perform press sequences as instructed below while test code shows passed seconds in command window.

    The test code will do this:

    1. Starts mySWBtn in enabled state and shows passed seconds in command pane
    2. Disables mySWBtn after 7 seconds (7 seconds after start)
    3. Re-enables mySWBtn after 7 more seconds (14 seconds after start)

    You perform these timely sensitive press sequences:

    1. About 1 to 2 second after test code started, begin and complete a press sequence with a few short presses.
      2 . About 4 to 5 seconds after test code started, begin a press sequence with at least four (5) long presses that lasts beyond second 7 or 8 after start. Try to make at least three (3) or more long presses by second 7.
    2. Before 14 seconds after test code started, perform a complete press sequence with a few short presses. Note that press sequence has to be completed before second 10 after start.
    3. After 14 seconds the test code started, perform a press sequence with just one (1) or two (2) long presses.

    The output you will see in the command pane should look like this (on [1v67] - at this time the most recent version):

    `
    ...
    Second: 1
    Second: 2
    BTN1 detected SSS
    Second: 3
    Second: 4
    Second: 5
    Second: 6
    Second: 7
    mySWBtn disabled - Partial press sequence:  .k={LLL}
    Second: 8
    Second: 9
    Second: 10
    Second: 11
    Second: 12
    Second: 13
    Second: 14
    mySWBtn re-enabled
    Second: 15
    Second: 16
    BTN1 detected LL
    Second: 17
    Second: 18
    ...
    `
    

    ...which means, that:

    1. Partial long presses sequence is noticed on disablement
    2. Short presses sequence between second 7 and 14 is not noticed
    3. Press sequences after re-enablement are not affected by partial sequences

    Note1: press the reset button to stop the test code's seconds to keep going on. Disconnect is not enough (After reconnect, passed seconds output shows at once). Of course, powering off does stop it too,

    Note2: At one time I got Uncaught Error: Unknown Timeout in the command pane (plus details about where in the code it happened) - this happened before I got all my robustness ducks in a row. But it raised the question:

    Should clearTimeout(withInvalidTimeoutId) or clearTimeout(withTimedOutTimeoutId) even 'throw' this or any error? - afaik, JavaScript in browsers do not 'throw' any error under these circumstances... may be those implementations arn't up to spec (yet)... and what about me... - :( oooops! - ?

    For fun, extend (and post your) test that begins with a disabled button and shows that it is disabled and starts observing press sequences when enabled.

    Notice that when a press sequence is going on and the button is (re-)enabled, only the part that leaps into the (re-)enabled period is picked up... and if the (re-)enablement happens during a long press, this long press may be detected as a short press.

    So far, only software and a (external) button operator are used for the testing. Adding some hardware - such as a wire that connects an output (configured) pin with and input (configured) pin or even using another Espruino board - and creating a SWBtn on the output pin controlled input pin allows to write complete software driven testing of the SWBtn. For sure something worth to be tackled at a later point in time.

    var mySWBtn = new SWBtn(function(k){ // create mySWBtn (on BTN1 and enabled)
        console.log("BTN1 detected " + k);
      });
    var secs = 0, t1 = 7000, t2 = 7000; // define seconds and t1/t2 inteval timings
    setInterval(function() { // get the seconds going 1,2,3...
      secs = secs + 1;
      console.log("Second: " + secs);
     },1000);
    setTimeout(function(){ // get the intervals t1 and t2 going with disable and re-enable
      mySWBtn.disable(1);
      console.log(["mySWBtn disabled - Partial sequence: {",mySWBtn.k,"}"].join(""));
      setTimeout(function(){
        mySWBtn.disable();
        console.log("mySWBtn enabled");
      },t1); // 7 [s]
     },t2); // 7 [s]
    
About

Avatar for allObjects @allObjects started