Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine micro:bit model version and add to Device Information Service #373

Open
wants to merge 2 commits into
base: dal-integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion inc/bluetooth/MicroBitBLEManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class MicroBitBLEManager : MicroBitComponent
* bleManager.init(uBit.getName(), uBit.getSerial(), uBit.messageBus, true);
* @endcode
*/
void init(ManagedString deviceName, ManagedString serialNumber, EventModel &messageBus, bool enableBonding);
void init(ManagedString deviceName, ManagedString serialNumber, EventModel &messageBus, bool enableBonding, ManagedString microbitModel = ManagedString("BBC micro:bit"));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way to avoid using heap memory to store this info?


/**
* Change the output power level of the transmitter to the given value.
Expand Down Expand Up @@ -324,6 +324,8 @@ class MicroBitBLEManager : MicroBitComponent
*/
uint8_t currentMode = MICROBIT_MODE_APPLICATION;

char* getMicrobitModel();

};

#endif
4 changes: 4 additions & 0 deletions inc/core/MicroBitDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ DEALINGS IN THE SOFTWARE.
#define MICROBIT_NAME_CODE_LETTERS 5
#define MICROBIT_PANIC_ERROR_CHARS 4

#define MICROBIT_MODEL_UNKNOWN "BBC micro:bit"
#define MICROBIT_MODEL_1_3_X "BBC micro:bit v1.3x"
#define MICROBIT_MODEL_1_5_X "BBC micro:bit v1.5"

#include "MicroBitConfig.h"
#include "MicroBitMatrixMaps.h"

Expand Down
7 changes: 7 additions & 0 deletions inc/drivers/FXOS8700.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ class FXOS8700 : public MicroBitAccelerometer, public MicroBitCompass
*/
virtual void idleTick();

/**
* Returns which accelerometer is detected
*
* @return MICROBIT_ACCELEROMETER_XXX
*/
virtual uint8_t whatAmI();

/**
* Destructor.
*/
Expand Down
7 changes: 7 additions & 0 deletions inc/drivers/LSM303Accelerometer.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ class LSM303Accelerometer : public MicroBitAccelerometer
*/
static int isDetected(MicroBitI2C &i2c, uint16_t address = LSM303_A_DEFAULT_ADDR);

/**
* Returns which accelerometer is detected
*
* @return MICROBIT_ACCELEROMETER_XXX
*/
virtual uint8_t whatAmI();

/**
* Destructor.
*/
Expand Down
6 changes: 6 additions & 0 deletions inc/drivers/MMA8653.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ class MMA8653 : public MicroBitAccelerometer
*/
static int isDetected(MicroBitI2C &i2c, uint16_t address = MMA8653_DEFAULT_ADDR);

/**
* Returns which accelerometer is detected
*
* @return MICROBIT_ACCELEROMETER_XXX
*/
virtual uint8_t whatAmI();

/**
* Destructor.
Expand Down
15 changes: 14 additions & 1 deletion inc/drivers/MicroBitAccelerometer.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ DEALINGS IN THE SOFTWARE.
#define MICROBIT_ACCELEROMETER_8G_THRESHOLD ((uint32_t)MICROBIT_ACCELEROMETER_8G_TOLERANCE * (uint32_t)MICROBIT_ACCELEROMETER_8G_TOLERANCE)
#define MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD 4

#define MICROBIT_ACCELEROMETER_UNKNOWN 0
#define MICROBIT_ACCELEROMETER_MMA8653 1
#define MICROBIT_ACCELEROMETER_LSM303 2
#define MICROBIT_ACCELEROMETER_FXOS8700 3

struct ShakeHistory
{
uint16_t shaken:1,
Expand Down Expand Up @@ -118,7 +123,7 @@ class MicroBitAccelerometer : public MicroBitComponent

public:

static MicroBitAccelerometer *detectedAccelerometer; // The autodetected instance of a MicroBitAcelerometer driver.
static MicroBitAccelerometer *detectedAccelerometer; // The autodetected instance of a MicroBitAccelerometer driver.

/**
* Constructor.
Expand Down Expand Up @@ -323,6 +328,13 @@ class MicroBitAccelerometer : public MicroBitComponent
{
getSample();
}

/**
* Returns which accelerometer is detected
*
* @return MICROBIT_ACCELEROMETER_XXX
*/
virtual uint8_t whatAmI();

/**
* Destructor.
Expand Down Expand Up @@ -365,6 +377,7 @@ class MicroBitAccelerometer : public MicroBitComponent
* @return A 'best guess' of the current posture of the device, based on instanataneous data.
*/
uint16_t instantaneousPosture();

};

