![](/media/cache/profiles/909f269e0b3ffbd61d906f9b25eecaf6.jpg.50x50_q85.jpg)
a hack to use buttons to fake a cube puck
Dependencies: MPU6050 Puck mbed
Fork of cube-puck by
main.cpp@12:a7051fc219b8, 2015-03-11 (annotated)
- Committer:
- stiaje
- Date:
- Wed Mar 11 17:26:36 2015 +0000
- Revision:
- 12:a7051fc219b8
- Parent:
- 10:3d708495b7a0
Make a button-hack-puck
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cristea | 7:4f2aaa06ff44 | 1 | /** |
cristea | 7:4f2aaa06ff44 | 2 | * Copyright 2014 Nordic Semiconductor |
cristea | 7:4f2aaa06ff44 | 3 | * |
cristea | 7:4f2aaa06ff44 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
cristea | 7:4f2aaa06ff44 | 5 | * you may not use this file except in compliance with the License. |
cristea | 7:4f2aaa06ff44 | 6 | * You may obtain a copy of the License at |
cristea | 7:4f2aaa06ff44 | 7 | * |
cristea | 7:4f2aaa06ff44 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
cristea | 7:4f2aaa06ff44 | 9 | * |
cristea | 7:4f2aaa06ff44 | 10 | * Unless required by applicable law or agreed to in writing, software |
cristea | 7:4f2aaa06ff44 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
cristea | 7:4f2aaa06ff44 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
cristea | 7:4f2aaa06ff44 | 13 | * See the License for the specific language governing permissions and |
cristea | 7:4f2aaa06ff44 | 14 | * limitations under the License |
cristea | 7:4f2aaa06ff44 | 15 | */ |
cristea | 7:4f2aaa06ff44 | 16 | |
sigveseb | 3:6a7310ea51f7 | 17 | #include "Puck.h" |
sigveseb | 3:6a7310ea51f7 | 18 | |
sigveseb | 3:6a7310ea51f7 | 19 | Puck* puck = &Puck::getPuck(); |
sigveseb | 3:6a7310ea51f7 | 20 | |
stiaje | 6:fc59099597cd | 21 | const UUID CUBE_SERVICE_UUID = stringToUUID("bftj cube "); |
stiaje | 6:fc59099597cd | 22 | const UUID DIRECTION_UUID = stringToUUID("bftj cube dirctn"); |
aleksanb | 0:449ee9595cf6 | 23 | |
aleksanb | 0:449ee9595cf6 | 24 | |
stiaje | 12:a7051fc219b8 | 25 | InterruptIn myButton(P0_16); |
stiaje | 12:a7051fc219b8 | 26 | InterruptIn button2(P0_17); |
aleksanb | 0:449ee9595cf6 | 27 | |
stiaje | 12:a7051fc219b8 | 28 | uint8_t buttonHasBeenPressed = 0; |
aleksanb | 0:449ee9595cf6 | 29 | |
stiaje | 12:a7051fc219b8 | 30 | void callback() { |
stiaje | 12:a7051fc219b8 | 31 | buttonHasBeenPressed = 1; |
aleksanb | 2:b9b42ff80e9a | 32 | } |
stiaje | 12:a7051fc219b8 | 33 | void callback2() { |
stiaje | 12:a7051fc219b8 | 34 | buttonHasBeenPressed = 2; |
stiaje | 12:a7051fc219b8 | 35 | } |
aleksanb | 2:b9b42ff80e9a | 36 | |
sigveseb | 3:6a7310ea51f7 | 37 | int main() { |
sigveseb | 3:6a7310ea51f7 | 38 | |
stiaje | 12:a7051fc219b8 | 39 | myButton.rise(&callback); |
stiaje | 12:a7051fc219b8 | 40 | myButton.enable_irq(); |
aleksanb | 2:b9b42ff80e9a | 41 | |
stiaje | 12:a7051fc219b8 | 42 | button2.rise(&callback2); |
stiaje | 12:a7051fc219b8 | 43 | button2.enable_irq(); |
aleksanb | 0:449ee9595cf6 | 44 | |
sigveseb | 4:6a2b306b6b41 | 45 | int characteristicValueLength = 1; |
sigveseb | 3:6a7310ea51f7 | 46 | puck->addCharacteristic( |
sigveseb | 3:6a7310ea51f7 | 47 | CUBE_SERVICE_UUID, |
sigveseb | 3:6a7310ea51f7 | 48 | DIRECTION_UUID, |
sigveseb | 4:6a2b306b6b41 | 49 | characteristicValueLength, |
sigveseb | 3:6a7310ea51f7 | 50 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); |
sigveseb | 3:6a7310ea51f7 | 51 | |
cristea | 7:4f2aaa06ff44 | 52 | puck->init(0xC1BE); |
sigveseb | 3:6a7310ea51f7 | 53 | |
stiaje | 12:a7051fc219b8 | 54 | while(puck->drive()) { |
stiaje | 12:a7051fc219b8 | 55 | if (buttonHasBeenPressed) { |
stiaje | 12:a7051fc219b8 | 56 | /* do stuff */ |
stiaje | 12:a7051fc219b8 | 57 | int length = 1; |
stiaje | 12:a7051fc219b8 | 58 | puck->updateCharacteristicValue(DIRECTION_UUID, &buttonHasBeenPressed, length); |
stiaje | 12:a7051fc219b8 | 59 | |
stiaje | 12:a7051fc219b8 | 60 | // Reset |
stiaje | 12:a7051fc219b8 | 61 | buttonHasBeenPressed = 0; |
stiaje | 12:a7051fc219b8 | 62 | } |
stiaje | 12:a7051fc219b8 | 63 | } |
aleksanb | 0:449ee9595cf6 | 64 | } |