Go Down

Topic: RN42 Bluetooth Serial for Amazon Fire Stick (Read 102 times) previous topic - next topic

westywest

Dec 16, 2017, 12:08 am Last Edit: Dec 16, 2017, 12:38 pm by westywest
I am creating a HID device to control my Amazon Fire Stick so I can integrate it with my home automation setup.

I have the RN42 all connected and working. I've created a sketch to listen for my request via the USB serial and output TX to the RN42. I've set it up for up, down, left, right, enter, escape and play/pause.

The HEX codes have been cobbled together from what seems like days of tinkering and testing. The code is below, you can see that for most functions, a single hex works. I got those codes from here. The play/pause function is supposed to be a space but I've not been able to find a similar code that works.

So, I've read (and tried to understand!) the official manual and found the solution for play/pause (see code). That seems to work. So I'm almost happy. Except for 1 remaining stumbling block. For fast forward/rewind, you need to be able to "hold down" the left or right keys to seek faster. I can't work out how to do this. I've tried variants of my play/pause function, swapping in the codes from that document to try and find a solution. It seems the only "official" code I can get to work is the play/pause. I'm sure it's got to be something to do with the 'release command'...

Any help or improvements on what I am trying to achieve would be greatly appreciated. Many thanks.

UPDATE: Sorry, I forgot to include the link to the manufacturer's PDF manual.

Code: [Select]

void setup()
{
Serial.begin(115200);
}

 
void loop()
{

String input = "";
while (Serial.available() > 0)
{
input += (char) Serial.read();
delay(3);
}

if (input > "") {
input.replace("\n","");

//1 left
if (input.charAt(0) == 49) {
Serial.write(0x0B);
}

//2 right
if (input.charAt(0) == 50) {
  Serial.write(0x07);
}

//3 up
if (input.charAt(0) == 51) {
  Serial.write(0x0E);
}

//4 down
if (input.charAt(0) == 52) {
  Serial.write(0x0C);
}

//5 enter
if (input.charAt(0) == 53) {
  Serial.write(0x0A);
}

//6 esc
if (input.charAt(0) == 54) {
  Serial.write(0x1B);
}

//7 playpause
if (input.charAt(0) == 55) {

byte cmd[] = {0xFD, 0x03, 0x03, 128, 0x00};
Serial.write(cmd, sizeof(cmd));

//release key
byte cmd2[] = {0xFD, 0x03, 0x03, 0x00, 0x00};
Serial.write(cmd2, sizeof(cmd2));
}


}

}





Go Up