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

BLE - make Device Info Service Model Number String sensitive to board ID #114

Merged
merged 2 commits into from
Aug 9, 2021
Merged
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
2 changes: 1 addition & 1 deletion inc/bluetooth/MicroBitBLEManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class MicroBitBLEManager : public CodalComponent
* bleManager.init(uBit.getName(), uBit.getSerial(), uBit.messageBus, true);
* @endcode
*/
void init(ManagedString deviceName, ManagedString serialNumber, EventModel &messageBus, MicroBitStorage &keyValuestorage, bool enableBonding);
void init(ManagedString deviceName, ManagedString serialNumber, EventModel &messageBus, MicroBitStorage &keyValuestorage, bool enableBonding, uint16_t board = 0x9904);

/**
* Change the output power level of the transmitter to the given value.
Expand Down
8 changes: 6 additions & 2 deletions model/MicroBit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ int MicroBit::init()
NVIC_SetPriority(UARTE0_UART0_IRQn, 2); // Serial port
NVIC_SetPriority(GPIOTE_IRQn, 2); // Pin interrupt events

#if CONFIG_ENABLED(DEVICE_BLE) && ( CONFIG_ENABLED(MICROBIT_BLE_PAIRING_MODE) || CONFIG_ENABLED(MICROBIT_BLE_ENABLED))
MicroBitVersion version = power.getVersion();
#endif

#if CONFIG_ENABLED(DEVICE_BLE) && CONFIG_ENABLED(MICROBIT_BLE_PAIRING_MODE)
int i=0;
// Test if we need to enter BLE pairing mode
Expand Down Expand Up @@ -237,7 +241,7 @@ int MicroBit::init()
delete flashIncomplete;

// Start the BLE stack, if it isn't already running.
bleManager.init( ManagedString( microbit_friendly_name()), getSerial(), messageBus, storage, true);
bleManager.init( ManagedString( microbit_friendly_name()), getSerial(), messageBus, storage, true, version.board);

// Enter pairing mode, using the LED matrix for any necessary pairing operations
bleManager.pairingMode(display, buttonA);
Expand All @@ -247,7 +251,7 @@ int MicroBit::init()

#if CONFIG_ENABLED(DEVICE_BLE) && CONFIG_ENABLED(MICROBIT_BLE_ENABLED)
// Start the BLE stack, if it isn't already running.
bleManager.init( ManagedString( microbit_friendly_name()), getSerial(), messageBus, storage, false);
bleManager.init( ManagedString( microbit_friendly_name()), getSerial(), messageBus, storage, false, version.board);
#endif

// Deschedule for a little while, just to allow for any components that finialise initialisation
Expand Down
15 changes: 12 additions & 3 deletions source/bluetooth/MicroBitBLEManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ DEALINGS IN THE SOFTWARE.

const char *MICROBIT_BLE_MANUFACTURER = NULL;
const char *MICROBIT_BLE_MODEL = "BBC micro:bit";
const char *MICROBIT_BLE_VERSION[2] = { "2.0", "2.X" };
const char *MICROBIT_BLE_HARDWARE_VERSION = NULL;
const char *MICROBIT_BLE_FIRMWARE_VERSION = MICROBIT_DAL_VERSION;
const char *MICROBIT_BLE_SOFTWARE_VERSION = NULL;
Expand Down Expand Up @@ -228,7 +229,7 @@ MicroBitBLEManager *MicroBitBLEManager::getInstance()
* bleManager.init(uBit.getName(), uBit.getSerial(), uBit.messageBus, true);
* @endcode
*/
void MicroBitBLEManager::init( ManagedString deviceName, ManagedString serialNumber, EventModel &messageBus, MicroBitStorage &keyValueStorage, bool enableBonding)
void MicroBitBLEManager::init( ManagedString deviceName, ManagedString serialNumber, EventModel &messageBus, MicroBitStorage &keyValueStorage, bool enableBonding, uint16_t board)
{
if ( this->status & DEVICE_COMPONENT_RUNNING)
return;
Expand Down Expand Up @@ -436,9 +437,17 @@ void MicroBitBLEManager::init( ManagedString deviceName, ManagedString serialNum
#if CONFIG_ENABLED(MICROBIT_BLE_DEVICE_INFORMATION_SERVICE)
MICROBIT_DEBUG_DMESG( "DEVICE_INFORMATION_SERVICE");

ManagedString modelVersion("V2.0"); // TODO use a calculated version
int versionIdx = 0;
switch ( board)
{
case 0x9903:
case 0x9904: break;
default: versionIdx = 1; break;
}

ManagedString modelVersion( MICROBIT_BLE_VERSION[versionIdx]);
ManagedString disName( MICROBIT_BLE_MODEL);
disName = disName + " " + modelVersion;
disName = disName + " V" + modelVersion;

ble_dis_init_t disi;
memset( &disi, 0, sizeof(disi));
Expand Down