-
Notifications
You must be signed in to change notification settings - Fork 0
/
Radio.ino
113 lines (95 loc) · 2.53 KB
/
Radio.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
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
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
//#include "printf.h"
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
RF24 radio(9, 10);
// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
void setup_radio() {
// printf_begin();
// Setup and configure rf radio
radio.begin();
// optionally, increase the delay between retries & # of retries
radio.setRetries(15, 15);
// optionally, reduce the payload size. seems to improve reliability
radio.setPayloadSize(8);
radio_open();
// Start listening
// radio.startListening();
// Dump the configuration of the rf unit for debugging
// radio.printDetails();
}
void radio_close() {
radio.powerDown();
}
void radio_open() {
// Open pipes to other nodes for communication
radio.openWritingPipe(pipes[0]);
// radio.openReadingPipe(1, pipes[1]);
}
void radio_wakeup() {
radio.startListening();
}
//void loop_radio() {
// // First, stop listening so we can talk.
// radio.stopListening();
//
// // Take the time, and send it. This will block until complete
// unsigned long time = millis();
// bool ok = radio.write(&time, sizeof(unsigned long));
//
//// printf(ok? "ok...": "failed.\n\r");
//
// // Now, continue listening
// radio.startListening();
//
// // Wait here until we get a response, or timeout (250ms)
// unsigned long started_waiting_at = millis();
// bool timeout = false;
// while (!radio.available() && !timeout)
// if (millis() - started_waiting_at > 200)
// timeout = true;
//
// // Describe the results
// if (timeout)
// {
//// printf("Timed out.\n\r");
// }
// else
// {
// // Grab the response, compare, and send to debugging spew
// unsigned long got_time;
// radio.read(&got_time, sizeof(unsigned long));
//
// // Spew it
//// printf("Got response %lu, round-trip delay: %lu\n\r", got_time, millis() - got_time);
// }
//
// // Try again 1s later
// delay(1000);
//}
bool radio_write(byte* bytes, byte length) {
// radio.stopListening();
bool ret = radio.write(bytes, length);
// if (!ret) {
// bool tx_ok = true;
// bool tx_fail = true;
// bool rx_ready = true;
// radio.whatHappened(tx_ok, tx_fail, rx_ready);
// if (tx_ok)
// Serial.println("TX ok");
// if (tx_fail)
// Serial.println("TX fail");
// if (rx_ready)
// Serial.println("RX ready");
//
//// radio_close();
//// delay(1000);
//// radio_open();
// }
// radio.startListening();
// delay(10);
// radio.stopListening();
return ret;
}