#endif
8 changes: 5 additions & 3 deletions source/bluetooth/MicroBitBLEManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,13 @@ void MicroBitBLEManager::deferredSysAttrWrite(Gap::Handle_t handle)
* @param serialNumber The serial number exposed by the device information service
* @param messageBus An instance of an EventModel, used during pairing.
* @param enableBonding If true, the security manager enabled bonding.
* @param microbitModel The model of the micro:bit if detected
*
* @code
* bleManager.init(uBit.getName(), uBit.getSerial(), uBit.messageBus, true);
* bleManager.init(uBit.getName(), uBit.getSerial(), uBit.messageBus, true, uBit.getModel());
* @endcode
*/
void MicroBitBLEManager::init(ManagedString deviceName, ManagedString serialNumber, EventModel &messageBus, bool enableBonding)
void MicroBitBLEManager::init(ManagedString deviceName, ManagedString serialNumber, EventModel &messageBus, bool enableBonding, ManagedString microbitModel)
{
ManagedString BLEName("BBC micro:bit");
this->deviceName = deviceName;
Expand Down Expand Up @@ -387,7 +388,7 @@ void MicroBitBLEManager::init(ManagedString deviceName, ManagedString serialNumb
#endif

#if CONFIG_ENABLED(MICROBIT_BLE_DEVICE_INFORMATION_SERVICE)
DeviceInformationService ble_device_information_service(*ble, MICROBIT_BLE_MANUFACTURER, MICROBIT_BLE_MODEL, serialNumber.toCharArray(), MICROBIT_BLE_HARDWARE_VERSION, MICROBIT_BLE_FIRMWARE_VERSION, MICROBIT_BLE_SOFTWARE_VERSION);
DeviceInformationService ble_device_information_service(*ble, MICROBIT_BLE_MANUFACTURER, microbitModel.toCharArray(), serialNumber.toCharArray(), MICROBIT_BLE_HARDWARE_VERSION, MICROBIT_BLE_FIRMWARE_VERSION, MICROBIT_BLE_SOFTWARE_VERSION);
#else
(void)serialNumber;
#endif
Expand Down Expand Up @@ -857,3 +858,4 @@ void MicroBitBLEManager::showNameHistogram(MicroBitDisplay &display)
uint8_t MicroBitBLEManager::getCurrentMode(){
return currentMode;
}

10 changes: 10 additions & 0 deletions source/drivers/FXOS8700.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,16 @@ void FXOS8700::idleTick()
requestUpdate();
}

/**
* Returns which accelerometer is detected
*
* @return MICROBIT_ACCELEROMETER_XXX
*/
uint8_t FXOS8700::whatAmI()
{
return MICROBIT_ACCELEROMETER_FXOS8700;
}

/**
* Destructor for FXS8700, where we deregister from the array of fiber components.
*/
Expand Down
10 changes: 10 additions & 0 deletions source/drivers/LSM303Accelerometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ int LSM303Accelerometer::isDetected(MicroBitI2C &i2c, uint16_t address)
return i2c.readRegister(address, LSM303_WHO_AM_I_A) == LSM303_A_WHOAMI_VAL;
}

/**
* Returns which accelerometer is detected
*
* @return MICROBIT_ACCELEROMETER_XXX
*/
uint8_t LSM303Accelerometer::whatAmI()
{
return MICROBIT_ACCELEROMETER_LSM303;
}

/**
* Destructor.
*/
Expand Down
10 changes: 10 additions & 0 deletions source/drivers/MMA8653.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@ int MMA8653::isDetected(MicroBitI2C &i2c, uint16_t address)
return i2c.readRegister(address, MMA8653_WHOAMI) == MMA8653_WHOAMI_VAL;
}

/**
* Returns which accelerometer is detected
*
* @return MICROBIT_ACCELEROMETER_XXX
*/
uint8_t MMA8653::whatAmI()
{
return MICROBIT_ACCELEROMETER_MMA8653;
}

/**
* Destructor.
*/
Expand Down
10 changes: 10 additions & 0 deletions source/drivers/MicroBitAccelerometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,16 @@ uint16_t MicroBitAccelerometer::getGesture()
return lastGesture;
}

/**
* Returns which accelerometer is detected
*
* @return MICROBIT_ACCELEROMETER_XXX
*/
uint8_t MicroBitAccelerometer::whatAmI()
{
return MICROBIT_ACCELEROMETER_UNKNOWN;
}

/**
* Destructor for FXS8700, where we deregister from the array of fiber components.
*/
Expand Down