Krolyxon
Commit bc1a8ec

Branches

Tags

Refs →

orion-rffirmwarenrf24.cpp

169 lines · 3.7 KB · C++

1#include <Arduino.h>
2#include <RF24.h>
3#include "buttons.h"
4#include "nrf24.h"
5#include "display.h"
6#define JAM_DURATION 500
7
8extern SPIClass *RADIO_SPI;
9extern RF24 radio1;
10extern RF24 radio2;
11
12const byte bleChannels[] = {2, 26, 80};
13
14const byte bluetoothChannels[] = {
15 32, 34, 46, 48, 50, 52,
16 0, 1, 2, 4, 6, 8,
17 22, 24, 26, 28, 30,
18 74, 76, 78, 80
19};
20
21void initNRF(RF24 &radio)
22{
23 if (!radio.begin(RADIO_SPI)) {
24 Serial.println("NRF not found");
25 return;
26 }
27
28 radio.setAutoAck(false);
29 radio.stopListening();
30 radio.setRetries(0, 0);
31 radio.setPALevel(RF24_PA_MAX);
32 radio.setDataRate(RF24_2MBPS);
33 radio.openWritingPipe(0xE7E7E7E7E7LL);
34 Serial.println("NRF Initialized");
35
36}
37
38
39
40//void startBleJammer() {
41// initNRF(radio1);
42// initNRF(radio2);
43//
44// Serial.println("NRF JAMMER STARTED");
45//
46// const char payload[] = "xxxxxxxxxxxxxxxx";
47//
48// u8g2.clearBuffer();
49// u8g2.drawStr(0, 10, "Jamming:");
50// u8g2.setCursor(60, 10);
51// u8g2.print("Bluetooth");
52// u8g2.sendBuffer();
53//
54// while(true) {
55//
56// // Channels (you can change this set)
57// const byte channels[] = {2, 26, 80};
58//
59//
60// for (int i = 0; i < sizeof(channels); i++) {
61// radio1.setChannel(channels[i]);
62// radio1.write(&payload, sizeof(payload));
63// //radio2.setChannel(channels[i]);
64// //radio2.write(&payload, sizeof(payload));
65// }
66//
67// if (btnBack())
68// {
69// Serial.println("Jammer stopped");
70// return;
71// }
72// }
73//
74//}
75//
76//void startBluetoothJammer()
77//{
78// initNRF(radio1);
79// initNRF(radio2);
80//
81// Serial.println("NRF JAMMER STARTED");
82//
83// const char payload[] = "xxxxxxxxxxxxxxxx";
84//
85// u8g2.clearBuffer();
86// u8g2.drawStr(0, 10, "Jamming:");
87// u8g2.setCursor(60, 10);
88// u8g2.print("Bluetooth");
89// u8g2.sendBuffer();
90//
91// while(true) {
92//
93// // Channels (you can change this set)
94// const byte channels[] = {32, 34, 46, 48, 50, 52, 0, 1, 2, 4, 6, 8, 22, 24, 26, 28, 30, 74, 76, 78, 80};
95//
96//
97// for (int i = 0; i < sizeof(channels); i++) {
98// radio1.setChannel(channels[i]);
99// radio1.write(&payload, sizeof(payload));
100// //radio2.setChannel(channels[i]);
101// //radio2.write(&payload, sizeof(payload));
102// }
103//
104// if (btnBack())
105// {
106// Serial.println("Jammer stopped");
107// return;
108// }
109// }
110//}
111
112void startJammer(const char* name, const byte* channels, size_t channelCount)
113{
114 initNRF(radio1);
115 initNRF(radio2);
116
117 Serial.println("NRF JAMMER STARTED");
118
119 const char payload[] = "xxxxxxxxxxxxxxxx";
120
121 u8g2.clearBuffer();
122 u8g2.drawStr(0, 10, "Jamming:");
123 u8g2.setCursor(60, 10);
124 u8g2.print(name);
125 u8g2.sendBuffer();
126
127 while (true)
128 {
129 for (size_t i = 0; i < channelCount; i++)
130 {
131 radio1.setChannel(channels[i]);
132 radio1.write(&payload, sizeof(payload));
133
134 // Optional second NRF
135 // radio2.setChannel(channels[i]);
136 // radio2.write(&payload, sizeof(payload));
137 }
138
139 if (btnBack())
140 {
141 Serial.println("Jammer stopped");
142 return;
143 }
144 }
145}
146
147void NRFToolsMenu(int index) {
148 switch (index) {
149 case 0:
150 // startBleJammer();
151 // BLE
152 startJammer(
153 "BLE",
154 bleChannels,
155 sizeof(bleChannels)
156 );
157
158 break;
159 case 1:
160 // startBluetoothJammer();
161 // Bluetooth
162 startJammer(
163 "Bluetooth",
164 bluetoothChannels,
165 sizeof(bluetoothChannels)
166 );
167 break;
168 }
169}