How to reset a Pico after USB HID examples?

Posted on
  • A question concerning this example page.
    Espruino USB HID

    If you copy one of the examples into the WebIde, send it to a Pico, and save it, how can you restore the Pico to its original state?
    Perhaps rig a push button on a pin and do a setwatch on that pin that does a reset()?

  • Yes, if you've remembered you could do a reset in software :)

    Otherwise have a look in Troubleshooting (http://www.espruino.com/Troubleshooting), under Espruino stopped working after I typed save() - there are some instructions there.

    The last-ditch option is just to reflash your board, which will wipe out any saved code :)

  • Had time to try the mouse driver today. Here's the code:

    //mymouse.js
    // 15 Nov 2017
    //
    // Use pushbutton on pin B3 to reset
    // Loads mouse driver into the USB boot
    // Every second move mouse cursor by 20 pixels
    // in a square pattern
    //
    //load and save the program
    // unplug and replug the Pico USB
    // mouse cursor should be moving in square pattern
    // reconnect to WebIde
    // mouse cursor still moving
    // Type reset() in left  pane of WebIde
    // Type save() in left pane of WebIde
    
    
    var mouse = require("USBMouse");
    
    // A way back to normal just in case
    var but1=B3;
    setWatch(function(){
      console.log("endit");
      reset();
    },but1, {debounce:100,repeat:true, edge:"falling"});
    
    var i=0;
    setInterval(function () {
    //console.log(i);
      switch (i){
        case 0:
          mouse.send(0, 20, mouse.BUTTONS.NONE); // X movement, Y movement,
        break;
        case 1:
          mouse.send(20, 0, mouse.BUTTONS.NONE); // X movement, Y movement,
        break;
        case 2:
          mouse.send(0, -20, mouse.BUTTONS.NONE); // X movement, Y movement,
        break;
        case 3:
          mouse.send(-20, 0, mouse.BUTTONS.NONE); // X movement, Y movement,
        break;
      }
      i++;
      if( i>3) i=0;
    }, 1000);
    

    It's interesting that the WebIde still talks through the USB port with the mouse functions.

  • Great!

    It's interesting that the WebIde still talks through the USB port with the mouse functions.

    Yes, that took a long time to get working right :)

  • I've been searching for some Vogan poetry to further understand what is going on. Some of it gets really deep in the weeds.
    Here is a link that seems to be about the right level to start with.

    Usb Made Simple

    It covers the hardware and bus messages but importantly the Descriptors that are used in the module.

    This tool looks like it could be useful for creating a descriptor

    HID Descriptor Tool from USB.org

    @Gordon Espruino continues to amaze!

  • Annotate the report descriptor

    /* Annotate the report descriptor 
    http://www.usbmadesimple.co.uk/ums_g_an_­ms_8.gif
    */
    /* Copyright (c) 2015 Gordon Williams, Pur3 Ltd. See the file LICENSE for copying permission. */
    /* 
    
    var mouse = require("USBMouse");
    
    setWatch(function() {
      mouse.send(20,20,mouse.BUTTONS.NONE); // X movement, Y movement, buttons pressed
    }, BTN, {debounce:100,repeat:true, edge:"rising"});
    
    
    */
    /*
    E.setUSBHID ⇒
    
    (top)
    Call type:
    
    E.setUSBHID(opts)
    Description
    
    USB HID will only take effect next time you unplug and re-plug your Espruino. If you're disconnecting it from power you'll have to make sure you have save()d after calling this function.
    
    Note: This is only available in devices that support USB HID (Espruino Pico and Espruino WiFi)
    
    Parameters
    
    opts - An object containing at least reportDescriptor, an array representing the report descriptor. Pass undefined to disable HID.
    */
    E.setUSBHID({
      reportDescriptor : [
      0x05,   0x01, //Usage Page (Generic Desktop Controls)
      0x09,   0x02, //Usage (Mouse)
      0xA1,   0x01, //Collection (application)
      0x09,   0x01, //Usage (Pointer)
    
      0xA1,   0x00, //Collextion (Physical)
      0x05,   0x09, //Usage Page (Button)
      0x19,   0x01, //Usage Minimum (1)
      0x29,   0x03, //Usage Maximum (5)
    
      0x15,   0x00, //Logical Minimum (0)
      0x25,   0x01, //Logical Maximum (5)
      0x95,   0x03, //Report Count (3)
      0x75,   0x01, //Report Size (1)
    
      0x81,   0x02, //Input (Data, Variable,Absolute,Bit Field)
      0x95,   0x01, //Report Coint (1)
      0x75,   0x05, //Report Size (5)
      0x81,   0x01, //Input (Constant, Array, Absolute, Bit Field)
    
      0x05,   0x01, //Usage Page (Generic Desktop Controls)
      0x09,   0x30, //Usage 00
      0x09,   0x31, //Usage (X)
      0x09,   0x38, //Usage (Wheel)
    
      0x15,   0x81, //Logical Minimum(-127)
      0x25,   0x7F, //Logical Maximum(127)
      0x75,   0x08, //Report Size (8)
      0x95,   0x03, //Report Count (3)
    
      0x81,   0x06, // Input (Data, Variablr,Relative, Bit Field)
      0xC0,  //End Collection
    
      0x09,  0x3c, // ?????
      0x05,  0xff, 
        
      0x09,  0x01, 
      0x15,  0x00, 
      0x25,  0x01, 
        
      0x75,  0x01, 
      0x95,  0x02, 
      0xb1,  0x22, 
        
      0x75,  0x06, 
      0x95,  0x01, 
      0xb1,  0x01, 
      0xc0  //end collection
    ]
    });
    
    exports.BUTTONS = {
      NONE : 0,
      LEFT : 1,
      RIGHT : 2,
      MIDDLE : 4
    };
    
    exports.send = function(x,y,b) {
      E.sendUSBHID([b&7,x,y,0]);
    };
    
    
    /*
    E.sendUSBHID ⇒
    
    (top)
    Call type:
    
    E.sendUSBHID(data)
    Parameters
    
    data - An array of bytes to send as a USB HID packet
    
    Returns
    
    1 on success, 0 on failure
    */
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

How to reset a Pico after USB HID examples?

Posted by Avatar for ClearMemory041063 @ClearMemory041063

Actions