source: trunk/Arduino/libraries/Adafruit_Circuit_Playground/utility/IRLibDecodeBase.h @ 9

Last change on this file since 9 was 3, checked in by markus, 7 years ago

Setup project structure

File size: 5.2 KB
Line 
1/* IRLibDecodeBase.h
2 * Part of IRLib Library for Arduino receiving, decoding, and sending
3 * infrared signals. See COPYRIGHT.txt and LICENSE.txt for more information.
4 */
5/*
6 * This module contains the base classes for decoding. You will not create instances
7 * of these classes, rather you will use them as base classes in creating derived
8 * protocol specific decoders.
9 */
10#ifndef IRLIBDECODEBASE_H
11#define IRLIBDECODEBASE_H
12#include "IRLibGlobals.h"
13#include "IRLibProtocols.h"
14
15// Base class for decoding raw results
16class IRdecodeBase {
17public:
18  IRdecodeBase(void);
19  uint8_t protocolNum;              // NEC, SONY, RC5, UNKNOWN etc.
20  uint32_t value;                   // Decoded value
21  uint16_t address;                 // Additional data for protocols using more than 32 bits
22  uint8_t bits;                     // Number of bits in decoded value
23  bool ignoreHeader;                // Relaxed header detection allows AGC to settle
24  bool decodeGeneric(uint8_t expectedLength, uint16_t headMark, uint16_t headSpace,
25                     uint16_t markData, uint16_t spaceOne, uint16_t spaceZero);
26  void dumpResults(bool verbose=true);//full dump of all timing values
27  bool MATCH(int16_t val,int16_t expected);
28  bool ABS_MATCH(int16_t val,int16_t expected,int16_t tolerance);
29protected:
30  virtual void resetDecoder(void);   // Initializes the decoder
31  bufIndex_t offset;                 // Index into decodeBuffer used various places
32};
33
34// Base class used by RC5 and RC6 protocols
35class IRdecodeRC: public virtual IRdecodeBase {
36public:
37  enum RCLevel {MARK, SPACE, ERROR};//used by decoders for RC5/RC6
38  RCLevel getRClevel(uint8_t *used, const uint16_t t1);
39protected:
40  uint8_t nBits;
41  uint8_t used;
42  uint32_t data;
43};
44
45/* The remainder of this file a variety of default values and macros which are
46 * used internally. They used to be in a separate file IRLibMatch.h but it's easier
47 * to include them here.  You need not worry about them unless you are creating
48 * your own decoding routines. See the documentation how to implement new protocols
49 * for a more detailed explanation of these definitions and routines.
50 */
51
52/*
53 * Originally all timing comparisons for decoding were based on a percent of the
54 * target value. However when target values are relatively large, the percent tolerance
55 * is too much.  In some instances an absolute tolerance is needed. In order to maintain
56 * backward compatibility, the default will be to continue to use percent. If you wish
57 * to default to an absolute tolerance, you should comment out the line below.
58 */
59#define IRLIB_USE_PERCENT
60
61/*
62 * These are some miscellaneous definitions that are needed by the decoding routines.
63 * You need not include this file unless you are creating custom decode routines
64 * which will require these macros and definitions. Even if you include it, you probably
65 * don't need to be intimately familiar with the internal details.
66 */
67
68#define TOPBIT 0x80000000
69#define PERCENT_TOLERANCE 25  // percent tolerance in measurements
70#define DEFAULT_ABS_TOLERANCE 75 //absolute tolerance in microseconds
71/* If you insert #define IRLIB_TRACE in your sketch before including this file,
72 * various debugging routines will be enabled in the dumpResults() method.
73 */
74#ifdef IRLIB_TRACE
75void IRLIB_ATTEMPT_MESSAGE(const __FlashStringHelper * s) {Serial.print(F("Attempting ")); Serial.print(s); Serial.println(F(" decode:"));};
76void IRLIB_TRACE_MESSAGE(const __FlashStringHelper * s) {Serial.print(F("Executing ")); Serial.println(s);};
77uint8_t IRLIB_REJECTION_MESSAGE(const __FlashStringHelper * s) { Serial.print(F(" Protocol failed because ")); Serial.print(s); Serial.println(F(" wrong.")); return false;};
78uint8_t IRLIB_DATA_ERROR_MESSAGE(const __FlashStringHelper * s, uint8_t index, uint16_t value, uint16_t expected) { 
79 IRLIB_REJECTION_MESSAGE(s); Serial.print(F("Error occurred with decodeBuffer[")); Serial.print(index,DEC); Serial.print(F("]=")); Serial.print(value,DEC);
80 Serial.print(F(" expected:")); Serial.println(expected,DEC); return false;
81};
82#define RAW_COUNT_ERROR IRLIB_REJECTION_MESSAGE(F("number of raw samples"));
83#define HEADER_MARK_ERROR(expected) IRLIB_DATA_ERROR_MESSAGE(F("header mark"),1,recvGlobal.decodeBuffer[1],expected);
84#define HEADER_SPACE_ERROR(expected) IRLIB_DATA_ERROR_MESSAGE(F("header space"),2,recvGlobal.decodeBuffer[2],expected);
85#define DATA_MARK_ERROR(expected) IRLIB_DATA_ERROR_MESSAGE(F("data mark"),offset,recvGlobal.decodeBuffer[offset],expected);
86#define DATA_SPACE_ERROR(expected) IRLIB_DATA_ERROR_MESSAGE(F("data space"),offset,recvGlobal.decodeBuffer[offset],expected);
87#define TRAILER_BIT_ERROR(expected) IRLIB_DATA_ERROR_MESSAGE(F("RC6 trailer bit length"),offset,recvGlobal.decodeBuffer[offset],expected);
88#define BIT_COUNT_ERROR IRLIB_REJECTION_MESSAGE(F("invalid number of bits"));
89#else
90#define IRLIB_ATTEMPT_MESSAGE(s)
91#define IRLIB_TRACE_MESSAGE(s)
92#define IRLIB_REJECTION_MESSAGE(s) false
93#define IRLIB_DATA_ERROR_MESSAGE(s,i,v,e) false
94#define RAW_COUNT_ERROR false
95#define HEADER_MARK_ERROR(expected) false
96#define HEADER_SPACE_ERROR(expected) false
97#define DATA_MARK_ERROR(expected) false
98#define DATA_SPACE_ERROR(expected) false
99#define TRAILER_BIT_ERROR(expected) false
100#define BIT_COUNT_ERROR false
101#endif
102
103#endif  //IRLIBDECODEBASE_H
104 
Note: See TracBrowser for help on using the repository browser.