B4R Question How to create new or update rIRremote library

bdunkleysmith

Active Member
Licensed User
Longtime User
Based on this project, I have the following code which I can compile in the Arduino IDE and it runs successfully on my breadboarded UNO. However I would like continue development in B4R rather than the Arduino IDE because I want to send characters via Bluetooth rather than hardware serial.

I can handle re-writing the body of the code, however I am unsure what I need to do with the #include <skIRremote.h> part. I expect it needs to be converted to a library which would handle the call to irsend. The ssIRremote library was written by the author of the above project and he said that is just the Arduino IRremote library to which he added support for the Foxtel IQ remote. His library files are here.

Would I be better working with the rIRremote library referenced here and modifying it based on the information above so it too will support for the Foxtel IQ remote?

Thanks in anticipation of any guidance as I'm now well out of my depth,

Bryon


B4X:
/*
 * Sending all Foxtel remote keys as IR codes with IRsend
 * An IR LED in series with a resistor (180r) must be connected to Arduino PWM pin 3 and GND long led lead to +ve.
 * Version 1.0 November 2018
 * Bryon Dunkley-Smith
 *
 */

#include <skIRremote.h>
IRsend irsend;


char receivedChar;
boolean newData = false;

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

void loop() {
 recvOneChar();
 showNewData();
}

void recvOneChar() {
 if (Serial.available() > 0) {
  receivedChar = Serial.read();
  newData = true;
  }
}

void showNewData() {
  if (newData == true) {
    switch(receivedChar){
    case '0':
    sendIR(0x00, receivedChar); // IQ 0 command
    break;
    case '1':
    sendIR(0x01, receivedChar); // IQ 1 command
    break;
    case '2':
    sendIR(0x02, receivedChar); // IQ 2 command
    break;
    case '3':
    sendIR(0x03, receivedChar); // IQ 3 command
    break;
    case '4':
    sendIR(0x04, receivedChar); // IQ 4 command
    break;
    case '5':
    sendIR(0x05, receivedChar); // IQ 5 command
    break;
    case '6':
    sendIR(0x06, receivedChar); // IQ 6 command
    break;
    case '7':
    sendIR(0x07, receivedChar); // IQ 7 command
    break;
    case '8':
    sendIR(0x08, receivedChar); // IQ 8 command
    break;
    case '9':
    sendIR(0x09, receivedChar); // IQ 9 command
    break;
    case 'A':
    sendIR(0x0C, receivedChar); // IQ Power command
    break;
    case 'B':
    sendIR(0x0D, receivedChar); // IQ Mute command
    break;
    case 'C':
    sendIR(0x0F, receivedChar); // IQ Mute command
    break;
    case 'D':
    sendIR(0x10, receivedChar); // IQ Vol+ command
    break;
    case 'E':
    sendIR(0x11, receivedChar); // IQ Vol- command
    break;
    case 'F':
    sendIR(0x20, receivedChar); // IQ Chn+ command
    break;
    case 'G':
    sendIR(0x21, receivedChar); // IQ Chn- command
    break;
    case 'H':
    sendIR(0x28, receivedChar); // IQ Fwd command
    break;
    case 'I':
    sendIR(0x29, receivedChar); // IQ Rew command
    break;
    case 'J':
    sendIR(0x2C, receivedChar); // IQ Play command
    break;
    case 'K':
    sendIR(0x30, receivedChar); // IQ Pause command
    break;
    case 'L':
    sendIR(0x31, receivedChar); // IQ Stop command
    break;
    case 'M':
    sendIR(0x37, receivedChar); // IQ Record command
    break;
    case 'N':
    sendIR(0x38, receivedChar); // IQ AV command
    break;
    case 'O':
    sendIR(0x4E, receivedChar); // IQ Foxtel command
    break;
    case 'P':
    sendIR(0x54, receivedChar); // IQ Setup command
    break;
    case 'Q':
    sendIR(0x58, receivedChar); // IQ Up command
    break;
    case 'R':
    sendIR(0x59, receivedChar); // IQ Down command
    break;
    case 'S':
    sendIR(0x5A, receivedChar); // IQ Left command
    break;
    case 'T':
    sendIR(0x5B, receivedChar); // IQ Right command
    break;
    case 'U':
    sendIR(0x5C, receivedChar); // IQ Select command
    break;
    case 'V':
    sendIR(0x6D, receivedChar); // IQ Red command
    break;
    case 'W':
    sendIR(0x6E, receivedChar); // IQ Green command
    break;
    case 'X':
    sendIR(0x6F, receivedChar); // IQ Yellow command
    break;
    case 'Y':
    sendIR(0x70, receivedChar); // IQ Blue command
    break;
    case 'Z':
    sendIR(0x81, receivedChar); // IQ Help command
    break;
    case 'a':
    sendIR(0x83, receivedChar); // IQ Back command
    break;
    case 'b':
    sendIR(0xCC, receivedChar); // IQ TV Guide command
    break;
    case 'c':
    sendIR(0xD5, receivedChar); // IQ Box Office command
    break;
    case 'd':
    sendIR(0xF4, receivedChar); // IQ Planner command
    break;
    case 'e':
    sendIR(0xFD, receivedChar); // IQ Active command
    break;
    }
  }
}

