-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomeControl.h
executable file
·151 lines (119 loc) · 4.96 KB
/
HomeControl.h
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
Author of HomeControl is Tommy Ziegler - http://tommyziegler.com
This file is a for of the RCSwitch class from https://github.com/denschu/rcswitch-pi
------------------------------------------------------------------------------------
Original license text:
RCSwitch - Arduino libary for remote control outlet switches
Copyright (c) 2011 Suat …zgŸr. All right reserved.
Contributors:
- Andre Koehler / info(at)tomate-online(dot)de
- Gordeev Andrey Vladimirovich / gordeev(at)openpyro(dot)com
- Skineffect / http://forum.ardumote.com/viewtopic.php?f=2&t=48
Project home: http://code.google.com/p/rc-switch/
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
------------------------------------------------------------------------------------
When there are questions, please contact me under: me@tommyziegler.com
*/
#ifndef _HomeControl_h
#define _HomeControl_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include <wiringPi.h>
#include <stdint.h>
#define NULL 0
#define CHANGE 1
#ifdef __cplusplus
extern "C"{
#endif
typedef uint8_t boolean;
typedef uint8_t byte;
#if !defined(NULL)
#endif
#ifdef __cplusplus
}
#endif
#endif
// Number of maximum High/Low changes per packet.
// We can handle up to (unsigned long) => 32 bit * 2 H/L changes per bit + 2 for sync
#define HOMECTRLSWITCH_MAX_CHANGES 67
#define PROTOCOL3_SYNC_FACTOR 71
#define PROTOCOL3_0_HIGH_CYCLES 4
#define PROTOCOL3_0_LOW_CYCLES 11
#define PROTOCOL3_1_HIGH_CYCLES 9
#define PROTOCOL3_1_LOW_CYCLES 6
class HomeControl {
public:
HomeControl();
void switchOn(char* sGroup, int nSwitchNumber);
void switchOff(char* sGroup, int nSwitchNumber);
void switchOnA(char* sGroup, char* sDevice);
void switchOffA(char* sGroup, char* sDevice);
void switchOnB(int nGroupNumber, int nSwitchNumber);
void switchOffB(int nGroupNumber, int nSwitchNumber);
void switchOnC(char sFamily, int nGroup, int nDevice);
void switchOffC(char sFamily, int nGroup, int nDevice);
void switchOnD(char sGroup, int nDevice);
void switchOffD(char sGroup, int nDevice);
void sendTriState(char* Code);
void send(unsigned long Code, unsigned int length);
void send(char* Code);
void enableReceive(int interrupt);
void enableReceive();
void disableReceive();
bool available();
void resetAvailable();
unsigned long getReceivedValue();
unsigned int getReceivedBitlength();
unsigned int getReceivedDelay();
unsigned int getReceivedProtocol();
unsigned int* getReceivedRawdata();
void enableTransmit(int nTransmitterPin);
void disableTransmit();
void setPulseLength(int nPulseLength);
void setRepeatTransmit(int nRepeatTransmit);
void setReceiveTolerance(int nPercent);
void setProtocol(int nProtocol);
void setProtocol(int nProtocol, int nPulseLength);
private:
char* getCodeWordB(int nGroupNumber, int nSwitchNumber, boolean bStatus);
char* getCodeWordA(char* sGroup, int nSwitchNumber, boolean bStatus);
char* getCodeWordA(char* sGroup, char* sDevice, boolean bStatus);
char* getCodeWordC(char sFamily, int nGroup, int nDevice, boolean bStatus);
char* getCodeWordD(char group, int nDevice, boolean bStatus);
void sendT0();
void sendT1();
void sendTF();
void send0();
void send1();
void sendSync();
void transmit(int nHighPulses, int nLowPulses);
static char* dec2binWzerofill(unsigned long dec, unsigned int length);
static char* dec2binWcharfill(unsigned long dec, unsigned int length, char fill);
static void handleInterrupt();
static bool receiveProtocol1(unsigned int changeCount);
static bool receiveProtocol2(unsigned int changeCount);
static bool receiveProtocol3(unsigned int changeCount);
int nReceiverInterrupt;
int nTransmitterPin;
int nPulseLength;
int nRepeatTransmit;
char nProtocol;
static int nReceiveTolerance;
static unsigned long nReceivedValue;
static unsigned int nReceivedBitlength;
static unsigned int nReceivedDelay;
static unsigned int nReceivedProtocol;
static unsigned int timings[HOMECTRLSWITCH_MAX_CHANGES];
};
#endif