orion-rfa51e4c5
add 2nd cc1101 in device check, remove link
+24 −59
1 file changed
- M firmware/device_check.cpp +24 −59
| @@ -16,10 +16,10 @@ extern U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2; | |||
| 16 | 16 | ||
| 17 | 17 | // ===== RESULTS ===== | |
| 18 | 18 | struct DeviceStatus { | |
| 19 | − | bool nrf_link = false; | |
| 20 | 19 | bool nrf1 = false; | |
| 21 | 20 | bool nrf2 = false; | |
| 22 | − | bool cc1101 = false; | |
| 21 | + | bool cc1101_1 = false; | |
| 22 | + | bool cc1101_2 = false; | |
| 23 | 23 | bool oled = true; | |
| 24 | 24 | bool buttons = false; | |
| 25 | 25 | }; | |
| @@ -37,7 +37,7 @@ bool checkNRF(RF24 &radio) | |||
| 37 | 37 | } | |
| 38 | 38 | ||
| 39 | 39 | // ===== CC1101 CHECK ===== | |
| 40 | − | bool checkCC1101() | |
| 40 | + | bool checkCC1101_1() | |
| 41 | 41 | { | |
| 42 | 42 | ELECHOUSE_cc1101.setSpiPin( | |
| 43 | 43 | cc1101_SCK, | |
| @@ -51,6 +51,21 @@ bool checkCC1101() | |||
| 51 | 51 | return ELECHOUSE_cc1101.getCC1101(); | |
| 52 | 52 | } | |
| 53 | 53 | ||
| 54 | + | bool checkCC1101_2() | |
| 55 | + | { | |
| 56 | + | ELECHOUSE_cc1101.setSpiPin( | |
| 57 | + | cc1101_SCK, | |
| 58 | + | cc1101_MISO, | |
| 59 | + | cc1101_MOSI, | |
| 60 | + | CC1101_2_CS | |
| 61 | + | ); | |
| 62 | + | ||
| 63 | + | delay(5); // important stabilization | |
| 64 | + | ||
| 65 | + | return ELECHOUSE_cc1101.getCC1101(); | |
| 66 | + | } | |
| 67 | + | ||
| 68 | + | ||
| 54 | 69 | // ===== BUTTON CHECK ===== | |
| 55 | 70 | bool checkButtons() | |
| 56 | 71 | { | |
| @@ -82,8 +97,8 @@ bool checkButtons() | |||
| 82 | 97 | const char* labels[MAX_ITEMS] = { | |
| 83 | 98 | "NRF1", | |
| 84 | 99 | "NRF2", | |
| 85 | − | "LINK", | |
| 86 | − | "CC1101", | |
| 100 | + | "CC1101_1", | |
| 101 | + | "CC1101_2", | |
| 87 | 102 | "BUTTONS", | |
| 88 | 103 | "OLED" | |
| 89 | 104 | }; | |
| @@ -97,8 +112,8 @@ void drawStatus(DeviceStatus &s) | |||
| 97 | 112 | { | |
| 98 | 113 | values[0] = s.nrf1; | |
| 99 | 114 | values[1] = s.nrf2; | |
| 100 | − | values[2] = s.nrf_link; | |
| 101 | − | values[3] = s.cc1101; | |
| 115 | + | values[2] = s.cc1101_1; | |
| 116 | + | values[3] = s.cc1101_2; | |
| 102 | 117 | values[4] = s.buttons; | |
| 103 | 118 | values[5] = s.oled; | |
| 104 | 119 | ||
| @@ -139,56 +154,6 @@ void drawStatus(DeviceStatus &s) | |||
| 139 | 154 | u8g2.sendBuffer(); | |
| 140 | 155 | } | |
| 141 | 156 | ||
| 142 | − | bool testNRFLink() | |
| 143 | − | { | |
| 144 | − | const byte address[6] = "00001"; | |
| 145 | − | uint8_t payload = 0xAB; | |
| 146 | − | uint8_t received = 0; | |
| 147 | − | ||
| 148 | − | // --- init radios --- | |
| 149 | − | if (!radio1.begin(RADIO_SPI)) return false; | |
| 150 | − | if (!radio2.begin(RADIO_SPI)) return false; | |
| 151 | − | ||
| 152 | − | radio1.setPALevel(RF24_PA_LOW); | |
| 153 | − | radio2.setPALevel(RF24_PA_LOW); | |
| 154 | − | ||
| 155 | − | radio1.setDataRate(RF24_1MBPS); | |
| 156 | − | radio2.setDataRate(RF24_1MBPS); | |
| 157 | − | ||
| 158 | − | radio1.setChannel(100); | |
| 159 | − | radio2.setChannel(100); | |
| 160 | − | ||
| 161 | − | radio1.setAutoAck(false); | |
| 162 | − | radio2.setAutoAck(false); | |
| 163 | − | ||
| 164 | − | // --- configure pipes --- | |
| 165 | − | radio1.openWritingPipe(address); | |
| 166 | − | radio2.openReadingPipe(0, address); | |
| 167 | − | ||
| 168 | − | radio2.startListening(); | |
| 169 | − | ||
| 170 | − | delay(50); | |
| 171 | − | ||
| 172 | − | // --- send --- | |
| 173 | − | radio1.stopListening(); | |
| 174 | − | bool sent = radio1.write(&payload, sizeof(payload)); | |
| 175 | − | ||
| 176 | − | if (!sent) return false; | |
| 177 | − | ||
| 178 | − | // --- receive --- | |
| 179 | − | unsigned long start = millis(); | |
| 180 | − | ||
| 181 | − | while (millis() - start < 200) | |
| 182 | − | { | |
| 183 | − | if (radio2.available()) | |
| 184 | − | { | |
| 185 | − | radio2.read(&received, sizeof(received)); | |
| 186 | − | return (received == payload); | |
| 187 | − | } | |
| 188 | − | } | |
| 189 | − | ||
| 190 | − | return false; | |
| 191 | − | } | |
| 192 | 157 | ||
| 193 | 158 | // ===== MAIN ===== | |
| 194 | 159 | void device_check_run() | |
| @@ -199,12 +164,12 @@ void device_check_run() | |||
| 199 | 164 | ||
| 200 | 165 | // NRF | |
| 201 | 166 | // NRF link test | |
| 202 | − | status.nrf_link = testNRFLink(); | |
| 203 | 167 | status.nrf1 = checkNRF(radio1); | |
| 204 | 168 | status.nrf2 = checkNRF(radio2); | |
| 205 | 169 | ||
| 206 | 170 | // CC1101 | |
| 207 | − | status.cc1101 = checkCC1101(); | |
| 171 | + | status.cc1101_1 = checkCC1101_1(); | |
| 172 | + | status.cc1101_2 = checkCC1101_1(); | |
| 208 | 173 | ||
| 209 | 174 | // Buttons | |
| 210 | 175 | status.buttons = checkButtons(); | |