void sendIR(byte code, char rxdChar) {
  irsend.sendFox(code); // IQ command
  newData = false;
  delay(500);
}
 

bdunkleysmith

Active Member
Licensed User
Longtime User
Thanks Erel - that solution appears to be within my capability!

Just to close this thread out I thought I'd post the code I finished up with based on your suggestion, in case it is of use to others:

B4X:
Sub Process_Globals
    Public sp As Serial
    Public ssp As SoftwareSerial
    Private astream As AsyncStreams
    Private receivedChar As Byte
End Sub

Private Sub AppStart
    sp.Initialize(9600)
    astream.Initialize(sp.Stream, "Astream_NewData", "Astream_Error")
    ssp.Initialize(9600, 12, 13)
    astream.Initialize(ssp.Stream, "Astream_NewData", "Astream_Error")
End Sub

Sub Astream_NewData (Buffer() As Byte)
    For Each char In Buffer
        receivedChar = char
        showNewData
        Delay(500) 
   Next
End Sub

Sub AStream_Error
   Log("error")
End Sub

Sub showNewData
    Select receivedChar
        Case 48 '0
            RunNative("sendIR", 0x00) 'IQ 0 command
        Case 49 '1
            RunNative("sendIR", 0x01) 'IQ 1 command
        Case 50 '2
            RunNative("sendIR", 0x02) 'IQ 2 command
        Case 51 '3
            RunNative("sendIR", 0x03) 'IQ 3 command
        Case 52 '4
              RunNative("sendIR", 0x04) 'IQ 4 command
        Case 53 '5
              RunNative("sendIR", 0x05) 'IQ 5 command
        Case 54 '6
              RunNative("sendIR", 0x06) 'IQ 6 command
        Case 55 '7
              RunNative("sendIR", 0x07) 'IQ 7 command
        Case 56 '8
              RunNative("sendIR", 0x08) 'IQ 8 command
        Case 57 '9
              RunNative("sendIR", 0x09) 'IQ 9 command
        Case 65 'A
              RunNative("sendIR", 0x0C) 'IQ Power command
        Case 66 'B
            RunNative("sendIR", 0x0D) 'IQ Mute command
        Case 67 'C
            RunNative("sendIR", 0x0F) 'IQ Mute command
        Case 68 'D
            RunNative("sendIR", 0x10) 'IQ Vol+ command
        Case 69 'E
              RunNative("sendIR", 0x11) 'IQ Vol- command
        Case 70 'F
              RunNative("sendIR", 0x20) 'IQ Chn+ command
        Case 71 'G
              RunNative("sendIR", 0x21) 'IQ Chn- command
        Case 72 'H
              RunNative("sendIR", 0x28) 'IQ Fwd command
        Case 73 'I
              RunNative("sendIR", 0x29) 'IQ Rew command
        Case 74 'J
              RunNative("sendIR", 0x2C) 'IQ Play command
        Case 75 'K
              RunNative("sendIR", 0x30) 'IQ Pause command
        Case 76 'L
              RunNative("sendIR", 0x31) 'IQ Stop command
        Case 77 'M
              RunNative("sendIR", 0x37) 'IQ Record command
        Case 78 'N
              RunNative("sendIR", 0x38) 'IQ AV command
        Case 79 'O
              RunNative("sendIR", 0x4E) 'IQ Foxtel command
        Case 80 'P
              RunNative("sendIR", 0x54) 'IQ Setup command
        Case 81 'Q
              RunNative("sendIR", 0x58) 'IQ Up command
        Case 82 'R
              RunNative("sendIR", 0x59) 'IQ Down command
        Case 83 'S
              RunNative("sendIR", 0x5A) 'IQ Left command
        Case 84 'T
              RunNative("sendIR", 0x5B) 'IQ Right command
        Case 85 'U
              RunNative("sendIR", 0x5C) 'IQ Select command
        Case 86 'V
              RunNative("sendIR", 0x6D) 'IQ Red command
        Case 87 'W
              RunNative("sendIR", 0x6E) 'IQ Green command
        Case 88 'X
              RunNative("sendIR", 0x6F) 'IQ Yellow command
          Case 89 'Y
              RunNative("sendIR", 0x70) 'IQ Blue command
        Case 90 'Z
              RunNative("sendIR", 0x81) 'IQ Help command
        Case 97 'a
              RunNative("sendIR", 0x83) 'IQ Back command
        Case 98 'b
              RunNative("sendIR", 0xCC) 'IQ TV Guide command
        Case 99 'c
              RunNative("sendIR", 0xD5) 'IQ Box Office command
        Case 100 'd
              RunNative("sendIR", 0xF4) 'IQ Planner command
        Case 101 'e
              RunNative("sendIR", 0xFD) 'IQ Active command
    End Select
End Sub

#if C
#include <skIRremote.h>
IRsend irsend;
void sendIR(B4R::Object* o) {
  irsend.sendFox(o->toULong()); // Send IQ command via IR
}
#End if

Note that this code also includes use of SoftwareSerial to which a Bluetooth module is connected so commands sent to my device from an Android app via Bluetooth is re-transmitted via IR to a Foxtel (pay tv) box.
 
Upvote 0
Top