@@ -221,6 +221,30 @@ void IRsend::sendJVC(int32_t data, int16_t nbits, int16_t repeat)
221
221
mark (JVC_BIT_MARK);
222
222
space (0 );
223
223
}
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
+
224
248
void IRsend::mark (int time) {
225
249
// Sends an IR mark for the specified number of microseconds.
226
250
// The mark output is modulated at the PWM frequency.
@@ -439,6 +463,12 @@ int16_t IRrecv::decode(decode_results *results) {
439
463
if (decodeJVC (results)) {
440
464
return DECODED;
441
465
}
466
+ #ifdef DEBUG
467
+ Serial.println (" Attempting MagiQuest decode" );
468
+ #endif
469
+ if (decodeMagiQuest (results)) {
470
+ return DECODED;
471
+ }
442
472
// decodeHash returns a hash on any input.
443
473
// Thus, it needs to be last in the list.
444
474
// If you add any decodes, add them before this.
@@ -896,6 +926,66 @@ int32_t IRrecv::decodeJVC(decode_results *results) {
896
926
return DECODED;
897
927
}
898
928
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
+
899
989
/* -----------------------------------------------------------------------
900
990
* hashdecode - decode an arbitrary IR code.
901
991
* Instead of decoding using a standard encoding scheme
0 commit comments