Knight Rider PIO sample for teckBASIC, konashi.js
Dependencies: BLE_API_Native_IRC mbed
Fork of BLE_konashi_PIO_test by
konashi.js mbed HRM1017でもナイトライダー!: http://jsdo.it/micutil/g1Hn
サンプル動画: https://www.youtube.com/watch?v=HSLdzS3sGLw
techBASICサンプル: https://www.dropbox.com/s/c1k25jlen7x3vqo/KnightRider.txt
BLE_API_Native_IRC/hw/Gap.h@2:6a3257fffa8c, 2014-07-27 (annotated)
- Committer:
- micono
- Date:
- Sun Jul 27 00:02:25 2014 +0000
- Revision:
- 2:6a3257fffa8c
- Parent:
- 0:8c643bfe55b7
PIO sample for teckBASIC, konashi.js
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:8c643bfe55b7 | 1 | /* mbed Microcontroller Library |
jksoft | 0:8c643bfe55b7 | 2 | * Copyright (c) 2006-2013 ARM Limited |
jksoft | 0:8c643bfe55b7 | 3 | * |
jksoft | 0:8c643bfe55b7 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
jksoft | 0:8c643bfe55b7 | 5 | * you may not use this file except in compliance with the License. |
jksoft | 0:8c643bfe55b7 | 6 | * You may obtain a copy of the License at |
jksoft | 0:8c643bfe55b7 | 7 | * |
jksoft | 0:8c643bfe55b7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
jksoft | 0:8c643bfe55b7 | 9 | * |
jksoft | 0:8c643bfe55b7 | 10 | * Unless required by applicable law or agreed to in writing, software |
jksoft | 0:8c643bfe55b7 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
jksoft | 0:8c643bfe55b7 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
jksoft | 0:8c643bfe55b7 | 13 | * See the License for the specific language governing permissions and |
jksoft | 0:8c643bfe55b7 | 14 | * limitations under the License. |
jksoft | 0:8c643bfe55b7 | 15 | */ |
jksoft | 0:8c643bfe55b7 | 16 | |
jksoft | 0:8c643bfe55b7 | 17 | #ifndef __GAP_H__ |
jksoft | 0:8c643bfe55b7 | 18 | #define __GAP_H__ |
jksoft | 0:8c643bfe55b7 | 19 | |
jksoft | 0:8c643bfe55b7 | 20 | #include "mbed.h" |
jksoft | 0:8c643bfe55b7 | 21 | #include "blecommon.h" |
jksoft | 0:8c643bfe55b7 | 22 | #include "GapAdvertisingData.h" |
jksoft | 0:8c643bfe55b7 | 23 | #include "GapAdvertisingParams.h" |
jksoft | 0:8c643bfe55b7 | 24 | #include "GapEvents.h" |
jksoft | 0:8c643bfe55b7 | 25 | |
jksoft | 0:8c643bfe55b7 | 26 | /**************************************************************************/ |
jksoft | 0:8c643bfe55b7 | 27 | /*! |
jksoft | 0:8c643bfe55b7 | 28 | \brief |
jksoft | 0:8c643bfe55b7 | 29 | The base class used to abstract GAP functionality to a specific radio |
jksoft | 0:8c643bfe55b7 | 30 | transceiver, SOC or BLE Stack. |
jksoft | 0:8c643bfe55b7 | 31 | */ |
jksoft | 0:8c643bfe55b7 | 32 | /**************************************************************************/ |
jksoft | 0:8c643bfe55b7 | 33 | class Gap |
jksoft | 0:8c643bfe55b7 | 34 | { |
jksoft | 0:8c643bfe55b7 | 35 | private: |
jksoft | 0:8c643bfe55b7 | 36 | GapEvents *m_pEventHandler; |
jksoft | 0:8c643bfe55b7 | 37 | |
jksoft | 0:8c643bfe55b7 | 38 | public: |
jksoft | 0:8c643bfe55b7 | 39 | /* These functions must be defined in the sub-class */ |
jksoft | 0:8c643bfe55b7 | 40 | virtual ble_error_t setAdvertisingData(GapAdvertisingData &, GapAdvertisingData &) = 0; |
jksoft | 0:8c643bfe55b7 | 41 | virtual ble_error_t startAdvertising(GapAdvertisingParams &) = 0; |
jksoft | 0:8c643bfe55b7 | 42 | virtual ble_error_t stopAdvertising(void) = 0; |
jksoft | 0:8c643bfe55b7 | 43 | virtual ble_error_t disconnect(void) = 0; |
jksoft | 0:8c643bfe55b7 | 44 | |
jksoft | 0:8c643bfe55b7 | 45 | /* Describes the current state of the device (more than one bit can be set) */ |
jksoft | 0:8c643bfe55b7 | 46 | typedef struct GapState_s |
jksoft | 0:8c643bfe55b7 | 47 | { |
jksoft | 0:8c643bfe55b7 | 48 | unsigned advertising : 1; /**< The device is current advertising */ |
jksoft | 0:8c643bfe55b7 | 49 | unsigned connected : 1; /**< The peripheral is connected to a central device */ |
jksoft | 0:8c643bfe55b7 | 50 | } GapState_t; |
jksoft | 0:8c643bfe55b7 | 51 | |
jksoft | 0:8c643bfe55b7 | 52 | /* Event callback handlers */ |
jksoft | 0:8c643bfe55b7 | 53 | void setEventHandler(GapEvents *pEventHandler) {m_pEventHandler = pEventHandler;} |
jksoft | 0:8c643bfe55b7 | 54 | void handleEvent(GapEvents::gapEvent_e type) { |
jksoft | 0:8c643bfe55b7 | 55 | if (NULL == m_pEventHandler) |
jksoft | 0:8c643bfe55b7 | 56 | return; |
jksoft | 0:8c643bfe55b7 | 57 | switch(type) { |
jksoft | 0:8c643bfe55b7 | 58 | case GapEvents::GAP_EVENT_TIMEOUT: |
jksoft | 0:8c643bfe55b7 | 59 | state.advertising = 0; |
jksoft | 0:8c643bfe55b7 | 60 | m_pEventHandler->onTimeout(); |
jksoft | 0:8c643bfe55b7 | 61 | break; |
jksoft | 0:8c643bfe55b7 | 62 | case GapEvents::GAP_EVENT_CONNECTED: |
jksoft | 0:8c643bfe55b7 | 63 | state.connected = 1; |
jksoft | 0:8c643bfe55b7 | 64 | m_pEventHandler->onConnected(); |
jksoft | 0:8c643bfe55b7 | 65 | break; |
jksoft | 0:8c643bfe55b7 | 66 | case GapEvents::GAP_EVENT_DISCONNECTED: |
jksoft | 0:8c643bfe55b7 | 67 | state.connected = 0; |
jksoft | 0:8c643bfe55b7 | 68 | m_pEventHandler->onDisconnected(); |
jksoft | 0:8c643bfe55b7 | 69 | break; |
jksoft | 0:8c643bfe55b7 | 70 | } |
jksoft | 0:8c643bfe55b7 | 71 | } |
jksoft | 0:8c643bfe55b7 | 72 | |
jksoft | 0:8c643bfe55b7 | 73 | GapState_t state; |
jksoft | 0:8c643bfe55b7 | 74 | }; |
jksoft | 0:8c643bfe55b7 | 75 | |
jksoft | 0:8c643bfe55b7 | 76 | #endif |