5
5
#include < Arduino.h>
6
6
#include < unity.h>
7
7
#include < Wire.h>
8
+ #include < vector>
9
+ #include < algorithm>
10
+ #include < WiFi.h>
11
+
12
+ #include " sdkconfig.h"
8
13
9
14
/* DS1307 functions */
10
15
@@ -24,6 +29,9 @@ static uint8_t read_month = 0;
24
29
static uint16_t read_year = 0 ;
25
30
static int peek_data = -1 ;
26
31
32
+ const char *ssid = " Wokwi-GUEST" ;
33
+ const char *password = " " ;
34
+
27
35
const auto BCD2DEC = [](uint8_t num) -> uint8_t {
28
36
return ((num / 16 * 10 ) + (num % 16 ));
29
37
};
@@ -245,6 +253,42 @@ void test_api() {
245
253
Wire.flush ();
246
254
}
247
255
256
+ bool device_found () {
257
+ uint8_t err;
258
+
259
+ for (uint8_t address = 1 ; address < 127 ; ++address) {
260
+ Wire.beginTransmission (address);
261
+ err = Wire.endTransmission ();
262
+ log_d (" Address: 0x%02X, Error: %d" , address, err);
263
+ if (err == 0 ) {
264
+ log_i (" Found device at address: 0x%02X" , address);
265
+ } else if (address == DS1307_ADDR) {
266
+ log_e (" Failed to find DS1307" );
267
+ return false ;
268
+ }
269
+ }
270
+
271
+ return true ;
272
+ }
273
+
274
+ void scan_bus () {
275
+ TEST_ASSERT_TRUE (device_found ());
276
+ }
277
+
278
+ #if SOC_WIFI_SUPPORTED
279
+ void scan_bus_with_wifi () {
280
+ // delete old config
281
+ WiFi.disconnect (true , true , 1000 );
282
+ delay (1000 );
283
+ WiFi.begin (ssid, password);
284
+ delay (5000 );
285
+ bool found = device_found ();
286
+ WiFi.disconnect (true , true , 1000 );
287
+
288
+ TEST_ASSERT_TRUE (found);
289
+ }
290
+ #endif
291
+
248
292
/* Main */
249
293
250
294
void setup () {
@@ -258,6 +302,10 @@ void setup() {
258
302
259
303
log_d (" Starting tests" );
260
304
UNITY_BEGIN ();
305
+ RUN_TEST (scan_bus);
306
+ #if SOC_WIFI_SUPPORTED
307
+ RUN_TEST (scan_bus_with_wifi);
308
+ #endif
261
309
RUN_TEST (rtc_set_time);
262
310
RUN_TEST (rtc_run_clock);
263
311
RUN_TEST (change_clock);
0 commit comments