microbit: BUGFIX Corrected incorrect handling of MicroBitMessageBus::add return values.
This commit is contained in:
parent
823a956d68
commit
7f64a4c703
3 changed files with 15 additions and 12 deletions
|
@ -256,7 +256,7 @@ class MicroBitMessageBus : public MicroBitComponent
|
|||
};
|
||||
|
||||
/**
|
||||
* A registrationt function to allow C++ member funcitons (methods) to be registered as an event
|
||||
* A registration function to allow C++ member funcitons (methods) to be registered as an event
|
||||
* listener.
|
||||
*
|
||||
* @param id The source of messages to listen for. Events sent from any other IDs will be filtered.
|
||||
|
@ -278,10 +278,11 @@ int MicroBitMessageBus::listen(uint16_t id, uint16_t value, T* object, void (T::
|
|||
|
||||
MicroBitListener *newListener = new MicroBitListener(id, value, object, handler, flags);
|
||||
|
||||
if(!add(newListener))
|
||||
delete newListener;
|
||||
if(add(newListener) == MICROBIT_OK)
|
||||
return MICROBIT_OK;
|
||||
|
||||
return MICROBIT_OK;
|
||||
delete newListener;
|
||||
return MICROBIT_NO_RESOURCES;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -288,10 +288,12 @@ int MicroBitMessageBus::listen(int id, int value, void (*handler)(MicroBitEvent)
|
|||
|
||||
MicroBitListener *newListener = new MicroBitListener(id, value, handler, flags);
|
||||
|
||||
if(add(newListener) != MICROBIT_OK)
|
||||
delete newListener;
|
||||
if(add(newListener) == MICROBIT_OK)
|
||||
return MICROBIT_OK;
|
||||
|
||||
delete newListener;
|
||||
return MICROBIT_NO_RESOURCES;
|
||||
|
||||
return MICROBIT_OK;
|
||||
}
|
||||
|
||||
int MicroBitMessageBus::listen(int id, int value, void (*handler)(MicroBitEvent, void*), void* arg, uint16_t flags)
|
||||
|
@ -301,10 +303,11 @@ int MicroBitMessageBus::listen(int id, int value, void (*handler)(MicroBitEvent,
|
|||
|
||||
MicroBitListener *newListener = new MicroBitListener(id, value, handler, arg, flags);
|
||||
|
||||
if(add(newListener) != MICROBIT_OK)
|
||||
delete newListener;
|
||||
|
||||
if(add(newListener) == MICROBIT_OK)
|
||||
return MICROBIT_OK;
|
||||
|
||||
delete newListener;
|
||||
return MICROBIT_NO_RESOURCES;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -48,8 +48,7 @@ MicroBitMagnetometerService::MicroBitMagnetometerService(BLEDevice &_ble) :
|
|||
ble.gattServer().write(magnetometerPeriodCharacteristicHandle, (const uint8_t *)&magnetometerPeriodCharacteristicBuffer, sizeof(magnetometerPeriodCharacteristicBuffer));
|
||||
|
||||
ble.onDataWritten(this, &MicroBitMagnetometerService::onDataWritten);
|
||||
uBit.MessageBus.listen(MICROBIT_ID_COMPASS, MICROBIT_COMPASS_EVT_DATA_UPDATE, this, &MicroBitMagnetometerService::magnetometerUpdate);
|
||||
|
||||
uBit.MessageBus.listen(MICROBIT_ID_COMPASS, MICROBIT_COMPASS_EVT_DATA_UPDATE, this, &MicroBitMagnetometerService::magnetometerUpdate, MESSAGE_BUS_LISTENER_IMMEDIATE);
|
||||
uBit.MessageBus.listen(MICROBIT_ID_COMPASS, MICROBIT_COMPASS_EVT_CONFIG_NEEDED, this, &MicroBitMagnetometerService::samplePeriodUpdateNeeded);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue