Infrared4Arduino 1.2.3
Loading...
Searching...
No Matches
Nec1Renderer.cpp
Go to the documentation of this file.
1#include "Nec1Renderer.h"
2
3// NOTE: writing intro[i++] = ... produces wrong result, compiler bug?
4// (Adding a print statement immediately after, and it works :-~)
5// So let's write intro[i] = ...; i++ at least for now.
6
7#define MIN(a, b) ((a) < (b) ? (a) : (b))
8
9const IrSignal *Nec1Renderer::newIrSignal(unsigned int D, unsigned int S, unsigned int F) {
10 microseconds_t *introData = new microseconds_t[introLength];
11 unsigned int i = 0U;
12 uint32_t sum = 9024U + 4512U + 564U;
13 introData[i] = 9024U; i++;
14 introData[i] = 4512U; i++;
15 lsbByte(introData, i, sum, D);
16 lsbByte(introData, i, sum, S);
17 lsbByte(introData, i, sum, F);
18 lsbByte(introData, i, sum, 255U-F);
19 introData[i] = 564U; i++;
20 introData[i] = static_cast<microseconds_t>(108000UL - sum); i++;
21 microseconds_t *repeatData = new microseconds_t[repeatLength];
22 repeatData[0] = 9024U;
23 repeatData[1] = 2256U;
24 repeatData[2] = 564U;
25 repeatData[3] = MIN(96156U, MICROSECONDS_T_MAX);
26 return new IrSignal(introData, introLength, repeatData, repeatLength, frequency, dutyCycle);
27}
28
29void Nec1Renderer::lsbByte(microseconds_t *intro, unsigned int& i, uint32_t& sum, unsigned int X) {
30 for (unsigned int index = 0; index < 8U; index++) {
31 transmitBit(intro, i, sum, X & 1U);
32 X >>= 1U;
33 }
34}
35
36void inline Nec1Renderer::transmitBit(microseconds_t *intro, unsigned int& i, uint32_t& sum, unsigned int data) {
37 intro[i++] = 564U;
38 intro[i++] = data ? 1692U : 564U;
39 sum += data ? 564U+1692U : 564U+564U;
40}
static constexpr microseconds_t MICROSECONDS_T_MAX
Largest microseconds_t number possible.
Definition: InfraredTypes.h:18
uint16_t microseconds_t
Type for durations in micro seconds.
Definition: InfraredTypes.h:15
#define MIN(a, b)
Definition: Nec1Renderer.cpp:7
This class models an IR signal with intro-, repeat-, and ending sequences.
Definition: IrSignal.h:11
static const IrSignal * newIrSignal(unsigned int D, unsigned int S, unsigned int F)
Generates am IrSignal from the NEC1 parameters.
Definition: Nec1Renderer.cpp:9