Skip to content

Commit 7bea72d

Browse files
committed
Added MagiQuest Wand
1 parent 6ccf883 commit 7bea72d

File tree

8 files changed

+140
-2
lines changed

8 files changed

+140
-2
lines changed

IRremote.cpp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,30 @@ void IRsend::sendJVC(int32_t data, int16_t nbits, int16_t repeat)
221221
mark(JVC_BIT_MARK);
222222
space(0);
223223
}
224+
225+
void IRsend::sendMagiQuest(uint32_t wand_id, uint16_t magnitude)
226+
{
227+
magiquest data;
228+
//data.cmd.scrap = 0x00;
229+
data.cmd.padding = 0x00;
230+
data.cmd.magnitude = magnitude;
231+
data.cmd.wand_id = wand_id;
232+
233+
enableIROut(38);
234+
for (uint16_t i = 0; i < 56; i++) {
235+
data.llword <<= 1;
236+
if (((int8_t) data.byte[6]) < 0) { // if negative then MSBit is one.
237+
mark(MAGIQUEST_MARK_ONE);
238+
space(MAGIQUEST_SPACE_ONE);
239+
}
240+
else {
241+
mark(MAGIQUEST_MARK_ZERO);
242+
space(MAGIQUEST_SPACE_ZERO);
243+
}
244+
}
245+
Serial.println();
246+
}
247+
224248
void IRsend::mark(int time) {
225249
// Sends an IR mark for the specified number of microseconds.
226250
// The mark output is modulated at the PWM frequency.
@@ -439,6 +463,12 @@ int16_t IRrecv::decode(decode_results *results) {
439463
if (decodeJVC(results)) {
440464
return DECODED;
441465
}
466+
#ifdef DEBUG
467+
Serial.println("Attempting MagiQuest decode");
468+
#endif
469+
if (decodeMagiQuest(results)) {
470+
return DECODED;
471+
}
442472
// decodeHash returns a hash on any input.
443473
// Thus, it needs to be last in the list.
444474
// If you add any decodes, add them before this.
@@ -896,6 +926,66 @@ int32_t IRrecv::decodeJVC(decode_results *results) {
896926
return DECODED;
897927
}
898928

929+
int32_t IRrecv::decodeMagiQuest(decode_results *results) {
930+
magiquest data;
931+
data.llword = 0;
932+
933+
int16_t offset = 1;
934+
uint16_t mark_;
935+
uint16_t space_;
936+
uint8_t multiple_;
937+
938+
if (irparams.rawlen < 2 * MAGIQUEST_BITS) {
939+
return ERR;
940+
}
941+
942+
while (offset + 1 < irparams.rawlen) {
943+
mark_ = results->rawbuf[offset];
944+
space_ = results->rawbuf[offset+1];
945+
multiple_ = space_ / mark_;
946+
// it is either 25% + 75% or 50% + 50%
947+
948+
#ifdef DEBUG
949+
Serial.print("mark=");
950+
Serial.print(mark_ * USECPERTICK);
951+
Serial.print(" space=");
952+
Serial.print(space_ * USECPERTICK);
953+
Serial.print(" mult=");
954+
Serial.print(multiple_);
955+
Serial.print(" ");
956+
#endif
957+
if (MATCH_MARK(space_ + mark_, MAGIQUEST_PERIOD)) {
958+
if (multiple_ > 1) {
959+
#ifdef DEBUG
960+
Serial.print("0-MPF ");
961+
MATCH_MARK(results->rawbuf[offset], MAGIQUEST_MARK_ZERO);
962+
#endif
963+
data.llword <<= 1;
964+
} else {
965+
#ifdef DEBUG
966+
Serial.print("1-MPF ");
967+
MATCH_MARK(results->rawbuf[offset], MAGIQUEST_MARK_ONE);
968+
#endif
969+
data.llword = (data.llword << 1) | 1;
970+
}
971+
} else {
972+
return ERR;
973+
}
974+
offset++;
975+
offset++;
976+
}
977+
// Success
978+
results->bits = (offset + 1) / 2;
979+
if (results->bits < 12) {
980+
results->bits = 0;
981+
return ERR;
982+
}
983+
results->magiquestMagnitude = data.cmd.magnitude;
984+
results->value = data.cmd.wand_id;
985+
results->decode_type = MAGIQUEST;
986+
return DECODED;
987+
}
988+
899989
/* -----------------------------------------------------------------------
900990
* hashdecode - decode an arbitrary IR code.
901991
* Instead of decoding using a standard encoding scheme

IRremote.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,26 @@
2424
// #define DEBUG
2525
// #define TEST
2626

27+
// MagiQuest packet is both Wand ID and magnitude of swish and flick
28+
union magiquest {
29+
uint64_t llword;
30+
uint8_t byte[8];
31+
// uint16_t word[4];
32+
// uint32_t lword[2];
33+
struct {
34+
uint16_t magnitude;
35+
uint32_t wand_id;
36+
uint8_t padding;
37+
uint8_t scrap;
38+
} cmd ;
39+
} ;
40+
2741
// Results returned from the decoder
2842
class decode_results {
2943
public:
3044
int16_t decode_type; // NEC, SONY, RC5, UNKNOWN
3145
uint16_t panasonicAddress; // This is only used for decoding Panasonic data
46+
uint16_t magiquestMagnitude; // This is only used for MagiQuest
3247
int32_t value; // Decoded value //mpf need to make unsigned.
3348
int16_t bits; // Number of bits in decoded value
3449
volatile uint16_t *rawbuf; // Raw intervals in .5 us ticks
@@ -46,6 +61,7 @@ class decode_results {
4661
#define JVC 8
4762
#define SANYO 9
4863
#define MITSUBISHI 10
64+
#define MAGIQUEST 11
4965
#define UNKNOWN -1
5066

5167
// Decoded value for NEC when a repeat code is received
@@ -71,6 +87,7 @@ class IRrecv
7187
int32_t decodeRC6(decode_results *results);
7288
int32_t decodePanasonic(decode_results *results);
7389
int32_t decodeJVC(decode_results *results);
90+
int32_t decodeMagiQuest(decode_results *results);
7491
int32_t decodeHash(decode_results *results);
7592
int16_t compare(uint16_t oldval, uint16_t newval);
7693

@@ -100,6 +117,7 @@ class IRsend
100117
void sendSharp(int32_t data, int16_t nbits);
101118
void sendPanasonic(uint16_t address, int32_t data);
102119
void sendJVC(int32_t data, int16_t nbits, int16_t 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.
120+
void sendMagiQuest(uint32_t wand_id, uint16_t magitude);
103121
// private:
104122
void enableIROut(int16_t khz);
105123
VIRTUAL void mark(int16_t usec);
@@ -110,7 +128,7 @@ class IRsend
110128
// Some useful constants
111129

112130
#define USECPERTICK 50 // microseconds per clock interrupt tick
113-
#define RAWBUF 100 // Length of raw duration buffer
131+
#define RAWBUF 112 // Length of raw duration buffer
114132

115133
// Marks tend to be 100us too long, and spaces 100us too short
116134
// when received due to sensor lag.

IRremoteInt.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@
162162
#define SHARP_BITS 15
163163
#define DISH_BITS 16
164164

165+
#define MAGIQUEST_PERIOD 1150
166+
#define MAGIQUEST_MARK_ZERO 280
167+
#define MAGIQUEST_SPACE_ZERO 850
168+
#define MAGIQUEST_MARK_ONE 580
169+
#define MAGIQUEST_SPACE_ONE 600
165170
#define TOLERANCE 25 // percent tolerance in measurements
166171
#define LTOL (1.0 - TOLERANCE/100.)
167172
#define UTOL (1.0 + TOLERANCE/100.)
@@ -213,7 +218,7 @@ extern volatile irparams_t irparams;
213218
#define MIN_RC6_SAMPLES 1
214219
#define PANASONIC_BITS 48
215220
#define JVC_BITS 16
216-
221+
#define MAGIQUEST_BITS 56
217222

218223

219224

examples/IRrecord/IRrecord.ino

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ void storeCode(decode_results *results) {
8686
else if (codeType == RC6) {
8787
Serial.print("Received RC6: ");
8888
}
89+
else if (codeType == MAGIQUEST) {
90+
Serial.print("Received MAGIQUEST: ");
91+
}
8992
else {
9093
Serial.print("Unexpected codeType ");
9194
Serial.print(codeType, DEC);
@@ -133,6 +136,11 @@ void sendCode(int repeat) {
133136
Serial.println(codeValue, HEX);
134137
}
135138
}
139+
else if (codeType == MAGIQUEST) {
140+
irsend.sendSony(codeValue, codeLen);
141+
Serial.print("Sent MAGIQUEST ");
142+
Serial.println(codeValue, HEX);
143+
}
136144
else if (codeType == UNKNOWN /* i.e. raw */) {
137145
// Assume 38 KHz
138146
irsend.sendRaw(rawCodes, codeLen, 38);

examples/IRrecvDump/IRrecvDump.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ void dump(decode_results *results) {
3737
else if (results->decode_type == SONY) {
3838
Serial.print("Decoded SONY: ");
3939
}
40+
else if (results->decode_type == MAGIQUEST) {
41+
Serial.print("Decoded MAGIQUEST - Magnitude=");
42+
Serial.print(results->magiquestMagnitude, HEX);
43+
Serial.print(", wand_id=");
44+
}
4045
else if (results->decode_type == RC5) {
4146
Serial.print("Decoded RC5: ");
4247
}

examples/IRrelay/IRrelay.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ void dump(decode_results *results) {
3737
else if (results->decode_type == RC6) {
3838
Serial.print("Decoded RC6: ");
3939
}
40+
else if (results->decode_type == MAGIQUEST) {
41+
Serial.print("Decoded MAGIQUEST: ");
42+
}
4043
Serial.print(results->value, HEX);
4144
Serial.print(" (");
4245
Serial.print(results->bits, DEC);

examples/IRtest2/IRtest2.ino

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ void dump(decode_results *results) {
9595
else if (results->decode_type == RC6) {
9696
Serial.print("Decoded RC6: ");
9797
}
98+
else if (results->decode_type == MAGIQUEST) {
99+
Serial.print("Decoded MAGIQUEST: ");
100+
}
98101
Serial.print(results->value, HEX);
99102
Serial.print(" (");
100103
Serial.print(results->bits, DEC);
@@ -140,6 +143,9 @@ void test(char *label, int type, unsigned long value, int bits) {
140143
else if (type == RC6) {
141144
irsend.sendRC6(value, bits);
142145
}
146+
else if (type == MAGIQUEST) {
147+
irsend.sendMagiQuest(value, bits);
148+
}
143149
else {
144150
Serial.print(label);
145151
Serial.println("Bad type!");
@@ -273,6 +279,7 @@ void loop() {
273279
test("RC61", RC6, 0x12345678, 32);
274280
test("RC62", RC6, 0x0, 32);
275281
test("RC63", RC6, 0xffffffff, 32);
282+
test("MAGIQUEST", MAGIQUEST, 0x12345678, 56);
276283

277284
// Tests of raw sending and receiving.
278285
// First test sending raw and receiving raw.

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ sendDISH KEYWORD2
3030
sendSharp KEYWORD2
3131
sendPanasonic KEYWORD2
3232
sendJVC KEYWORD2
33+
sendMagiQuest KEYWORD2
3334

3435
#
3536
#######################################
@@ -46,5 +47,6 @@ DISH LITERAL1
4647
SHARP LITERAL1
4748
PANASONIC LITERAL1
4849
JVC LITERAL1
50+
MAGIQUEST LITERAL1
4951
UNKNOWN LITERAL1
5052
REPEAT LITERAL1

0 commit comments

Comments
 (0)