Knight Rider PIO sample for teckBASIC, konashi.js

Dependencies:   BLE_API_Native_IRC mbed

Fork of BLE_konashi_PIO_test by Michio Ono

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

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?

UserRevisionLine numberNew 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 #include <stdio.h>
jksoft 0:8c643bfe55b7 18 #include <string.h>
jksoft 0:8c643bfe55b7 19
jksoft 0:8c643bfe55b7 20 #include "blecommon.h"
jksoft 0:8c643bfe55b7 21 #include "GapAdvertisingParams.h"
jksoft 0:8c643bfe55b7 22
jksoft 0:8c643bfe55b7 23 /**************************************************************************/
jksoft 0:8c643bfe55b7 24 /*!
jksoft 0:8c643bfe55b7 25 \brief
jksoft 0:8c643bfe55b7 26 Instantiates a new GapAdvertisingParams instance
jksoft 0:8c643bfe55b7 27
jksoft 0:8c643bfe55b7 28 \param[in] advType
jksoft 0:8c643bfe55b7 29 The GAP advertising mode to use for this device. Valid
jksoft 0:8c643bfe55b7 30 values are defined in AdvertisingType:
jksoft 0:8c643bfe55b7 31
jksoft 0:8c643bfe55b7 32 \par ADV_NON_CONNECTABLE_UNDIRECTED
jksoft 0:8c643bfe55b7 33 All connections to the peripheral device will be refused.
jksoft 0:8c643bfe55b7 34
jksoft 0:8c643bfe55b7 35 \par ADV_CONNECTABLE_DIRECTED
jksoft 0:8c643bfe55b7 36 Only connections from a pre-defined central device will be
jksoft 0:8c643bfe55b7 37 accepted.
jksoft 0:8c643bfe55b7 38
jksoft 0:8c643bfe55b7 39 \par ADV_CONNECTABLE_UNDIRECTED
jksoft 0:8c643bfe55b7 40 Any central device can connect to this peripheral.
jksoft 0:8c643bfe55b7 41
jksoft 0:8c643bfe55b7 42 \par ADV_SCANNABLE_UNDIRECTED
jksoft 0:8c643bfe55b7 43 Any central device can connect to this peripheral, and
jksoft 0:8c643bfe55b7 44 the secondary Scan Response payload will be included or
jksoft 0:8c643bfe55b7 45 available to central devices.
jksoft 0:8c643bfe55b7 46
jksoft 0:8c643bfe55b7 47 \par
jksoft 0:8c643bfe55b7 48 See Bluetooth Core Specification 4.0 (Vol. 3), Part C,
jksoft 0:8c643bfe55b7 49 Section 9.3 and Core Specification 4.0 (Vol. 6), Part B,
jksoft 0:8c643bfe55b7 50 Section 2.3.1 for further information on GAP connection
jksoft 0:8c643bfe55b7 51 modes
jksoft 0:8c643bfe55b7 52
jksoft 0:8c643bfe55b7 53 \param[in] interval
jksoft 0:8c643bfe55b7 54 Advertising interval between 0x0020 and 0x4000 in 0.625ms
jksoft 0:8c643bfe55b7 55 units (20ms to 10.24s). If using non-connectable mode
jksoft 0:8c643bfe55b7 56 (ADV_NON_CONNECTABLE_UNDIRECTED) this min value is
jksoft 0:8c643bfe55b7 57 0x00A0 (100ms).
jksoft 0:8c643bfe55b7 58
jksoft 0:8c643bfe55b7 59 \par
jksoft 0:8c643bfe55b7 60 Increasing this value will allow central devices to detect
jksoft 0:8c643bfe55b7 61 your peripheral faster at the expense of more power being
jksoft 0:8c643bfe55b7 62 used by the radio due to the higher data transmit rate.
jksoft 0:8c643bfe55b7 63
jksoft 0:8c643bfe55b7 64 \par
jksoft 0:8c643bfe55b7 65 This field must be set to 0 if connectionMode is equal
jksoft 0:8c643bfe55b7 66 to ADV_CONNECTABLE_DIRECTED
jksoft 0:8c643bfe55b7 67
jksoft 0:8c643bfe55b7 68 \par
jksoft 0:8c643bfe55b7 69 See Bluetooth Core Specification, Vol 3., Part C,
jksoft 0:8c643bfe55b7 70 Appendix A for suggested advertising intervals.
jksoft 0:8c643bfe55b7 71
jksoft 0:8c643bfe55b7 72 \param[in] timeout
jksoft 0:8c643bfe55b7 73 Advertising timeout between 0x1 and 0x3FFF (1 and 16383)
jksoft 0:8c643bfe55b7 74 in seconds. Enter 0 to disable the advertising timeout.
jksoft 0:8c643bfe55b7 75
jksoft 0:8c643bfe55b7 76 \par EXAMPLE
jksoft 0:8c643bfe55b7 77
jksoft 0:8c643bfe55b7 78 \code
jksoft 0:8c643bfe55b7 79
jksoft 0:8c643bfe55b7 80 \endcode
jksoft 0:8c643bfe55b7 81 */
jksoft 0:8c643bfe55b7 82 /**************************************************************************/
jksoft 0:8c643bfe55b7 83 GapAdvertisingParams::GapAdvertisingParams(AdvertisingType advType, uint16_t interval, uint16_t timeout)
jksoft 0:8c643bfe55b7 84 {
jksoft 0:8c643bfe55b7 85 _advType = advType;
jksoft 0:8c643bfe55b7 86 _interval = interval;
jksoft 0:8c643bfe55b7 87 _timeout = timeout;
jksoft 0:8c643bfe55b7 88
jksoft 0:8c643bfe55b7 89 /* Interval checks */
jksoft 0:8c643bfe55b7 90 if (_advType == ADV_CONNECTABLE_DIRECTED)
jksoft 0:8c643bfe55b7 91 {
jksoft 0:8c643bfe55b7 92 /* Interval must be 0 in directed connectable mode */
jksoft 0:8c643bfe55b7 93 _interval = 0;
jksoft 0:8c643bfe55b7 94 }
jksoft 0:8c643bfe55b7 95 else if (_advType == ADV_NON_CONNECTABLE_UNDIRECTED)
jksoft 0:8c643bfe55b7 96 {
jksoft 0:8c643bfe55b7 97 /* Min interval is slightly larger than in other modes */
jksoft 0:8c643bfe55b7 98 if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN_NONCON)
jksoft 0:8c643bfe55b7 99 {
jksoft 0:8c643bfe55b7 100 _interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON;
jksoft 0:8c643bfe55b7 101 }
jksoft 0:8c643bfe55b7 102 if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX)
jksoft 0:8c643bfe55b7 103 {
jksoft 0:8c643bfe55b7 104 _interval = GAP_ADV_PARAMS_INTERVAL_MAX;
jksoft 0:8c643bfe55b7 105 }
jksoft 0:8c643bfe55b7 106 }
jksoft 0:8c643bfe55b7 107 else
jksoft 0:8c643bfe55b7 108 {
jksoft 0:8c643bfe55b7 109 /* Stay within interval limits */
jksoft 0:8c643bfe55b7 110 if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN)
jksoft 0:8c643bfe55b7 111 {
jksoft 0:8c643bfe55b7 112 _interval = GAP_ADV_PARAMS_INTERVAL_MIN;
jksoft 0:8c643bfe55b7 113 }
jksoft 0:8c643bfe55b7 114 if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX)
jksoft 0:8c643bfe55b7 115 {
jksoft 0:8c643bfe55b7 116 _interval = GAP_ADV_PARAMS_INTERVAL_MAX;
jksoft 0:8c643bfe55b7 117 }
jksoft 0:8c643bfe55b7 118 }
jksoft 0:8c643bfe55b7 119
jksoft 0:8c643bfe55b7 120 /* Timeout checks */
jksoft 0:8c643bfe55b7 121 if (timeout)
jksoft 0:8c643bfe55b7 122 {
jksoft 0:8c643bfe55b7 123 /* Stay within timeout limits */
jksoft 0:8c643bfe55b7 124 if (_timeout > GAP_ADV_PARAMS_TIMEOUT_MAX)
jksoft 0:8c643bfe55b7 125 {
jksoft 0:8c643bfe55b7 126 _timeout = GAP_ADV_PARAMS_TIMEOUT_MAX;
jksoft 0:8c643bfe55b7 127 }
jksoft 0:8c643bfe55b7 128 }
jksoft 0:8c643bfe55b7 129 }
jksoft 0:8c643bfe55b7 130
jksoft 0:8c643bfe55b7 131 /**************************************************************************/
jksoft 0:8c643bfe55b7 132 /*!
jksoft 0:8c643bfe55b7 133 Destructor
jksoft 0:8c643bfe55b7 134 */
jksoft 0:8c643bfe55b7 135 /**************************************************************************/
jksoft 0:8c643bfe55b7 136 GapAdvertisingParams::~GapAdvertisingParams(void)
jksoft 0:8c643bfe55b7 137 {
jksoft 0:8c643bfe55b7 138 }
jksoft 0:8c643bfe55b7 139
jksoft 0:8c643bfe55b7 140 /**************************************************************************/
jksoft 0:8c643bfe55b7 141 /*!
jksoft 0:8c643bfe55b7 142 \brief returns the current Advertising Type value
jksoft 0:8c643bfe55b7 143 */
jksoft 0:8c643bfe55b7 144 /**************************************************************************/
jksoft 0:8c643bfe55b7 145 GapAdvertisingParams::AdvertisingType GapAdvertisingParams::getAdvertisingType(void)
jksoft 0:8c643bfe55b7 146 {
jksoft 0:8c643bfe55b7 147 return _advType;
jksoft 0:8c643bfe55b7 148 }
jksoft 0:8c643bfe55b7 149
jksoft 0:8c643bfe55b7 150 /**************************************************************************/
jksoft 0:8c643bfe55b7 151 /*!
jksoft 0:8c643bfe55b7 152 \brief returns the current Advertising Delay (in units of 0.625ms)
jksoft 0:8c643bfe55b7 153 */
jksoft 0:8c643bfe55b7 154 /**************************************************************************/
jksoft 0:8c643bfe55b7 155 uint16_t GapAdvertisingParams::getInterval(void)
jksoft 0:8c643bfe55b7 156 {
jksoft 0:8c643bfe55b7 157 return _interval;
jksoft 0:8c643bfe55b7 158 }
jksoft 0:8c643bfe55b7 159
jksoft 0:8c643bfe55b7 160 /**************************************************************************/
jksoft 0:8c643bfe55b7 161 /*!
jksoft 0:8c643bfe55b7 162 \brief returns the current Advertising Timeout (in seconds)
jksoft 0:8c643bfe55b7 163 */
jksoft 0:8c643bfe55b7 164 /**************************************************************************/
jksoft 0:8c643bfe55b7 165 uint16_t GapAdvertisingParams::getTimeout(void)
jksoft 0:8c643bfe55b7 166 {
jksoft 0:8c643bfe55b7 167 return _timeout;
jksoft 0:8c643bfe55b7 168 }