orion-rf3672abc
remove cc1101_2 from device check
+78 −134
1 file changed
- M src/utils/device_check.cpp +78 −134
| @@ -1,12 +1,12 @@ | |||
| 1 | + | #include "../libs/ELECHOUSE_CC1101_SRC_DRV.h" | |
| 1 | 2 | #include <Arduino.h> | |
| 3 | + | #include <RF24.h> | |
| 2 | 4 | #include <SPI.h> | |
| 3 | 5 | #include <Wire.h> | |
| 4 | − | #include <RF24.h> | |
| 5 | − | #include "../libs/ELECHOUSE_CC1101_SRC_DRV.h" | |
| 6 | 6 | ||
| 7 | + | #include "../config.h" | |
| 7 | 8 | #include "../ui/display.h" | |
| 8 | 9 | #include "buttons.h" | |
| 9 | − | #include "../config.h" | |
| 10 | 10 | ||
| 11 | 11 | // ===== EXTERNALS ===== | |
| 12 | 12 | extern RF24 radio1; | |
| @@ -16,16 +16,14 @@ extern U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2; | |||
| 16 | 16 | ||
| 17 | 17 | // ===== RESULTS ===== | |
| 18 | 18 | 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; | |
| 25 | 23 | }; | |
| 26 | 24 | ||
| 27 | 25 | // ===== NRF CHECK ===== | |
| 28 | − | //bool checkNRF(RF24 &radio) | |
| 26 | + | // bool checkNRF(RF24 &radio) | |
| 29 | 27 | //{ | |
| 30 | 28 | // // safer: only init if needed | |
| 31 | 29 | // if (!radio.isChipConnected()) { | |
| @@ -36,172 +34,118 @@ struct DeviceStatus { | |||
| 36 | 34 | // return radio.isChipConnected(); | |
| 37 | 35 | //} | |
| 38 | 36 | ||
| 39 | − | bool checkNRF(RF24 &radio) | |
| 40 | − | { | |
| 41 | − | radio.powerDown(); | |
| 42 | − | delay(5); | |
| 37 | + | bool checkNRF(RF24 &radio) { | |
| 38 | + | radio.powerDown(); | |
| 39 | + | delay(5); | |
| 43 | 40 | ||
| 44 | − | if (!radio.begin(RADIO_SPI)) | |
| 45 | − | return false; | |
| 41 | + | if (!radio.begin(RADIO_SPI)) | |
| 42 | + | return false; | |
| 46 | 43 | ||
| 47 | − | delay(5); | |
| 44 | + | delay(5); | |
| 48 | 45 | ||
| 49 | − | return radio.isChipConnected(); | |
| 46 | + | return radio.isChipConnected(); | |
| 50 | 47 | } | |
| 51 | 48 | ||
| 52 | 49 | // ===== 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); | |
| 66 | 52 | ||
| 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); | |
| 89 | 54 | ||
| 90 | − | return false; | |
| 55 | + | return ELECHOUSE_cc1101.getCC1101(); | |
| 91 | 56 | } | |
| 92 | 57 | ||
| 93 | 58 | // ===== DRAW ===== | |
| 94 | − | #define MAX_ITEMS 6 | |
| 59 | + | #define MAX_ITEMS 4 | |
| 95 | 60 | #define VISIBLE_ROWS 5 | |
| 96 | 61 | ||
| 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"}; | |
| 105 | 63 | ||
| 106 | 64 | bool values[MAX_ITEMS]; | |
| 107 | 65 | ||
| 108 | 66 | int selectedIndex = 0; | |
| 109 | 67 | int offset = 0; | |
| 110 | 68 | ||
| 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; | |
| 119 | 74 | ||
| 75 | + | u8g2.clearBuffer(); | |
| 76 | + | u8g2.setFont(u8g2_font_6x10_tr); | |
| 120 | 77 | ||
| 121 | − | u8g2.clearBuffer(); | |
| 122 | − | u8g2.setFont(u8g2_font_6x10_tr); | |
| 78 | + | // scrolling logic | |
| 79 | + | if (selectedIndex < offset) | |
| 80 | + | offset = selectedIndex; | |
| 123 | 81 | ||
| 124 | − | // scrolling logic | |
| 125 | − | if (selectedIndex < offset) | |
| 126 | − | offset = selectedIndex; | |
| 82 | + | if (selectedIndex >= offset + VISIBLE_ROWS) | |
| 83 | + | offset = selectedIndex - VISIBLE_ROWS + 1; | |
| 127 | 84 | ||
| 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; | |
| 130 | 89 | ||
| 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; | |
| 135 | 91 | ||
| 136 | − | int y = 12 + i * 10; | |
| 92 | + | if (item == selectedIndex) { | |
| 93 | + | u8g2.drawBox(0, y - 9, 128, 10); | |
| 94 | + | u8g2.setDrawColor(0); | |
| 95 | + | } | |
| 137 | 96 | ||
| 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]); | |
| 143 | 98 | ||
| 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"); | |
| 145 | 103 | ||
| 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 | + | } | |
| 150 | 107 | ||
| 151 | − | if (item == selectedIndex) | |
| 152 | − | u8g2.setDrawColor(1); | |
| 153 | − | } | |
| 154 | − | ||
| 155 | − | u8g2.sendBuffer(); | |
| 108 | + | u8g2.sendBuffer(); | |
| 156 | 109 | } | |
| 157 | 110 | ||
| 158 | 111 | // ===== 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; | |
| 164 | 114 | ||
| 165 | − | // NRF | |
| 166 | − | status.nrf1 = checkNRF(radio1); | |
| 167 | − | status.nrf2 = checkNRF(radio2); | |
| 115 | + | Serial.println("Running device diagnostics..."); | |
| 168 | 116 | ||
| 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); | |
| 173 | 120 | ||
| 174 | − | // Buttons | |
| 175 | − | status.buttons = checkButtons(); | |
| 121 | + | // CC1101 | |
| 122 | + | status.cc1101 = checkCC1101(CC1101_CS); | |
| 123 | + | // status.cc1101 = true; | |
| 176 | 124 | ||
| 177 | − | drawStatus(status); | |
| 125 | + | drawStatus(status); | |
| 178 | 126 | ||
| 179 | − | Serial.println("Diagnostics complete"); | |
| 127 | + | Serial.println("Diagnostics complete"); | |
| 180 | 128 | ||
| 181 | − | while (1) | |
| 182 | − | { | |
| 129 | + | while (1) { | |
| 183 | 130 | drawStatus(status); | |
| 184 | 131 | ||
| 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); | |
| 190 | 137 | } | |
| 191 | 138 | ||
| 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); | |
| 197 | 144 | } | |
| 198 | 145 | ||
| 199 | − | if (btnBack()) | |
| 200 | − | { | |
| 201 | − | delay(150); | |
| 202 | − | break; | |
| 146 | + | if (btnBack()) { | |
| 147 | + | delay(150); | |
| 148 | + | break; | |
| 203 | 149 | } | |
| 204 | − | }} | |
| 205 | − | ||
| 206 | − | ||
| 207 | − | ||
| 150 | + | } | |
| 151 | + | } | |