Changed to work with St Board
Dependencies: BLE_API X_NUCLEO_IDB0XA1 mbed
Fork of BLE_URIBeacon by
main.cpp@11:c77cc2b74101, 2015-01-21 (annotated)
- Committer:
- rgrover1
- Date:
- Wed Jan 21 10:14:04 2015 +0000
- Revision:
- 11:c77cc2b74101
- Parent:
- 9:e7f47bec97b8
- Child:
- 13:b82d8db73633
adding implementation for nrfURIBeaconConfigService, which ports the platform-agnostic URIBeaconConfigService to the nRF51822 and implements lock persistence.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 0:790a27ffc99b | 1 | /* mbed Microcontroller Library |
rgrover1 | 0:790a27ffc99b | 2 | * Copyright (c) 2006-2013 ARM Limited |
rgrover1 | 0:790a27ffc99b | 3 | * |
rgrover1 | 0:790a27ffc99b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 0:790a27ffc99b | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 0:790a27ffc99b | 6 | * You may obtain a copy of the License at |
rgrover1 | 0:790a27ffc99b | 7 | * |
rgrover1 | 0:790a27ffc99b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 0:790a27ffc99b | 9 | * |
rgrover1 | 0:790a27ffc99b | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 0:790a27ffc99b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 0:790a27ffc99b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 0:790a27ffc99b | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 0:790a27ffc99b | 14 | * limitations under the License. |
rgrover1 | 0:790a27ffc99b | 15 | */ |
rgrover1 | 0:790a27ffc99b | 16 | |
rgrover1 | 0:790a27ffc99b | 17 | #include "mbed.h" |
rgrover1 | 0:790a27ffc99b | 18 | #include "BLEDevice.h" |
rgrover1 | 11:c77cc2b74101 | 19 | #include "nrfURIBeaconConfigService.h" |
rgrover1 | 11:c77cc2b74101 | 20 | #include "DFUService.h" |
rgrover1 | 11:c77cc2b74101 | 21 | #include "DeviceInformationService.h" |
rgrover1 | 0:790a27ffc99b | 22 | |
rgrover1 | 0:790a27ffc99b | 23 | BLEDevice ble; |
rgrover1 | 0:790a27ffc99b | 24 | |
rgrover1 | 6:31b65d4ea67d | 25 | void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) |
rgrover1 | 6:31b65d4ea67d | 26 | { |
rgrover1 | 6:31b65d4ea67d | 27 | ble.startAdvertising(); |
rgrover1 | 6:31b65d4ea67d | 28 | } |
rgrover1 | 0:790a27ffc99b | 29 | |
rgrover1 | 0:790a27ffc99b | 30 | int main(void) |
rgrover1 | 0:790a27ffc99b | 31 | { |
rgrover1 | 0:790a27ffc99b | 32 | ble.init(); |
rgrover1 | 6:31b65d4ea67d | 33 | ble.onDisconnection(disconnectionCallback); |
rgrover1 | 0:790a27ffc99b | 34 | |
rgrover1 | 11:c77cc2b74101 | 35 | nrfURIBeaconConfigService uriBeaconConfig(ble, "http://www.mbed.org"); |
rgrover1 | 11:c77cc2b74101 | 36 | if (!uriBeaconConfig.configuredSuccessfully()) { |
rgrover1 | 6:31b65d4ea67d | 37 | error("failed to accommodate URI"); |
rgrover1 | 6:31b65d4ea67d | 38 | } |
rgrover1 | 7:6faec5978fb4 | 39 | /* optional use of the API offered by URIBeaconConfigService */ |
rgrover1 | 7:6faec5978fb4 | 40 | const int8_t powerLevels[] = {-20, -4, 0, 10}; |
rgrover1 | 11:c77cc2b74101 | 41 | uriBeaconConfig.setTxPowerLevels(powerLevels); |
rgrover1 | 11:c77cc2b74101 | 42 | uriBeaconConfig.setTxPowerMode(URIBeaconConfigService::TX_POWER_MODE_LOW); |
rgrover1 | 0:790a27ffc99b | 43 | |
rgrover1 | 11:c77cc2b74101 | 44 | /* Setup auxiliary services. */ |
rgrover1 | 11:c77cc2b74101 | 45 | DFUService dfu(ble); /* To allow over-the-air firmware udpates. optional. */ |
rgrover1 | 11:c77cc2b74101 | 46 | DeviceInformationService deviceInfo(ble, "ARM", "URIBeacon2", "SN1", "hw-rev1", "fw-rev1", "soft-rev1"); /* optional */ |
rgrover1 | 11:c77cc2b74101 | 47 | |
rgrover1 | 0:790a27ffc99b | 48 | ble.startAdvertising(); |
rgrover1 | 0:790a27ffc99b | 49 | |
rgrover1 | 0:790a27ffc99b | 50 | while (true) { |
rgrover1 | 0:790a27ffc99b | 51 | ble.waitForEvent(); |
rgrover1 | 0:790a27ffc99b | 52 | } |
rgrover1 | 0:790a27ffc99b | 53 | } |