Comments (4)
The problem is not specific to USB implementation and is actually caused by keypress event being used in web application. Chrome on Android doesn't support keypress event for Gboard and it "won't be fixed". However some codes may be detected properly. There is a bug for this: https://code.google.com/p/chromium/issues/detail?id=118639. I've got some characters working with Hacker's Keyboard but not letters, specifically: 1234567890[]=\;',
Also I've been able to see output in receive window when I used Serial USB Terminal app for communicating with CDC interface.
Possible workaround is to replace keypress event with input event. But then it is necessary to parse content manually to get new characters as it returns full content of input field. The following is one possible way to see output in receiver window on Android.
commandLine.addEventListener("keypress", function(event) {
if (event.keyCode === 13) {
if (commandLine.value.length > 0) {
addLine('sender_lines', commandLine.value);
commandLine.value = '';
port.send(new TextEncoder('utf-8').encode('\r'));
}
}
});
commandLine.addEventListener("input", function(event) {
let textContent = event.target.value;
let lastChar = textContent.slice(textContent.length - 1);
port.send(new TextEncoder('utf-8').encode(lastChar));
});
Thanks for TinyUSB library!
from adafruit_tinyusb_arduino.
thank you for explanation and the suggestion. #151 try to use keydown event instead of keypress, which seems to be supported on Android. would you mind trying it out to see if that works on your board.
from adafruit_tinyusb_arduino.
Unfortunately, it looks like keyboard events on Android Chrome are messy. Keydown event is detected, but doesn't return practical value under key property. It always returns 229 code (which is Undefined). You can test it yourself on your phone using this website: https://w3c.github.io/uievents/tools/key-event-viewer.html.
Result seen on WebUSB Serial page is as follows:
Frankly speaking I don't know any other cross-platform way than using input event and manually parsing for changes in input field. Other workaround would be to send message only after some button is clicked, but then it won't feel like data is propagated in real time, so it depends on your requirements.
For the sake of completeness, actually I'm not using Adafruit_TinyUSB_Arduino library or Arduino core.
I am testing WebUSB Serial example with Pi Pico board and https://github.com/raspberrypi/pico-sdk. Binary is built from repository: https://github.com/mars-low/pico-usb-gadget and USB part is copy-paste from official TinyUSB example.
I've posted it here, because issue is independent of used board. Some time ago I've also tested it with Arduino Nano 33 IoT used in conjuction with https://github.com/adafruit/ArduinoCore-samd (files to support Arduino Nano 33 IoT were copied from mainstream). I've tested it on web using Blazor app https://github.com/mars-low/HardwebBlazor and I saw for the first time that communication works correctly on Android when API is used programatically. Because it was working for my purpose I haven't digged further until recently I've come across Pi Pico and saw the same problem.
from adafruit_tinyusb_arduino.
thanks @mars-low , the keyboard event viewer page is very handy. I confirm my android v9 keycode and key is both unidentified. Weirdly only Enter key is correctly reported. The issue with the walkaround is handling backspace and enter, in which we should send \r
and backspace, instead it will send nothing (with enter) and the next-to-last char (with backspace).
For the sake of completeness, actually I'm not using Adafruit_TinyUSB_Arduino library or Arduino core. I am testing WebUSB Serial example with Pi Pico board and https://github.com/raspberrypi/pico-sdk.
Thanks for the info, it is pretty much the web application. So this would help other as well. Once it is confirmed to work, I will update code on the main repo (then get pull by pico-sdk etc ..). The webserial is actually not very helpful app, I am thinking to change/add another app that would allow to control the on-board LED and/or report the state of on-board button. Which is more apparent that the code run on the actual hardware. (the echo can be easily thought as web-only echoing).
Thank you for following this up, I am sure we could figure out way to handle enter/backspace with android. I am in the middle of other works, and will come back to this later on.
from adafruit_tinyusb_arduino.
Related Issues (20)
- Request to add the CH375 Chip USB Host feature HOT 1
- cant verify correctly error: missing Adafruit_USBD_CDC.h file eventhough i have it. HOT 2
- examples/HID/hid_boot_keyboard not working. HOT 1
- Conflicting Types in 3.1.3 HOT 5
- Failed to compile msc_sd example
- Compiler states: SPI header is missing, causing compilation to terminate. HOT 1
- CFG_TUSB_DEBUG=2 Serial deadlock on nRF52840
- "midi_test" does not compile for ESP32S3 HOT 5
- Allow setting of USB Power parameter
- How should I be compatible when encountering unsupported USB devices? For example, a mouse?
- 3.1.3 and 3.1.4 cause delay in enumeration
- My mouse is not working properly in the example of hid_device_report.ino, as it is unable to output data for the scroll wheel
- ESP32-S3: Adafruit_TinyUSB sending garbage / loopback-like traffic on reading only sketch. HOT 2
- Add custom report descriptors HOT 1
- Allow to see progress of file copy HOT 1
- Not working USB HID examples, device is never ready
- USB MSC on Not Attaching Feather ESP32-S3 Reverse TFT HOT 5
- usb host not working with pio-usb v0.6
- USB Host implementation hangs when sending long strings HOT 1
- TinyUSB - RP2040 Compilation Error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adafruit_tinyusb_arduino.