cyborg5 / IRLib2

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

Cast short ints to uint8_t wherever necessary #95

Open pwnage101 opened 4 years ago

pwnage101 commented 4 years ago

Before this commit, I couldn't compile with a SAMD21 chip because of the following error:

/home/sankey/Arduino/libraries/IRLibProtocols/IRLibSAMD21.cpp:108:1: error: narrowing conversion of '(_ETCChannel)-1' from 'short int' to 'uint8_t {aka
 unsigned char}' inside { } [-Wnarrowing]                                                                                                              
 };                                                                                                                                                    
 ^                                                                                                                                                     

Not saying this is the correct way to fix the error, it's just how I solved it.

Minimal code example is based on one of the checked-in examples, and is what I used to test this PR:

#include <IRLibDecodeBase.h>
#include <IRLib_P02_Sony.h>
#include <IRLibCombo.h>
IRdecode myDecoder;

#include <IRLibRecv.h> 
IRrecv myReceiver(6);  //pin number for the receiver

void setup() {
  Serial.begin(9600);
  delay(2000); while (!Serial); //delay for Leonardo
  myReceiver.enableIRIn(); // Start the receiver
  Serial.println(F("Ready to receive IR signals"));
}
void loop() {
  //Continue looping until you get a complete signal received
  if (myReceiver.getResults()) { 
    myDecoder.decode();           //Decode it
    myDecoder.dumpResults(true);  //Now print results. Use false for less detail
    myReceiver.enableIRIn();      //Restart receiver
  }
}
cyborg5 commented 4 years ago

The correct fix is to change

uint8_t IR_PER_EorF;

to

int8_t IR_PER_EorF;

in IRLibSAMD21.cpp at approximately line 30. I will fix it soon but I need to double check on something else first.