Infrared4Arduino 1.2.3
Loading...
Searching...
No Matches
HashDecoder.h
Go to the documentation of this file.
1
6#pragma once
7
8#include "IrDecoder.h"
9#include "IrReader.h"
10#include "IrSignal.h"
11
19class HashDecoder : public IrDecoder {
20private:
21 uint32_t hash;
22
23 char decodeBuffer[2 * sizeof (hash) + 1];
24
25 static uint32_t compare(microseconds_t oldval, microseconds_t newval);
26
27 void decode(const microseconds_t* data, size_t length);
28
29 void decode(const IrReader& irReader);
30
31 void decode(const IrSequence& irSequence) {
32 decode(irSequence.getDurations(), irSequence.getLength());
33 }
34
35 void decode(const IrSignal& irSignal) {
36 decode(irSignal.getIntro());
37 decode(irSignal.getRepeat());
38 decode(irSignal.getEnding());
39 }
40
41 static constexpr unsigned int offset = 2;
42 static constexpr const char *format = "%0lx";
43 static constexpr uint32_t FNVprime = 16777619UL;
44 static constexpr uint32_t FNVoffsetBasis = 2166136261UL;
45 static constexpr unsigned int minMeaningfulLength = 4U;
46
47public:
48
49#ifndef DOXYGEN
50 HashDecoder() = delete;
51 HashDecoder(const HashDecoder&) = delete;
52 HashDecoder(HashDecoder&&) = delete;
53 HashDecoder& operator=(const HashDecoder&) = delete;
54 HashDecoder& operator=(HashDecoder&&) = delete;
55#endif // ! DOXYGEN
56
57 virtual ~HashDecoder() {}
58
63 HashDecoder(const IrReader& irReader) : IrDecoder(),hash(FNVoffsetBasis) {
64 decode(irReader);
65 sprintf(decodeBuffer, format, static_cast<unsigned long>(hash));
66 }
67
72 HashDecoder(const IrSequence& irSequence) : IrDecoder(),hash(FNVoffsetBasis) {
73 decode(irSequence);
74 sprintf(decodeBuffer, format, static_cast<unsigned long>(hash));
75 }
76
77 HashDecoder(const IrSignal& irSignal) : IrDecoder(),hash(FNVoffsetBasis) {
78 decode(irSignal);
79 sprintf(decodeBuffer, format, static_cast<unsigned long>(hash));
80 }
81
86 uint32_t getHash() const {
87 return hash;
88 }
89
90 static uint32_t decodeHash(const IrSequence& irSequence);
91
92 static uint32_t decodeHash(const IrReader& irReader);
93
100 static bool tryDecode(const IrReader& irReader, Stream& stream);
101
102 const char *getDecode() const {
103 return decodeBuffer;
104 }
105};
uint16_t microseconds_t
Type for durations in micro seconds.
Definition: InfraredTypes.h:15
A decoder class using FNV-1 hashes of length 32.
Definition: HashDecoder.h:19
virtual ~HashDecoder()
Definition: HashDecoder.h:57
HashDecoder(const IrSignal &irSignal)
Definition: HashDecoder.h:77
HashDecoder(const IrReader &irReader)
Constructs a HashDecoder from an IrReader, containing data.
Definition: HashDecoder.h:63
uint32_t getHash() const
Returns the hash value.
Definition: HashDecoder.h:86
static bool tryDecode(const IrReader &irReader, Stream &stream)
Convenience function; constructs a HashDecoder and calls its printDecode.
Definition: HashDecoder.cpp:10
const char * getDecode() const
Returns a textual description the decode for human consumption.
Definition: HashDecoder.h:102
HashDecoder(const IrSequence &irSequence)
Constructs a HashDecoder from an IrSequence.
Definition: HashDecoder.h:72
static uint32_t decodeHash(const IrSequence &irSequence)
Definition: HashDecoder.cpp:40
Abstract base class for all decoder classes.
Definition: IrDecoder.h:8
Abstract base class for all IR readers, capturing or receiving.
Definition: IrReader.h:30
This class consists of a vector of durations.
Definition: IrSequence.h:11
const microseconds_t * getDurations() const
Definition: IrSequence.h:73
size_t getLength() const
Returns the number of durations.
Definition: IrSequence.h:65
This class models an IR signal with intro-, repeat-, and ending sequences.
Definition: IrSignal.h:11
const IrSequence & getIntro() const
Definition: IrSignal.h:146
const IrSequence & getRepeat() const
Definition: IrSignal.h:142
const IrSequence & getEnding() const
Definition: IrSignal.h:138