Skip to content

Commit 5ae5323

Browse files
committed
Added support for DigiSpark
mostly by adding defines as to select which decodes, to fit in Tiny's size. updated keywords.txt add public function to manually turn on or sending marks
1 parent 9c7247c commit 5ae5323

File tree

5 files changed

+181
-14
lines changed

5 files changed

+181
-14
lines changed

IRremote.cpp

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,24 @@
2424
#include <util/delay_basic.h>
2525

2626
#if defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
27-
#define IS_AVTINY
27+
#define IS_AVTINY
28+
#define ENABLE_MagiQuest
29+
// add others as to fit in Tiny
30+
#else
31+
#define ENABLE_MagiQuest
32+
#define ENABLE_NEC
33+
#define ENABLE_SONY
34+
#define ENABLE_Sanyo
35+
#define ENABLE_Mitsubishi
36+
#define ENABLE_Panasonic
37+
#define ENABLE_RC5
38+
#define ENABLE_RC6
39+
#define ENABLE_SymaR3
40+
#define ENABLE_SymaR5
41+
#define ENABLE_Useries
42+
#define ENABLE_FastLane
43+
#define ENABLE_JVC
44+
#define ENABLE_RCMM
2845
#endif
2946

3047
#define MIN(x,y) (x < y ? x : y)
@@ -52,6 +69,21 @@ void IRsend::space(int time) {
5269
#define US_TO_ITER(x) uint16_t(((x)*(SYSCLOCK/1000))/4000)
5370
#define mark(x) do { this->mark ((x)); _delay_loop_2(US_TO_ITER(x)); } while (0)
5471
#define space(x) do { this->space ((x)); _delay_loop_2(US_TO_ITER(x)); } while (0)
72+
73+
void IRsend::on(unsigned int freq) {
74+
// Sends an IR mark
75+
// The mark output is modulated at the PWM frequency.
76+
enableIROut(freq);
77+
TIMER_ENABLE_PWM; // Enable pin 3 PWM output
78+
}
79+
void IRsend::off() {
80+
// Sends an IR mark
81+
// The mark output is modulated at the PWM frequency.
82+
TIMER_DISABLE_PWM; // Enable pin 3 PWM output
83+
}
84+
85+
86+
5587
#endif
5688

5789
// These versions of MATCH, MATCH_MARK, and MATCH_SPACE are only for debugging.
@@ -563,96 +595,131 @@ int IRrecv::decode(decode_results *results) {
563595
if (irparams.rcvstate != STATE_STOP) {
564596
return ERR;
565597
}
566-
#ifndef IS_AVTINY
598+
#ifdef ENABLE_MagiQuest
567599
#ifdef DEBUG
568600
Serial.println("Attempting MagiQuest decode");
569601
#endif
570602
if (decodeMagiQuest(results)) {
571603
return DECODED;
572604
}
605+
#endif //ENABLE_MagiQuest
606+
607+
#ifndef ENABLE_NEC
573608
#ifdef DEBUG
574609
Serial.println("Attempting NEC decode");
575610
#endif
576611
if (decodeNEC(results)) {
577612
return DECODED;
578613
}
579-
#endif
614+
#endif //ENABLE_NEC
615+
616+
#ifdef ENABLE_SONY
580617
#ifdef DEBUG
581618
Serial.println("Attempting Sony decode");
582619
#endif
583620
if (decodeSony(results)) {
584621
return DECODED;
585622
}
586-
#ifndef IS_AVTINY
623+
#endif //ENABLE_SONY
624+
625+
#ifdef ENABLE_Sanyo
587626
#ifdef DEBUG
588627
Serial.println("Attempting Sanyo decode");
589628
#endif
590629
if (decodeSanyo(results)) {
591630
return DECODED;
592631
}
632+
#endif //ENABLE_Sanyo
633+
634+
#ifdef ENABLE_Mitsubishi
593635
#ifdef DEBUG
594636
Serial.println("Attempting Mitsubishi decode");
595637
#endif
596638
if (decodeMitsubishi(results)) {
597639
return DECODED;
598640
}
641+
#endif //ENABLE_Mitsubishi
642+
643+
#ifdef ENABLE_Panasonic
599644
#ifdef DEBUG
600645
Serial.println("Attempting Panasonic decode");
601-
#endif
646+
#endif
602647
if (decodePanasonic(results)) {
603648
return DECODED;
604649
}
650+
#endif //ENABLE_Panasonic
651+
652+
#ifdef ENABLE_RC5
605653
#ifdef DEBUG
606654
Serial.println("Attempting RC5 decode");
607-
#endif
655+
#endif
608656
if (decodeRC5(results)) {
609657
return DECODED;
610658
}
611-
#endif
659+
#endif //ENABLE_RC5
660+
661+
#ifdef ENABLE_RC6
612662
#ifdef DEBUG
613663
Serial.println("Attempting RC6 decode");
614-
#endif
664+
#endif
615665
if (decodeRC6(results)) {
616666
return DECODED;
617667
}
618-
#ifndef IS_AVTINY
668+
#endif //ENABLE_RC6
669+
670+
#ifdef ENABLE_Syma
619671
#ifdef DEBUG
620672
Serial.println("Attempting Syma decode");
621673
#endif
622674
if (decodeSyma(results)) {
623675
return DECODED;
624676
}
677+
#endif //ENABLE_Syma
678+
679+
#ifdef ENABLE_Useries
625680
#ifdef DEBUG
626681
Serial.println("Attempting Useries decode");
627682
#endif
628683
if (decodeUseries(results)) {
629684
return DECODED;
630685
}
686+
#endif //ENABLE_Useries
687+
688+
#ifdef ENABLE_FastLane
631689
#ifdef DEBUG
632690
Serial.println("Attempting FastLane decode");
633691
#endif
634692
if (decodeFastLane(results)) {
635693
return DECODED;
636694
}
695+
#endif //ENABLE_FastLane
696+
697+
#ifdef ENABLE_JVC
637698
#ifdef DEBUG
638699
Serial.println("Attempting JVC decode");
639-
#endif
700+
#endif
640701
if (decodeJVC(results)) {
641702
return DECODED;
642703
}
704+
#endif //ENABLE_JVC
705+
706+
#ifdef ENABLE_RCMM
643707
#ifdef DEBUG
644708
Serial.println("Attempting RCMM decode");
645709
#endif
646710
if (decodeRCMM(results)) {
647711
return DECODED;
648712
}
649-
#endif
713+
#endif //ENABLE_RCMM
714+
715+
#ifndef IS_AVTINY
650716
// decodeHash returns a hash on any input.
651717
// Thus, it needs to be last in the list.
652718
// If you add any decodes, add them before this.
653719
if (decodeHash(results)) {
654720
return DECODED;
655721
}
722+
#endif //IS_AVTINY
656723
// Throw away and start over
657724
resume();
658725
return ERR;

IRremote.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ class IRsend
187187
void enableIROut(int khz);
188188
VIRTUAL void mark(int usec);
189189
VIRTUAL void space(int usec);
190+
void on(unsigned int freq);
191+
void off(void);
190192
}
191193
;
192194

IRremoteInt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
// is not usable for PWM waveforms where the frequency, not just the duty cycle,
7676
// needs to be controlled.
7777
#elif defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
78-
// #define IR_USE_TIMER1_TINY // tx = pin 4 (OC1B)
79-
#define IR_USE_TIMER0// tx = pin 1 (OC0B)
78+
#define IR_USE_TIMER1_TINY// tx = pin 4 (OC1B)
79+
// #define IR_USE_TIMER0 // tx = pin 1 (OC0B)
8080
// Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, etc
8181
#else
8282
//#define IR_USE_TIMER1 // tx = pin 9

examples/IRrecvDump/IRrecvDump.ino

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,30 @@
99
*/
1010

1111
#include <IRremote.h>
12-
int RECV_PIN = 11;
12+
13+
#if defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
14+
#define IS_AVTINY
15+
int RECV_PIN = 2;
16+
#define ENABLE_MagiQuest
17+
// add others as to fit in Tiny
18+
#else
19+
int RECV_PIN = 11;
20+
#define ENABLE_MagiQuest
21+
#define ENABLE_NEC
22+
#define ENABLE_SONY
23+
#define ENABLE_Sanyo
24+
#define ENABLE_Mitsubishi
25+
#define ENABLE_Panasonic
26+
#define ENABLE_RC5
27+
#define ENABLE_RC6
28+
#define ENABLE_SymaR3
29+
#define ENABLE_SymaR5
30+
#define ENABLE_Useries
31+
#define ENABLE_FastLane
32+
#define ENABLE_JVC
33+
#define ENABLE_RCMM
34+
#endif
35+
1336

1437
IRrecv irrecv(RECV_PIN);
1538

@@ -20,6 +43,18 @@ void setup()
2043
Serial.begin(9600);
2144
Serial.println("starting...");
2245
irrecv.enableIRIn(); // Start the receiver
46+
#ifdef IS_AVTINY
47+
pinMode(1, OUTPUT); //LED on Model A
48+
49+
50+
for (int i = 0; i < 5; i++) {
51+
digitalWrite(1, HIGH);
52+
delay(125); // wait for a second
53+
digitalWrite(1, LOW);
54+
delay(125); // wait for a second
55+
}
56+
57+
#endif //IS_AVTINY
2358
}
2459

