Skip to content

Commit

Permalink
Update KeyboardioHID formatting to Kaleidoscope style
Browse files Browse the repository at this point in the history
  • Loading branch information
obra committed Dec 14, 2023
1 parent 9da5316 commit f3c5cdc
Show file tree
Hide file tree
Showing 34 changed files with 1,542 additions and 1,376 deletions.
26 changes: 13 additions & 13 deletions plugins/KeyboardioHID/examples/Consumer/Consumer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@

#include "KeyboardioHID.h"

const int pinLed = LED_BUILTIN;
const int pinLed = LED_BUILTIN;
const int pinButton = 2;

void setup() {
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);

// Sends a clean report to the host. This is important on any Arduino type.
ConsumerControl.begin();
// Sends a clean report to the host. This is important on any Arduino type.
ConsumerControl.begin();
}

void loop() {
if (!digitalRead(pinButton)) {
digitalWrite(pinLed, HIGH);
if (!digitalRead(pinButton)) {
digitalWrite(pinLed, HIGH);

// See HID Project documentation for more Consumer keys
ConsumerControl.write(HID_CONSUMER_PLAY_SLASH_PAUSE);
// See HID Project documentation for more Consumer keys
ConsumerControl.write(HID_CONSUMER_PLAY_SLASH_PAUSE);

// Simple debounce
delay(300);
digitalWrite(pinLed, LOW);
}
// Simple debounce
delay(300);
digitalWrite(pinLed, LOW);
}
}
70 changes: 35 additions & 35 deletions plugins/KeyboardioHID/examples/Gamepad/Gamepad.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,52 @@

#include "KeyboardioHID.h"

const int pinLed = LED_BUILTIN;
const int pinLed = LED_BUILTIN;
const int pinButton = 2;

void setup() {
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);

// Sends a clean report to the host. This is important on any Arduino type.
Gamepad.begin();
// Sends a clean report to the host. This is important on any Arduino type.
Gamepad.begin();
}

void loop() {
if (!digitalRead(pinButton)) {
digitalWrite(pinLed, HIGH);
if (!digitalRead(pinButton)) {
digitalWrite(pinLed, HIGH);

// Press button 1-32
static uint8_t count = 0;
count++;
if (count == 33) {
Gamepad.releaseAll();
count = 0;
} else
Gamepad.press(count);
// Press button 1-32
static uint8_t count = 0;
count++;
if (count == 33) {
Gamepad.releaseAll();
count = 0;
} else
Gamepad.press(count);

// Move x/y Axis to a new position (16bit)
Gamepad.xAxis(random(0xFFFF));
Gamepad.yAxis(random(0xFFFF));
// 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==centered)
static uint8_t dpad1 = GAMEPAD_DPAD_CENTERED;
Gamepad.dPad1(dpad1++);
if (dpad1 > GAMEPAD_DPAD_UP_LEFT)
dpad1 = GAMEPAD_DPAD_CENTERED;
// Go through all dPad positions
// values: 0-8 (0==centered)
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 < GAMEPAD_DPAD_CENTERED)
dpad2 = GAMEPAD_DPAD_UP_LEFT;
static int8_t dpad2 = GAMEPAD_DPAD_CENTERED;
Gamepad.dPad2(dpad2--);
if (dpad2 < GAMEPAD_DPAD_CENTERED)
dpad2 = GAMEPAD_DPAD_UP_LEFT;

// Functions above only set the values.
// This writes the report to the host.
Gamepad.write();
// Functions above only set the values.
// This writes the report to the host.
Gamepad.write();

// Simple debounce
delay(300);
digitalWrite(pinLed, LOW);
}
// Simple debounce
delay(300);
digitalWrite(pinLed, LOW);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@

#include "KeyboardioHID.h"

const int pinLed = LED_BUILTIN;
const int pinLed = LED_BUILTIN;
const int pinButton = 2;

void setup() {
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);

// Sends a clean report to the host. This is important on any Arduino type.
BootKeyboard.begin();
// Sends a clean report to the host. This is important on any Arduino type.
BootKeyboard.begin();
}


void loop() {
// Light led if keyboard uses the boot protocol (normally while in bios)
// Keep in mind that on a 16u2 and Arduino Micro HIGH and LOW for TX/RX Leds are inverted.
if (BootKeyboard.getProtocol() == HID_BOOT_PROTOCOL)
digitalWrite(pinLed, HIGH);
else
digitalWrite(pinLed, LOW);

// Trigger caps lock manually via button
if (!digitalRead(pinButton)) {
BootKeyboard.press(HID_KEYBOARD_ENTER);
BootKeyboard.sendReport();
BootKeyboard.releaseAll();
BootKeyboard.sendReport();

// Simple debounce
delay(300);
}
// Light led if keyboard uses the boot protocol (normally while in bios)
// Keep in mind that on a 16u2 and Arduino Micro HIGH and LOW for TX/RX Leds are inverted.
if (BootKeyboard.getProtocol() == HID_BOOT_PROTOCOL)
digitalWrite(pinLed, HIGH);
else
digitalWrite(pinLed, LOW);

// Trigger caps lock manually via button
if (!digitalRead(pinButton)) {
BootKeyboard.press(HID_KEYBOARD_ENTER);
BootKeyboard.sendReport();
BootKeyboard.releaseAll();
BootKeyboard.sendReport();

// Simple debounce
delay(300);
}
}
44 changes: 22 additions & 22 deletions plugins/KeyboardioHID/examples/Keyboard/KeyboardLed/KeyboardLed.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,34 @@

