Infrared4Arduino 1.2.3
Loading...
Searching...
No Matches
Rc5Renderer.cpp
Go to the documentation of this file.
1#include "Rc5Renderer.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
9uint8_t Rc5Renderer::T = 1U;
10
11const IrSignal *Rc5Renderer::newIrSignal(unsigned int D, unsigned int F) {
12 T = ! T;
13 return newIrSignal(D, F, T);
14}
15
17
18const IrSignal *Rc5Renderer::newIrSignal(unsigned int D, unsigned int F, unsigned int T) {
19 unsigned int index = 0U;
20 int pending = 0;
21 microseconds_t *repeat = new microseconds_t[28];
22 emit(1U, index, pending, repeat);
23 emit(((~F) & 0x40U) >> 6U, index, pending, repeat);
24 emit(T & 1U, index, pending, repeat);
25 emitMsb(D, 5U, index, pending, repeat);
26 emitMsb(F, 6U, index, pending, repeat);
27 emitEnd(index, pending, repeat);
28 return new IrSignal(nullptr, 0, repeat, index, frequency);
29}
30
31void Rc5Renderer::emitMsb(unsigned int x, unsigned int length,
32 unsigned int& index, int& pending, microseconds_t *repeat) {
33 unsigned int mask = 1U << (length - 1U);
34 while (mask != 0U) {
35 emit((x & mask) != 0, index, pending, repeat);
36 mask >>= 1U;
37 }
38}
39
40void Rc5Renderer::emit(unsigned int x, unsigned int& index, int& pending,
41 microseconds_t *repeat) {
42 if (pending == 0) {
43 // First, do nothing, just stuff in pending.
44 } else if ((pending > 0) == ((x & 1U) != 0U)) {
45 repeat[index] = timebase;
46 index++;
47 repeat[index] = timebase;
48 index++;
49 } else {
50 repeat[index] = 2U * timebase;
51 index++;
52 }
53 pending = (x & 1U) ? 1 : -1;
54}
55
56void Rc5Renderer::emitEnd(unsigned int& index, int& pending, microseconds_t *repeat) {
57 if (pending > 0) {
58 repeat[index] = timebase; index++;
59 }
60 repeat[index] = MIN(90000U, MICROSECONDS_T_MAX); index++;
61}
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
static const IrSequence emptyIrSequence
Definition: Rc5Renderer.cpp:16
This class consists of a vector of durations.
Definition: IrSequence.h:11
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 F, unsigned int T)
Generates an RC5 signal from the RC5 parameters.
Definition: Rc5Renderer.cpp:18