|
11 | 11 |
|
12 | 12 | #include "Adafruit_TinyUSB.h"
|
13 | 13 |
|
14 |
| -/* This sketch demonstrates WebUSB |
| 14 | +/* This sketch demonstrates WebUSB as web serial with Chrome browser. |
| 15 | + * After enumerated successfully, Chrome will pop-up notification |
| 16 | + * with URL to landing page, click on it to test |
| 17 | + * - Click "Connect" and select device, When connected the on-board LED will litted up. |
| 18 | + * - Any charaters received from either webusb/Serial will be echo back to webusb and Serial |
| 19 | + * |
| 20 | + * Note: |
| 21 | + * - The WebUSB landing page notification is currently disabled in Chrome |
| 22 | + * on Windows due to Chromium issue 656702 (https://crbug.com/656702). You have to |
| 23 | + * go to https://adafruit.github.io/Adafruit_TinyUSB_Arduino/examples/webusb-serial to test |
| 24 | + * |
| 25 | + * - On Windows 7 and prior: You need to use Zadig tool to manually bind the |
| 26 | + * WebUSB interface with the WinUSB driver for Chrome to access. From windows 8 and 10, this |
| 27 | + * is done automatically by firmware. |
15 | 28 | */
|
16 | 29 |
|
17 | 30 | // USB WebUSB object
|
@@ -40,10 +53,23 @@ void setup()
|
40 | 53 | Serial.println("Adafruit TinyUSB WebUSB example");
|
41 | 54 | }
|
42 | 55 |
|
| 56 | +// function to echo to both Serial and WebUSB |
| 57 | +void echo_all(char chr) |
| 58 | +{ |
| 59 | + Serial.write(chr); |
| 60 | + // print extra newline for Serial |
| 61 | + if ( chr == '\r' ) Serial.write('\n'); |
| 62 | + |
| 63 | + usb_web.write(chr); |
| 64 | +} |
| 65 | + |
43 | 66 | void loop()
|
44 | 67 | {
|
45 |
| -// delay(1000); |
46 |
| -// digitalWrite(LED_BUILTIN, 1-digitalRead(LED_BUILTIN)); |
| 68 | + // from WebUSB to both Serial & webUSB |
| 69 | + if (usb_web.available()) echo_all(usb_web.read()); |
| 70 | + |
| 71 | + // From Serial to both Serial & webUSB |
| 72 | + if (Serial.available()) echo_all(Serial.read()); |
47 | 73 | }
|
48 | 74 |
|
49 | 75 | void line_state_callback(bool connected)
|
|
0 commit comments