IRremote
ir_FAST.hpp
Go to the documentation of this file.
1 /*
2  * ir_FAST.hpp
3  *
4  * Contains functions for receiving and sending FAST IR protocol
5  * with no address and 16 bit data, interpreted as 8 bit command and 8 bit inverted command
6  *
7  * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
8  *
9  ************************************************************************************
10  * MIT License
11  *
12  * Copyright (c) 2023 Armin Joachimsmeyer
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a copy
15  * of this software and associated documentation files (the "Software"), to deal
16  * in the Software without restriction, including without limitation the rights
17  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18  * copies of the Software, and to permit persons to whom the Software is furnished
19  * to do so, subject to the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be included in all
22  * copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
25  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
26  * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
28  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
29  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30  *
31  ************************************************************************************
32  */
33 #ifndef _IR_FAST_HPP
34 #define _IR_FAST_HPP
35 
36 #include "TinyIR.h"
37 
38 #if defined(DEBUG)
39 #define LOCAL_DEBUG
40 #else
41 //#define LOCAL_DEBUG // This enables debug output only for this file
42 #endif
43 
47 // generated with https://patorjk.com/software/taag/#p=display&f=Alphabet&t=FAST
48 //==============================================================================
49 // FFFF AA SSS TTTTTT
50 // F A A S TT
51 // FFF AAAA SSS TT
52 // F A A S TT
53 // F A A SSSS TT
54 //==============================================================================
55 #include "TinyIR.h"
56 /*
57  Protocol=FAST Address=0x0 Command=0x76 Raw-Data=0x8976 16 bits LSB first
58  +2100,-1050
59  + 550,- 500 + 550,-1550 + 550,-1550 + 550,- 500
60  + 550,-1550 + 550,-1550 + 550,-1550 + 550,- 500
61  + 550,-1550 + 550,- 500 + 550,- 500 + 550,-1550
62  + 550,- 500 + 550,- 500 + 550,- 500 + 550,-1550
63  + 550
64  Sum: 28900
65  */
66 struct PulseDistanceWidthProtocolConstants const FASTProtocolConstants PROGMEM = { FAST, FAST_KHZ, FAST_HEADER_MARK,
69 
70 /************************************
71  * Start of send and decode functions
72  ************************************/
73 
77 void IRsend::sendFAST(uint8_t aCommand, int_fast8_t aNumberOfRepeats) {
78  // Set IR carrier frequency
79  enableIROut(FAST_KHZ); // 38 kHz
80 
81  uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
82  while (tNumberOfCommands > 0) {
83 
86 
87  sendPulseDistanceWidthData_P(&FASTProtocolConstants, aCommand | (((uint8_t)(~aCommand)) << 8), FAST_BITS);
88 
89  tNumberOfCommands--;
90  // skip last delay!
91  if (tNumberOfCommands > 0) {
92  // send repeated command in a fixed raster
94  }
95  }
96 }
97 
99 
100 // uint_fast8_t tRawlen = decodedIRData.rawlen; // Using a local variable does not improve code size
101 
102  // Check we have the right amount of data (36). The +4 is for initial gap, start bit mark and space + stop bit mark.
103  if (decodedIRData.rawlen != ((2 * FAST_BITS) + 4)) {
104  IR_DEBUG_PRINT(F("FAST: "));
105  IR_DEBUG_PRINT(F("Data length="));
107  IR_DEBUG_PRINTLN(F(" is not 36"));
108  return false;
109  }
110 
111  if (!checkHeader_P(&FASTProtocolConstants)) {
112  return false;
113  }
114 
115  decodePulseDistanceWidthData_P(&FASTProtocolConstants, FAST_BITS);
116  WordUnion tValue;
118 
119  if (tValue.UByte.LowByte != (uint8_t) ~(tValue.UByte.HighByte)) {
120 #if defined(LOCAL_DEBUG)
121  Serial.print(F("FAST: "));
122  Serial.print(F("8 bit parity is not correct. Expected=0x"));
123  Serial.print((uint8_t) ~(tValue.UByte.LowByte), HEX);
124  Serial.print(F(" received=0x"));
125  Serial.print(tValue.UByte.HighByte, HEX);
126  Serial.print(F(" data=0x"));
127  Serial.println(tValue.UWord, HEX);
128 #endif
130  }
131 
133 
134  // Success
135 // decodedIRData.flags = IRDATA_FLAGS_IS_LSB_FIRST; // Not required, since this is the start value
137  decodedIRData.address = 0; // No address for this protocol
140 
141  return true;
142 }
143 
145 #if defined(LOCAL_DEBUG)
146 #undef LOCAL_DEBUG
147 #endif
148 #endif // _IR_FAST_HPP
IRData::address
uint16_t address
Decoded address, Distance protocol (tMarkTicksLong (if tMarkTicksLong == 0, then tMarkTicksShort) << ...
Definition: IRremoteInt.h:152
FAST_BITS
#define FAST_BITS
Definition: TinyIR.h:92
MICROS_PER_TICK
#define MICROS_PER_TICK
microseconds per clock interrupt tick
Definition: IRremote.hpp:207
IRData::numberOfBits
uint16_t numberOfBits
Number of bits received for data (address + command + parity) - to determine protocol length if diffe...
Definition: IRremoteInt.h:161
IRsend::aNumberOfRepeats
void int_fast8_t aNumberOfRepeats
Definition: IRremoteInt.h:538
WordUnion
Union to specify parts / manifestations of a 16 bit Word without casts and shifts.
Definition: LongUnion.h:36
FAST
@ FAST
Definition: IRProtocol.h:125
FAST_BIT_MARK
#define FAST_BIT_MARK
Definition: TinyIR.h:96
IRrecv::decodePulseDistanceWidthData_P
void decodePulseDistanceWidthData_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset=3)
Definition: IRReceive.hpp:1117
MICROS_IN_ONE_MILLI
#define MICROS_IN_ONE_MILLI
Definition: IRremote.hpp:212
IRrecv::checkHeader_P
bool checkHeader_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM)
Definition: IRReceive.hpp:1309
WordUnion::UByte
struct WordUnion::@2 UByte
WordUnion::HighByte
uint8_t HighByte
Definition: LongUnion.h:39
PROTOCOL_IS_PULSE_DISTANCE
#define PROTOCOL_IS_PULSE_DISTANCE
Definition: IRProtocol.h:173
IRsend::mark
void mark(uint16_t aMarkMicros)
Sends an IR mark for the specified number of microseconds.
Definition: IRSend.hpp:1153
TinyIR.h
IRData::decodedRawData
IRRawDataType decodedRawData
Up to 32/64 bit decoded raw data, to be used for send<protocol>Raw functions.
Definition: IRremoteInt.h:155
IRrecv::checkForRepeatSpaceTicksAndSetFlag
void checkForRepeatSpaceTicksAndSetFlag(uint16_t aMaximumRepeatSpaceTicks)
Definition: IRReceive.hpp:1333
IR_DEBUG_PRINT
#define IR_DEBUG_PRINT(...)
If DEBUG, print the arguments, otherwise do nothing.
Definition: IRremoteInt.h:186
IRDATA_FLAGS_PARITY_FAILED
#define IRDATA_FLAGS_PARITY_FAILED
The current (autorepeat) frame violated parity check.
Definition: IRProtocol.h:149
IRrecv::decodeFAST
bool decodeFAST()
Definition: ir_FAST.hpp:98
PulseDistanceWidthProtocolConstants
Definition: IRProtocol.h:161
IRsend::sendPulseDistanceWidthData_P
void sendPulseDistanceWidthData_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, IRRawDataType aData, uint_fast8_t aNumberOfBits)
Definition: IRSend.hpp:586
PROGMEM
struct PulseDistanceWidthProtocolConstants const FASTProtocolConstants PROGMEM
Definition: ir_FAST.hpp:66
IRrecv::decodedIRData
IRData decodedIRData
Definition: IRremoteInt.h:409
IRData::flags
uint8_t flags
IRDATA_FLAGS_IS_REPEAT, IRDATA_FLAGS_WAS_OVERFLOW etc. See IRDATA_FLAGS_* definitions above.
Definition: IRremoteInt.h:162
PROTOCOL_IS_LSB_FIRST
#define PROTOCOL_IS_LSB_FIRST
Definition: IRProtocol.h:179
IRData::command
uint16_t command
Decoded command, Distance protocol (tMarkTicksShort << 8) | tSpaceTicksShort.
Definition: IRremoteInt.h:153
FAST_MAXIMUM_REPEAT_DISTANCE
#define FAST_MAXIMUM_REPEAT_DISTANCE
Definition: TinyIR.h:105
FAST_ZERO_SPACE
#define FAST_ZERO_SPACE
Definition: TinyIR.h:98
FAST_REPEAT_PERIOD
#define FAST_REPEAT_PERIOD
Definition: TinyIR.h:103
IRsend::space
static void space(uint16_t aSpaceMicros)
Sends an IR space for the specified number of microseconds.
Definition: IRSend.hpp:1364
FAST_KHZ
#define FAST_KHZ
The FAST protocol is a proprietary modified JVC protocol without address, with parity and with a shor...
Definition: TinyIR.h:89
IRData::rawlen
IRRawlenType rawlen
Counter of entries in rawbuf of last received frame.
Definition: IRremoteInt.h:170
FAST_HEADER_SPACE
#define FAST_HEADER_SPACE
Definition: TinyIR.h:101
FAST_REPEAT_DISTANCE
#define FAST_REPEAT_DISTANCE
Definition: TinyIR.h:104
sendFAST
void sendFAST(uint8_t aSendPin, uint16_t aCommand, uint_fast8_t aNumberOfRepeats=0)
Definition: TinyIRSender.hpp:351
WordUnion::LowByte
uint8_t LowByte
Definition: LongUnion.h:38
FAST_HEADER_MARK
#define FAST_HEADER_MARK
Definition: TinyIR.h:100
WordUnion::UWord
uint16_t UWord
Definition: LongUnion.h:47
IR_DEBUG_PRINTLN
#define IR_DEBUG_PRINTLN(...)
If DEBUG, print the arguments as a line, otherwise do nothing.
Definition: IRremoteInt.h:190
IRData::protocol
decode_type_t protocol
UNKNOWN, NEC, SONY, RC5, PULSE_DISTANCE, ...
Definition: IRremoteInt.h:151
IRsend::aCommand
void aCommand
Definition: IRremoteInt.h:688
FAST_ONE_SPACE
#define FAST_ONE_SPACE
Definition: TinyIR.h:97
IRsend::enableIROut
void enableIROut(uint_fast8_t aFrequencyKHz)
Enables IR output.
Definition: IRSend.hpp:1404