Shut Console.log with unplugged usb by code?

Posted on
  • Hello.

    I use console.log for debugging purpose, when the board is unplugged but powered, the prog stop after a while because of the fullness (sorry for the word) of the buffer.
    Is there a way to kill output if usb is unplugged? (I'm a lazy guy and don't want to comments all my console.logline.😱)
    I suppose there is something to write in the onInit()...

    Many Thanks

    é.

  • It'll only happen for you if the board is powered from a PC (so there's an active USB connection) - if it's powered from a USB wall supply or any external power then it won't be a problem.

    You can move the console to something like Loopback with LoopbackA.setConsole(1) - but you probably want some way to move it back with USB.setConsole() when you want to interface to the device.

    Of course the other option is just to do console.log = function(){}; - but if there are other prints (for example exceptions) then that is capable of filling up the buffer as well.

  • hum, i'm a bit confuse

    LoopbackA.setConsole(1)
    

    in the code... to avoid the buffer pb (or need to open the webide)
    and

    USB.setConsole()
    

    in the console in the webide, if i want the log back?

    regards

    é.

  • Once you move the console with LoopbackA.setConsole(1) nothing you type in the Web IDE will work.

    Ideally you would call it somehow from within Espruino. Eg.:

    setWatch(function() {
      USB.setConsole();
    }, BTN, {repeat:true,edge:"rising",debounce:50})­;
    

    Then when you press the button you get control back.

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

Shut Console.log with unplugged usb by code?

Posted by Avatar for Mrbbp @Mrbbp

Actions