Skip to content

Commit

Permalink
Added protocolAvailable function
Browse files Browse the repository at this point in the history
Removed the decode+nop function and improved even a few more bytes
  • Loading branch information
Nico committed May 1, 2015
1 parent 4fbd88b commit daf9182
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
9 changes: 2 additions & 7 deletions IRLremote.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class CIRLremote{
template <IRType ir> static void buttonHolding(void);

// decode functions
template <IRType ir> static void decode(uint16_t duration) __attribute__((always_inline));
template <IRType ir> static bool protocolAvailable(void) __attribute__((always_inline));
static void decodeNec(const uint16_t duration) __attribute__((always_inline));
static void decodePanasonic(const uint16_t duration) __attribute__((always_inline));
static void decodeSony12(const uint16_t duration) __attribute__((always_inline));
Expand All @@ -105,7 +105,7 @@ class CIRLremote{
uint16_t spaceLeadHoldingThreshold, uint16_t markThreshold, uint16_t spaceThreshold,
uint16_t markTimeout, uint16_t spaceTimeout>
static bool IRLdecode(uint16_t duration, uint8_t data[], uint8_t &count) __attribute__((always_inline));

// variables to save received data
static uint8_t protocol;
static uint16_t address;
Expand All @@ -117,11 +117,6 @@ class CIRLremote{

//TODO
static uint32_t k[30];

static void nop(...) {
// little hack to take as many arguments as possible
// to execute several functions for the analogPins
}
};

// implementation inline, moved to another .hpp file
Expand Down
51 changes: 25 additions & 26 deletions IRLremoteReceive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,17 @@ IRLinterrupt(void){
if (duration_32 <= 0xFFFF)
duration = duration_32;

// go through all known protocols and decode if they are selected
// check if the user specified the protocols
if (sizeof...(irProtocol) > 0)
{
// decode all specified protocols
nop((decode<irProtocol>(duration), 0)...);
}
else
{
// go through all known protocols and decode with more (resource unfriendly) accuration
// reorder the protocols to get the optimal sketch size
decode<IR_SONY12>(duration);
decode<IR_PANASONIC>(duration);
decode<IR_NEC>(duration);
}
// reorder the protocols to get the optimal sketch size
if (protocolAvailable<IR_SONY12>())
decodeSony12(duration);
if (protocolAvailable<IR_PANASONIC>())
decodePanasonic(duration);
if (protocolAvailable<IR_NEC>())
decodeNec(duration);
if (protocolAvailable<IR_SONY20>())
decodeSony20(duration);
}


Expand Down Expand Up @@ -232,19 +229,21 @@ buttonHolding(void){

template <uint32_t debounce, IRType ...irProtocol>
template <IRType ir>
inline void CIRLremote<debounce, irProtocol...>::
decode(uint16_t duration){
if (ir == IR_NEC)
decodeNec(duration);

else if (ir == IR_PANASONIC)
decodePanasonic(duration);

else if (ir == IR_SONY12)
decodeSony12(duration);

else if (ir == IR_SONY20)
decodeSony20(duration);
inline bool CIRLremote<debounce, irProtocol...>::
protocolAvailable(void) {
if (sizeof...(irProtocol) == 0)
return true;

// unroll all used protocols in array and check if its the needed one
bool inArray[]{
((irProtocol == ir) ? true : false)...
};

// go through all protocols and check if the needed one is there
for (uint8_t i = 0; i < sizeof...(irProtocol); i++)
if (inArray[i] == true)
return true;
return false;
}


Expand Down

0 comments on commit daf9182

Please sign in to comment.