Example Puck (BLE)

Dependencies:   Puck mbed

The example puck will give your smartphone context about its whereabouts, as well as set up a simple Gatt characteristic. You can later set up rules for what should happen at different locations in the smartphone companion application (Puck Central).

Tutorials for the different Pucks (location, cube, IR) and in-depth documentation for the Puck platform is available at the project's GitHub page

Committer:
aleksanb
Date:
Mon Mar 09 13:41:03 2015 +0000
Revision:
4:552bda03c07a
Parent:
3:76ff01e97555
Add power usage note, update puck lib dependency.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aleksanb 0:8d7583961274 1 /**
aleksanb 0:8d7583961274 2 * Copyright 2014 Nordic Semiconductor
aleksanb 0:8d7583961274 3 *
aleksanb 0:8d7583961274 4 * Licensed under the Apache License, Version 2.0 (the "License");
aleksanb 0:8d7583961274 5 * you may not use this file except in compliance with the License.
aleksanb 0:8d7583961274 6 * You may obtain a copy of the License at
aleksanb 0:8d7583961274 7 *
aleksanb 0:8d7583961274 8 * http://www.apache.org/licenses/LICENSE-2.0
aleksanb 0:8d7583961274 9 *
aleksanb 0:8d7583961274 10 * Unless required by applicable law or agreed to in writing, software
aleksanb 0:8d7583961274 11 * distributed under the License is distributed on an "AS IS" BASIS,
aleksanb 0:8d7583961274 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
aleksanb 0:8d7583961274 13 * See the License for the specific language governing permissions and
aleksanb 0:8d7583961274 14 * limitations under the License
aleksanb 0:8d7583961274 15 */
aleksanb 0:8d7583961274 16
aleksanb 0:8d7583961274 17 #define LOG_LEVEL_INFO
aleksanb 4:552bda03c07a 18
aleksanb 4:552bda03c07a 19 /**
aleksanb 4:552bda03c07a 20 * Warning: remove LOG_LEVEL_* defines in production for major power savings.
aleksanb 4:552bda03c07a 21 *
aleksanb 4:552bda03c07a 22 * Defining a log level will set up a serial connection to use for logging.
aleksanb 4:552bda03c07a 23 * This serial connection sets up a timer prohibiting the mbed chip
aleksanb 4:552bda03c07a 24 * from entering low power states, drawing ~1.4mAh instead of ~20µAh with logging disabled.
aleksanb 4:552bda03c07a 25 */
aleksanb 4:552bda03c07a 26
aleksanb 0:8d7583961274 27 #include "Puck.h"
aleksanb 0:8d7583961274 28
aleksanb 0:8d7583961274 29 Puck* puck = &Puck::getPuck();
aleksanb 0:8d7583961274 30
aleksanb 0:8d7583961274 31 // Sample Gatt characteristic and service UUIDs
aleksanb 4:552bda03c07a 32 const UUID SAMPLE_GATT_SERVICE = stringToUUID("bftj http post ");
aleksanb 4:552bda03c07a 33 const UUID SAMPLE_GATT_CHARACTERISTIC = stringToUUID("bftj post body ");
aleksanb 0:8d7583961274 34
aleksanb 0:8d7583961274 35 int main(void) {
aleksanb 0:8d7583961274 36 // Add the Gatt characteristic
aleksanb 0:8d7583961274 37 int characteristicValueLength = 1;
aleksanb 0:8d7583961274 38 puck->addCharacteristic(
aleksanb 0:8d7583961274 39 SAMPLE_GATT_SERVICE,
aleksanb 0:8d7583961274 40 SAMPLE_GATT_CHARACTERISTIC,
aleksanb 0:8d7583961274 41 characteristicValueLength,
aleksanb 0:8d7583961274 42 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
aleksanb 0:8d7583961274 43
aleksanb 0:8d7583961274 44 // Initialize the puck
aleksanb 0:8d7583961274 45 puck->init(0xFEED);
aleksanb 0:8d7583961274 46
aleksanb 0:8d7583961274 47 // Set the initial value of the characteristic
aleksanb 0:8d7583961274 48 uint8_t new_value = 42;
aleksanb 0:8d7583961274 49 puck->updateCharacteristicValue(SAMPLE_GATT_CHARACTERISTIC, &new_value, characteristicValueLength);
aleksanb 0:8d7583961274 50
aleksanb 3:76ff01e97555 51 // Let the puck do its thing
aleksanb 0:8d7583961274 52 while(puck->drive());
aleksanb 0:8d7583961274 53 }