From f41b2b59e4d2a85c91b067dbce3af9339a7bab48 Mon Sep 17 00:00:00 2001 From: Kevin Townsend Date: Tue, 1 Aug 2017 15:31:53 +0200 Subject: [PATCH 1/2] Added invalidation to the main loop --- .../rssi_proximity_central.ino | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/libraries/Bluefruit52Lib/examples/Projects/rssi_proximity/rssi_proximity_central/rssi_proximity_central.ino b/libraries/Bluefruit52Lib/examples/Projects/rssi_proximity/rssi_proximity_central/rssi_proximity_central.ino index 4f6ab2a6..6d12c719 100644 --- a/libraries/Bluefruit52Lib/examples/Projects/rssi_proximity/rssi_proximity_central/rssi_proximity_central.ino +++ b/libraries/Bluefruit52Lib/examples/Projects/rssi_proximity/rssi_proximity_central/rssi_proximity_central.ino @@ -649,6 +649,27 @@ void loop() { /* Toggle red LED every second */ digitalToggle(LED_RED); - + + /* Invalidate old results once per second in addition + * to the invalidation in the callback handler. */ + /* ToDo: Update to use a mutex or semaphore since this + * can lead to list corruption as-is if the scann results + * callback is fired in the middle of the invalidation + * function. */ + if (invalidateRecords()) + { + /* The list was updated, print the new values */ + printRecordList(); + Serial.println(""); + /* Display the device list on the TFT if available */ + #if ENABLE_TFT + renderResultsToTFT(); + #endif + /* Display the device list on the OLED if available */ + #if ENABLE_OLED + renderResultsToOLED(); + #endif + } + delay(1000); } From 710a8751e3e53e7064a7e8d6849df264f0891378 Mon Sep 17 00:00:00 2001 From: Kevin Townsend Date: Tue, 1 Aug 2017 17:06:08 +0200 Subject: [PATCH 2/2] Set ARRAY_SIZE to at least 2 records --- .../rssi_proximity_central/rssi_proximity_central.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/Bluefruit52Lib/examples/Projects/rssi_proximity/rssi_proximity_central/rssi_proximity_central.ino b/libraries/Bluefruit52Lib/examples/Projects/rssi_proximity/rssi_proximity_central/rssi_proximity_central.ino index 6d12c719..b33f92f2 100644 --- a/libraries/Bluefruit52Lib/examples/Projects/rssi_proximity/rssi_proximity_central/rssi_proximity_central.ino +++ b/libraries/Bluefruit52Lib/examples/Projects/rssi_proximity/rssi_proximity_central/rssi_proximity_central.ino @@ -38,7 +38,7 @@ * ARRAY_SIZE * ---------- * The numbers of peripherals tracked and sorted can be set via the - * ARRAY_SIZE macro. + * ARRAY_SIZE macro. Must be at least 2. * * TIMEOUT_MS * ---------- @@ -69,8 +69,8 @@ #define ENABLE_TFT (0) // Set this to 1 to enable ILI9341 TFT display support #define ENABLE_OLED (0) // Set this to 1 to enable SSD1306 128x32 OLED display support -#if (ARRAY_SIZE <= 0) - #error "ARRAY_SIZE must be a non-zero value" +#if (ARRAY_SIZE <= 1) + #error "ARRAY_SIZE must be at least 2" #endif #if (ENABLE_TFT) && (ENABLE_OLED) #error "ENABLE_TFT and ENABLE_OLED can not both be set at the same time"