Krolyxon
Commit 0a40daf

Branches

Tags

Refs →

orion-rffirmwaremenu.cpp

278 lines · 5.6 KB · C++

1#include <Arduino.h>
2#include "menu.h"
3#include "display.h"
4#include "buttons.h"
5#include "badusb.h"
6#include "nrf24.h"
7#include "cc1101.h"
8#include "blescanner.h"
9#include "wifi_scan.h"
10#include "wifi_analyzer.h"
11#include "device_check.h"
12
13// ================= FEATURE HANDLERS =================
14void runSystemInfoFeature();
15void runRFCaptureFeature();
16void runBLEScanFeature();
17
18
19
20// ================= MENU DATA =================
21
22// Root menu
23const char *mainMenuItems[] = {
24 "BadUSB",
25 "RF Capture",
26 "NRF Jammer",
27 "BLE Scan",
28 "Wifi Scan",
29 "Wifi Analyzer",
30 "System Info",
31 "Device Check",
32 "Restart"
33};
34
35Menu mainMenu = {mainMenuItems, sizeof(mainMenuItems) / sizeof(mainMenuItems[0])};
36
37// BadUSB submenu
38const char *badusbItems[] = {
39 "Demo",
40 "Open CMD",
41 "Rickroll"};
42
43Menu badusbMenu = {badusbItems, 3};
44
45// ================= MENU STATE =================
46
47Menu *currentMenu = &mainMenu;
48
49int menuIndex = 0;
50int menuOffset = 0;
51
52#define MENU_VISIBLE_ROWS 4
53
54bool insideFeature = false;
55
56// ================= DRAW =================
57
58void drawMenu()
59{
60 u8g2.clearBuffer();
61
62 // scroll handling
63 if (menuIndex < menuOffset)
64 menuOffset = menuIndex;
65
66 if (menuIndex >= menuOffset + MENU_VISIBLE_ROWS)
67 menuOffset = menuIndex - MENU_VISIBLE_ROWS + 1;
68
69 for (int i = 0; i < MENU_VISIBLE_ROWS; i++)
70 {
71 int item = menuOffset + i;
72
73 if (item >= currentMenu->size)
74 break;
75
76 if (item == menuIndex)
77 u8g2.drawStr(0, 14 + i * 14, ">");
78
79 u8g2.drawStr(10, 14 + i * 14, currentMenu->items[item]);
80 }
81
82 // scroll indicators
83 if (menuOffset > 0)
84 u8g2.drawStr(118, 10, "^");
85
86 if (menuOffset + MENU_VISIBLE_ROWS < currentMenu->size)
87 u8g2.drawStr(118, 62, "v");
88
89 u8g2.sendBuffer();
90}
91
92// ================= FEATURE EXECUTION =================
93
94void launchFeature()
95{
96 insideFeature = true;
97
98 if (currentMenu == &mainMenu)
99 {
100 switch (menuIndex)
101 {
102 case 0: // BadUSB → enter submenu
103 currentMenu = &badusbMenu;
104 menuIndex = 0;
105 menuOffset = 0;
106 break;
107
108 case 1:
109 if (!isCC1101Ready()) {
110 if (!initCC1101()) {
111 Serial.println("CC1101 failed");
112 return;
113 }
114 }
115
116 Serial.println("Ready to capture...");
117
118 startCapture();
119 delay(5000);
120 stopCapture();
121 printCapture();
122 break;
123 case 2:
124 startNRFJammer();
125 break;
126
127 case 3:
128 ble_scan();
129 ble_drawMenu();
130 while (1) {
131 ble_loop();
132 if (btnBack())
133 break;
134 }
135 break;
136
137 case 4:
138 {
139 // Start scan once
140 wifi_scan_start();
141 wifi_scan_draw();
142
143 while (1) {
144 wifi_scan_loop();
145 // EXIT condition handled ONLY here
146 if (btnBack()) {
147 delay(150); // debounce
148 break;
149 }
150 }
151 break;
152 }
153 case 5:
154 {
155
156 wifi_analyzer_start();
157
158 bool prevBack = false;
159 while (1)
160 {
161 wifi_analyzer_loop();
162 bool nowBack = btnBack();
163 if (nowBack && !prevBack)
164 {
165 delay(150);
166 break;
167 }
168 prevBack = nowBack;
169 }
170 break;
171 }
172
173 case 6:
174 runSystemInfoFeature();
175 break;
176 case 7:
177 device_check_run();
178 break;
179 case 8:
180 u8g2.clearBuffer();
181 u8g2.setFont(u8g2_font_6x13_tr);
182 u8g2.drawStr(30, 30, "Restarting...");
183 u8g2.sendBuffer();
184 delay(1000);
185 ESP.restart();
186 break;
187 }
188 }
189 else if (currentMenu == &badusbMenu)
190 {
191 switch (menuIndex)
192 {
193 case 0:
194 runBadUSBDemo();
195 break;
196
197 case 1:
198 Serial.println("Open CMD payload");
199 runBadUSBOpenCMD();
200 break;
201
202 case 2:
203 Serial.println("Rickroll payload");
204 runBadUSBRickroll();
205 break;
206 }
207 }
208
209 insideFeature = false;
210
211 drawMenu();
212}
213
214// ================= INIT =================
215
216void menuInit()
217{
218 currentMenu = &mainMenu;
219 menuIndex = 0;
220 menuOffset = 0;
221
222 drawMenu();
223}
224
225// ================= LOOP =================
226
227void menuLoop()
228{
229 static uint32_t lastPress = 0;
230
231 if (insideFeature)
232 return;
233
234 if (millis() - lastPress < 150)
235 return;
236
237 if (btnUp())
238 {
239 menuIndex--;
240
241 if (menuIndex < 0)
242 menuIndex = currentMenu->size - 1;
243
244 drawMenu();
245 lastPress = millis();
246 }
247
248 else if (btnDown())
249 {
250 menuIndex++;
251
252 if (menuIndex >= currentMenu->size)
253 menuIndex = 0;
254
255 drawMenu();
256 lastPress = millis();
257 }
258
259 else if (btnSelect())
260 {
261 launchFeature();
262 lastPress = millis();
263 }
264
265 else if (btnBack())
266 {
267 if (currentMenu != &mainMenu)
268 {
269 currentMenu = &mainMenu;
270 menuIndex = 0;
271 menuOffset = 0;
272
273 drawMenu();
274 }
275
276 lastPress = millis();
277 }
278}