cyborg5 / IRLib2

Library for receiving, decoding, and sending infrared signals using Arduino
GNU General Public License v3.0
384 stars 138 forks source link

Combining rawRecv & rawSend #59

Open hkraal opened 5 years ago

hkraal commented 5 years ago

So I got the idea to make my own IR repeater so that I can control IR devices in a closed cabinet in another room. I've ended up with an Arduino which has an IR receiver (pin 2) and an IR led (pin 3) on the end of a ~10m wire which pretty much does the trick.

Reading a IR signal with rawRecv.ino and pasting the result in the rawSend.ino (with a little modification #define IR_SEND_PWM_PIN = 3;) results in the ability to send IR signals to the other room.

When attempting to do this in one single .ino it simply doesn't work. I ended up with this code which is nothing more than a combined rawRecv.ino and rawSend.ino: https://gist.github.com/hkraal/d80653b27d9b371b9a66b8ff96c69d3c

The Arduino IDE yields the following warning on the closing bracket of mySender.send()

ir-receiver.ino: In function 'void loop()':
ir-receiver.ino:34:5: warning: invalid conversion from 'volatile uint16_t* {aka volatile unsigned int*}' to 'uint16_t* {aka unsigned int*}' [-fpermissive]
     );
     ^
In file included from ir-receiver.ino:6:0:
Arduino/libraries/IRLibProtocols/IRLib_HashRaw.h:41:10: note: initializing argument 1 of 'void IRsendRaw::send(uint16_t*, uint8_t, uint8_t)'
     void send(uint16_t *buf, uint8_t len, uint8_t khz) {
          ^

I've tried to correct this by replacing my loop with the code below but with the same result; my devices don't react. I'm pretty sure it's something relative simple but I don't see it myself. Any pointers / links to resources at this moment are more than welcome!

void loop() {
  //Continue looping until you get a complete signal received
  if (myReceiver.getResults()) {
    int dataLength = recvGlobal.recvLength;
    uint16_t rawData[dataLength];

    for(bufIndex_t i=1;i<recvGlobal.recvLength;i++) {
      rawData[i] = recvGlobal.recvBuffer[i];
    }

    mySender.send(
      rawData,
      recvGlobal.recvLength,
      36
    );    
    myReceiver.enableIRIn();      //Restart receiver
  }
}
crazyquark commented 4 years ago

I am struggling with something similar; my code does work but the repeat is slow, too slow. Here is my code: https://bitbucket.org/crazyquark/edifier_remote/src/master/src/main.cpp

I think the issue is the enableIRin() part, meaning that receiving and sending cannot function independently which is really a shame. I am wondering if switching to a teensy would speed things up.