remove cc1101_2 from device check

This commit is contained in:
krolyxon 2026-05-14 23:12:19 +05:30
parent 0b8b30d25d
commit 3672abc8b4
1 changed files with 81 additions and 137 deletions

View File

@ -1,12 +1,12 @@
#include "../libs/ELECHOUSE_CC1101_SRC_DRV.h"
#include <Arduino.h> #include <Arduino.h>
#include <RF24.h>
#include <SPI.h> #include <SPI.h>
#include <Wire.h> #include <Wire.h>
#include <RF24.h>
#include "../libs/ELECHOUSE_CC1101_SRC_DRV.h"
#include "../config.h"
#include "../ui/display.h" #include "../ui/display.h"
#include "buttons.h" #include "buttons.h"
#include "../config.h"
// ===== EXTERNALS ===== // ===== EXTERNALS =====
extern RF24 radio1; extern RF24 radio1;
@ -16,16 +16,14 @@ extern U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2;
// ===== RESULTS ===== // ===== RESULTS =====
struct DeviceStatus { struct DeviceStatus {
bool nrf1 = false; bool nrf1 = false;
bool nrf2 = false; bool nrf2 = false;
bool cc1101_1 = false; bool cc1101 = false;
bool cc1101_2 = false; bool oled = true;
bool oled = true;
bool buttons = false;
}; };
// ===== NRF CHECK ===== // ===== NRF CHECK =====
//bool checkNRF(RF24 &radio) // bool checkNRF(RF24 &radio)
//{ //{
// // safer: only init if needed // // safer: only init if needed
// if (!radio.isChipConnected()) { // if (!radio.isChipConnected()) {
@ -36,172 +34,118 @@ struct DeviceStatus {
// return radio.isChipConnected(); // return radio.isChipConnected();
//} //}
bool checkNRF(RF24 &radio) bool checkNRF(RF24 &radio) {
{ radio.powerDown();
radio.powerDown(); delay(5);
delay(5);
if (!radio.begin(RADIO_SPI)) if (!radio.begin(RADIO_SPI))
return false; return false;
delay(5); delay(5);
return radio.isChipConnected(); return radio.isChipConnected();
} }
// ===== CC1101 CHECK ===== // ===== CC1101 CHECK =====
bool checkCC1101(uint8_t csPin) bool checkCC1101(uint8_t csPin) {
{ ELECHOUSE_cc1101.setSpiPin(cc1101_SCK, cc1101_MISO, cc1101_MOSI, csPin);
ELECHOUSE_cc1101.setSpiPin(
cc1101_SCK,
cc1101_MISO,
cc1101_MOSI,
csPin
);
delay(5); delay(5);
return ELECHOUSE_cc1101.getCC1101(); return ELECHOUSE_cc1101.getCC1101();
}
// ===== BUTTON CHECK =====
bool checkButtons()
{
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_6x10_tr);
u8g2.drawStr(0, 20, "Press any button...");
u8g2.sendBuffer();
unsigned long start = millis();
while (millis() - start < 2000)
{
if (!digitalRead(BTN_UP) ||
!digitalRead(BTN_DOWN) ||
!digitalRead(BTN_SELECT) ||
!digitalRead(BTN_BACK) ||
!digitalRead(BTN_RIGHT) ||
!digitalRead(BTN_LEFT))
{
return true;
}
}
return false;
} }
// ===== DRAW ===== // ===== DRAW =====
#define MAX_ITEMS 6 #define MAX_ITEMS 4
#define VISIBLE_ROWS 5 #define VISIBLE_ROWS 5
const char* labels[MAX_ITEMS] = { const char *labels[MAX_ITEMS] = {"NRF1", "NRF2", "CC1101", "OLED"};
"NRF1",
"NRF2",
"CC1101-1",
"CC1101-2",
"BUTTONS",
"OLED"
};
bool values[MAX_ITEMS]; bool values[MAX_ITEMS];
int selectedIndex = 0; int selectedIndex = 0;
int offset = 0; int offset = 0;
void drawStatus(DeviceStatus &s) void drawStatus(DeviceStatus &s) {
{ values[0] = s.nrf1;
values[0] = s.nrf1; values[1] = s.nrf2;
values[1] = s.nrf2; values[2] = s.cc1101;
values[2] = s.cc1101_1; values[3] = s.oled;
values[3] = s.cc1101_2;
values[4] = s.buttons;
values[5] = s.oled;
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_6x10_tr);
u8g2.clearBuffer(); // scrolling logic
u8g2.setFont(u8g2_font_6x10_tr); if (selectedIndex < offset)
offset = selectedIndex;
// scrolling logic if (selectedIndex >= offset + VISIBLE_ROWS)
if (selectedIndex < offset) offset = selectedIndex - VISIBLE_ROWS + 1;
offset = selectedIndex;
if (selectedIndex >= offset + VISIBLE_ROWS) for (int i = 0; i < VISIBLE_ROWS; i++) {
offset = selectedIndex - VISIBLE_ROWS + 1; int item = offset + i;
if (item >= MAX_ITEMS)
break;
for (int i = 0; i < VISIBLE_ROWS; i++) int y = 12 + i * 10;
{
int item = offset + i;
if (item >= MAX_ITEMS) break;
int y = 12 + i * 10; if (item == selectedIndex) {
u8g2.drawBox(0, y - 9, 128, 10);
if (item == selectedIndex) u8g2.setDrawColor(0);
{
u8g2.drawBox(0, y - 9, 128, 10);
u8g2.setDrawColor(0);
}
u8g2.drawStr(2, y, labels[item]);
if (values[item])
u8g2.drawStr(80, y, "OK");
else
u8g2.drawStr(80, y, "FAIL");
if (item == selectedIndex)
u8g2.setDrawColor(1);
} }
u8g2.sendBuffer(); u8g2.drawStr(2, y, labels[item]);
if (values[item])
u8g2.drawStr(80, y, "OK");
else
u8g2.drawStr(80, y, "FAIL");
if (item == selectedIndex)
u8g2.setDrawColor(1);
}
u8g2.sendBuffer();
} }
// ===== MAIN ===== // ===== MAIN =====
void device_check_run() void device_check_run() {
{ DeviceStatus status;
DeviceStatus status;
Serial.println("Running device diagnostics..."); Serial.println("Running device diagnostics...");
// NRF // NRF
status.nrf1 = checkNRF(radio1); status.nrf1 = checkNRF(radio1);
status.nrf2 = checkNRF(radio2); status.nrf2 = checkNRF(radio2);
// CC1101 // CC1101
status.cc1101_1 = checkCC1101(CC1101_CS); status.cc1101 = checkCC1101(CC1101_CS);
status.cc1101_2 = checkCC1101(CC1101_2_CS); // status.cc1101 = true;
//status.cc1101_1 = status.cc1101_2 = false;
// Buttons drawStatus(status);
status.buttons = checkButtons();
Serial.println("Diagnostics complete");
while (1) {
drawStatus(status); drawStatus(status);
Serial.println("Diagnostics complete"); if (btnUp()) {
selectedIndex--;
while (1) if (selectedIndex < 0)
{ selectedIndex = MAX_ITEMS - 1;
drawStatus(status); delay(150);
if (btnUp())
{
selectedIndex--;
if (selectedIndex < 0) selectedIndex = MAX_ITEMS - 1;
delay(150);
} }
if (btnDown()) if (btnDown()) {
{ selectedIndex++;
selectedIndex++; if (selectedIndex >= MAX_ITEMS)
if (selectedIndex >= MAX_ITEMS) selectedIndex = 0; selectedIndex = 0;
delay(150); delay(150);
} }
if (btnBack()) if (btnBack()) {
{ delay(150);
delay(150); break;
break;
} }
}} }
}