How to update progress bar in real time while scanning for bluetooth devices.
What MCU/Processor/Board and compiler are you using?
esp32dev, VSCode/PlatformIO
What LVGL version are you using?
8.3
What do you want to achieve?
Show the progress of scanning BLE devices in real time while using h2zero/NimBLE-Arduino@^1.4.1 library.
What have you tried so far?
I built couple of robotic toys for my granddaughter and now working on one common bluetooth remote for them all. Remote will have ILI9341 touchscreen and on power up will search for toys within the range. Nevertheless the scan takes just about 5 seconds, I don’t want the screen to freeze for the time of scanning and trying to draw and update the progress bar during the scan. So far with no success.
I am using h2zero/NimBLE library that supports BLE on ESP32. BT scanner in this library has callback function that is triggered every time new BT device is found. I am trying to update my progress bar from within this function but as soon I add lv_bar_get_value(progressBar); or lv_bar_set_value(progressBar, bar, LV_ANIM_OFF); ESP32 crashes and goes into cyclic reboot. progressBar is declared as global variable and I am not getting compilation errors.
Since I don’t know how many BT devices will be found, I decided to increase the value by 4 for each unknown device and increase it by 30 for each found toy (at the moment there are only 3 toys to control). So here is the code of my callback function:
The code block(s) should be formatted like:
class AdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
/**
* Called for each advertising BLE server.
*/
void onResult(BLEAdvertisedDevice* advertisedDevice) {
int bar = lv_bar_get_value(progressBar);
if (advertisedDevice->haveName()) {
std::string btServerName = advertisedDevice->getName();
if (btServerName == "TOY1") {
toy1Online = true;
toy1Device = advertisedDevice; // Just save the reference now, no need to copy the object
bar += 30;
} else if (btServerName == "TOY2") {
toy2Online = true;
toy2Device = advertisedDevice;
bar += 30;
} else if (btServerName == "TOY3") {
toy3Online = true;
toy3Device = advertisedDevice;
bar += 30;
} else {
bar += 4;
}
Serial.println(btServerName.c_str());
if (bar > 100) bar = 100;
lv_bar_set_value(progressBar, bar, LV_ANIM_OFF);
lv_refr_now(NULL); // refresh the screen
}
} // onResult
}; // AdvertisedDeviceCallbacks
Screenshot and/or video
Any advice/suggestions on how to resolve this will be very much appreciated.
Thanks