mirror of
https://github.com/Theaninova/Arduino-IRremote.git
synced 2025-12-12 17:36:15 +00:00
Added Samsung protocol
This commit is contained in:
81
IRremote.cpp
81
IRremote.cpp
@@ -65,6 +65,11 @@ int MATCH_SPACE(int measured_ticks, int desired_us) {
|
||||
Serial.println(TICKS_HIGH(desired_us - MARK_EXCESS), DEC);
|
||||
return measured_ticks >= TICKS_LOW(desired_us - MARK_EXCESS) && measured_ticks <= TICKS_HIGH(desired_us - MARK_EXCESS);
|
||||
}
|
||||
#else
|
||||
int MATCH(int measured, int desired) {return measured >= TICKS_LOW(desired) && measured <= TICKS_HIGH(desired);}
|
||||
int MATCH_MARK(int measured_ticks, int desired_us) {return MATCH(measured_ticks, (desired_us + MARK_EXCESS));}
|
||||
int MATCH_SPACE(int measured_ticks, int desired_us) {return MATCH(measured_ticks, (desired_us - MARK_EXCESS));}
|
||||
// Debugging versions are in IRremote.cpp
|
||||
#endif
|
||||
|
||||
void IRsend::sendNEC(unsigned long data, int nbits)
|
||||
@@ -221,6 +226,27 @@ void IRsend::sendJVC(unsigned long data, int nbits, int repeat)
|
||||
mark(JVC_BIT_MARK);
|
||||
space(0);
|
||||
}
|
||||
|
||||
void IRsend::sendSAMSUNG(unsigned long data, int nbits)
|
||||
{
|
||||
enableIROut(38);
|
||||
mark(SAMSUNG_HDR_MARK);
|
||||
space(SAMSUNG_HDR_SPACE);
|
||||
for (int i = 0; i < nbits; i++) {
|
||||
if (data & TOPBIT) {
|
||||
mark(SAMSUNG_BIT_MARK);
|
||||
space(SAMSUNG_ONE_SPACE);
|
||||
}
|
||||
else {
|
||||
mark(SAMSUNG_BIT_MARK);
|
||||
space(SAMSUNG_ZERO_SPACE);
|
||||
}
|
||||
data <<= 1;
|
||||
}
|
||||
mark(SAMSUNG_BIT_MARK);
|
||||
space(0);
|
||||
}
|
||||
|
||||
void IRsend::mark(int time) {
|
||||
// Sends an IR mark for the specified number of microseconds.
|
||||
// The mark output is modulated at the PWM frequency.
|
||||
@@ -439,6 +465,12 @@ int IRrecv::decode(decode_results *results) {
|
||||
if (decodeJVC(results)) {
|
||||
return DECODED;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
Serial.println("Attempting SAMSUNG decode");
|
||||
#endif
|
||||
if (decodeSAMSUNG(results)) {
|
||||
return DECODED;
|
||||
}
|
||||
// decodeHash returns a hash on any input.
|
||||
// Thus, it needs to be last in the list.
|
||||
// If you add any decodes, add them before this.
|
||||
@@ -896,6 +928,55 @@ long IRrecv::decodeJVC(decode_results *results) {
|
||||
return DECODED;
|
||||
}
|
||||
|
||||
// SAMSUNGs have a repeat only 4 items long
|
||||
long IRrecv::decodeSAMSUNG(decode_results *results) {
|
||||
long data = 0;
|
||||
int offset = 1; // Skip first space
|
||||
// Initial mark
|
||||
if (!MATCH_MARK(results->rawbuf[offset], SAMSUNG_HDR_MARK)) {
|
||||
return ERR;
|
||||
}
|
||||
offset++;
|
||||
// Check for repeat
|
||||
if (irparams.rawlen == 4 &&
|
||||
MATCH_SPACE(results->rawbuf[offset], SAMSUNG_RPT_SPACE) &&
|
||||
MATCH_MARK(results->rawbuf[offset+1], SAMSUNG_BIT_MARK)) {
|
||||
results->bits = 0;
|
||||
results->value = REPEAT;
|
||||
results->decode_type = SAMSUNG;
|
||||
return DECODED;
|
||||
}
|
||||
if (irparams.rawlen < 2 * SAMSUNG_BITS + 4) {
|
||||
return ERR;
|
||||
}
|
||||
// Initial space
|
||||
if (!MATCH_SPACE(results->rawbuf[offset], SAMSUNG_HDR_SPACE)) {
|
||||
return ERR;
|
||||
}
|
||||
offset++;
|
||||
for (int i = 0; i < SAMSUNG_BITS; i++) {
|
||||
if (!MATCH_MARK(results->rawbuf[offset], SAMSUNG_BIT_MARK)) {
|
||||
return ERR;
|
||||
}
|
||||
offset++;
|
||||
if (MATCH_SPACE(results->rawbuf[offset], SAMSUNG_ONE_SPACE)) {
|
||||
data = (data << 1) | 1;
|
||||
}
|
||||
else if (MATCH_SPACE(results->rawbuf[offset], SAMSUNG_ZERO_SPACE)) {
|
||||
data <<= 1;
|
||||
}
|
||||
else {
|
||||
return ERR;
|
||||
}
|
||||
offset++;
|
||||
}
|
||||
// Success
|
||||
results->bits = SAMSUNG_BITS;
|
||||
results->value = data;
|
||||
results->decode_type = SAMSUNG;
|
||||
return DECODED;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------
|
||||
* hashdecode - decode an arbitrary IR code.
|
||||
* Instead of decoding using a standard encoding scheme
|
||||
|
||||
Reference in New Issue
Block a user