7 return static_cast<uint16_t
>((
static_cast<uint32_t
>(duration) + timebase / 2) / timebase);
11 microseconds_t timebase = (microsecondsInSeconds * data[1] + referenceFrequency/2) / referenceFrequency;
15 frequency = toFrequency(data[1]);
17 case learnedNonModulatedToken:
23 size_t introPairs = data[2];
24 size_t repetitionPairs = data[3];
31 return new IrSignal(intro, 2*introPairs, repeat, 2*repetitionPairs, frequency);
36 uint16_t* data =
new uint16_t[len];
39 for (
unsigned int i = 0; i < len; i++) {
40 long x = strtol(p, endptr, 16);
54#if HAS_FLASH_READ || defined(DOXYGEN)
73 for (
unsigned int i = 0; i < 2*noPairs; i++) {
74 uint32_t duration =
static_cast<uint32_t
>(data[i]) * timebase;
81 return referenceFrequency / code;
84uint16_t Pronto::toFrequencyCode(
frequency_t frequency) {
85 return referenceFrequency / effectiveFrequency(frequency);
89 return frequency > 0 ? frequency : fallbackFrequency;
93 return microsecondsInSeconds / effectiveFrequency(frequency);
96size_t Pronto::lengthHexString(
size_t introLength,
size_t repeatLength) {
100char Pronto::hexDigit(
unsigned int x) {
101 return x <= 9 ? (
'0' + x) : (
'A' + (x - 10));
104void Pronto::appendChar(
char *result,
unsigned int& index,
char ch) {
109void Pronto::appendDigit(
char *result,
unsigned int& index,
unsigned int number) {
110 appendChar(result, index, hexDigit(number));
113void Pronto::appendNumber(
char *result,
unsigned int& index, uint16_t number) {
116 appendDigit(result, index, (number >> shifts) & hexMask);
118 appendChar(result, index,
' ');
122 appendNumber(result, index,
divRound(duration, timebase));
126 for (
unsigned int i = 0; i < length; i++)
127 appendDuration(result, index, data[i], timebase);
130void Pronto::appendSequence(
char *result,
unsigned int& index,
const IrSequence& irSequence,
microseconds_t timebase) {
134char* Pronto::prelude(
frequency_t frequency,
size_t introLength,
size_t repeatLength) {
135 char *result =
new char[lengthHexString(introLength, repeatLength)];
136 unsigned int index = 0;
137 appendNumber(result, index, frequency > 0 ? learnedToken : learnedNonModulatedToken);
138 appendNumber(result, index, toFrequencyCode(frequency));
139 appendNumber(result, index, introLength / 2);
140 appendNumber(result, index, repeatLength / 2);
145 char *result = prelude(frequency, introLength, repeatLength);
148 appendSequence(result, index, introData, introLength, timebase);
149 appendSequence(result, index, repeatData, repeatLength, timebase);
150 result[index - 1] =
'\0';
155 dumpNumber(stream, frequency > 0 ? learnedToken : learnedNonModulatedToken);
157 dumpNumber(stream, toFrequencyCode(frequency));
159 dumpNumber(stream, introLength / 2);
161 dumpNumber(stream, repeatLength / 2);
164 dumpSequence(stream, introData, introLength, timebase);
166 dumpSequence(stream, repeatData, repeatLength, timebase);
170 for (
unsigned int i = 0; i < length; i++) {
171 dumpDuration(stream, data[i], timebase);
178 dumpNumber(stream,
divRound(duration, timebase));
181void Pronto::dumpNumber(Stream& stream, uint16_t number) {
184 dumpDigit(stream, (number >> shifts) & hexMask);
188void Pronto::dumpDigit(Stream& stream,
unsigned int number) {
189 stream.print(hexDigit(number));
#define STRCPY_PF_CAST(x)
static constexpr microseconds_t MICROSECONDS_T_MAX
Largest microseconds_t number possible.
uint16_t microseconds_t
Type for durations in micro seconds.
uint32_t frequency_t
Type for modulation frequency in Hz.
uint16_t divRound(microseconds_t duration, microseconds_t timebase)
This class consists of a vector of durations.
const microseconds_t * getDurations() const
size_t getLength() const
Returns the number of durations.
This class models an IR signal with intro-, repeat-, and ending sequences.
static constexpr unsigned int numbersInPreamble
static char * toProntoHex(const IrSignal &irSignal)
Function for generating a Pronto Hex string from the argument.
static IrSignal * parse(const uint16_t *data, size_t size)
Function for parsing its input data into an IrSignal.
static void dump(Stream &stream, const IrSignal &irSignal)
Function for printing data as Pronto Hex string on the stream given as argument.
static constexpr unsigned int digitsInProntoNumber
static IrSignal * parse_PF(const uint_farptr_t str)
Function for parsing its input data into an IrSignal.