-
Notifications
You must be signed in to change notification settings - Fork 74
Open
Description
This programme creates a new instance of LevelDetectorSPL from the raw splitter (the same way as done in uBit.audio constructor), and every call to localLevelSPL->getValue() gets stuck. It seems to be yielding, so likely locked at the internal resourceLock.wait():
#include "MicroBit.h"
MicroBit uBit;
static LevelDetectorSPL *localLevelSPL = NULL;
const int DEVICE_ID_UNUSED = 50;
int localLevelGetValue() {
if (localLevelSPL == NULL) {
localLevelSPL = new LevelDetectorSPL(*(uBit.audio.rawSplitter->createChannel()), 85.0, 65.0, 16.0, 35.0f, DEVICE_ID_UNUSED);
}
uBit.serial.send("Before localLevelSPL->getValue()\n");
int localLevelValue = localLevelSPL->getValue();
uBit.serial.send("After localLevelSPL->getValue()\n");
return localLevelValue;
}
int main() {
uBit.init();
uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_DOWN, [](MicroBitEvent) {
uBit.serial.send("Button A: ", SYNC_SPINWAIT);
uBit.serial.printf("%d\n", localLevelGetValue());
});
uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_DOWN, [](MicroBitEvent) {
uBit.serial.send("Button B: ", SYNC_SPINWAIT);
uBit.serial.printf("%d\n", localLevelGetValue());
});
while (true) {
uBit.serial.send("Loop: ", SYNC_SPINWAIT);
uBit.serial.printf("%d; %d\n",
(int)uBit.audio.levelSPL->getValue(),
localLevelGetValue()
);
uBit.sleep(200);
}
}The main() function infinite loop calls getValue, so do the button handlers, so we can see this output after pressing button A and B, and nothing more is printed. The uBit.serial.send("After localLevelSPL->getValue()") is never reached:
Loop: Before localLevelSPL->getValue()
Button A: Before localLevelSPL->getValue()
Button B: Before localLevelSPL->getValue()
Reactions are currently unavailable