Pop Ups + text and mouse inputs

Posted on
  • Hi,

    I'm writing some Blockly Blocks and would like to alert the user when they do something bad (e.g. try to move a servo beyond its limits). Can I have the code generate a pop up when this happens? Something like





    Also, how do I accept text input on the terminal side of the Chrome IDE? I know I can input JavaScript functions there, but what about text strings? If not possible, then how do I write my own function that will be recognized there, so the user can type "hello" and it executes the function


    Finally, is there any way to accept a mouse input? e.g.



  • Hi,

    Popups are a bit tricky because as the code runs on Espruino, there's not a clear path from Espruino back to the UI. You could however do something like console.log("+++Your Error"); on the code that is sent to Espruino, and then you can detect that text arriving in terminal.js and can use it to show off the alert.

    It's also made a bit more difficult in chrome web apps because for some reason you're banned from using window.alert. You'd have to use the popup window code that's in the IDE (it's best to look at how other code does it).

    In a way it might be nicer to make terminal.js handle the VT100 character colour commands, and then you could just display the message in the terminal.

    As far as accepting input in the terminal, if you're trying to do that in Espruino itseslf you've got to move the original terminal out of the way, and write your own handler for characters:

    function getInput() {
     line = "";
     USB.onData(function(d) {
      if ((line!="" && d.data=="\r") || d.data=="\3") {
       console.log("Got text "+line);
      } else if (d.data!="\r")
        line += d.data;

    Note the "\3" check, which checks for Ctrl+C so you can break out of it.

    For mouse input, you'd have to check on the Blockly forums. There are already handlers in terminal.js (the terminal area) for mouse clicks and stuff, so you could potentially add something to those... Maybe even sending the VT100 escape codes, which you could then detect on Espruino with the USB.onData handler (like above).

  • Thanks Gordon. I tried your getInput() function and it complains that LoopbackA is undefined.


  • Thanks Gordon. I tried your getInput() function and it complains that LoopbackA is undefined.

    Are you using version 64? The loopbacks were just added in v64.

  • Thanks DrAzzy. Upgrading the version solved the problem.
    Is there anywhere I can write these functions once, so I can just call them when I boot up? i.e. is there code somewhere that always runs on boot up?

  • If you create a function called onInit and then save it to the board with save(), it'll be run on startup. But it you type save() then every function you defined is saved a well.

    Or are you after something in the web ide? I'd imagine you're better just tacking the code to the front of whatever you send from blockly...

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

Pop Ups + text and mouse inputs

Posted by Avatar for rsm @rsm