Arduino pololu micro keyboardps4.ino

//New Requirement PS4 rest mode must always supply USB power or else all chained i2c SECONDARY devices are lost
//Reason for disconnect in unknown when one of the i2c SECONDARY devices is powered and the other is unpowered
//It would make more sense if we just lost one i2c connection
//Use i2cdetect -y 1 to query devices from PRIMARY
//Could provide power for i2c SECONDARY devices via raspi in the future

#include <Keyboard.h>
#include <Wire.h>

#define SECONDARY_ADDRESS 0x10

void setup() {
  //i2c
  Wire.begin(SECONDARY_ADDRESS);  
  Wire.onReceive(receiveEvent);
  //only available some Arduinos (32U4)
  Keyboard.begin();
  //Debugging
  //Serial.begin(9600);
}

void loop() {
}

// function that executes whenever data is received from i2c PRIMARY
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
  while (1 < Wire.available()) { // loop through all but the last
    char c = Wire.read(); // receive byte as a character
    //Serial.print(c);         // print the character
  }

  int intKey  = Wire.read();    // Master sends the ascii decimal value of key, keyboard modifiers are listed in Arduino docs
  //Serial.println(intKey);         // print the integer
  Keyboard.press(intKey);
  //keep pressed so USB host registers it
  //HP laptops used low values
  //PS4 requires key to be depressed for a very long time
  //For the DS4 PS button a even longer press is required
  //TODO: send key and delay length from i2c Primary
  if(intKey==208){
    delay(200000);
  }
  else{
    delay(10000);
  }
  
  Keyboard.release(intKey);  
}