This repository has been archived by the owner on Nov 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDualFunctions.ino
73 lines (68 loc) · 1.76 KB
/
DualFunctions.ino
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
void switch_relay(byte DIRECTION) {
DEBUG("Schalte Relais Num " + String(DIRECTION));
relay_switched_millis = millis();
DRIVING_DIRECTION = DIRECTION;
if (DRIVING_DIRECTION > DIRECTION_NONE) shutter_start_value_percent = ShutterConfig.CurrentValue;
switch (GlobalConfig.Model) {
case Model_Dual:
switch_dual_relay(DIRECTION);
break;
case Model_HVIO:
switch_hvio_dualr2_relay(DIRECTION);
break;
case Model_DualR2:
switch_hvio_dualr2_relay(DIRECTION);
break;
}
}
void switch_hvio_dualr2_relay(byte DIRECTION) {
switch (DIRECTION) {
case DIRECTION_NONE:
digitalWrite(Relay1, LOW);
digitalWrite(Relay2, LOW);
break;
case DIRECTION_UP:
digitalWrite(Relay2, LOW);
digitalWrite(Relay1, HIGH);
break;
case DIRECTION_DOWN:
digitalWrite(Relay1, LOW);
digitalWrite(Relay2, HIGH);
break;
}
}
void switch_dual_relay(byte DIRECTION) {
Serial.write(0xA0);
Serial.write(0x04);
Serial.write(DIRECTION & 0xFF);
Serial.write(0xA1);
Serial.write('\n');
Serial.flush();
}
byte serial_in_byte; // Received byte
byte dual_hex_code = 0; // Sonoff dual input flag
uint16_t dual_button_code = 0;
bool ButtonPressed() {
while (Serial.available()) {
yield();
serial_in_byte = Serial.read();
if (dual_hex_code) {
dual_hex_code--;
if (dual_hex_code) {
dual_button_code = (dual_button_code << 8) | serial_in_byte;
serial_in_byte = 0;
} else {
if (serial_in_byte != 0xA1) {
dual_button_code = 0;
}
}
}
if (0xA0 == serial_in_byte) {
serial_in_byte = 0;
dual_button_code = 0;
dual_hex_code = 3;
return true;
}
}
return false;
}