This repository has been archived by the owner on Feb 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
intertechno.cpp
110 lines (92 loc) · 2.89 KB
/
intertechno.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
Intertechno library for the Arduino.
This library implements the following features:
- generate command sequences that once sent to an OOK rf stage are able
to control intertechno radio switches.
- ability to use an RFM22 transceiver (not implemented yet)
Author: Petre Rodan <2b4eda@subdimension.ro>
Available from: https://github.com/rodan/intertechno
GNU GPLv3 license:
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 "intertechno.h"
// a HI LO sequence
void rf_ook_pulse(struct it its, uint16_t on, uint16_t off)
{
digitalWrite(its.pin, HIGH);
delayMicroseconds(on);
digitalWrite(its.pin, LOW);
delayMicroseconds(off);
}
// 0 is 10001000
void rf_tx_0(struct it its)
{
// each ook_pulse sends 4 bits
rf_ook_pulse(its, BITD + its.rf_cal_on, 3 * (BITD + its.rf_cal_off));
rf_ook_pulse(its, BITD + its.rf_cal_on, 3 * (BITD + its.rf_cal_off));
}
// 1 is 10001110
void rf_tx_1(struct it its)
{
// each ook_pulse sends 4 bits
rf_ook_pulse(its, BITD + its.rf_cal_on, 3 * (BITD + its.rf_cal_off));
rf_ook_pulse(its, 3 * (BITD + its.rf_cal_on), BITD + its.rf_cal_off);
}
// sync sequence is 1000000000000000000000000000000
void rf_tx_sync(struct it its)
{
rf_ook_pulse(its, BITD + its.rf_cal_on, 31 * (BITD + its.rf_cal_off));
}
uint8_t rf_tx_cmd(struct it its, uint8_t prefix, uint8_t cmd)
{
int8_t i, j;
uint8_t rprefix;
rprefix = rotate_byte(prefix);
// any message has to be sent 4 times
for (j = 0; j < 4; j++) {
for (i = 7; i >= 0; i--) {
switch (rprefix & (1 << i)) {
case 0:
rf_tx_0(its);
break;
default:
rf_tx_1(its);
break;
}
}
for (i = 3; i >= 0; i--) {
switch (cmd & (1 << i)) {
case 0:
rf_tx_0(its);
break;
default:
rf_tx_1(its);
break;
}
}
rf_tx_sync(its);
}
return 0;
}
uint8_t rotate_byte(uint8_t in)
{
uint8_t rv = 0;
rv += (in & 0x10) << 3;
rv += (in & 0x20) << 1;
rv += (in & 0x40) >> 1;
rv += (in & 0x80) >> 3;
rv += (in & 0x1) << 3;
rv += (in & 0x2) << 1;
rv += (in & 0x4) >> 1;
rv += (in & 0x8) >> 3;
return rv;
}