Go to the documentation of this file.
38 #ifndef _IR_MAGIQUEST_HPP
39 #define _IR_MAGIQUEST_HPP
41 #if defined(DEBUG) && !defined(LOCAL_DEBUG)
84 #define MAGIQUEST_CHECKSUM_BITS 8 // magiquest_t.cmd.checksum
85 #define MAGIQUEST_MAGNITUDE_BITS 9 // magiquest_t.cmd.magnitude
86 #define MAGIQUEST_WAND_ID_BITS 31 // magiquest_t.cmd.wand_id -> wand-id is handled as 32 bit and always even
87 #define MAGIQUEST_START_BITS 8 // magiquest_t.cmd.StartBits
89 #define MAGIQUEST_PERIOD 1150 // Time for a full MagiQuest "bit" (1100 - 1200 usec)
91 #define MAGIQUEST_DATA_BITS (MAGIQUEST_CHECKSUM_BITS + MAGIQUEST_MAGNITUDE_BITS + MAGIQUEST_WAND_ID_BITS) // 48 Size of the command without the start bits
92 #define MAGIQUEST_BITS (MAGIQUEST_CHECKSUM_BITS + MAGIQUEST_MAGNITUDE_BITS + MAGIQUEST_WAND_ID_BITS + MAGIQUEST_START_BITS) // 56 Size of the command with the start bits
102 #define MAGIQUEST_UNIT (MAGIQUEST_PERIOD / 4) // 287.5
104 #define MAGIQUEST_ONE_MARK (2 * MAGIQUEST_UNIT) // 576
105 #define MAGIQUEST_ONE_SPACE (2 * MAGIQUEST_UNIT) // 576
106 #define MAGIQUEST_ZERO_MARK MAGIQUEST_UNIT // 287.5
107 #define MAGIQUEST_ZERO_SPACE (3 * MAGIQUEST_UNIT) // 864
125 tWandId.
ULong = aWandId << 1;
126 uint8_t tChecksum = (tWandId.
Bytes[0]) + tWandId.
Bytes[1] + tWandId.
Bytes[2] + tWandId.
Bytes[3];
127 tChecksum += aMagnitude + (aMagnitude >> 8);
128 tChecksum = ~tChecksum + 1;
136 #if defined(LOCAL_DEBUG)
138 Serial.print(F(
"MagiQuest checksum=0x"));
139 Serial.println(tChecksum, HEX);
166 #if defined(LOCAL_DEBUG)
167 Serial.print(F(
"MagiQuest: "));
168 Serial.println(F(
"Start bit decode failed"));
173 #if defined(LOCAL_DEBUG)
174 Serial.print(F(
"MagiQuest: "));
175 Serial.print(F(
"Not 8 leading zero start bits received, RawData=0x"));
185 #if defined(LOCAL_DEBUG)
186 Serial.print(F(
"MagiQuest: "));
187 Serial.println(F(
"ID decode failed"));
192 #if defined(LOCAL_DEBUG)
193 Serial.print(F(
"31 bit WandId=0x"));
198 uint8_t tChecksum = tDecodedRawData.
Bytes[0] + tDecodedRawData.
Bytes[1] + tDecodedRawData.
Bytes[2] + tDecodedRawData.
Bytes[3];
199 #if defined(LOCAL_DEBUG)
200 Serial.print(F(
"31 bit WandId=0x"));
202 Serial.print(F(
" shifted=0x"));
203 Serial.println(tDecodedRawData.
ULong, HEX);
210 #if defined(LOCAL_DEBUG)
211 Serial.print(F(
"MagiQuest: "));
212 Serial.println(F(
"Magnitude + checksum decode failed"));
217 #if defined(LOCAL_DEBUG)
218 Serial.print(F(
"Magnitude + checksum=0x"));
224 tChecksum += tDecodedRawData.
UBytes[2] + tDecodedRawData.
UBytes[1] + tDecodedRawData.
UBytes[0];
225 if (tChecksum != 0) {
227 #if defined(LOCAL_DEBUG)
228 Serial.print(F(
"Checksum 0x"));
229 Serial.print(tChecksum, HEX);
230 Serial.println(F(
" is not 0"));
245 #if defined(LOCAL_DEBUG)
248 #endif // _IR_MAGIQUEST_HPP
uint16_t address
Decoded address, Distance protocol (tMarkTicksLong (if tMarkTicksLong == 0, then tMarkTicksShort) << ...
Union to specify parts / manifestations of a 32 bit Long without casts and shifts.
void sendMagiQuest(uint32_t aWandId, uint16_t aMagnitude)
#define PROTOCOL_IS_MSB_FIRST
uint16_t numberOfBits
Number of bits received for data (address + command + parity) - to determine protocol length if diffe...
#define MAGIQUEST_ONE_SPACE
uint_fast8_t rawlen
counter of entries in rawbuf
IRRawDataType decodedRawData
Up to 32/64 bit decoded raw data, to be used for send functions.
#define IR_DEBUG_PRINT(...)
If DEBUG, print the arguments, otherwise do nothing.
struct PulseDistanceWidthProtocolConstants MagiQuestProtocolConstants
bool decodePulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, uint_fast8_t aNumberOfBits, uint_fast8_t aStartOffset=3)
Decode pulse distance protocols for PulseDistanceWidthProtocolConstants.
#define MAGIQUEST_ZERO_MARK
#define IRDATA_FLAGS_PARITY_FAILED
The current (autorepeat) frame violated parity check.
uint8_t flags
IRDATA_FLAGS_IS_REPEAT, IRDATA_FLAGS_WAS_OVERFLOW etc. See IRDATA_FLAGS_* definitions above.
#define MAGIQUEST_ZERO_SPACE
#define MAGIQUEST_CHECKSUM_BITS
#define MAGIQUEST_ONE_MARK
#define MAGIQUEST_MAGNITUDE_BITS
uint16_t command
Decoded command, Distance protocol (tMarkTicksShort << 8) | tSpaceTicksShort.
#define MAGIQUEST_WAND_ID_BITS
#define IRDATA_FLAGS_IS_MSB_FIRST
Value is mainly determined by the (known) protocol.
uint16_t extra
Contains upper 16 bit of Magiquest WandID, Kaseikyo unknown vendor ID and Distance protocol (HeaderMa...
#define MAGIQUEST_START_BITS
void sendPulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, IRRawDataType aData, uint_fast8_t aNumberOfBits)
Sends PulseDistance data The output always ends with a space Each additional call costs 16 bytes prog...
#define IR_DEBUG_PRINTLN(...)
If DEBUG, print the arguments as a line, otherwise do nothing.
decode_type_t protocol
UNKNOWN, NEC, SONY, RC5, PULSE_DISTANCE, ...
void enableIROut(uint_fast8_t aFrequencyKHz)
Enables IR output.