-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnRFMgt.cpp
124 lines (101 loc) · 2.77 KB
/
nRFMgt.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
/*
TODO: Define controls
controllable values:
1-4 -speed up/down/absolute/read (uint8_t r = value)
5-8 -mode up/down/absolute/read (uint8_t r = value)
9-12 -brightness up/down/absolute/read (uint8_t r = value)
15-16 -color up/down
21-26 -set/get fade colors (rgb) (21=set1,22=get1, 23=set2,24=get2, 25=set3,26=get3
50 -get speed,mode,brightness (r=speed,g=mode,b=brightness)
to get all variables:
4 (get speed)
8 (get mode)
12 (get brightness)
22 (get color 1)
24 (get color 2)
26 (get color 3)
30 save current values to eeprom
50 get speed, mode, brightness
*/
#include "zGlobals.h"
#include "nRFMgt.h"
#include <gmaRGBLight.h>
#include <RF24.h>
RF24 radio(9,10);
void RF_Init() {
radio.begin();
radio.setDataRate(RF24_1MBPS); // RF24_250KBPS
radio.setChannel(50); // 2.450 GHz
radio.setPayloadSize(sizeof(rf_hat_payload_t));
radio.setAutoAck(false); // fixed payload size + autoAck(false) = ShockBurst transmission (quicker)
//radio.setRetries(15,10);
radio.setCRCLength(RF24_CRC_8);
radio.openWritingPipe(RF_SOUND_FOR_EVERYONE_PIPE);
radio.openReadingPipe(1,RF_CONTROL_THE_HAT_PIPE);
radio.startListening();
}
void RF_SoundForEveryone(Config_t *_cnf) {
rf_hat_payload_t payload;
payload.command = 1;
payload.mode = 0;
for(uint8_t i=0; i<7; i++) {
payload.vol[i] = _cnf->eq7Band[i];
}
//do not need --radio.stopListening();
radio.write( &payload, sizeof(payload));
radio.startListening();
}
void RF_Read() {
if(radio.available()) {
rf_hat_payload_t payload;
radio.read( &payload, sizeof(payload));
if(payload.command > 1) {
RF_RgbLightCommand(&payload);
}
}
}
void RF_RgbLightCommand(rf_hat_payload_t *_command) {
switch(_command->command) {
// commands that make sense (imho):
// brightness up/down/abs
// mode up/down/abs
// enable/disable automodechange
// enable music broadcast? always enabled?
case 2:
break;
/*
case 2: // speed down
ChangeDelay(0);
_command->value = s.currDelay;
break;
case 3: // speed absolute
SetDelay(_command->r);
_command->value = s.currDelay;
break;
case 5: // mode up
ChangeMode(1);
_command->value = s.currMode;
break;
case 6: // mode down
ChangeMode(0);
_command->value = s.currMode;
break;
case 7: // mode absolute
SetMode(_command->value);
_command->value = s.currMode;
break;
case 9: // brightness up
ChangeBrightness(1);
_command->value = s.currBrightness;
break;
case 10: // brightness down
ChangeBrightness(0);
_command->value = s.currBrightness;
break;
case 11: // brightness absolute
SetBrightness(_command->value);
_command->value = s.currBrightness;
break;
*/
}
}