2560
// Dumps out the decode_results structure.
@@ -28,32 +63,66 @@ void setup()
2863
//void dump(void *v) {
2964
// decode_results *results = (decode_results *)v
3065
void dump(decode_results *results) {
66+
3167
int count = results->rawlen;
68+
69+
//#ifndef IS_AVTINY
3270
if (results->decode_type == UNKNOWN) {
3371
Serial.print("Unknown encoding: ");
3472
}
73+
//#endif //IS_AVTINY
74+
75+
#ifdef ENABLE_NEC
3576
else if (results->decode_type == NEC) {
3677
Serial.print("Decoded NEC: ");
3778
}
3879
else if (results->decode_type == SONY) {
3980
Serial.print("Decoded SONY: ");
4081
}
82+
#endif //ENABLE_NEC
83+
84+
#ifdef ENABLE_MagiQuest
4185
else if (results->decode_type == MAGIQUEST) {
86+
#ifndef IS_AVTINY
4287
Serial.print("Decoded MAGIQUEST - Magnitude=");
4388
Serial.print(results->magiquestMagnitude, HEX);
4489
Serial.print(", wand_id=");
90+
#endif //IS_AVTINY
91+
if (results->value == 0x4FAB881) {
92+
for (int i = 0; i < 2; i++) {
93+
digitalWrite(1, HIGH);
94+
delay(250); // wait for a second
95+
digitalWrite(1, LOW);
96+
delay(125); // wait for a second
97+
}
98+
}
4599
}
100+
#endif //ENABLE_MagiQuest
101+
102+
#ifdef ENABLE_RC5
46103
else if (results->decode_type == RC5) {
47104
Serial.print("Decoded RC5: ");
48105
}
49106
else if (results->decode_type == RC6) {
50107
Serial.print("Decoded RC6: ");
51108
}
109+
#endif //ENABLE_RC5
110+
111+
#ifdef ENABLE_Panasonic
52112
else if (results->decode_type == PANASONIC) {
53113
Serial.print("Decoded PANASONIC - Address: ");
54114
Serial.print(results->panasonicAddress,HEX);
55115
Serial.print(", Value: ");
116+
for (int i = 0; i < 3; i++) {
117+
digitalWrite(1, HIGH);
118+
delay(250); // wait for a second
119+
digitalWrite(1, LOW);
120+
delay(125); // wait for a second
121+
}
56122
}
123+
#endif //ENABLE_Panasonic
124+
125+
#ifdef ENABLE_Syma
57126
else if (results->decode_type == SYMA_R5) {
58127
Serial.print("Decoded SYMA_R5 - ");
59128
Serial.print(" C="); Serial.print(results->helicopter.symaR5.Channel);
@@ -63,6 +132,9 @@ void dump(decode_results *results) {
63132
Serial.print(" Y="); Serial.print(results->helicopter.symaR5.Yaw,DEC);
64133
Serial.print(" t="); Serial.print(results->helicopter.symaR5.Trim,DEC);
65134
}
135+
#endif //ENABLE_Syma
136+
137+
#ifdef ENABLE_Syma
66138
else if (results->decode_type == SYMA_R3) {
67139
Serial.print("Decoded SYMA_R3 - ");
68140
Serial.print(" C="); Serial.print(results->helicopter.symaR3.Channel);
@@ -71,6 +143,9 @@ void dump(decode_results *results) {
71143
Serial.print(" P="); Serial.print(results->helicopter.symaR3.Pitch,DEC);
72144
Serial.print(" Y="); Serial.print(results->helicopter.symaR3.Yaw,DEC);
73145
}
146+
#endif //ENABLE_Syma
147+
148+
#ifdef ENABLE_Useries
74149
else if (results->decode_type == USERIES) {
75150
// temp variables to hold Channel from propietary format.
76151
uint8_t Channel = results->helicopter.uSeries.Channel;
@@ -99,6 +174,9 @@ void dump(decode_results *results) {
99174
Serial.print(" Leftover="); Serial.print(results->helicopter.uSeries.cksum,DEC);
100175
Serial.print(" Parity="); Serial.print(results->parity,DEC);
101176
}
177+
#endif //ENABLE_Useries
178+
179+
#ifdef ENABLE_FastLane
102180
else if (results->decode_type == FASTLANE) {
103181
// temp variables to hold FastLane's unsigned integers from propietary magnitude and direction bits.
104182
uint8_t Yaw;
@@ -137,9 +215,15 @@ void dump(decode_results *results) {
137215
Serial.print(" F="); Serial.print(results->helicopter.fastlane.Fire,DEC);
138216

139217
}
218+
#endif //ENABLE_FastLane
219+
220+
#ifdef ENABLE_JVC
140221
else if (results->decode_type == JVC) {
141222
Serial.print("Decoded JVC: ");
142223
}
224+
#endif //ENABLE_JVC
225+
226+
#ifdef ENABLE_RCMM
143227
else if (results->decode_type == RCMM) {
144228
Serial.print("Decoded RCMM: ");
145229
}
@@ -162,6 +246,7 @@ void dump(decode_results *results) {
162246
Serial.print(" ");
163247
}
164248
Serial.println("");
249+
#endif //ENABLE_RCMM
165250
}
166251

167252

0 commit comments

Comments
 (0)