microbit: BUGFIX Prevent BLE Magnetometer service from initiating compass

calibration

MicroBitCompass initiates a calibration procedure on demand if a heading is
requested from an uncalibrated device. The BLE MagnetometerService also
attempts to retrieve a heading periodically, but it is not good behaviour to
initiate calibration as a response to this.

This patch introduces a check such that the BLE MagnetometerService will only
attempt to read heading data from a previously calibrated compass.
This commit is contained in:
Joe Finney 2016-01-19 00:32:02 +00:00
parent d2e1798258
commit a4c0915fff

View file

@ -81,12 +81,16 @@ void MicroBitMagnetometerService::magnetometerUpdate(MicroBitEvent e)
magnetometerDataCharacteristicBuffer[0] = uBit.compass.getX();
magnetometerDataCharacteristicBuffer[1] = uBit.compass.getY();
magnetometerDataCharacteristicBuffer[2] = uBit.compass.getZ();
magnetometerBearingCharacteristicBuffer = (uint16_t) uBit.compass.heading();
magnetometerPeriodCharacteristicBuffer = uBit.compass.getPeriod();
ble.gattServer().write(magnetometerPeriodCharacteristicHandle, (const uint8_t *)&magnetometerPeriodCharacteristicBuffer, sizeof(magnetometerPeriodCharacteristicBuffer));
ble.gattServer().notify(magnetometerDataCharacteristicHandle,(uint8_t *)magnetometerDataCharacteristicBuffer, sizeof(magnetometerDataCharacteristicBuffer));
ble.gattServer().notify(magnetometerBearingCharacteristicHandle,(uint8_t *)&magnetometerBearingCharacteristicBuffer, sizeof(magnetometerBearingCharacteristicBuffer));
if (uBit.compass.isCalibrated())
{
magnetometerBearingCharacteristicBuffer = (uint16_t) uBit.compass.heading();
ble.gattServer().notify(magnetometerBearingCharacteristicHandle,(uint8_t *)&magnetometerBearingCharacteristicBuffer, sizeof(magnetometerBearingCharacteristicBuffer));
}
}
}