Run on TY51822r3 board with ACC sensor (LIS3DH or BMC050)
Dependencies: BLE_API LIS3DH mbed nRF51822 BMC050 nRF51_LowPwr nRF51_Vdd
Fork of BLE_EddystoneBeacon_Service by
main.cpp@34:f6d4a699a1ea, 2015-11-26 (annotated)
- Committer:
- andresag
- Date:
- Thu Nov 26 16:36:04 2015 +0000
- Revision:
- 34:f6d4a699a1ea
- Parent:
- 33:862e6e0831ea
- Child:
- 35:c64495aac4d1
Update example to use latest version of BLE_API and nRF51822 library. Furthermore, the example now uses a new Eddystone implementation rather than the deprecated implementation under ble/services.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
screamer | 0:c04d932e96c9 | 1 | /* mbed Microcontroller Library |
mbedAustin | 32:41840b78597e | 2 | * Copyright (c) 2006-2013 ARM Limited |
screamer | 0:c04d932e96c9 | 3 | * |
screamer | 0:c04d932e96c9 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
screamer | 0:c04d932e96c9 | 5 | * you may not use this file except in compliance with the License. |
screamer | 0:c04d932e96c9 | 6 | * You may obtain a copy of the License at |
screamer | 0:c04d932e96c9 | 7 | * |
screamer | 0:c04d932e96c9 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
screamer | 0:c04d932e96c9 | 9 | * |
screamer | 0:c04d932e96c9 | 10 | * Unless required by applicable law or agreed to in writing, software |
screamer | 0:c04d932e96c9 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
screamer | 0:c04d932e96c9 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
screamer | 0:c04d932e96c9 | 13 | * See the License for the specific language governing permissions and |
screamer | 0:c04d932e96c9 | 14 | * limitations under the License. |
screamer | 0:c04d932e96c9 | 15 | */ |
screamer | 0:c04d932e96c9 | 16 | |
screamer | 0:c04d932e96c9 | 17 | #include "mbed.h" |
andresag | 34:f6d4a699a1ea | 18 | #include "ble/BLE.h" |
andresag | 34:f6d4a699a1ea | 19 | #include "EddystoneService.h" |
andresag | 34:f6d4a699a1ea | 20 | |
andresag | 34:f6d4a699a1ea | 21 | EddystoneService *eddyServicePtr; |
screamer | 0:c04d932e96c9 | 22 | |
andresag | 34:f6d4a699a1ea | 23 | void onBleInitError(BLE::InitializationCompleteCallbackContext* initContext) |
andresag | 34:f6d4a699a1ea | 24 | { |
andresag | 34:f6d4a699a1ea | 25 | /* Initialization error handling goes here... */ |
andresag | 34:f6d4a699a1ea | 26 | (void) initContext; |
andresag | 34:f6d4a699a1ea | 27 | } |
mbedAustin | 30:6c2db8bf5b17 | 28 | |
andresag | 34:f6d4a699a1ea | 29 | /* |
andresag | 34:f6d4a699a1ea | 30 | * Update TLM frame battery voltage value. |
andresag | 34:f6d4a699a1ea | 31 | */ |
andresag | 34:f6d4a699a1ea | 32 | uint16_t tlmBatteryVoltageCallback(uint16_t prevBatteryVoltage) |
andresag | 34:f6d4a699a1ea | 33 | { |
andresag | 34:f6d4a699a1ea | 34 | prevBatteryVoltage++; |
andresag | 34:f6d4a699a1ea | 35 | return prevBatteryVoltage; |
andresag | 34:f6d4a699a1ea | 36 | } |
mbedAustin | 30:6c2db8bf5b17 | 37 | |
andresag | 34:f6d4a699a1ea | 38 | /* |
andresag | 34:f6d4a699a1ea | 39 | * Update TLM frame beacon temperature value. |
andresag | 34:f6d4a699a1ea | 40 | */ |
andresag | 34:f6d4a699a1ea | 41 | uint16_t tlmBeaconTemperatureCallback(uint16_t prevBeaconTemperature) |
andresag | 34:f6d4a699a1ea | 42 | { |
andresag | 34:f6d4a699a1ea | 43 | prevBeaconTemperature++; |
andresag | 34:f6d4a699a1ea | 44 | return prevBeaconTemperature; |
mbedAustin | 30:6c2db8bf5b17 | 45 | } |
mbedAustin | 30:6c2db8bf5b17 | 46 | |
andresag | 34:f6d4a699a1ea | 47 | void bleInitComplete(BLE::InitializationCompleteCallbackContext* initContext) |
andresag | 34:f6d4a699a1ea | 48 | { |
andresag | 34:f6d4a699a1ea | 49 | BLE &ble = initContext->ble; |
andresag | 34:f6d4a699a1ea | 50 | ble_error_t error = initContext->error; |
andresag | 34:f6d4a699a1ea | 51 | |
andresag | 34:f6d4a699a1ea | 52 | if (error != BLE_ERROR_NONE) { |
andresag | 34:f6d4a699a1ea | 53 | onBleInitError(initContext); |
andresag | 34:f6d4a699a1ea | 54 | return; |
andresag | 34:f6d4a699a1ea | 55 | } |
andresag | 34:f6d4a699a1ea | 56 | |
andresag | 34:f6d4a699a1ea | 57 | /* Set UID and TLM frame data */ |
andresag | 34:f6d4a699a1ea | 58 | const UIDNamespaceID_t uidNamespaceID = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99}; |
andresag | 34:f6d4a699a1ea | 59 | const UIDInstanceID_t uidInstanceID = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}; |
andresag | 34:f6d4a699a1ea | 60 | uint8_t tlmVersion = 0x00; |
andresag | 34:f6d4a699a1ea | 61 | |
andresag | 34:f6d4a699a1ea | 62 | /* Initialize a EddystoneBeaconConfig service providing config params, default URI, and power levels. */ |
andresag | 34:f6d4a699a1ea | 63 | static const PowerLevels_t defaultAdvPowerLevels = {-47, -33, -21, -13}; // Values for ADV packets related to firmware levels, calibrated based on measured values at 1m |
andresag | 34:f6d4a699a1ea | 64 | static const PowerLevels_t radioPowerLevels = {-30, -16, -4, 4}; // Values for radio power levels, provided by manufacturer. |
andresag | 34:f6d4a699a1ea | 65 | |
andresag | 34:f6d4a699a1ea | 66 | /* Set everything to defaults */ |
andresag | 34:f6d4a699a1ea | 67 | eddyServicePtr = new EddystoneService(ble, defaultAdvPowerLevels, radioPowerLevels); |
andresag | 34:f6d4a699a1ea | 68 | |
andresag | 34:f6d4a699a1ea | 69 | /* Set default URL, UID and TLM frame data if not initialized through the config service */ |
andresag | 34:f6d4a699a1ea | 70 | eddyServicePtr->setURLData("http://mbed.org"); |
andresag | 34:f6d4a699a1ea | 71 | eddyServicePtr->setUIDData(&uidNamespaceID, &uidInstanceID); |
andresag | 34:f6d4a699a1ea | 72 | eddyServicePtr->setTLMData(tlmVersion); |
andresag | 34:f6d4a699a1ea | 73 | |
andresag | 34:f6d4a699a1ea | 74 | /* Set battery voltage and temperature callbacks */ |
andresag | 34:f6d4a699a1ea | 75 | eddyServicePtr->onTLMBatteryVoltageUpdate(tlmBatteryVoltageCallback); |
andresag | 34:f6d4a699a1ea | 76 | eddyServicePtr->onTLMBeaconTemperatureUpdate(tlmBeaconTemperatureCallback); |
andresag | 34:f6d4a699a1ea | 77 | |
andresag | 34:f6d4a699a1ea | 78 | /* Start Eddystone in config mode */ |
andresag | 34:f6d4a699a1ea | 79 | eddyServicePtr->startBeaconService(5, 5, 5); |
mbedAustin | 30:6c2db8bf5b17 | 80 | } |
screamer | 0:c04d932e96c9 | 81 | |
screamer | 0:c04d932e96c9 | 82 | int main(void) |
screamer | 0:c04d932e96c9 | 83 | { |
andresag | 34:f6d4a699a1ea | 84 | BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE); |
andresag | 34:f6d4a699a1ea | 85 | ble.init(bleInitComplete); |
andresag | 34:f6d4a699a1ea | 86 | |
andresag | 34:f6d4a699a1ea | 87 | /* SpinWait for initialization to complete. This is necessary because the |
andresag | 34:f6d4a699a1ea | 88 | * BLE object is used in the main loop below. */ |
andresag | 34:f6d4a699a1ea | 89 | while (ble.hasInitialized() == false) { /* spin loop */ } |
mbedAustin | 32:41840b78597e | 90 | |
screamer | 0:c04d932e96c9 | 91 | while (true) { |
andresag | 34:f6d4a699a1ea | 92 | ble.waitForEvent(); /* this will return upon any system event (such as an interrupt or a ticker wakeup) */ |
screamer | 0:c04d932e96c9 | 93 | } |
screamer | 0:c04d932e96c9 | 94 | } |