Skip to content

Commit 0de2d18

Browse files
committed
Added Samsung protocol
1 parent 46b4e10 commit 0de2d18

File tree

3 files changed

+117
-42
lines changed

3 files changed

+117
-42
lines changed

IRremote.cpp

+81
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ int MATCH_SPACE(int measured_ticks, int desired_us) {
6565
Serial.println(TICKS_HIGH(desired_us - MARK_EXCESS), DEC);
6666
return measured_ticks >= TICKS_LOW(desired_us - MARK_EXCESS) && measured_ticks <= TICKS_HIGH(desired_us - MARK_EXCESS);
6767
}
68+
#else
69+
int MATCH(int measured, int desired) {return measured >= TICKS_LOW(desired) && measured <= TICKS_HIGH(desired);}
70+
int MATCH_MARK(int measured_ticks, int desired_us) {return MATCH(measured_ticks, (desired_us + MARK_EXCESS));}
71+
int MATCH_SPACE(int measured_ticks, int desired_us) {return MATCH(measured_ticks, (desired_us - MARK_EXCESS));}
72+
// Debugging versions are in IRremote.cpp
6873
#endif
6974

7075
void IRsend::sendNEC(unsigned long data, int nbits)
@@ -221,6 +226,27 @@ void IRsend::sendJVC(unsigned long data, int nbits, int repeat)
221226
mark(JVC_BIT_MARK);
222227
space(0);
223228
}
229+
230+
void IRsend::sendSAMSUNG(unsigned long data, int nbits)
231+
{
232+
enableIROut(38);
233+
mark(SAMSUNG_HDR_MARK);
234+
space(SAMSUNG_HDR_SPACE);
235+
for (int i = 0; i < nbits; i++) {
236+
if (data & TOPBIT) {
237+
mark(SAMSUNG_BIT_MARK);
238+
space(SAMSUNG_ONE_SPACE);
239+
}
240+
else {
241+
mark(SAMSUNG_BIT_MARK);
242+
space(SAMSUNG_ZERO_SPACE);
243+
}
244+
data <<= 1;
245+
}
246+
mark(SAMSUNG_BIT_MARK);
247+
space(0);
248+
}
249+
224250
void IRsend::mark(int time) {
225251
// Sends an IR mark for the specified number of microseconds.
226252
// The mark output is modulated at the PWM frequency.
@@ -439,6 +465,12 @@ int IRrecv::decode(decode_results *results) {
439465
if (decodeJVC(results)) {
440466
return DECODED;
441467
}
468+
#ifdef DEBUG
469+
Serial.println("Attempting SAMSUNG decode");
470+
#endif
471+
if (decodeSAMSUNG(results)) {
472+
return DECODED;
473+
}
442474
// decodeHash returns a hash on any input.
443475
// Thus, it needs to be last in the list.
444476
// If you add any decodes, add them before this.
@@ -896,6 +928,55 @@ long IRrecv::decodeJVC(decode_results *results) {
896928
return DECODED;
897929
}
898930

931+
// SAMSUNGs have a repeat only 4 items long
932+
long IRrecv::decodeSAMSUNG(decode_results *results) {
933+
long data = 0;
934+
int offset = 1; // Skip first space
935+
// Initial mark
936+
if (!MATCH_MARK(results->rawbuf[offset], SAMSUNG_HDR_MARK)) {
937+
return ERR;
938+
}
939+
offset++;
940+
// Check for repeat
941+
if (irparams.rawlen == 4 &&
942+
MATCH_SPACE(results->rawbuf[offset], SAMSUNG_RPT_SPACE) &&
943+
MATCH_MARK(results->rawbuf[offset+1], SAMSUNG_BIT_MARK)) {
944+
results->bits = 0;
945+
results->value = REPEAT;
946+
results->decode_type = SAMSUNG;
947+
return DECODED;
948+
}
949+
if (irparams.rawlen < 2 * SAMSUNG_BITS + 4) {
950+
return ERR;
951+
}
952+
// Initial space
953+
if (!MATCH_SPACE(results->rawbuf[offset], SAMSUNG_HDR_SPACE)) {
954+
return ERR;
955+
}
956+
offset++;
957+
for (int i = 0; i < SAMSUNG_BITS; i++) {
958+
if (!MATCH_MARK(results->rawbuf[offset], SAMSUNG_BIT_MARK)) {
959+
return ERR;
960+
}
961+
offset++;
962+
if (MATCH_SPACE(results->rawbuf[offset], SAMSUNG_ONE_SPACE)) {
963+
data = (data << 1) | 1;
964+
}
965+
else if (MATCH_SPACE(results->rawbuf[offset], SAMSUNG_ZERO_SPACE)) {
966+
data <<= 1;
967+
}
968+
else {
969+
return ERR;
970+
}
971+
offset++;
972+
}
973+
// Success
974+
results->bits = SAMSUNG_BITS;
975+
results->value = data;
976+
results->decode_type = SAMSUNG;
977+
return DECODED;
978+
}
979+
899980
/* -----------------------------------------------------------------------
900981
* hashdecode - decode an arbitrary IR code.
901982
* Instead of decoding using a standard encoding scheme

IRremote.h

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class decode_results {
4545
#define JVC 8
4646
#define SANYO 9
4747
#define MITSUBISHI 10
48+
#define SAMSUNG 11
4849
#define UNKNOWN -1
4950

5051
// Decoded value for NEC when a repeat code is received
@@ -70,6 +71,7 @@ class IRrecv
7071
long decodeRC6(decode_results *results);
7172
long decodePanasonic(decode_results *results);
7273
long decodeJVC(decode_results *results);
74+
long decodeSAMSUNG(decode_results *results);
7375
long decodeHash(decode_results *results);
7476
int compare(unsigned int oldval, unsigned int newval);
7577

@@ -100,6 +102,7 @@ class IRsend
100102
void sendPanasonic(unsigned int address, unsigned long data);
101103
void sendJVC(unsigned long data, int nbits, int repeat); // *Note instead of sending the REPEAT constant if you want the JVC repeat signal sent, send the original code value and change the repeat argument from 0 to 1. JVC protocol repeats by skipping the header NOT by sending a separate code value like NEC does.
102104
// private:
105+
void sendSAMSUNG(unsigned long data, int nbits);
103106
void enableIROut(int khz);
104107
VIRTUAL void mark(int usec);
105108
VIRTUAL void space(int usec);

IRremoteInt.h

+33-42
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@
6161
#elif defined(__AVR_ATmega8P__) || defined(__AVR_ATmega8__)
6262
#define IR_USE_TIMER1 // tx = pin 9
6363

64-
#elif defined( __AVR_ATtinyX4__ )
65-
#define IR_USE_TIMER1 // tx = pin 6
66-
6764
// Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, etc
6865
#else
6966
//#define IR_USE_TIMER1 // tx = pin 9
@@ -93,46 +90,46 @@
9390
// Pulse parms are *50-100 for the Mark and *50+100 for the space
9491
// First MARK is the one after the long gap
9592
// pulse parameters in usec
96-
#define NEC_HDR_MARK 9000
97-
#define NEC_HDR_SPACE 4500
98-
#define NEC_BIT_MARK 560
99-
#define NEC_ONE_SPACE 1600
100-
#define NEC_ZERO_SPACE 560
101-
#define NEC_RPT_SPACE 2250
102-
103-
#define SONY_HDR_MARK 2400
104-
#define SONY_HDR_SPACE 600
105-
#define SONY_ONE_MARK 1200
106-
#define SONY_ZERO_MARK 600
93+
#define NEC_HDR_MARK 9000
94+
#define NEC_HDR_SPACE 4500
95+
#define NEC_BIT_MARK 560
96+
#define NEC_ONE_SPACE 1600
97+
#define NEC_ZERO_SPACE 560
98+
#define NEC_RPT_SPACE 2250
99+
100+
#define SONY_HDR_MARK 2400
101+
#define SONY_HDR_SPACE 600
102+
#define SONY_ONE_MARK 1200
103+
#define SONY_ZERO_MARK 600
107104
#define SONY_RPT_LENGTH 45000
108105
#define SONY_DOUBLE_SPACE_USECS 500 // usually ssee 713 - not using ticks as get number wrapround
109106

110107
// SA 8650B
111-
#define SANYO_HDR_MARK 3500 // seen range 3500
112-
#define SANYO_HDR_SPACE 950 // seen 950
113-
#define SANYO_ONE_MARK 2400 // seen 2400
108+
#define SANYO_HDR_MARK 3500 // seen range 3500
109+
#define SANYO_HDR_SPACE 950 // seen 950
110+
#define SANYO_ONE_MARK 2400 // seen 2400
114111
#define SANYO_ZERO_MARK 700 // seen 700
115112
#define SANYO_DOUBLE_SPACE_USECS 800 // usually ssee 713 - not using ticks as get number wrapround
116113
#define SANYO_RPT_LENGTH 45000
117114

118115
// Mitsubishi RM 75501
119116
// 14200 7 41 7 42 7 42 7 17 7 17 7 18 7 41 7 18 7 17 7 17 7 18 7 41 8 17 7 17 7 18 7 17 7
120117

121-
// #define MITSUBISHI_HDR_MARK 250 // seen range 3500
122-
#define MITSUBISHI_HDR_SPACE 350 // 7*50+100
123-
#define MITSUBISHI_ONE_MARK 1950 // 41*50-100
118+
// #define MITSUBISHI_HDR_MARK 250 // seen range 3500
119+
#define MITSUBISHI_HDR_SPACE 350 // 7*50+100
120+
#define MITSUBISHI_ONE_MARK 1950 // 41*50-100
124121
#define MITSUBISHI_ZERO_MARK 750 // 17*50-100
125122
// #define MITSUBISHI_DOUBLE_SPACE_USECS 800 // usually ssee 713 - not using ticks as get number wrapround
126123
// #define MITSUBISHI_RPT_LENGTH 45000
127124

128125

129-
#define RC5_T1 889
130-
#define RC5_RPT_LENGTH 46000
126+
#define RC5_T1 889
127+
#define RC5_RPT_LENGTH 46000
131128

132-
#define RC6_HDR_MARK 2666
133-
#define RC6_HDR_SPACE 889
134-
#define RC6_T1 444
135-
#define RC6_RPT_LENGTH 46000
129+
#define RC6_HDR_MARK 2666
130+
#define RC6_HDR_SPACE 889
131+
#define RC6_T1 444
132+
#define RC6_RPT_LENGTH 46000
136133

137134
#define SHARP_BIT_MARK 245
138135
#define SHARP_ONE_SPACE 1805
@@ -162,6 +159,14 @@
162159
#define JVC_ZERO_SPACE 550
163160
#define JVC_RPT_LENGTH 60000
164161

162+
#define SAMSUNG_HDR_MARK 5000
163+
#define SAMSUNG_HDR_SPACE 5000
164+
#define SAMSUNG_BIT_MARK 560
165+
#define SAMSUNG_ONE_SPACE 1600
166+
#define SAMSUNG_ZERO_SPACE 560
167+
#define SAMSUNG_RPT_SPACE 2250
168+
169+
165170
#define SHARP_BITS 15
166171
#define DISH_BITS 16
167172

@@ -175,13 +180,6 @@
175180
#define TICKS_LOW(us) (int) (((us)*LTOL/USECPERTICK))
176181
#define TICKS_HIGH(us) (int) (((us)*UTOL/USECPERTICK + 1))
177182

178-
#ifndef DEBUG
179-
int MATCH(int measured, int desired) {return measured >= TICKS_LOW(desired) && measured <= TICKS_HIGH(desired);}
180-
int MATCH_MARK(int measured_ticks, int desired_us) {return MATCH(measured_ticks, (desired_us + MARK_EXCESS));}
181-
int MATCH_SPACE(int measured_ticks, int desired_us) {return MATCH(measured_ticks, (desired_us - MARK_EXCESS));}
182-
// Debugging versions are in IRremote.cpp
183-
#endif
184-
185183
// receiver states
186184
#define STATE_IDLE 2
187185
#define STATE_MARK 3
@@ -216,6 +214,7 @@ extern volatile irparams_t irparams;
216214
#define MIN_RC6_SAMPLES 1
217215
#define PANASONIC_BITS 48
218216
#define JVC_BITS 16
217+
#define SAMSUNG_BITS 32
219218

220219

221220

@@ -274,13 +273,7 @@ extern volatile irparams_t irparams;
274273
#define TIMER_ENABLE_INTR (TIMSK1 = _BV(OCIE1A))
275274
#define TIMER_DISABLE_INTR (TIMSK1 = 0)
276275
#endif
277-
278-
#if defined(__AVR_ATtinyX4__)
279-
#define TIMER_INTR_NAME TIM1_COMPA_vect
280-
#else
281-
#define TIMER_INTR_NAME TIMER1_COMPA_vect
282-
#endif
283-
276+
#define TIMER_INTR_NAME TIMER1_COMPA_vect
284277
#define TIMER_CONFIG_KHZ(val) ({ \
285278
const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
286279
TCCR1A = _BV(WGM11); \
@@ -300,8 +293,6 @@ extern volatile irparams_t irparams;
300293
#define TIMER_PWM_PIN 11 /* Arduino Mega */
301294
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
302295
#define TIMER_PWM_PIN 13 /* Sanguino */
303-
#elif defined(__AVR_ATtinyX4__)
304-
#define TIMER_PWM_PIN 6 /* ATTiny84 */
305296
#else
306297
#define TIMER_PWM_PIN 9 /* Arduino Duemilanove, Diecimila, LilyPad, etc */
307298
#endif

0 commit comments

Comments
 (0)