Infrared4Arduino 1.2.3
Loading...
Searching...
No Matches
Pronto.h
Go to the documentation of this file.
1
11// Maintainer note:
12// Make sure that this class does not use floating point arithmetics.
13
14#pragma once
15
16#include "InfraredTypes.h"
17#include "IrSignal.h"
18#include "Board.h"
19
20class Pronto {
21public:
22 static constexpr unsigned int digitsInProntoNumber = 4U;
23 static constexpr unsigned int numbersInPreamble = 4U;
24
25private:
26 static constexpr unsigned int bitsInHexadecimal = 4U;
27 static constexpr unsigned int hexMask = 0xFU;
28 static constexpr uint16_t learnedToken = 0x0000U;
29 static constexpr uint16_t learnedNonModulatedToken = 0x0100U;
30 static constexpr uint32_t referenceFrequency = 4145146UL;
31 static constexpr uint16_t fallbackFrequencyCode = 0x0040U; // To use with frequency = 0;
32 static constexpr frequency_t fallbackFrequency = 64767U; // To use with frequency = 0;
33 static constexpr uint32_t microsecondsInSeconds = 1000000UL;
34
35 Pronto() = delete;
36
37 static microseconds_t* mkSequence(const uint16_t *data, size_t pairs, microseconds_t timebase);
38
39 static frequency_t toFrequency(uint16_t code);
40
41 static uint16_t toFrequencyCode(frequency_t frequency);
42
43 static frequency_t effectiveFrequency(frequency_t frequency);
44
45 static microseconds_t toTimebase(frequency_t frequency_t);
46
47 static size_t lengthHexString(size_t introLength, size_t repeatLength);
48
49 static char* prelude(frequency_t frequency, size_t introLength, size_t repeatLength);
50
51 static char hexDigit(unsigned int x);
52
53 static void appendChar(char *result, unsigned int& index, char ch);
54
55 static void appendDuration(char *result, unsigned int& index, uint16_t duration, microseconds_t timebase);
56
57 static void appendDigit(char *result, unsigned int& index, unsigned int number);
58
59 static void appendNumber(char *result, unsigned int& index, uint16_t number);
60
61 static void appendSequence(char *result, unsigned int& index, const microseconds_t *data, size_t length, microseconds_t timebase);
62
63 static void appendSequence(char *result, unsigned int& index, const IrSequence& irSequence, microseconds_t timebase);
64
65 static void dumpSequence(Stream& stream, const microseconds_t *data, size_t length, microseconds_t timebase);
66
67 static void dumpDuration(Stream& stream, microseconds_t duration, microseconds_t timebase);
68
69 static void dumpNumber(Stream& stream, uint16_t number);
70
71 static void dumpDigit(Stream& stream, unsigned int number);
72
73public:
80 static IrSignal *parse(const uint16_t *data, size_t size);
81
87 static IrSignal *parse(const char *str);
88
89#if HAS_FLASH_READ || defined(DOXYGEN)
95 static IrSignal *parse_PF(const uint_farptr_t str);
96
97 static IrSignal *parse_PF(const char * ptr);
98
106 static IrSignal *parse(const __FlashStringHelper *str);
107#endif
108
114 static char* toProntoHex(const IrSignal& irSignal) {
115 return toProntoHex(irSignal.getIntro(), irSignal.getRepeat(), irSignal.getFrequency());
116 }
117
126 static char* toProntoHex(const IrSequence& introSequence, const IrSequence& repeatSequence = IrSequence::emptyInstance, frequency_t frequency = IrSignal::defaultFrequency) {
127 return toProntoHex(introSequence.getDurations(), introSequence.getLength(), repeatSequence.getDurations(), repeatSequence.getLength(), frequency);
128 }
129
138 static char* toProntoHex(const microseconds_t* introData, size_t introLength, frequency_t frequency = IrSignal::defaultFrequency) {
139 return toProntoHex(introData, introLength, nullptr, 0, frequency);
140 }
141
152 static char* toProntoHex(const microseconds_t* introData, size_t introLength, const microseconds_t* repeatData = nullptr, size_t repeatLength = 0, frequency_t frequency = IrSignal::defaultFrequency);
153
159 static void dump(Stream& stream, const IrSignal& irSignal) {
160 return dump(stream, irSignal.getIntro(), irSignal.getRepeat(), irSignal.getFrequency());
161 }
162
171 static void dump(Stream& stream, const IrSequence& introSequence, const IrSequence& repeatSequence = IrSequence::emptyInstance, frequency_t frequency = IrSignal::defaultFrequency) {
172 return dump(stream, introSequence.getDurations(), introSequence.getLength(), repeatSequence.getDurations(), repeatSequence.getLength(), frequency);
173 }
174
185 static void dump(Stream& stream, const microseconds_t* introData, size_t introLength, const microseconds_t* repeatData = nullptr, size_t repeatLength = 0, frequency_t frequency = IrSignal::defaultFrequency);
186};
void * uint_farptr_t
Definition: Board.h:288
This file defines some general data types that are used in the library.
uint16_t microseconds_t
Type for durations in micro seconds.
Definition: InfraredTypes.h:15
uint32_t frequency_t
Type for modulation frequency in Hz.
Definition: InfraredTypes.h:31
This class consists of a vector of durations.
Definition: IrSequence.h:11
static const IrSequence emptyInstance
Definition: IrSequence.h:53
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
frequency_t getFrequency() const
Definition: IrSignal.h:130
const IrSequence & getIntro() const
Definition: IrSignal.h:146
const IrSequence & getRepeat() const
Definition: IrSignal.h:142
static constexpr frequency_t defaultFrequency
Definition: IrSignal.h:13
Static class consisting of functions for parsing a Pronto Hex string (like 0000 006C 0022 0002 015B 0...
Definition: Pronto.h:20
static constexpr unsigned int numbersInPreamble
Definition: Pronto.h:23
static char * toProntoHex(const IrSignal &irSignal)
Function for generating a Pronto Hex string from the argument.
Definition: Pronto.h:114
static void dump(Stream &stream, const IrSequence &introSequence, const IrSequence &repeatSequence=IrSequence::emptyInstance, frequency_t frequency=IrSignal::defaultFrequency)
Function for printing data as Pronto Hex string on the stream given as argument.
Definition: Pronto.h:171
static IrSignal * parse(const uint16_t *data, size_t size)
Function for parsing its input data into an IrSignal.
Definition: Pronto.cpp:10
static char * toProntoHex(const IrSequence &introSequence, const IrSequence &repeatSequence=IrSequence::emptyInstance, frequency_t frequency=IrSignal::defaultFrequency)
Function for generating a Pronto Hex string from the arguments.
Definition: Pronto.h:126
static void dump(Stream &stream, const IrSignal &irSignal)
Function for printing data as Pronto Hex string on the stream given as argument.
Definition: Pronto.h:159
static char * toProntoHex(const microseconds_t *introData, size_t introLength, frequency_t frequency=IrSignal::defaultFrequency)
Function for generating a Pronto Hex string from the arguments.
Definition: Pronto.h:138
static constexpr unsigned int digitsInProntoNumber
Definition: Pronto.h:22
static IrSignal * parse_PF(const uint_farptr_t str)
Function for parsing its input data into an IrSignal.
Definition: Pronto.cpp:55