Solution for Bluetooth SIG hands-on training course
Dependencies: BLE_API mbed-dev-bin nRF51822-bluetooth-mdw
Fork of microbit-dal-bluetooth-mdw_starter by
MicroBitMagnetometerService.h
00001 /* 00002 The MIT License (MIT) 00003 00004 Copyright (c) 2016 British Broadcasting Corporation. 00005 This software is provided by Lancaster University by arrangement with the BBC. 00006 00007 Permission is hereby granted, free of charge, to any person obtaining a 00008 copy of this software and associated documentation files (the "Software"), 00009 to deal in the Software without restriction, including without limitation 00010 the rights to use, copy, modify, merge, publish, distribute, sublicense, 00011 and/or sell copies of the Software, and to permit persons to whom the 00012 Software is furnished to do so, subject to the following conditions: 00013 00014 The above copyright notice and this permission notice shall be included in 00015 all copies or substantial portions of the Software. 00016 00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00020 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00021 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00022 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00023 DEALINGS IN THE SOFTWARE. 00024 */ 00025 00026 #ifndef MICROBIT_MAGNETOMETER_SERVICE_H 00027 #define MICROBIT_MAGNETOMETER_SERVICE_H 00028 00029 #include "ble/BLE.h" 00030 #include "MicroBitConfig.h" 00031 #include "MicroBitCompass.h" 00032 #include "EventModel.h" 00033 00034 // UUIDs for our service and characteristics 00035 extern const uint8_t MicroBitMagnetometerServiceUUID[]; 00036 extern const uint8_t MicroBitMagnetometerServiceDataUUID[]; 00037 extern const uint8_t MicroBitMagnetometerServiceBearingUUID[]; 00038 extern const uint8_t MicroBitMagnetometerServicePeriodUUID[]; 00039 00040 00041 /** 00042 * Class definition for the MicroBit BLE Magnetometer Service. 00043 * Provides access to live magnetometer data via BLE, and provides basic configuration options. 00044 */ 00045 class MicroBitMagnetometerService 00046 { 00047 public: 00048 00049 /** 00050 * Constructor. 00051 * Create a representation of the MagnetometerService. 00052 * @param _ble The instance of a BLE device that we're running on. 00053 * @param _compass An instance of MicroBitCompass to use as our Magnetometer source. 00054 */ 00055 MicroBitMagnetometerService(BLEDevice &_ble, MicroBitCompass &_compass); 00056 00057 private: 00058 00059 /** 00060 * Callback. Invoked when any of our attributes are written via BLE. 00061 */ 00062 void onDataWritten(const GattWriteCallbackParams *params); 00063 00064 /** 00065 * Magnetometer update callback 00066 */ 00067 void magnetometerUpdate(MicroBitEvent e); 00068 00069 /** 00070 * Sample Period Change Needed callback. 00071 * Reconfiguring the magnetometer can to a REALLY long time (sometimes even seconds to complete) 00072 * So we do this in the background when necessary, through this event handler. 00073 */ 00074 void samplePeriodUpdateNeeded(MicroBitEvent e); 00075 00076 // Bluetooth stack we're running on. 00077 BLEDevice &ble; 00078 MicroBitCompass &compass; 00079 00080 // memory for our 8 bit control characteristics. 00081 int16_t magnetometerDataCharacteristicBuffer[3]; 00082 uint16_t magnetometerBearingCharacteristicBuffer; 00083 uint16_t magnetometerPeriodCharacteristicBuffer; 00084 00085 // Handles to access each characteristic when they are held by Soft Device. 00086 GattAttribute::Handle_t magnetometerDataCharacteristicHandle; 00087 GattAttribute::Handle_t magnetometerBearingCharacteristicHandle; 00088 GattAttribute::Handle_t magnetometerPeriodCharacteristicHandle; 00089 }; 00090 00091 #endif
Generated on Tue Jul 12 2022 20:39:13 by 1.7.2