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 // This block must be located after the includes of other *.hpp files
39 //#define LOCAL_DEBUG // This enables debug output only for this file - only for development
40 #include "LocalDebugLevelStart.h"
41 
45 // generated with https://patorjk.com/software/taag/#p=display&f=Alphabet&t=FAST
46 //==============================================================================
47 // FFFF AA SSS TTTTTT
48 // F A A S TT
49 // FFF AAAA SSS TT
50 // F A A S TT
51 // F A A SSSS TT
52 //==============================================================================
53 #include "TinyIR.h"
54 /*
55  Protocol=FAST Address=0x0 Command=0x76 Raw-Data=0x8976 16 bits LSB first
56  +2100,-1050
57  + 550,- 500 + 550,-1550 + 550,-1550 + 550,- 500
58  + 550,-1550 + 550,-1550 + 550,-1550 + 550,- 500
59  + 550,-1550 + 550,- 500 + 550,- 500 + 550,-1550
60  + 550,- 500 + 550,- 500 + 550,- 500 + 550,-1550
61  + 550
62  Sum: 28900
63  */
64 struct PulseDistanceWidthProtocolConstants const FASTProtocolConstants PROGMEM = { FAST, FAST_KHZ, FAST_HEADER_MARK,
67 
68 /************************************
69  * Start of send and decode functions
70  ************************************/
71 
75 void IRsend::sendFAST(uint8_t aCommand, int_fast8_t aNumberOfRepeats) {
76  // Set IR carrier frequency
77  enableIROut(FAST_KHZ); // 38 kHz
78 
79  uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
80  while (tNumberOfCommands > 0) {
81 
84 
85  sendPulseDistanceWidthData_P(&FASTProtocolConstants, aCommand | (((uint8_t)(~aCommand)) << 8), FAST_BITS);
86 
87  tNumberOfCommands--;
88  // skip last delay!
89  if (tNumberOfCommands > 0) {
90  // send repeated command in a fixed raster
92  }
93  }
94 }
95 
97 
98 // uint_fast8_t tRawlen = decodedIRData.rawlen; // Using a local variable does not improve code size
99 
100  // Check we have the right amount of data (36). The +4 is for initial gap, start bit mark and space + stop bit mark.
101  if (decodedIRData.rawlen != ((2 * FAST_BITS) + 4)) {
102  DEBUG_PRINT(F("FAST: Data length="));
104  DEBUG_PRINTLN(F(" is not 36"));
105  return false;
106  }
107 
108  if (!checkHeader_P(&FASTProtocolConstants)) {
109  return false;
110  }
111 
112  decodePulseDistanceWidthData_P(&FASTProtocolConstants, FAST_BITS);
113  WordUnion tValue;
115 
116  if (tValue.UByte.LowByte != (uint8_t) ~(tValue.UByte.HighByte)) {
117  DEBUG_PRINT(F("FAST: 8 bit parity is not correct. Expected=0x"));
118  DEBUG_PRINT((uint8_t) ~(tValue.UByte.LowByte), HEX);
119  DEBUG_PRINT(F(" received=0x"));
120  DEBUG_PRINT(tValue.UByte.HighByte, HEX);
121  DEBUG_PRINT(F(" data=0x"));
122  DEBUG_PRINTLN(tValue.UWord, HEX);
123 
125  }
126 
128 
129  // Success
130 // decodedIRData.flags = IRDATA_FLAGS_IS_LSB_FIRST; // Not required, since this is the start value
132  decodedIRData.address = 0; // No address for this protocol
135 
136  return true;
137 }
138 
140 #include "LocalDebugLevelEnd.h"
141 
142 #endif // _IR_FAST_HPP
IRData::address
uint16_t address
Decoded address, Distance protocol (tMarkTicksLong (if tMarkTicksLong == 0, then tMarkTicksShort) << ...
Definition: IRremoteInt.h:164
FAST_BITS
#define FAST_BITS
Definition: TinyIR.h:92
MICROS_PER_TICK
#define MICROS_PER_TICK
microseconds per clock interrupt tick
Definition: IRremote.hpp:133
IRData::numberOfBits
uint16_t numberOfBits
Number of bits received for data (address + command + parity) - to determine protocol length if diffe...
Definition: IRremoteInt.h:173
DEBUG_PRINT
#define DEBUG_PRINT(...)
Definition: LocalDebugLevelStart.h:79
IRsend::aNumberOfRepeats
void int_fast8_t aNumberOfRepeats
Definition: IRremoteInt.h:528
WordUnion
Union to specify parts / manifestations of a 16 bit Word without casts and shifts.
Definition: LongUnion.h:36
FAST
@ FAST
Definition: IRProtocol.h:104
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:1112
MICROS_IN_ONE_MILLI
#define MICROS_IN_ONE_MILLI
Definition: IRremote.hpp:217
IRrecv::checkHeader_P
bool checkHeader_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM)
Definition: IRReceive.hpp:1228
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:151
IRsend::mark
void mark(uint16_t aMarkMicros)
Sends an IR mark for the specified number of microseconds.
Definition: IRSend.hpp:1247
TinyIR.h
IRrecv::checkForRepeatSpaceTicksAndSetFlag
void checkForRepeatSpaceTicksAndSetFlag(uint16_t aMaximumRepeatSpaceTicks)
Definition: IRReceive.hpp:1248
LocalDebugLevelStart.h
IRDATA_FLAGS_PARITY_FAILED
#define IRDATA_FLAGS_PARITY_FAILED
The current (autorepeat) frame violated parity check.
Definition: IRProtocol.h:127
IRrecv::decodeFAST
bool decodeFAST()
Definition: ir_FAST.hpp:96
PulseDistanceWidthProtocolConstants
Definition: IRProtocol.h:139
PROGMEM
struct PulseDistanceWidthProtocolConstants const FASTProtocolConstants PROGMEM
Definition: ir_FAST.hpp:64
IRrecv::decodedIRData
IRData decodedIRData
Definition: IRremoteInt.h:401
IRData::flags
uint8_t flags
IRDATA_FLAGS_IS_REPEAT, IRDATA_FLAGS_WAS_OVERFLOW etc. See IRDATA_FLAGS_* definitions above.
Definition: IRremoteInt.h:174
PROTOCOL_IS_LSB_FIRST
#define PROTOCOL_IS_LSB_FIRST
Definition: IRProtocol.h:157
IRData::command
uint16_t command
Decoded command, Distance protocol (tMarkTicksShort << 8) | tSpaceTicksShort.
Definition: IRremoteInt.h:165
IRsend::sendFAST
void sendFAST(uint8_t aCommand, int_fast8_t aNumberOfRepeats)
The FAST protocol repeats by skipping the header mark and space -> this leads to a poor repeat detect...
Definition: ir_FAST.hpp:75
IRData::decodedRawData
IRDecodedRawDataType decodedRawData
Up to 32/64 bit decoded raw data, to be used for send<protocol>Raw functions.
Definition: IRremoteInt.h:167
IRsend::sendPulseDistanceWidthData_P
void sendPulseDistanceWidthData_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, IRDecodedRawDataType aData, uint_fast8_t aNumberOfBits)
Definition: IRSend.hpp:670
FAST_MAXIMUM_REPEAT_DISTANCE
#define FAST_MAXIMUM_REPEAT_DISTANCE
Definition: TinyIR.h:105
FAST_ZERO_SPACE
#define FAST_ZERO_SPACE
Definition: TinyIR.h:98
DEBUG_PRINTLN
#define DEBUG_PRINTLN(...)
Definition: LocalDebugLevelStart.h:80
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:1458
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:182
FAST_HEADER_SPACE
#define FAST_HEADER_SPACE
Definition: TinyIR.h:101
FAST_REPEAT_DISTANCE
#define FAST_REPEAT_DISTANCE
Definition: TinyIR.h:104
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
IRData::protocol
decode_type_t protocol
UNKNOWN, NEC, SONY, RC5, PULSE_DISTANCE, ...
Definition: IRremoteInt.h:163
IRsend::aCommand
void aCommand
Definition: IRremoteInt.h:617
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:1498
LocalDebugLevelEnd.h