Krolyxon
Commit 3672abc

Branches

Tags

Refs →

orion-rf3672abc

remove cc1101_2 from device check

Author
krolyxon
Date
2026-05-14 23:12 +0530
Parent
0b8b30d
Commit
3672abc8b44c50ab344aeaf3c720c8502ccc128d

+78 −134

1 file changed

  1. M src/utils/device_check.cpp +78 −134
M src/utils/device_check.cpp View
@@ -1,12 +1,12 @@
1+#include "../libs/ELECHOUSE_CC1101_SRC_DRV.h"
12 #include <Arduino.h>
3+#include <RF24.h>
24 #include <SPI.h>
35 #include <Wire.h>
4−#include <RF24.h>
5−#include "../libs/ELECHOUSE_CC1101_SRC_DRV.h"
66
7+#include "../config.h"
78 #include "../ui/display.h"
89 #include "buttons.h"
9−#include "../config.h"
1010
1111 // ===== EXTERNALS =====
1212 extern RF24 radio1;
@@ -16,16 +16,14 @@ extern U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2;
1616
1717 // ===== RESULTS =====
1818 struct DeviceStatus {
19− bool nrf1 = false;
20− bool nrf2 = false;
21− bool cc1101_1 = false;
22− bool cc1101_2 = false;
23− bool oled = true;
24− bool buttons = false;
19+ bool nrf1 = false;
20+ bool nrf2 = false;
21+ bool cc1101 = false;
22+ bool oled = true;
2523 };
2624
2725 // ===== NRF CHECK =====
28−//bool checkNRF(RF24 &radio)
26+// bool checkNRF(RF24 &radio)
2927 //{
3028 // // safer: only init if needed
3129 // if (!radio.isChipConnected()) {
@@ -36,172 +34,118 @@ struct DeviceStatus {
3634 // return radio.isChipConnected();
3735 //}
3836
39−bool checkNRF(RF24 &radio)
40−{
41− radio.powerDown();
42− delay(5);
37+bool checkNRF(RF24 &radio) {
38+ radio.powerDown();
39+ delay(5);
4340
44− if (!radio.begin(RADIO_SPI))
45− return false;
41+ if (!radio.begin(RADIO_SPI))
42+ return false;
4643
47− delay(5);
44+ delay(5);
4845
49− return radio.isChipConnected();
46+ return radio.isChipConnected();
5047 }
5148
5249 // ===== CC1101 CHECK =====
53−bool checkCC1101(uint8_t csPin)
54−{
55− ELECHOUSE_cc1101.setSpiPin(
56− cc1101_SCK,
57− cc1101_MISO,
58− cc1101_MOSI,
59− csPin
60− );
61−
62− delay(5);
63−
64− return ELECHOUSE_cc1101.getCC1101();
65−}
50+bool checkCC1101(uint8_t csPin) {
51+ ELECHOUSE_cc1101.setSpiPin(cc1101_SCK, cc1101_MISO, cc1101_MOSI, csPin);
6652
67−// ===== BUTTON CHECK =====
68−bool checkButtons()
69−{
70− u8g2.clearBuffer();
71− u8g2.setFont(u8g2_font_6x10_tr);
72− u8g2.drawStr(0, 20, "Press any button...");
73− u8g2.sendBuffer();
74−
75− unsigned long start = millis();
76−
77− while (millis() - start < 2000)
78− {
79− if (!digitalRead(BTN_UP) ||
80− !digitalRead(BTN_DOWN) ||
81− !digitalRead(BTN_SELECT) ||
82− !digitalRead(BTN_BACK) ||
83− !digitalRead(BTN_RIGHT) ||
84− !digitalRead(BTN_LEFT))
85− {
86− return true;
87− }
88− }
53+ delay(5);
8954
90− return false;
55+ return ELECHOUSE_cc1101.getCC1101();
9156 }
9257
9358 // ===== DRAW =====
94−#define MAX_ITEMS 6
59+#define MAX_ITEMS 4
9560 #define VISIBLE_ROWS 5
9661
97−const char* labels[MAX_ITEMS] = {
98− "NRF1",
99− "NRF2",
100− "CC1101-1",
101− "CC1101-2",
102− "BUTTONS",
103− "OLED"
104−};
62+const char *labels[MAX_ITEMS] = {"NRF1", "NRF2", "CC1101", "OLED"};
10563
10664 bool values[MAX_ITEMS];
10765
10866 int selectedIndex = 0;
10967 int offset = 0;
11068
111−void drawStatus(DeviceStatus &s)
112−{
113− values[0] = s.nrf1;
114− values[1] = s.nrf2;
115− values[2] = s.cc1101_1;
116− values[3] = s.cc1101_2;
117− values[4] = s.buttons;
118− values[5] = s.oled;
69+void drawStatus(DeviceStatus &s) {
70+ values[0] = s.nrf1;
71+ values[1] = s.nrf2;
72+ values[2] = s.cc1101;
73+ values[3] = s.oled;
11974
75+ u8g2.clearBuffer();
76+ u8g2.setFont(u8g2_font_6x10_tr);
12077
121− u8g2.clearBuffer();
122− u8g2.setFont(u8g2_font_6x10_tr);
78+ // scrolling logic
79+ if (selectedIndex < offset)
80+ offset = selectedIndex;
12381
124− // scrolling logic
125− if (selectedIndex < offset)
126− offset = selectedIndex;
82+ if (selectedIndex >= offset + VISIBLE_ROWS)
83+ offset = selectedIndex - VISIBLE_ROWS + 1;
12784
128− if (selectedIndex >= offset + VISIBLE_ROWS)
129− offset = selectedIndex - VISIBLE_ROWS + 1;
85+ for (int i = 0; i < VISIBLE_ROWS; i++) {
86+ int item = offset + i;
87+ if (item >= MAX_ITEMS)
88+ break;
13089
131− for (int i = 0; i < VISIBLE_ROWS; i++)
132− {
133− int item = offset + i;
134− if (item >= MAX_ITEMS) break;
90+ int y = 12 + i * 10;
13591
136− int y = 12 + i * 10;
92+ if (item == selectedIndex) {
93+ u8g2.drawBox(0, y - 9, 128, 10);
94+ u8g2.setDrawColor(0);
95+ }
13796
138− if (item == selectedIndex)
139− {
140− u8g2.drawBox(0, y - 9, 128, 10);
141− u8g2.setDrawColor(0);
142− }
97+ u8g2.drawStr(2, y, labels[item]);
14398
144− u8g2.drawStr(2, y, labels[item]);
99+ if (values[item])
100+ u8g2.drawStr(80, y, "OK");
101+ else
102+ u8g2.drawStr(80, y, "FAIL");
145103
146− if (values[item])
147− u8g2.drawStr(80, y, "OK");
148− else
149− u8g2.drawStr(80, y, "FAIL");
104+ if (item == selectedIndex)
105+ u8g2.setDrawColor(1);
106+ }
150107
151− if (item == selectedIndex)
152− u8g2.setDrawColor(1);
153− }
154−
155− u8g2.sendBuffer();
108+ u8g2.sendBuffer();
156109 }
157110
158111 // ===== MAIN =====
159−void device_check_run()
160−{
161− DeviceStatus status;
162−
163− Serial.println("Running device diagnostics...");
112+void device_check_run() {
113+ DeviceStatus status;
164114
165− // NRF
166− status.nrf1 = checkNRF(radio1);
167− status.nrf2 = checkNRF(radio2);
115+ Serial.println("Running device diagnostics...");
168116
169− // CC1101
170− status.cc1101_1 = checkCC1101(CC1101_CS);
171− status.cc1101_2 = checkCC1101(CC1101_2_CS);
172− //status.cc1101_1 = status.cc1101_2 = false;
117+ // NRF
118+ status.nrf1 = checkNRF(radio1);
119+ status.nrf2 = checkNRF(radio2);
173120
174− // Buttons
175− status.buttons = checkButtons();
121+ // CC1101
122+ status.cc1101 = checkCC1101(CC1101_CS);
123+ // status.cc1101 = true;
176124
177− drawStatus(status);
125+ drawStatus(status);
178126
179− Serial.println("Diagnostics complete");
127+ Serial.println("Diagnostics complete");
180128
181− while (1)
182−{
129+ while (1) {
183130 drawStatus(status);
184131
185− if (btnUp())
186− {
187− selectedIndex--;
188− if (selectedIndex < 0) selectedIndex = MAX_ITEMS - 1;
189− delay(150);
132+ if (btnUp()) {
133+ selectedIndex--;
134+ if (selectedIndex < 0)
135+ selectedIndex = MAX_ITEMS - 1;
136+ delay(150);
190137 }
191138
192− if (btnDown())
193− {
194− selectedIndex++;
195− if (selectedIndex >= MAX_ITEMS) selectedIndex = 0;
196− delay(150);
139+ if (btnDown()) {
140+ selectedIndex++;
141+ if (selectedIndex >= MAX_ITEMS)
142+ selectedIndex = 0;
143+ delay(150);
197144 }
198145
199− if (btnBack())
200− {
201− delay(150);
202− break;
146+ if (btnBack()) {
147+ delay(150);
148+ break;
203149 }
204−}}
205−
206−
207−
150+ }
151+}