Avatar for Steffen


Member since Jan 2017 • Last active Jan 2019
  • 15 conversations

Most recent activity

  • in JavaScript
    Avatar for Steffen

    I don't call analogRead() but there is another Waveform active (looking for brightness every 10 s).
    Does it have the same sort of interferences? In this case I'll need to coordinate them.

  • in JavaScript
    Avatar for Steffen

    After putting process.memory() at the end of the callback the errors seem to be gone, along with the inexplicable delays.

    @allObjects: On top of this, I've replaced setInterval with setTimeouts as you suggested. This ensures that the intervals never overlap, allowing to use much shorter intervals.

    Leaves the - somewhat academic - question open why explicitly calling the garbage collection via process.memory was necessary. GC takes about 15 ms, while the idle time between intervals is about 200 ms. I don't mind calling it, quite the contrary. Just thought that > 100 ms were enough for Espruino to decide to do it itself.

  • in JavaScript
    Avatar for Steffen

    .. published part of the code: well, it is pretty nested.
    The code is basically a presence sensor that needs to react snappy (turning on the kitchen light!!).
    I like your suggestion of using setTimeout instead of the more rigid setInterval. Although I think this way the root cause of the (very rare but annoying) delays is only obfuscated.
    I was trying something in the line of setTimeout within the callback but it didn't help so far. I obviously missed some point :(

  • in JavaScript
    Avatar for Steffen

    I'm using Waveform to rapidly read a sequence of data, very successfully. The code is like this:

    wfrm = new Waveform(5)
    wfrm.on('finish', callback)
    setInterval(() => {
      wfrm.startInput(A0, 50)
    }, 500)
    function callback(buf) {
      // do something with buf

    Every 500 ms a 'task' is started to do an A/D converesion, 5 times, at 50 Hz.
    When ready the callback evaluates the passed Uint8Array (argument 'buf') very quickly -> no problem at all.
    Sometimes, however, there are errors

    Uncaught Error: Waveform is already running
    Uncaught InternalError: Timeout on ADC

    Sometimes the callback has to do more, including an HTTP call. This might take longer than the repat interval of 500 ms an cause these errors.
    Does a long running callback (longer than 500 ms) really make the Waveform complain at the next startInput, as I'm thinking?
    Is there a way to effectively make the callback appear as completed although parts of the code still need to be executed - like process.nextTick?

  • in General
    Avatar for Steffen

    Wow, a basic JS technique I didn't even think of. This makes the introduction of a new echo-off-char really unnecessary. Thank you so much Gordon for engaging in this discussion!

  • in General
    Avatar for Steffen

    Yes, I've made good experience prefixing all commands with \x15\x10.
    Once I've disovered these magic characters a lot of trouble was gone! There are still constellations where an additional echo(0) seems to be required but I cannot tell which ones specifically.
    Btw, I understand that for \x10print(1);print(2)\n echo is off for both print statements, while for \x10print(1)\nprint(2)\n the second print statement is echoed (if echo was on). I believe that my need for echo(0) comes from more complex code snippets that are separated by \n.

  • in General
    Avatar for Steffen

    Thanks for your replies.
    @Gordon: Yes, it is mostly when starting a small "session" after a while. I agree with your concerns about accidentially pasted code, that's why I didn't just suggest it as enhancement.
    And for the exactly same reason the example has \x1f instead of \x02 (Ctrl-b).
    @Wilberforce: E.getTemperature was just an example. I don't always know which code is needed. If it's more than 1 line of code the only safe way is to send echo(0) first.

    Although I'm able to make code changes I don't want to run propriatary code builds. A year from now I might have lost interest in making own Espruino builds (not in Espruino) - then I'll loose either the official Espruino improvements or my propriatary enhancements.
    So I'll continue wasting 20 bytes with each session :)