Debugging HID/Keyboard with serial to another Puck? #3530
Replies: 47 comments
-
Posted at 2017-03-29 by @gfwilliams Wow, that's pretty extreme! I'd say try using a Pico if your USB-TTL converter doesn't work - the flashing code for http://www.espruino.com/ESP8266 actually sets a Pico up as a pass-through. With Puck-Puck there's a bit of a catch-22. The serial port takes power, so won't initialise itself if the Puck is powered on without serial connected (the RX pin pulled high). Obviously if you connect 2 Pucks together neither will initialise, so you'd have to manually enable serial on one first with I actually fixed a whole bunch of HID-related bugs just recently, so first it might be worth trying the attached zip file. I'm still trying to get it working stably, but the attached build just happens to work fine by the look of it. There are 2 issues that might cause problems that the recent build fixes:
Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-29 by tom.gidden Ah, okay... I'm DFU'ing that build now, thanks. I was thinking exactly of that Pico pass-through code before I wondered if I could use a second puck. I see what you mean about the Catch-22. Anyway, I'll try this out. FYI, this is how it's being used: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-29 by @gfwilliams Cool - what's the idea? Is that some kind of rubbery gauntlet thing? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-29 by tom.gidden It's actually rigid: Thermomorph / Polymorph, ie. polyester plastic that melts in hot water. It's so that when I'm relaxing and recovering from back pain, lying down, I can just turn page on iBooks on iPad by sending a "right" keypress. That way I don't have to hold the iPad or reach up to turn page, thus saving my shoulder and upper back muscles from unnecessary tension. Incidentally, I haven't managed to get the new firmware talking yet. In fact, it's having trouble connecting to the Web IDE. I think my Mac needs a reboot. Still trying. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-29 by tom.gidden Nope.. this build seems to just do a full reset (RGB LEDs all to full for about a second, then off, then a short red blink) when I try to connect to it via Web IDE, or pair it with the iPad. I'm going to DFU it again to make sure it's not my code, but I doubt it. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-30 by @gfwilliams That's really neat! I'd love to see Puck.js used for some more stuff like this! I guess you could detect long presses (or maybe even use the magnetometer) and mimic other keypresses with it. That's odd - maybe it's an issue with saved code (I had to move the saved code location and it might be messing up the pairing). Can you try this on a working firmware, and then uploading the new one?
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-30 by tom.gidden Okay, that did the trick: I DFU'ed to 1.91, did the lines above, and then DFU'ed to 1.91.715. It now pairs more successfully. However, it hasn't been entirely successful. It took about three goes of code tweaking, re-upload, resets, unpair/pair before the iPad would actually do the "page right" function. It's working okay now, even after an FYI: at least with this firmware, |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-30 by @gfwilliams Thanks for checking - I'll make sure I do something about wiping the old saved code in the final version. Odd about the dump() problems though. I'll take another look - it's all really flaky at the moment for some reason - I've had a lot of problems with the Nordic peer management stuff :( |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-30 by tom.gidden (Incidentally, I've just written up the project) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-08 by tom.gidden After exhausting a CR2032 in about a month, I've been tweaking my page-turner trying to make it more efficient. I'm wondering about the best approach for saving energy between clicks as well as between sessions. I've got a timeout of ~10 seconds that is reset every time the button is clicked; when the timeout does activate, it performs an I've tried doing However, I get some weird bugs. With When
I assume It's to be woken by a button click, and doesn't really require discovery when the device is "cold", so sleeping all of the BLE stuff seems reasonable; I'm not sure if an entire shutdown of the softdevice is in order. Disconnecting any HID connections when the device isn't being used is also desirable for the on-screen keyboard reason given above. My code's attached, with the Any thoughts?
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-09 by @gfwilliams Have you tried Realistically it'll be the actual HID connection to the computer that sucks all the power, rather than the advertising. setLowPowerConnection modifies the connection interval so next time you connect it's only polling twice a second rather than ~50 times a second. Worrying about the I'd give it a shot with all the wake/sleep/disconnect stuff removed, and just with setLowPowerConnection - I reckon that should make a massive difference. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-09 by tom.gidden Thanks, I'll try that. I do want to get So, do you think keeping track of the HID connection (the (EDIT: Oh, hang on... that won't work... these connections are initiated by the iPad; there's no |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-09 by @gfwilliams Yes - I think you'll need to just do If you can reproducably get the 3 lights on with a small big of code it'd be great (even better if it was without HID) - then I should be able to track it down a lot better. I wonder whether it might be related to Bonding again... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-09 by tom.gidden I was going to say I've managed to isolate it down to a few lines of code, but ended up with this situation:
Hmm. I think there's something rather wrong. I've DFU'ed it back to 1v92, and tried various resets and flash resets. This is since I started doing UPDATE (#3): I've managed to get it (and the other Puck I soft-bricked) back using the five-green-flashes method, This is all on 1v92 stock on one puck and 1v92.3045 (a fresh build) on the other. I think the I've had big problems with From my limited understanding of BLE, I can see that the idea of getting the client (the iPad) to stop connecting to the Puck is problematic. The only way I can see this working is if I can shut down BLE, or HID advertisement, and then restart it when a button is pressed to wake it up. I'm still rather unclear on what can and can't be done while connections are open, and so forth. Some commands will queue for the next reset, but things like I'm still trying to isolate some code to demonstrate it. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-12 by @gfwilliams It's really strange about your error 8 - I guess it must have been something in the saved code. I think I need to come up with a better way of handling the 'save on send' thing - it seems a lot of people are hitting problems when turning it on, uploading, then trying to do things after it's turned off if the existing code is still saved. It definitely looks like there's some issue with |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-26 by @gfwilliams Yes, thanks for spotting it! It's a strange one as for whatever reason I wasn't able to trigger it manually before. I've just pushed new code with the extra advertising library removed, so hopefully you'll get better results using the delay. Hopefully other changes I made haven't messed up the bonding/HID stuff :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-26 by tom.gidden Ah, okay. I just tried your Thanks for the fix; I'm eager to try it. Have you got the most recent Puck binary, by any chance? I haven't got cross-compilation rigged up at the moment. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-26 by @gfwilliams Maybe try using a shorter delay? The latest Travis build should have it in... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-26 by @gfwilliams |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-27 by tom.gidden After scrapping my FTDI232 for now and buying a new USB-to-Serial, I've finally got it talking via serial; I'm now getting a range of errors, including:
on disconnect; the dreaded 13313 appeared once or twice, as well as Anyway, I'm going to clear this down and start again. I really appreciate your patience. :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-27 by @gfwilliams Weird... Error 15 is 'FORBIDDEN'! NRF_ERROR_INVALID_STATE is error 8 - I've just been adding text versions of the errors. At least you're getting something via serial now - that should hopefully help things along quite a lot. Any luck with the |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-27 by @gfwilliams By the way, just to confuse matters: The UART needs the high speed clock on, which kills power consumption - so the act of actually having the UART connected at startup will affect the power draw all by itself :( |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-27 by tom.gidden 250ms seems to work. I've also eliminated a lot of the problems by encapsulating the entire program within When I use serial, it tends to behave a little differently on the BLE side, and since serial will suck the battery dry -- I've used up two CR2032s this afternoon alone! Thank IKEA and Lidl for cheap cells -- it's not much use for the original purpose of testing power consumption. Saying that, the new firmware has seemed to stop the 3mA current draw when sleeping. I'm having to unpair/pair the device on the iPad to get it to properly act, sometimes. I've updated the Gist above with my current code, if interested. I'm going to try it out properly tonight. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-27 by @gfwilliams Great! Glad it's working!
The new firmware will still break if you don't have the delay though. I've filed a bug with Nordic in the hope that they'll have some workaround - it does seem to be an issue with the Nordic SDK rather than Espruino itself. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-27 by @gfwilliams Also, 2 batteries in one day?? I'm really surprised. They're supposed to be 200mAh batteries at least, and usually even if you're doing a bunch of stuff with the microcontroller it'll only draw 4mA - so you'd hope to get 50 hours out of it. If you turned the LEDs on the power draw would go right up, but still - it takes commitment to drain them so quickly :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-10-05 by Gene Hello, what's the latest status on this project Tom & Gordon ? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-10-05 by Gene (ie the most up-to-date code / link ) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-10-05 by @gfwilliams Which bit are you interested in? As of 2v07 Bluetooth HID is pretty stable now, power usage is right down as well. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-10-13 by tom.gidden I’ll have to update too! Incidentally, I just noticed this new message on my iPad... must be something in the latest iOS as I haven’t done anything to my Puck for months — if it ain’t broke... Any ideas? Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-10-14 by @gfwilliams My initial thought is that's probably Apple's way of saying "you didn't pay us to be part of our MFi program". At least they didn't go out of their way to actually block it from working. But after some googling it seems it even affects some Apple Bluetooth accessories, and Apple's website says "some iPad models": https://support.apple.com/en-us/HT211009 So my guess is that it shares the same radio hardware for WiFi and Bluetooth, so whenever it has to service Bluetooth it has to stop transmitting on WiFi. It's possible that if you do |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-29 by tom.gidden
Hey,
I'm using the HID Keyboard example - https://www.espruino.com/Puck.js+Keyboard plus simple LED on/off with button press/release - to try to send a single keypress to an iPad.
While it sometimes works, once it's cut off it does nothing: the LED still lights when pressed so the code's still working, but there's no effect on the iPad. The Puck is still paired and connected with the iPad.
Now, I've noticed espruino/Espruino#1101 and some other ideas, but what's really tricky is the limitation that the Puck must be disconnected from the IDE to pair it with the iPad: only one connection at a time. It means I have no error messages visible to debug the problem.
My NoName™ FT232 USB-to-serial board is not working for some reason - probably lack of flow control - and the wiring is unwieldy, so I was thinking the other Puck I got from Kickstarter might be an easy way to do it. Failing that, I might rope a spare Pico in to act as a dumb serial converter.
So, I guess my question is, what's a straightforward way to cross-connect the serials of one Puck with another Puck, so the IDE (or at least the command-line errors) can be viewed while still connected as a HID device? Or, any other approaches to try?
Thanks,
Tom
Beta Was this translation helpful? Give feedback.
All reactions