Infrared4Arduino
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 
9 const microseconds_t Nec1Renderer::repeatData[repeatLength] = { 9024, 2256, 564, MIN(96156, MICROSECONDS_T_MAX) };
10 const IrSequence Nec1Renderer::repeat(repeatData, repeatLength, false);
12 
13 const IrSignal *Nec1Renderer::newIrSignal(unsigned int D, unsigned int S, unsigned int F) {
14  microseconds_t *introData = new microseconds_t[introLength];
15  unsigned int i = 0U;
16  uint32_t sum = 9024U + 4512U + 564U;
17  introData[i] = 9024U; i++;
18  introData[i] = 4512U; i++;
19  lsbByte(introData, i, sum, D);
20  lsbByte(introData, i, sum, S);
21  lsbByte(introData, i, sum, F);
22  lsbByte(introData, i, sum, 255U-F);
23  introData[i] = 564U; i++;
24  introData[i] = (microseconds_t) (108000U - sum); i++;
25  IrSequence *introPtr = new IrSequence(introData, introLength, true);
26  return new IrSignal(*introPtr, repeat, emptyIrSequence, frequency);
27 }
28 
29 void 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 
36 void 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 const IrSequence emptyIrSequence
uint16_t microseconds_t
Type for durations in micro seconds.
Definition: InfraredTypes.h:15
#define MICROSECONDS_T_MAX
Largest microseconds_t number possible.
Definition: InfraredTypes.h:18
This class models an IR signal with intro-, repeat-, and ending sequences.
Definition: IrSignal.h:10
#define MIN(a, b)
Definition: Nec1Renderer.cpp:7
This class consists of a vector of durations.
Definition: IrSequence.h:11
static const IrSignal * newIrSignal(unsigned int D, unsigned int S, unsigned int F)
Generates am IrSignal from the NEC1 parameters.