-
Notifications
You must be signed in to change notification settings - Fork 0
/
IRsend.cpp
72 lines (59 loc) · 1.64 KB
/
IRsend.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
Copyright (C) 2017 Bengt Martensson.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see http://www.gnu.org/licenses/.
*/
#include "IRremote.h"
#include <iostream>
static const int DUMMYENDING = 50000;
static unsigned int pending;
static bool pendingIsMark;
unsigned long frequency;
IRsend irsend;
void delay(unsigned int ms) {
irsend.space(1000*ms);
}
static void flush() {
if (pending > 0)
std::cout << (pendingIsMark ? "+" : "-") << pending << " ";
pending = 0;
}
void finalize() {
if (!pendingIsMark)
pending = DUMMYENDING;
flush();
std::cout << std::endl << std::endl;
}
void IRsend::enableIROut(int khz) {
std::cout << std::dec;
pending = 0;
pendingIsMark = false;
frequency = 1000 * khz;
}
void IRsend::mark(unsigned time) {
if (pendingIsMark)
pending += time;
else {
flush();
pending = time;
pendingIsMark = true;
}
}
void IRsend::space(unsigned time) {
unsigned t = time > 0 ? time : DUMMYENDING;
if (!pendingIsMark)
pending += t;
else {
flush();
pending = t;
pendingIsMark = false;
}
}