diff --git a/examples/Advanced/AdvancedGamepad/AdvancedGamepad.ino b/examples/HID_Advanced/AdvancedGamepad/AdvancedGamepad.ino similarity index 80% rename from examples/Advanced/AdvancedGamepad/AdvancedGamepad.ino rename to examples/HID_Advanced/AdvancedGamepad/AdvancedGamepad.ino index eef660d..04cee3e 100644 --- a/examples/Advanced/AdvancedGamepad/AdvancedGamepad.ino +++ b/examples/HID_Advanced/AdvancedGamepad/AdvancedGamepad.ino @@ -3,11 +3,11 @@ See the readme for credit to other people. Advanced Gamepad example + + Make sure the Gamepad report is set in: + sketchbook/hardware/HID/avr/variants/hid_descriptors/hid_descriptors.h */ -// include HID library -#include - // see HID_Reports.h for all data structures HID_GamepadReport_Data_t Gamepadreport; @@ -22,9 +22,8 @@ void setup() { pinMode(pinButton, INPUT_PULLUP); // Sends a clean report to the host. This is important on any Arduino type. - // Make sure all desired USB functions are activated in USBAPI.h! memset(&Gamepadreport, 0, sizeof(Gamepadreport)); - HID_SendReport(HID_REPORTID_Gamepad1Report, &Gamepadreport, sizeof(Gamepadreport)); + HID_SendReport(HID_REPORTID_GAMEPAD, &Gamepadreport, sizeof(Gamepadreport)); } void loop() { @@ -43,7 +42,7 @@ void loop() { // functions before only set the values // this writes the report to the host - HID_SendReport(HID_REPORTID_Gamepad1Report, &Gamepadreport, sizeof(Gamepadreport)); + HID_SendReport(HID_REPORTID_GAMEPAD, &Gamepadreport, sizeof(Gamepadreport)); // simple debounce delay(300); diff --git a/examples/Advanced/AdvancedKeyboard/AdvancedKeyboard.ino b/examples/HID_Advanced/AdvancedKeyboard/AdvancedKeyboard.ino similarity index 94% rename from examples/Advanced/AdvancedKeyboard/AdvancedKeyboard.ino rename to examples/HID_Advanced/AdvancedKeyboard/AdvancedKeyboard.ino index e6d71cf..8e8d5bb 100644 --- a/examples/Advanced/AdvancedKeyboard/AdvancedKeyboard.ino +++ b/examples/HID_Advanced/AdvancedKeyboard/AdvancedKeyboard.ino @@ -17,7 +17,6 @@ void setup() { pinMode(pinButton, INPUT_PULLUP); // Sends a clean report to the host. This is important on any Arduino type. - // Make sure all desired USB functions are activated in USBAPI.h! pressRawKeyboard(0, 0); } @@ -45,7 +44,7 @@ void pressRawKeyboard(uint8_t modifiers, uint8_t key) { uint8_t keys[8] = { modifiers, 0, key, 0, 0, 0, 0, 0 }; //modifiers, reserved, key[0] - HID_SendReport(HID_REPORTID_KeyboardReport, keys, sizeof(keys)); + HID_SendReport(HID_REPORTID_KEYBOARD, keys, sizeof(keys)); } /* diff --git a/examples/Advanced/AdvancedRawHID/AdvancedRawHID.ino b/examples/HID_Advanced/AdvancedRawHID/AdvancedRawHID.ino similarity index 93% rename from examples/Advanced/AdvancedRawHID/AdvancedRawHID.ino rename to examples/HID_Advanced/AdvancedRawHID/AdvancedRawHID.ino index 202e3b2..ffadce7 100644 --- a/examples/Advanced/AdvancedRawHID/AdvancedRawHID.ino +++ b/examples/HID_Advanced/AdvancedRawHID/AdvancedRawHID.ino @@ -2,7 +2,7 @@ Copyright (c) 2014 NicoHood See the readme for credit to other people. - Advanced RawHID example + Advanced RawHID example (currently not available) Shows how to send bytes via raw HID Press a button to send some example values. @@ -23,7 +23,6 @@ void setup() { pinMode(pinButton, INPUT_PULLUP); // no begin function needed for RawHID - // Make sure all desired USB functions are activated in USBAPI.h! } void loop() { @@ -32,7 +31,7 @@ void loop() { // direct without library. Always send RAWHID_RX_SIZE bytes! uint8_t buff[RAWHID_RX_SIZE]; // unitialized, has random values - HID_SendReport(HID_REPORTID_RawKeyboardReport, buff, sizeof(buff)); + HID_SendReport(HID_REPORTID_RAWHID, buff, sizeof(buff)); // with library memset(&buff, 42, sizeof(buff)); diff --git a/examples/HID_Basic/HID_Consumer/HID_Consumer.ino b/examples/HID_Basic/HID_Consumer/HID_Consumer.ino new file mode 100644 index 0000000..186f6e1 --- /dev/null +++ b/examples/HID_Basic/HID_Consumer/HID_Consumer.ino @@ -0,0 +1,48 @@ +/* + Copyright (c) 2014 NicoHood + See the readme for credit to other people. + + Consumer example (former Media example) + + Press a button to play/pause music player + See HID Project documentation for more Consumer keys. + + Make sure the Consumer report is set in: + sketchbook/hardware/HID/avr/variants/hid_descriptors/hid_descriptors.h + +// basic Media key definitions, see HID Project and official USB docs for more +#define MEDIA_FAST_FORWARD 0xB3 +#define MEDIA_REWIND 0xB4 +#define MEDIA_NEXT 0xB5 +#define MEDIA_PREVIOUS 0xB6 +#define MEDIA_STOP 0xB7 +#define MEDIA_PLAY_PAUSE 0xCD + +#define MEDIA_VOLUME_MUTE 0xE2 +#define MEDIA_VOLUME_UP 0xE9 +#define MEDIA_VOLUME_DOWN 0xEA +*/ + +const int pinLed = LED_BUILTIN; +const int pinButton = 2; + +void setup() { + pinMode(pinLed, OUTPUT); + pinMode(pinButton, INPUT_PULLUP); + + // Sends a clean report to the host. This is important on any Arduino type. + Consumer.begin(); +} + +void loop() { + if (!digitalRead(pinButton)) { + digitalWrite(pinLed, HIGH); + + // See list above for more definitions or the official usb documentation + Consumer.write(MEDIA_PLAY_PAUSE); + + // simple debounce + delay(300); + digitalWrite(pinLed, LOW); + } +} diff --git a/examples/HID_Basic/HID_Gamepad/HID_Gamepad.ino b/examples/HID_Basic/HID_Gamepad/HID_Gamepad.ino new file mode 100644 index 0000000..b72887d --- /dev/null +++ b/examples/HID_Basic/HID_Gamepad/HID_Gamepad.ino @@ -0,0 +1,86 @@ +/* + Copyright (c) 2014 NicoHood + See the readme for credit to other people. + + Gamepad example + + Press a button and demonstrate Gamepad actions + + Make sure the Gamepad report is set in: + sketchbook/hardware/HID/avr/variants/hid_descriptors/hid_descriptors.h + + Function prototypes: + void begin(void); + void end(void); + void write(void); + void press(uint8_t b); + void release(uint8_t b); + void releaseAll(void); + void buttons(uint32_t b); + void xAxis(int16_t a); + void yAxis(int16_t a); + void rxAxis(int16_t a); + void ryAxis(int16_t a); + void zAxis(int8_t a); + void rzAxis(int8_t a); + void dPad1(int8_t d); + void dPad2(int8_t d); + + Definitions: + GAMEPAD_DPAD_CENTERED 0 + GAMEPAD_DPAD_UP 1 + GAMEPAD_DPAD_UP_RIGHT 2 + GAMEPAD_DPAD_RIGHT 3 + GAMEPAD_DPAD_DOWN_RIGHT 4 + GAMEPAD_DPAD_DOWN 5 + GAMEPAD_DPAD_DOWN_LEFT 6 + GAMEPAD_DPAD_LEFT 7 + GAMEPAD_DPAD_UP_LEFT 8 + */ + +const int pinLed = LED_BUILTIN; +const int pinButton = 2; + +void setup() { + pinMode(pinLed, OUTPUT); + pinMode(pinButton, INPUT_PULLUP); + + // Sends a clean report to the host. This is important on any Arduino type. + Gamepad.begin(); +} + +void loop() { + if (!digitalRead(pinButton)) { + digitalWrite(pinLed, HIGH); + + // press button 1-32 and reset (34 becaue its written later) + static uint8_t count = 1; + Gamepad.press(count++); + if (count == 34) { + Gamepad.releaseAll(); + count = 1; + } + + // move x/y Axis to a new position (16bit) + Gamepad.xAxis(random(0xFFFF)); + Gamepad.yAxis(random(0xFFFF)); + + // go through all dPad positions + // values: 0-8 (0==centred) + static uint8_t dpad1 = GAMEPAD_DPAD_CENTERED; + Gamepad.dPad1(dpad1++); + if(dpad1>GAMEPAD_DPAD_UP_LEFT) dpad1 = GAMEPAD_DPAD_CENTERED; + static int8_t dpad2 = GAMEPAD_DPAD_CENTERED; + Gamepad.dPad2(dpad2--); + if(dpad2 1) { + Serial.println("Please only input a single character or deactivate linefeed!"); + return; + } + + if (c != -1) { + Serial.println(c); + switch (c) { + case 'a': + Keyboard.write('b'); + break; + + case 'p': + Consumer.write(MEDIA_PLAY_PAUSE); + break; + + case 'o': + { + // uint8_t k[8] = {0}; + // k[1] = 1 << 4; + // //k[2] = 4; + // HID_SendReport(HID_REPORTID_KEYBOARD, &k, sizeof(k)); + // Keyboard.releaseAll(); + break; + } + + case 's': + System.write(SYSTEM_SLEEP); + break; + + case 'r': + Mouse.move(100, 0); + break; + + case 'l': + Mouse.move(-100, 0); + break; + + case 't': + Mouse.moveTo(1000, 1000); + break; + + case 'c': + case 'C': + Keyboard.write(KEY_CAPS_LOCK); + Serial.println("Leds"); + Serial.println(Keyboard.getLEDs(), BIN); + break; + + case 'k': + Keyboard.print("Testing USB functions xyz"); + break; + + case '\r': + case '\n': + Serial.println("Please only input a single character!"); + break; + + case 'g': { + // press button 1-32 and reset (34 becaue its written later) + static uint8_t count = 1; + Gamepad.press(count++); + if (count == 34) { + Gamepad.releaseAll(); + count = 1; + } + Gamepad.write(); + } + break; + + case 'd': + Serial.println("Serial"); + Serial.println(Serial.dtr()); + Serial.println(Serial.rts()); + Serial.println(Serial.baud()); + Serial.println(Serial.stopbits()); + Serial.println(Serial.paritytype()); + Serial.println(Serial.numbits()); + break; + + default: + Serial.println("unknown"); + } + } + } + + + if (eventBaud) { + Serial.println("Event"); + Serial.println(eventBaud); + eventBaud = 0; + } +} + +void CDC_LineEncodingEvent(void) +{ + eventBaud = Serial.baud(); +} diff --git a/examples/HoodLoader1/HoodLoader1_API_Legacy/HoodLoader1_API_Legacy.ino b/examples/Projects/HoodLoader1_API_Legacy/HoodLoader1_API_Legacy.ino similarity index 100% rename from examples/HoodLoader1/HoodLoader1_API_Legacy/HoodLoader1_API_Legacy.ino rename to examples/Projects/HoodLoader1_API_Legacy/HoodLoader1_API_Legacy.ino diff --git a/examples/HoodLoader2/HoodLoader2_PWM_Fade/HoodLoader2_PWM_Fade.ino b/examples/Projects/HoodLoader2_PWM_Fade/HoodLoader2_PWM_Fade.ino similarity index 100% rename from examples/HoodLoader2/HoodLoader2_PWM_Fade/HoodLoader2_PWM_Fade.ino rename to examples/Projects/HoodLoader2_PWM_Fade/HoodLoader2_PWM_Fade.ino diff --git a/examples/HoodLoader2/HoodLoader2_SerialKeyboard/HoodLoader2_SerialKeyboard.ino b/examples/Projects/HoodLoader2_SerialKeyboard/HoodLoader2_SerialKeyboard.ino similarity index 100% rename from examples/HoodLoader2/HoodLoader2_SerialKeyboard/HoodLoader2_SerialKeyboard.ino rename to examples/Projects/HoodLoader2_SerialKeyboard/HoodLoader2_SerialKeyboard.ino