#include "KeyboardioHID.h"

const int pinLed = LED_BUILTIN;
const int pinLed = LED_BUILTIN;
const int pinButton = 2;

void setup() {
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);

// Sends a clean report to the host. This is important on any Arduino type.
BootKeyboard.begin();
// Sends a clean report to the host. This is important on any Arduino type.
BootKeyboard.begin();
}


void loop() {
// Update Led equal to the caps lock state.
// Keep in mind that on a 16u2 and Arduino Micro HIGH and LOW for TX/RX Leds are inverted.
if (BootKeyboard.getLeds() & LED_CAPS_LOCK)
digitalWrite(pinLed, HIGH);
else
digitalWrite(pinLed, LOW);

// Trigger caps lock manually via button
if (!digitalRead(pinButton)) {
BootKeyboard.press(HID_KEYBOARD_CAPS_LOCK);
BootKeyboard.sendReport();
BootKeyboard.releaseAll();
BootKeyboard.sendReport();

// Simple debounce
delay(300);
}
// Update Led equal to the caps lock state.
// Keep in mind that on a 16u2 and Arduino Micro HIGH and LOW for TX/RX Leds are inverted.
if (BootKeyboard.getLeds() & LED_CAPS_LOCK)
digitalWrite(pinLed, HIGH);
else
digitalWrite(pinLed, LOW);

// Trigger caps lock manually via button
if (!digitalRead(pinButton)) {
BootKeyboard.press(HID_KEYBOARD_CAPS_LOCK);
BootKeyboard.sendReport();
BootKeyboard.releaseAll();
BootKeyboard.sendReport();

// Simple debounce
delay(300);
}
}
69 changes: 34 additions & 35 deletions plugins/KeyboardioHID/examples/Keyboard/NKRO/NKRO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,45 @@

#include "KeyboardioHID.h"

const int pinLed = LED_BUILTIN;
const int pinLed = LED_BUILTIN;
const int pinButton = 2;

void setup() {
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);

// Sends a clean report to the host. This is important on any Arduino type.
Keyboard.begin();
// Sends a clean report to the host. This is important on any Arduino type.
Keyboard.begin();
}

void loop() {
// Hold a lot of keys at the same time
if (!digitalRead(pinButton)) {
digitalWrite(pinLed, HIGH);

// Do not press too many at once or some OS will have problems.
// Note that the resulting pressed order might differ,
// because all keys are pressed at the same time.
Keyboard.press(HID_KEYBOARD_0_AND_RIGHT_PAREN);
Keyboard.press(HID_KEYBOARD_1_AND_EXCLAMATION_POINT);
Keyboard.press(HID_KEYBOARD_2_AND_AT);
Keyboard.press(HID_KEYBOARD_3_AND_POUND);
Keyboard.press(HID_KEYBOARD_4_AND_DOLLAR);
Keyboard.press(HID_KEYBOARD_5_AND_PERCENT);
Keyboard.press(HID_KEYBOARD_6_AND_CARAT);
Keyboard.press(HID_KEYBOARD_7_AND_AMPERSAND);
Keyboard.press(HID_KEYBOARD_8_AND_ASTERISK);
Keyboard.press(HID_KEYBOARD_9_AND_LEFT_PAREN);
Keyboard.sendReport();

// Release all keys and hit enter
Keyboard.releaseAll();
Keyboard.press(HID_KEYBOARD_ENTER);
Keyboard.sendReport();
Keyboard.releaseAll();
Keyboard.sendReport();

// Simple debounce
delay(300);
}
// Hold a lot of keys at the same time
if (!digitalRead(pinButton)) {
digitalWrite(pinLed, HIGH);

// Do not press too many at once or some OS will have problems.
// Note that the resulting pressed order might differ,
// because all keys are pressed at the same time.
Keyboard.press(HID_KEYBOARD_0_AND_RIGHT_PAREN);
Keyboard.press(HID_KEYBOARD_1_AND_EXCLAMATION_POINT);
Keyboard.press(HID_KEYBOARD_2_AND_AT);
Keyboard.press(HID_KEYBOARD_3_AND_POUND);
Keyboard.press(HID_KEYBOARD_4_AND_DOLLAR);
Keyboard.press(HID_KEYBOARD_5_AND_PERCENT);
Keyboard.press(HID_KEYBOARD_6_AND_CARAT);
Keyboard.press(HID_KEYBOARD_7_AND_AMPERSAND);
Keyboard.press(HID_KEYBOARD_8_AND_ASTERISK);
Keyboard.press(HID_KEYBOARD_9_AND_LEFT_PAREN);
Keyboard.sendReport();

// Release all keys and hit enter
Keyboard.releaseAll();
Keyboard.press(HID_KEYBOARD_ENTER);
Keyboard.sendReport();
Keyboard.releaseAll();
Keyboard.sendReport();

// Simple debounce
delay(300);
}
}

Loading

0 comments on commit f3c5cdc

Please sign in to comment.