From 58fc0d17cc2d7c5dfb4ce268b7e43d35eebac342 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Sun, 18 Dec 2011 17:52:35 -0500 Subject: added asynchronous buffering of received CDC characters This fixes the issue Federico reported where bytes written by host but not read by sketch would cause serial connection to lock up. Ring buffer implementation is based on HardwareSerial.cpp. Adds public accept() method to CDC. --- cores/arduino/USBAPI.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cores/arduino/USBAPI.h') diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index 26a2032..1772c3c 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -27,11 +27,14 @@ extern USB_ USB; class Serial_ : public Stream { +private: + ring_buffer *_cdc_rx_buffer; public: void begin(uint16_t baud_count); void end(void); virtual int available(void); + virtual void accept(void); virtual int peek(void); virtual int read(void); virtual void flush(void); -- cgit v1.2.3-18-g5258 From e4930f866d41baa7e8ac615f22dc3e92ec0f1c5a Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Tue, 20 Dec 2011 17:00:19 -0500 Subject: changed Keyboard write() method to type(). Made write() an alias for type() to allow subclassing by Stream. --- cores/arduino/USBAPI.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cores/arduino/USBAPI.h') diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index 1772c3c..326fd6c 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -105,6 +105,7 @@ private: public: Keyboard_(); virtual size_t write(uint8_t); + virtual size_t type(uint8_t); }; extern Keyboard_ Keyboard; -- cgit v1.2.3-18-g5258 From e405a6eb6099a71959c664cab8ca8241634c6b91 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Tue, 20 Dec 2011 17:08:07 -0500 Subject: Revert "changed Keyboard write() method to type(). Made write() an alias for type() to allow subclassing by Stream." This reverts commit de1d5fc0cb82874c0dcb766c5fb27ab36c5cb32c. --- cores/arduino/USBAPI.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cores/arduino/USBAPI.h') diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index 326fd6c..1772c3c 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -105,7 +105,6 @@ private: public: Keyboard_(); virtual size_t write(uint8_t); - virtual size_t type(uint8_t); }; extern Keyboard_ Keyboard; -- cgit v1.2.3-18-g5258 From 4e9fb924b2ea4c1373edc09408db2ac0c402e68c Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Tue, 20 Dec 2011 17:09:44 -0500 Subject: changed Keyboard write() method to type(). Made write() an alias for type() to allow subclassing by Stream. --- cores/arduino/USBAPI.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cores/arduino/USBAPI.h') diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index 1772c3c..6a0b989 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -104,7 +104,8 @@ private: void setKeyMap(KeyMap* keyMap); public: Keyboard_(); - virtual size_t write(uint8_t); + virtual size_t write(uint8_t c) {type(c);}; + virtual size_t type(uint8_t c); }; extern Keyboard_ Keyboard; -- cgit v1.2.3-18-g5258 From 8f5869009ccddad8698969ff2ebe204d7b574b37 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Sat, 3 Mar 2012 13:26:57 -0500 Subject: fixed minor compilation warnings for Leonardo --- cores/arduino/USBAPI.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cores/arduino/USBAPI.h') diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index 6a0b989..3c97ff1 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -104,7 +104,7 @@ private: void setKeyMap(KeyMap* keyMap); public: Keyboard_(); - virtual size_t write(uint8_t c) {type(c);}; + virtual size_t write(uint8_t c) {return type(c);}; virtual size_t type(uint8_t c); }; extern Keyboard_ Keyboard; -- cgit v1.2.3-18-g5258 From fbea67532a03cbcb35c47209f902797c80c499f7 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Sat, 3 Mar 2012 22:54:45 -0500 Subject: added Keyboard methods press(), release(), and releaseAll() Changes mean that a single, persistent key report must be used so keys can be added or removed. Also reimplemented type() using the new methods. --- cores/arduino/USBAPI.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'cores/arduino/USBAPI.h') diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index 3c97ff1..6615fa8 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -100,12 +100,16 @@ class Keyboard_ : public Print { private: KeyMap* _keyMap; + KeyReport _keyReport; void sendReport(KeyReport* keys); void setKeyMap(KeyMap* keyMap); public: Keyboard_(); - virtual size_t write(uint8_t c) {return type(c);}; - virtual size_t type(uint8_t c); + virtual size_t write(uint8_t k) {return type(k);}; + virtual size_t type(uint8_t k); + virtual size_t press(uint8_t k); + virtual size_t release(uint8_t k); + virtual void releaseAll(void); }; extern Keyboard_ Keyboard; -- cgit v1.2.3-18-g5258 From 54fb0bf3f54a37d4dd9370d5f545a52b54ad1775 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Sat, 3 Mar 2012 23:06:44 -0500 Subject: Removed support for key mapping in Keyboard. Was no longer being used and would be damn near impossible to support with the new scheme for handling modifiers and non-printing keyboard characters. --- cores/arduino/USBAPI.h | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'cores/arduino/USBAPI.h') diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index 6615fa8..3f71856 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -87,22 +87,11 @@ typedef struct uint8_t keys[6]; } KeyReport; -// Map a character into a key report -// Called from Print to map text to keycodes -class KeyMap -{ -public: - virtual void charToKey(int c, KeyReport* keyReport) = 0; -}; - -// class Keyboard_ : public Print { private: - KeyMap* _keyMap; KeyReport _keyReport; void sendReport(KeyReport* keys); - void setKeyMap(KeyMap* keyMap); public: Keyboard_(); virtual size_t write(uint8_t k) {return type(k);}; -- cgit v1.2.3-18-g5258 From 15660068717c4721c60c9caefc1a8eaff702cc24 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Sat, 3 Mar 2012 23:37:39 -0500 Subject: Added Keyboard support for all modifier and all common non-printing keys. --- cores/arduino/USBAPI.h | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) (limited to 'cores/arduino/USBAPI.h') diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index 3f71856..05f7318 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -70,14 +70,42 @@ extern Mouse_ Mouse; //================================================================================ // Keyboard -#define KEY_MODIFIER_LEFT_CTRL 0x01 -#define KEY_MODIFIER_LEFT_SHIFT 0x02 -#define KEY_MODIFIER_LEFT_ALT 0x04 -#define KEY_MODIFIER_LEFT_GUI 0x08 -#define KEY_MODIFIER_RIGHT_CTRL 0x010 -#define KEY_MODIFIER_RIGHT_SHIFT 0x020 -#define KEY_MODIFIER_RIGHT_ALT 0x040 -#define KEY_MODIFIER_RIGHT_GUI 0x080 +#define KEY_LEFT_CTRL 0x80 +#define KEY_LEFT_SHIFT 0x81 +#define KEY_LEFT_ALT 0x82 +#define KEY_LEFT_GUI 0x83 +#define KEY_RIGHT_CTRL 0x84 +#define KEY_RIGHT_SHIFT 0x85 +#define KEY_RIGHT_ALT 0x86 +#define KEY_RIGHT_GUI 0x87 + +#define KEY_UP_ARROW 0xDA +#define KEY_DOWN_ARROW 0xD9 +#define KEY_LEFT_ARROW 0xD8 +#define KEY_RIGHT_ARROW 0xD7 +#define KEY_BACKSPACE 0xB2 +#define KEY_TAB 0xB3 +#define KEY_RETURN 0xB0 +#define KEY_ESC 0xB1 +#define KEY_INSERT 0xD1 +#define KEY_DELETE 0xD4 +#define KEY_PAGE_UP 0xD3 +#define KEY_PAGE_DOWN 0xD6 +#define KEY_HOME 0xD2 +#define KEY_END 0xD5 +#define KEY_CAPS_LOCK 0xC1 +#define KEY_F1 0xC2 +#define KEY_F2 0xC3 +#define KEY_F3 0xC4 +#define KEY_F4 0xC5 +#define KEY_F5 0xC6 +#define KEY_F6 0xC7 +#define KEY_F7 0xC8 +#define KEY_F8 0xC9 +#define KEY_F9 0xCA +#define KEY_F10 0xCB +#define KEY_F11 0xCC +#define KEY_F12 0xCD // Low level key report: up to 6 keys and shift, ctrl etc at once typedef struct -- cgit v1.2.3-18-g5258 From 9c040a8a2bcc7ec8d128df05479b2e741fe192c2 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Mon, 26 Mar 2012 16:02:40 -0400 Subject: added stub methods for begin() and end() to Mouse and Keyboard --- cores/arduino/USBAPI.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'cores/arduino/USBAPI.h') diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index 05f7318..c8948c1 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -57,7 +57,9 @@ private: uint8_t _buttons; void buttons(uint8_t b); public: - Mouse_(); + Mouse_(void); + void begin(void); + void end(void); void click(uint8_t b = MOUSE_LEFT); void move(signed char x, signed char y, signed char wheel = 0); void press(uint8_t b = MOUSE_LEFT); // press LEFT by default @@ -121,7 +123,9 @@ private: KeyReport _keyReport; void sendReport(KeyReport* keys); public: - Keyboard_(); + Keyboard_(void); + void begin(void); + void end(void); virtual size_t write(uint8_t k) {return type(k);}; virtual size_t type(uint8_t k); virtual size_t press(uint8_t k); -- cgit v1.2.3-18-g5258 From 58c36f76d51d1fe4859140acf5c9c056b4204da5 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Mon, 26 Mar 2012 17:28:02 -0400 Subject: added methods to Keyboard to handle multiple simultaneous key presses or releases (up to six each) --- cores/arduino/USBAPI.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'cores/arduino/USBAPI.h') diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index c8948c1..e83089a 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -130,6 +130,21 @@ public: virtual size_t type(uint8_t k); virtual size_t press(uint8_t k); virtual size_t release(uint8_t k); + + virtual size_t press(uint8_t k[], uint8_t len); + virtual size_t press(uint8_t k1, uint8_t k2); + virtual size_t press(uint8_t k1, uint8_t k2, uint8_t k3); + virtual size_t press(uint8_t k1, uint8_t k2, uint8_t k3, uint8_t k4); + virtual size_t press(uint8_t k1, uint8_t k2, uint8_t k3, uint8_t k4, uint8_t k5); + virtual size_t press(uint8_t k1, uint8_t k2, uint8_t k3, uint8_t k4, uint8_t k5, uint8_t k6); + + virtual size_t release(uint8_t k[], uint8_t len); + virtual size_t release(uint8_t k1, uint8_t k2); + virtual size_t release(uint8_t k1, uint8_t k2, uint8_t k3); + virtual size_t release(uint8_t k1, uint8_t k2, uint8_t k3, uint8_t k4); + virtual size_t release(uint8_t k1, uint8_t k2, uint8_t k3, uint8_t k4, uint8_t k5); + virtual size_t release(uint8_t k1, uint8_t k2, uint8_t k3, uint8_t k4, uint8_t k5, uint8_t k6); + virtual void releaseAll(void); }; extern Keyboard_ Keyboard; -- cgit v1.2.3-18-g5258 From d3eabc9c015dc02b6044b491cd04dde66d40a0ac Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Wed, 28 Mar 2012 18:35:26 -0400 Subject: eliminated Keyboard.type() - unnecessary duplication of Keyboard.write() (David Mellis). Also edit KeyboardReprogram example which was the only example using type() --- cores/arduino/USBAPI.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'cores/arduino/USBAPI.h') diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index e83089a..ee35af9 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -126,8 +126,7 @@ public: Keyboard_(void); void begin(void); void end(void); - virtual size_t write(uint8_t k) {return type(k);}; - virtual size_t type(uint8_t k); + virtual size_t write(uint8_t k); virtual size_t press(uint8_t k); virtual size_t release(uint8_t k); -- cgit v1.2.3-18-g5258 From 83feb140138d1c7900619ac2a733885e192987a8 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Wed, 28 Mar 2012 18:46:10 -0400 Subject: removed horrible multi-key Keyboard.press() and Keyboard.release() methods Saves 924 bytes of Flash --- cores/arduino/USBAPI.h | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'cores/arduino/USBAPI.h') diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index ee35af9..5169e65 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -129,21 +129,6 @@ public: virtual size_t write(uint8_t k); virtual size_t press(uint8_t k); virtual size_t release(uint8_t k); - - virtual size_t press(uint8_t k[], uint8_t len); - virtual size_t press(uint8_t k1, uint8_t k2); - virtual size_t press(uint8_t k1, uint8_t k2, uint8_t k3); - virtual size_t press(uint8_t k1, uint8_t k2, uint8_t k3, uint8_t k4); - virtual size_t press(uint8_t k1, uint8_t k2, uint8_t k3, uint8_t k4, uint8_t k5); - virtual size_t press(uint8_t k1, uint8_t k2, uint8_t k3, uint8_t k4, uint8_t k5, uint8_t k6); - - virtual size_t release(uint8_t k[], uint8_t len); - virtual size_t release(uint8_t k1, uint8_t k2); - virtual size_t release(uint8_t k1, uint8_t k2, uint8_t k3); - virtual size_t release(uint8_t k1, uint8_t k2, uint8_t k3, uint8_t k4); - virtual size_t release(uint8_t k1, uint8_t k2, uint8_t k3, uint8_t k4, uint8_t k5); - virtual size_t release(uint8_t k1, uint8_t k2, uint8_t k3, uint8_t k4, uint8_t k5, uint8_t k6); - virtual void releaseAll(void); }; extern Keyboard_ Keyboard; -- cgit v1.2.3-18-g5258 From a984b581a8ad093b55ec9f2d4677afdd77bf4705 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Sun, 1 Apr 2012 12:54:35 -0400 Subject: added Boolean operators to HardwareSerial and CDC to test whether the port is ready to send data. Mostly useful for Leonardo - simple way to test whether the port is actually opened by an application and ready to receive data. For Serial objects attached to real UARTs always returns true. --- cores/arduino/USBAPI.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cores/arduino/USBAPI.h') diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index 5169e65..f66cb16 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -39,6 +39,7 @@ public: virtual int read(void); virtual void flush(void); virtual size_t write(uint8_t); + operator bool(); }; extern Serial_ Serial; -- cgit v1.2.3-18-g5258 From 757a77ab67edb9831fe11fe95c80cb08a695e4a1 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Tue, 1 May 2012 11:18:15 -0400 Subject: renamed Leonardo USB_ class to USBDevice_ to be unambiguous. renamed "USB" object to "USBDevice" to prevent conflict with USB Host library (thanks Massimo) --- cores/arduino/USBAPI.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'cores/arduino/USBAPI.h') diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index f66cb16..1c21845 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -9,17 +9,17 @@ //================================================================================ // USB -class USB_ +class USBDevice_ { public: - USB_(); + USBDevice_(); bool configured(); void attach(); void detach(); // Serial port goes down too... void poll(); }; -extern USB_ USB; +extern USBDevice_ USBDevice; //================================================================================ //================================================================================ -- cgit v1.2.3-18-g5258 From efa75937723c2b868ddb7cec93a0a3bf6fa01959 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Tue, 15 May 2012 15:48:51 -0400 Subject: Mouse.isPressed() now checks only for left button by default if no argument is given now checks left button by default to be consistent with press() and release() (thanks, David Mellis) --- cores/arduino/USBAPI.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cores/arduino/USBAPI.h') diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index 1c21845..d5abdb6 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -65,7 +65,7 @@ public: void move(signed char x, signed char y, signed char wheel = 0); void press(uint8_t b = MOUSE_LEFT); // press LEFT by default void release(uint8_t b = MOUSE_LEFT); // release LEFT by default - bool isPressed(uint8_t b = MOUSE_ALL); // check all buttons by default + bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default }; extern Mouse_ Mouse; -- cgit v1.2.3-18-g5258 From 29ff4f779a37019c5218145cb15b036b51fc5e25 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Thu, 14 Jun 2012 15:53:27 +0100 Subject: Adding write(str) and write(buf, size) for USB CDC. So that they work on the Leonardo. http://code.google.com/p/arduino/issues/detail?id=958 --- cores/arduino/USBAPI.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cores/arduino/USBAPI.h') diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index d5abdb6..eb2e593 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -39,6 +39,7 @@ public: virtual int read(void); virtual void flush(void); virtual size_t write(uint8_t); + using Print::write; // pull in write(str) and write(buf, size) from Print operator bool(); }; extern Serial_ Serial; -- cgit v1.2.3-18-g5258