Skip to content

Commit 52ad0b5

Browse files
finneyjmicrobit-carlos
authored andcommitted
Add message bus listener removal handler for LevelDetectorSPL instance
1 parent 7afff1a commit 52ad0b5

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

model/MicroBit.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ int MicroBit::init()
201201
// which saves processor time, memeory and battery life.
202202
messageBus.listen(DEVICE_ID_MESSAGE_BUS_LISTENER, DEVICE_EVT_ANY, this, &MicroBit::onListenerRegisteredEvent);
203203
messageBus.listen(DEVICE_ID_MESSAGE_BUS_LISTENER, ID_PIN_P0, this, &MicroBit::onP0ListenerRegisteredEvent, MESSAGE_BUS_LISTENER_IMMEDIATE);
204+
messageBus.listen(DEVICE_ID_MESSAGE_BUS_IGNORED, DEVICE_EVT_ANY, this, &MicroBit::onListenerRemovedEvent);
204205

205206
#if CONFIG_ENABLED(DMESG_SERIAL_DEBUG) && DEVICE_DMESG_BUFFER_SIZE > 0
206207
codal_dmesg_set_flush_fn(microbit_dmesg_flush);
@@ -375,6 +376,22 @@ void MicroBit::onListenerRegisteredEvent(Event evt)
375376
}
376377
}
377378

379+
/**
380+
* A listener to perform actions as a result of Message Bus reflection.
381+
*
382+
* This callback is triggered upon a MessageBus listneer being removed.
383+
* We may wish to perform cleanup operations as a result, etc.
384+
*
385+
*/
386+
void MicroBit::onListenerRemovedEvent(Event evt)
387+
{
388+
switch(evt.value)
389+
{
390+
case DEVICE_ID_SYSTEM_LEVEL_DETECTOR:
391+
audio.levelSPL->listenerRemoved();
392+
break;
393+
}
394+
}
378395

379396
/**
380397
* Perfom scheduler idle

model/MicroBit.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ namespace codal
122122
*/
123123
void onP0ListenerRegisteredEvent(Event evt);
124124

125+
/**
126+
* A callback listener to disable default audio streaming to P0 if an event handler is registered on that pin.
127+
*/
128+
void onListenerRemovedEvent(Event evt);
129+
125130
// Pin ranges used for LED matrix display.
126131

127132
public:

0 commit comments

Comments
 (0)