• I tried for several hours to use my Puck (with latest firmware) as a BLE keyboard for macOS 15.1, but not even the example from "https://www.espruino.com/BLE+Keyboard" is working.

    I managed to pair my Puck and it was recognized as a keyboard. Somehow I was also able to skip the keyboard assistent, but pressing the Puck button simply does nothing (even when I prepare an editor and give it the keyboard focus)

    Did anybody else succeed with such a scenario?

  • I have just been able to successfully connect a "Flipper Zero" (see https://flipperzero.one/) to my Mac with macOS 13.6.1 and let it act as a keyboard (although it wasn't explicitly recognized as such, but only as a generic device)

    Thus, microcontroller-based devices are principally able to act like a keyboard - it's just that the Espruino Puck doesn't...(not out-of-the-box, at least)

  • This seems related to the other post you made yesterday as well? Let's discuss on there: https://forum.espruino.com/conversations/400568/#comment17571727

  • sure, but this one is more general. Nevertheless, as mentioned there: just a minute ago I was able to pair a Puck with one of my Macs and send keystrokes to it - details will follow!

  • what I can write so far is, that the Puck can not be paired with macOS 13.6.1, but with 15.0.1 and 15.1. However, from a macOS viewpoint, the Puck's behaviour does not seem to be "perfect" - i.e., while keystrokes can be sent, the Bluetooth section of the system settings tend to crash in various ways (sometimes, the settings app has to be restarted)

    My code will follow in a few hours - I have to stop here for the moment.

  • Ok, here is my report: what was expected to work within an hour (I am so naive!) finally took longer than a full day...

    My idea was to program a Puck to send the keystrokes needed to start the dictate mode under macOS. With a BT headset and the puck in my shirt pocket, I can then dictate effortlessly without needing access to a keyboard while having full control over when the Mac is listening and when not.

    As mentioned above, I lost an awful lot of time with macOS 13.6.1 where the HID emulation does not seem to work at all. With macOS 15.0.1 and the new 15.1, however, it seems to work good enough to be used. "Good enough" means, that pairing still works strange from time to time:

    • "forgetting" the device seems to be difficult, often you still have to connect the device once again in order to be actually forgotten
    • sometimes, the bluetooth section of the settings app crashes
    • sometimes, the "connect" buttons do no longer appear when hovering over the listed BT devices - in that case, just quit a settings app and open it again
    • sometimes, it's the best to "sudo pkill bluetoothd" from a terminal to reset the BT controller

    That said, here is my code:

      var Keyboard = require("ble_hid_keyboard");
    
      LED1.write(0); // switch red   LED off
      LED2.write(0); // switch green LED off
      LED3.write(0); // switch blue  LED off
    
    /**** configure Bluetooth keyboard ****/
    
      NRF.setServices(undefined, { hid:Keyboard.report });
    
    /**** configure advertising ****/
    
      NRF.setAdvertising([
        {}, {
          0x01: [0x06],
          0x02: [0x0A, 0x00],
          0x03: [0x12, 0x18],
          0x19: [0xC1, 0x03], // appearance: keyboard
        }
      ], { name: "Dictate Trigger" });
    
    /**** simulate keystrokes and give feedback in case of exceptions ****/
    
      function sendHIDReport (Report) {
        try {
          NRF.sendHIDReport(Report);
          LED1.write(LED1.read() > 0 ? 0 : 1);
        } catch (Signal) {
          LED1.write(1);
          throw Signal;
        }
      }
    
    /**** simulate key presses ****/
    
      function simulateKeyPresses () {
        LED1.write(0); // switch red LED off
        
                                 sendHIDReport([1, 0, 0, 0, 0, 0, 0, 0]);
        setTimeout(function () { sendHIDReport([0, 0, 0, 0, 0, 0, 0, 0]); }, 100);
        
        setTimeout(function () { sendHIDReport([1, 0, 0, 0, 0, 0, 0, 0]); }, 300);    
        setTimeout(function () { sendHIDReport([0, 0, 0, 0, 0, 0, 0, 0]); }, 400);
      } // red LED should now be off again
    
    /**** run keyboard simulation when Puck button is pressed ****/
    
      setWatch(function () {
        if (isConnected) {
          simulateKeyPresses();
        }
      }, BTN, {edge:"rising", debounce:50, repeat:true});
    
    
    /**** light green for 5 seconds after connection is established ****/
    
      var isConnected = false;
    
      NRF.on('connect', function () {
        isConnected = true;
    
        LED1.write(0);   // switch red   LED off
        LED2.write(0.2); // switch green LED on
        LED3.write(0);   // switch blue  LED off
    
        setTimeout(function () { // switch green LED off after 5 seconds
          LED2.write(0);
        }, 5000);
      });
    
    /**** start blinking blue again after disconnection ****/
    
      NRF.on('disconnect', function () {
        isConnected = false;
    
        LED1.write(0);  // switch red   LED off
        LED2.write(0);  // switch green LED off
        blinkBlueLED(); // start blinking blue again
      });
    
    /**** blink blue while advertising ****/
    
      function blinkBlueLED () {
        if (! isConnected) {
          LED3.write(LED3.read() > 0 ? 0 : 0.2);
          setTimeout(blinkBlueLED, 500);
        } else {
          LED3.write(0);
        }
      }
    
    /**** start advertising ****/
    
      NRF.setAdvertising(undefined, { connectable:true, discoverable:true });
      blinkBlueLED();
    

    As you can see, I added a lot of visual feedback in form of LED signals as there is no longer any console where one could report the current state or any exceptions...

    Have fun!

  • just a final note: I'm now looking like Captain Kirk in Star Trek when he touches his emblem to start communicating with the Enterprise...

    ok, perhaps not the Captain, not even Mr. Spock nor Scotty...but hopefully also not the completely unknown staff member who has to die before the episode ends...

  • Thanks for the update, and the code! Having something to trigger the dictation mode seems like a neat ideal.

    In that code I don't see anything to work around the keyboard detection dialog - was that not needed in the end?

    Having the Bluetooth connection dialog crash and have buttons not appear sounds pretty worrying. Personally, I think regardless of what a Bluetooth device does the OS shouldn't have stuff like that happen, so I'm inclined to blame Apple for the connection issues especially as other OSes seem fine with it. Lets hope they get a fix out soon.

    If it helps for the future, it is possible to attach a USB-TTL dongle to the Puck (https://www.espruino.com/Puck.js#serial-console) so you can fiddle around and send commands even when you're using the Bluetooth for other things. Not ideal obviously, but better than nothing!

  • Yes, I was able to simply quit the keyboard assistant without any bad consequences (what I did not know when it first appeared)

    And, yes, Apple never handled BT properly in the past - I always had problems. Working with a "black box" and just guessing why it does not work is quite difficult - and Apple wasn't of any help here.

    That said, the serial console you mentioned would have been helpful - although I wanted to avoid having to solder on the Puck device...in fact, I once hoped to complete that "little" project within an hour (oh God, I was so naive!)

    Nevertheless, in the end I succeeded!

    Thus: thanks a lot for that wonderful device called "Puck"!

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

I managed to use a Puck as HID for macOS (was: did anybody manage to use a Puck as a HID for macOS?)

Posted by Avatar for Andreas_Rozek @Andreas_Rozek

Actions