Hey I’ve recently flashed a CC2541 Bluetooth chip with a HID firmware and am wondering if any one can help with adding extra keys to this code? The device as it stands at the moment is acting as a keyboard and pulling pin 3 to ground sends the Winkey, (0xE3) to my connected android device.
Ive hit a wall because coding is my weak point, great technical skills but feel completely held back by my programming understanding, hahaha.
well, cheers in advance!
#define hutLeftGUI 0xE3
#define BT Serial1
void cmd(const char * s, int timeout=100, bool bSendCR=true) {
Serial.write("> ");
Serial.write(s);
Serial.write("\r\n");
BT.write(s);
if (bSendCR) {
BT.write("\r\n");
}
// serial output is tricky, let's use read timeout for now
long t = millis();
while(millis() < t + timeout) {
while (BT.available()) {
Serial.write(BT.read());
}
delay(1);
}
}
void keyCommand(uint8_t modifiers, uint8_t key1, uint8_t key2 = 0, uint8_t key3 = 0, uint8_t key4 = 0, uint8_t key5 = 0, uint8_t key6 = 0) {
char buf[16];
sprintf(buf, "%s%c", modifiers==0x80 ? "KD" : "KU", key1);
cmd(buf);
cmd("KUPDATE");
}
void setup() {
Serial.begin(115200); // This pipes to the serial monitor
BT.begin(57600); // This is the UART, attached to HM-10
pinMode(3, INPUT); // input mode for the button pin (D3)
digitalWrite(3, HIGH); // set button pin to HIGH (software pullup) so it triggers when pulled to GND
}
bool wasPressed = false;
void loop() {
int keyCode = hutLeftGUI; // winkey
bool pressed = digitalRead(3)==LOW;
if (pressed != wasPressed) {
keyCommand(pressed ? 0x80 : keyCode, keyCode);
wasPressed = pressed;
delay(25);
}
}