diff options
| author | krolyxon <me@krolyxon.com> | 2026-05-14 23:19:41 +0530 |
|---|---|---|
| committer | krolyxon <me@krolyxon.com> | 2026-05-14 23:19:41 +0530 |
| commit | 58c9c8f51dcec555250195d127a49572c1b9fd9a (patch) | |
| tree | bbf6f4003fbb36882ee81ed511eec66fd15e735f /src/utils | |
| parent | 206ed229198be252a9ae94342b39618aaab55925 (diff) | |
add .clang-format, and apply formatting
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/buttons.cpp | 12 | ||||
| -rw-r--r-- | src/utils/device_check.cpp | 146 | ||||
| -rw-r--r-- | src/utils/sysinfo.cpp | 112 |
3 files changed, 135 insertions, 135 deletions
diff --git a/src/utils/buttons.cpp b/src/utils/buttons.cpp index 1e93150..d257c58 100644 --- a/src/utils/buttons.cpp +++ b/src/utils/buttons.cpp @@ -3,12 +3,12 @@ #include <Arduino.h> void buttonsInit() { - pinMode(BTN_UP, INPUT_PULLUP); - pinMode(BTN_DOWN, INPUT_PULLUP); - pinMode(BTN_SELECT, INPUT_PULLUP); - pinMode(BTN_BACK, INPUT_PULLUP); - pinMode(BTN_RIGHT, INPUT_PULLUP); - pinMode(BTN_LEFT, INPUT_PULLUP); + pinMode(BTN_UP, INPUT_PULLUP); + pinMode(BTN_DOWN, INPUT_PULLUP); + pinMode(BTN_SELECT, INPUT_PULLUP); + pinMode(BTN_BACK, INPUT_PULLUP); + pinMode(BTN_RIGHT, INPUT_PULLUP); + pinMode(BTN_LEFT, INPUT_PULLUP); } bool btnUp() { return !digitalRead(BTN_UP); } diff --git a/src/utils/device_check.cpp b/src/utils/device_check.cpp index 986c344..29f50cf 100644 --- a/src/utils/device_check.cpp +++ b/src/utils/device_check.cpp @@ -16,10 +16,10 @@ extern U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2; // ===== RESULTS ===== struct DeviceStatus { - bool nrf1 = false; - bool nrf2 = false; - bool cc1101 = false; - bool oled = true; + bool nrf1 = false; + bool nrf2 = false; + bool cc1101 = false; + bool oled = true; }; // ===== NRF CHECK ===== @@ -35,24 +35,24 @@ struct DeviceStatus { //} bool checkNRF(RF24 &radio) { - radio.powerDown(); - delay(5); + radio.powerDown(); + delay(5); - if (!radio.begin(RADIO_SPI)) - return false; + if (!radio.begin(RADIO_SPI)) + return false; - delay(5); + delay(5); - return radio.isChipConnected(); + return radio.isChipConnected(); } // ===== CC1101 CHECK ===== 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(); } // ===== DRAW ===== @@ -67,85 +67,85 @@ int selectedIndex = 0; int offset = 0; void drawStatus(DeviceStatus &s) { - values[0] = s.nrf1; - values[1] = s.nrf2; - values[2] = s.cc1101; - values[3] = s.oled; + values[0] = s.nrf1; + values[1] = s.nrf2; + values[2] = s.cc1101; + values[3] = s.oled; - u8g2.clearBuffer(); - u8g2.setFont(u8g2_font_6x10_tr); + u8g2.clearBuffer(); + u8g2.setFont(u8g2_font_6x10_tr); - // scrolling logic - if (selectedIndex < offset) - offset = selectedIndex; + // scrolling logic + if (selectedIndex < offset) + offset = selectedIndex; - if (selectedIndex >= offset + VISIBLE_ROWS) - offset = selectedIndex - VISIBLE_ROWS + 1; + if (selectedIndex >= offset + VISIBLE_ROWS) + offset = selectedIndex - VISIBLE_ROWS + 1; - for (int i = 0; i < VISIBLE_ROWS; i++) { - int item = offset + i; - if (item >= MAX_ITEMS) - break; + for (int i = 0; i < VISIBLE_ROWS; i++) { + int item = offset + i; + if (item >= MAX_ITEMS) + break; - int y = 12 + i * 10; + int y = 12 + i * 10; - if (item == selectedIndex) { - u8g2.drawBox(0, y - 9, 128, 10); - u8g2.setDrawColor(0); - } + if (item == selectedIndex) { + u8g2.drawBox(0, y - 9, 128, 10); + u8g2.setDrawColor(0); + } - u8g2.drawStr(2, y, labels[item]); + u8g2.drawStr(2, y, labels[item]); - if (values[item]) - u8g2.drawStr(80, y, "OK"); - else - u8g2.drawStr(80, y, "FAIL"); + if (values[item]) + u8g2.drawStr(80, y, "OK"); + else + u8g2.drawStr(80, y, "FAIL"); - if (item == selectedIndex) - u8g2.setDrawColor(1); - } + if (item == selectedIndex) + u8g2.setDrawColor(1); + } - u8g2.sendBuffer(); + u8g2.sendBuffer(); } // ===== MAIN ===== void device_check_run() { - DeviceStatus status; - - Serial.println("Running device diagnostics..."); - - // NRF - status.nrf1 = checkNRF(radio1); - status.nrf2 = checkNRF(radio2); + DeviceStatus status; - // CC1101 - status.cc1101 = checkCC1101(CC1101_CS); - // status.cc1101 = true; + Serial.println("Running device diagnostics..."); - drawStatus(status); + // NRF + status.nrf1 = checkNRF(radio1); + status.nrf2 = checkNRF(radio2); - Serial.println("Diagnostics complete"); + // CC1101 + status.cc1101 = checkCC1101(CC1101_CS); + // status.cc1101 = true; - while (1) { drawStatus(status); - if (btnUp()) { - selectedIndex--; - if (selectedIndex < 0) - selectedIndex = MAX_ITEMS - 1; - delay(150); - } - - if (btnDown()) { - selectedIndex++; - if (selectedIndex >= MAX_ITEMS) - selectedIndex = 0; - delay(150); - } - - if (btnBack()) { - delay(150); - break; + Serial.println("Diagnostics complete"); + + while (1) { + drawStatus(status); + + if (btnUp()) { + selectedIndex--; + if (selectedIndex < 0) + selectedIndex = MAX_ITEMS - 1; + delay(150); + } + + if (btnDown()) { + selectedIndex++; + if (selectedIndex >= MAX_ITEMS) + selectedIndex = 0; + delay(150); + } + + if (btnBack()) { + delay(150); + break; + } } - } } diff --git a/src/utils/sysinfo.cpp b/src/utils/sysinfo.cpp index a852aad..cb3871d 100644 --- a/src/utils/sysinfo.cpp +++ b/src/utils/sysinfo.cpp @@ -5,80 +5,80 @@ #include <esp_heap_caps.h> void runSystemInfoFeature() { - esp_chip_info_t chip_info; + esp_chip_info_t chip_info; - esp_chip_info(&chip_info); + esp_chip_info(&chip_info); - while (true) { - // u8g2.clearBuffer(); + while (true) { + // u8g2.clearBuffer(); - // char buf[32]; + // char buf[32]; - // sprintf(buf, "Cores: %d", chip_info.cores); - // u8g2.drawStr(0, 14, buf); + // sprintf(buf, "Cores: %d", chip_info.cores); + // u8g2.drawStr(0, 14, buf); - // sprintf(buf, "Heap: %d", - // heap_caps_get_free_size(MALLOC_CAP_DEFAULT)); - // u8g2.drawStr(0, 28, buf); + // sprintf(buf, "Heap: %d", + // heap_caps_get_free_size(MALLOC_CAP_DEFAULT)); + // u8g2.drawStr(0, 28, buf); - // u8g2.drawStr(0, 60, "BACK to exit"); + // u8g2.drawStr(0, 60, "BACK to exit"); - // Get RAM info - size_t freeHeap = heap_caps_get_free_size(MALLOC_CAP_DEFAULT); - size_t totalHeap = heap_caps_get_total_size(MALLOC_CAP_DEFAULT); - int ramUsage = 100 - ((freeHeap * 100) / totalHeap); + // Get RAM info + size_t freeHeap = heap_caps_get_free_size(MALLOC_CAP_DEFAULT); + size_t totalHeap = heap_caps_get_total_size(MALLOC_CAP_DEFAULT); + int ramUsage = 100 - ((freeHeap * 100) / totalHeap); - // Get Flash info - // uint32_t flashSize = spi_flash_get_chip_size(); - uint32_t flashSize = ESP.getFlashChipSize(); - uint32_t flashUsed = ESP.getSketchSize(); - int flashUsage = (flashUsed * 100) / flashSize; + // Get Flash info + // uint32_t flashSize = spi_flash_get_chip_size(); + uint32_t flashSize = ESP.getFlashChipSize(); + uint32_t flashUsed = ESP.getSketchSize(); + int flashUsage = (flashUsed * 100) / flashSize; - // Temperature (approx) - uint8_t temperature = temperatureRead(); + // Temperature (approx) + uint8_t temperature = temperatureRead(); - // Chip info - esp_chip_info_t chip_info; - esp_chip_info(&chip_info); + // Chip info + esp_chip_info_t chip_info; + esp_chip_info(&chip_info); - u8g2.clearBuffer(); - u8g2.setFont(u8g2_font_6x12_tr); + u8g2.clearBuffer(); + u8g2.setFont(u8g2_font_6x12_tr); - char buf[32]; + char buf[32]; - // Box 1 - RAM - u8g2.drawFrame(0, 0, 128, 12); - sprintf(buf, "RAM: %d%% used", ramUsage); - u8g2.drawStr(4, 9, buf); + // Box 1 - RAM + u8g2.drawFrame(0, 0, 128, 12); + sprintf(buf, "RAM: %d%% used", ramUsage); + u8g2.drawStr(4, 9, buf); - // Box 2 - Flash - u8g2.drawFrame(0, 12, 128, 12); - sprintf(buf, "Flash: %d%% used", flashUsage); - u8g2.drawStr(4, 21, buf); + // Box 2 - Flash + u8g2.drawFrame(0, 12, 128, 12); + sprintf(buf, "Flash: %d%% used", flashUsage); + u8g2.drawStr(4, 21, buf); - // Box 3 - Temp (FULL WIDTH now) - u8g2.drawFrame(0, 24, 128, 12); - sprintf(buf, "Temp: %d C", temperature); - u8g2.drawStr(4, 33, buf); + // Box 3 - Temp (FULL WIDTH now) + u8g2.drawFrame(0, 24, 128, 12); + sprintf(buf, "Temp: %d C", temperature); + u8g2.drawStr(4, 33, buf); - // Box 4 - Chip info (FULL WIDTH) - u8g2.drawFrame(0, 36, 128, 12); - sprintf(buf, "Cores: %d Rev: %d", chip_info.cores, chip_info.revision); - u8g2.drawStr(4, 45, buf); + // Box 4 - Chip info (FULL WIDTH) + u8g2.drawFrame(0, 36, 128, 12); + sprintf(buf, "Cores: %d Rev: %d", chip_info.cores, chip_info.revision); + u8g2.drawStr(4, 45, buf); - // Box 5 - PSRAM (KB) - u8g2.drawFrame(0, 48, 128, 12); - sprintf(buf, "PSRAM: %lu KB", - heap_caps_get_free_size(MALLOC_CAP_SPIRAM) / 1024); - u8g2.drawStr(4, 57, buf); + // Box 5 - PSRAM (KB) + u8g2.drawFrame(0, 48, 128, 12); + sprintf(buf, "PSRAM: %lu KB", + heap_caps_get_free_size(MALLOC_CAP_SPIRAM) / 1024); + u8g2.drawStr(4, 57, buf); - u8g2.sendBuffer(); + u8g2.sendBuffer(); - if (btnBack()) { - delay(200); - return; - } + if (btnBack()) { + delay(200); + return; + } - delay(100); - } + delay(100); + } } |
