/
LabDome.cpp
149 lines (123 loc) · 3.29 KB
/
LabDome.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
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
#include "LabDome.h"
///////////////////////////////////
// REMOVER -- APENAS PARA TESTES
//#include "LabBeep.h"
//#define BEEPER 10
//LabBeep beepx(BEEPER);
///////////////////////////////////
LabDome::LabDome() {
}
void LabDome::doEvent() {
bool tx, fail, rx;
_radioPtr->whatHappened(tx, fail, rx);
if (tx) {
printf("<tx> Data Sent OK: %s\n\r", command.getName());
}
if (fail) {
printf("<fail> Data Failed to Sent: %s\n\r", command.getName());
}
if (tx || fail) {
//_radioPtr->powerDown();
}
if (rx) {
printf("<rx> ...");
unsigned long started_waiting_at = millis();
bool timeout = false;
bool done = false;
while (!_radioPtr->isAckPayloadAvailable() && !timeout) {
if (millis() - started_waiting_at > 250) {
timeout = true;
}
}
if (!timeout) {
while(!done) {
done = _radioPtr->read( &command, sizeof(command) );
if (!done) {
printf("<rx> Ack: %s\n\r", command.getName());
}
}
printf("<rx> Last Ack: %s\n\r", command.getName());
}
}
}
void LabDome::setRadio(RF24 *radioPtr) {
if (radioPtr!=NULL) {
_radioPtr=radioPtr;
_radioPtr->begin();
_radioPtr->enableAckPayload();
_radioPtr->openWritingPipe(pipes[0]);
}
}
void LabDome::setIRReceiver(LabIRReceiver *irReceiverPtr) {
if (irReceiverPtr!=NULL) {
_irReceiverPtr=irReceiverPtr;
}
}
void LabDome::doTest() {
command.cmd=SHUTTER_EVENT_OPEN;
printf("\n\r> Call: %s\n\r", command.getName());
_radioPtr->startWrite(&command, sizeof(command));
//beepx.play();
delay_ms(4000);
command.cmd=SHUTTER_EVENT_STOP;
printf("\n\r> Call: %s\n\r", command.getName());
_radioPtr->startWrite(&command, sizeof(command));
//beepx.play();
delay_ms(4000);
command.cmd=SHUTTER_EVENT_CLOSE;
printf("\n\r> Call: %s\n\r", command.getName());
_radioPtr->startWrite(&command, sizeof(command));
//beepx.play();
delay_ms(4000);
command.cmd=SHUTTER_STATE;
printf("\n\r> Call: %s\n\r", command.getName());
_radioPtr->startWrite(&command, sizeof(command));
//beepx.play();
delay_ms(4000);
command.cmd=SHUTTER_EVENT_STOP;
printf("\n\r> Call: %s\n\r", command.getName());
_radioPtr->startWrite(&command, sizeof(command));
//beepx.play();
//beepx.play();
delay_ms(4000);
}
//------------------------
//void setupRadio() {
// radio.begin();
// radio.enableAckPayload();
// radio.openWritingPipe(pipes[0]);
//}
//void radioEvent() {
// bool tx, fail, rx;
// radio.whatHappened(tx, fail, rx);
// //if (tx) {
// // Serial.println("Sent OK");
// //}
// //if (fail) {
// // Serial.println("Sent fail");
// //}
// if (tx || fail) {
// radio.powerDown();
// }
// if (rx) {
// radio.read(&command, sizeof(command));
// //Serial.print("Ack:");
// //Serial.println(command.cmd);
// }
//}
// command.cmd=CMD_OPEN;
// //Serial.println("\nCMD_OPEN");
// radio.startWrite(&command, sizeof(command));
// delay(5000);
// command.cmd=CMD_STOP;
// //Serial.println("\nCMD_STOP");
// radio.startWrite(&command, sizeof(command));
// delay(5000);
// command.cmd=CMD_CLOSE;
// //Serial.println("\nCMD_CLOSE");
// radio.startWrite(&command, sizeof(command));
// delay(5000);
// command.cmd=CMD_STOP;
// Serial.println("CMD_STOP");
// radio.write(&command, sizeof(command));
// delay(1000);