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 #ifndef __GAP_ADVERTISING_DATA_H__
jksoft 0:8c643bfe55b7 18 #define __GAP_ADVERTISING_DATA_H__
jksoft 0:8c643bfe55b7 19
jksoft 0:8c643bfe55b7 20 #include "blecommon.h"
jksoft 0:8c643bfe55b7 21
jksoft 0:8c643bfe55b7 22 #define GAP_ADVERTISING_DATA_MAX_PAYLOAD (31)
jksoft 0:8c643bfe55b7 23
jksoft 0:8c643bfe55b7 24 /**************************************************************************/
jksoft 0:8c643bfe55b7 25 /*!
jksoft 0:8c643bfe55b7 26 \brief
jksoft 0:8c643bfe55b7 27 This class provides several helper functions to generate properly
jksoft 0:8c643bfe55b7 28 formatted GAP Advertising and Scan Response data payloads
jksoft 0:8c643bfe55b7 29
jksoft 0:8c643bfe55b7 30 \note
jksoft 0:8c643bfe55b7 31 See Bluetooth Specification 4.0 (Vol. 3), Part C, Section 11 and 18
jksoft 0:8c643bfe55b7 32 for further information on Advertising and Scan Response data.
jksoft 0:8c643bfe55b7 33
jksoft 0:8c643bfe55b7 34 \par Advertising and Scan Response Payloads
jksoft 0:8c643bfe55b7 35 Advertising data and Scan Response data are organized around a set of
jksoft 0:8c643bfe55b7 36 data types called 'AD types' in Bluetooth 4.0 (see the Bluetooth Core
jksoft 0:8c643bfe55b7 37 Specification v4.0, Vol. 3, Part C, Sections 11 and 18).
jksoft 0:8c643bfe55b7 38
jksoft 0:8c643bfe55b7 39 \par
jksoft 0:8c643bfe55b7 40 Each AD type has it's own standardized 'assigned number', as defined
jksoft 0:8c643bfe55b7 41 by the Bluetooth SIG:
jksoft 0:8c643bfe55b7 42 https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile
jksoft 0:8c643bfe55b7 43
jksoft 0:8c643bfe55b7 44 \par
jksoft 0:8c643bfe55b7 45 For convenience sake, all appropriate AD types have been encapsulated
jksoft 0:8c643bfe55b7 46 into GapAdvertisingData::DataType.
jksoft 0:8c643bfe55b7 47
jksoft 0:8c643bfe55b7 48 \par
jksoft 0:8c643bfe55b7 49 Before the AD Types and their payload (if any) can be inserted into
jksoft 0:8c643bfe55b7 50 the Advertising or Scan Response frames, they need to be formatted as
jksoft 0:8c643bfe55b7 51 follows:
jksoft 0:8c643bfe55b7 52
jksoft 0:8c643bfe55b7 53 \li \c Record length (1 byte)
jksoft 0:8c643bfe55b7 54 \li \c AD Type (1 byte)
jksoft 0:8c643bfe55b7 55 \li \c AD payload (optional, only present if record length > 1)
jksoft 0:8c643bfe55b7 56
jksoft 0:8c643bfe55b7 57 \par
jksoft 0:8c643bfe55b7 58 This class takes care of properly formatting the payload, performs
jksoft 0:8c643bfe55b7 59 some basic checks on the payload length, and tries to avoid common
jksoft 0:8c643bfe55b7 60 errors like adding an exclusive AD field twice in the Advertising
jksoft 0:8c643bfe55b7 61 or Scan Response payload.
jksoft 0:8c643bfe55b7 62
jksoft 0:8c643bfe55b7 63 \par EXAMPLE
jksoft 0:8c643bfe55b7 64
jksoft 0:8c643bfe55b7 65 \code
jksoft 0:8c643bfe55b7 66
jksoft 0:8c643bfe55b7 67 // ToDo
jksoft 0:8c643bfe55b7 68
jksoft 0:8c643bfe55b7 69 \endcode
jksoft 0:8c643bfe55b7 70 */
jksoft 0:8c643bfe55b7 71 /**************************************************************************/
jksoft 0:8c643bfe55b7 72 class GapAdvertisingData
jksoft 0:8c643bfe55b7 73 {
jksoft 0:8c643bfe55b7 74 public:
jksoft 0:8c643bfe55b7 75 /**********************************************************************/
jksoft 0:8c643bfe55b7 76 /*!
jksoft 0:8c643bfe55b7 77 \brief
jksoft 0:8c643bfe55b7 78 A list of Advertising Data types commonly used by peripherals.
jksoft 0:8c643bfe55b7 79 These AD types are used to describe the capabilities of the
jksoft 0:8c643bfe55b7 80 peripheral, and get inserted inside the advertising or scan
jksoft 0:8c643bfe55b7 81 response payloads.
jksoft 0:8c643bfe55b7 82
jksoft 0:8c643bfe55b7 83 \par Source
jksoft 0:8c643bfe55b7 84 \li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18
jksoft 0:8c643bfe55b7 85 \li \c https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile
jksoft 0:8c643bfe55b7 86 */
jksoft 0:8c643bfe55b7 87 /**********************************************************************/
jksoft 0:8c643bfe55b7 88 enum DataType
jksoft 0:8c643bfe55b7 89 {
jksoft 0:8c643bfe55b7 90 FLAGS = 0x01, /**< \ref Flags */
jksoft 0:8c643bfe55b7 91 INCOMPLETE_LIST_16BIT_SERVICE_IDS = 0x02, /**< Incomplete list of 16-bit Service IDs */
jksoft 0:8c643bfe55b7 92 COMPLETE_LIST_16BIT_SERVICE_IDS = 0x03, /**< Complete list of 16-bit Service IDs */
jksoft 0:8c643bfe55b7 93 INCOMPLETE_LIST_32BIT_SERVICE_IDS = 0x04, /**< Incomplete list of 32-bit Service IDs (not relevant for Bluetooth 4.0) */
jksoft 0:8c643bfe55b7 94 COMPLETE_LIST_32BIT_SERVICE_IDS = 0x05, /**< Complete list of 32-bit Service IDs (not relevant for Bluetooth 4.0) */
jksoft 0:8c643bfe55b7 95 INCOMPLETE_LIST_128BIT_SERVICE_IDS = 0x06, /**< Incomplete list of 128-bit Service IDs */
jksoft 0:8c643bfe55b7 96 COMPLETE_LIST_128BIT_SERVICE_IDS = 0x07, /**< Complete list of 128-bit Service IDs */
jksoft 0:8c643bfe55b7 97 SHORTENED_LOCAL_NAME = 0x08, /**< Shortened Local Name */
jksoft 0:8c643bfe55b7 98 COMPLETE_LOCAL_NAME = 0x09, /**< Complete Local Name */
jksoft 0:8c643bfe55b7 99 TX_POWER_LEVEL = 0x0A, /**< TX Power Level (in dBm) */
jksoft 0:8c643bfe55b7 100 DEVICE_ID = 0x10, /**< Device ID */
jksoft 0:8c643bfe55b7 101 SLAVE_CONNECTION_INTERVAL_RANGE = 0x12, /**< Slave Connection Interval Range */
jksoft 0:8c643bfe55b7 102 SERVICE_DATA = 0x16, /**< Service Data */
jksoft 0:8c643bfe55b7 103 APPEARANCE = 0x19, /**< \ref Appearance */
jksoft 0:8c643bfe55b7 104 ADVERTISING_INTERVAL = 0x1A, /**< Advertising Interval */
jksoft 0:8c643bfe55b7 105 MANUFACTURER_SPECIFIC_DATA = 0xFF /**< Manufacturer Specific Data */
jksoft 0:8c643bfe55b7 106 };
jksoft 0:8c643bfe55b7 107
jksoft 0:8c643bfe55b7 108 /**********************************************************************/
jksoft 0:8c643bfe55b7 109 /*!
jksoft 0:8c643bfe55b7 110 \brief
jksoft 0:8c643bfe55b7 111 A list of values for the FLAGS AD Type
jksoft 0:8c643bfe55b7 112
jksoft 0:8c643bfe55b7 113 \note
jksoft 0:8c643bfe55b7 114 You can use more than one value in the FLAGS AD Type (ex.
jksoft 0:8c643bfe55b7 115 LE_GENERAL_DISCOVERABLE and BREDR_NOT_SUPPORTED).
jksoft 0:8c643bfe55b7 116
jksoft 0:8c643bfe55b7 117 \par Source
jksoft 0:8c643bfe55b7 118 \li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 18.1
jksoft 0:8c643bfe55b7 119 */
jksoft 0:8c643bfe55b7 120 /**********************************************************************/
jksoft 0:8c643bfe55b7 121 enum Flags
jksoft 0:8c643bfe55b7 122 {
jksoft 0:8c643bfe55b7 123 LE_LIMITED_DISCOVERABLE = 0x01, /**< Peripheral device is discoverable for a limited period of time */
jksoft 0:8c643bfe55b7 124 LE_GENERAL_DISCOVERABLE = 0x02, /**< Peripheral device is discoverable at any moment */
jksoft 0:8c643bfe55b7 125 BREDR_NOT_SUPPORTED = 0x04, /**< Peripheral device is LE only */
jksoft 0:8c643bfe55b7 126 SIMULTANEOUS_LE_BREDR_C = 0x08, /**< Not relevant - central mode only */
jksoft 0:8c643bfe55b7 127 SIMULTANEOUS_LE_BREDR_H = 0x10 /**< Not relevant - central mode only */
jksoft 0:8c643bfe55b7 128 };
jksoft 0:8c643bfe55b7 129
jksoft 0:8c643bfe55b7 130 /**********************************************************************/
jksoft 0:8c643bfe55b7 131 /*!
jksoft 0:8c643bfe55b7 132 \brief
jksoft 0:8c643bfe55b7 133 A list of values for the APPEARANCE AD Type, which describes the
jksoft 0:8c643bfe55b7 134 physical shape or appearance of the device
jksoft 0:8c643bfe55b7 135
jksoft 0:8c643bfe55b7 136 \par Source
jksoft 0:8c643bfe55b7 137 \li \c Bluetooth Core Specification Supplement, Part A, Section 1.12
jksoft 0:8c643bfe55b7 138 \li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 12.2
jksoft 0:8c643bfe55b7 139 \li \c https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml
jksoft 0:8c643bfe55b7 140 */
jksoft 0:8c643bfe55b7 141 /**********************************************************************/
jksoft 0:8c643bfe55b7 142 enum Appearance
jksoft 0:8c643bfe55b7 143 {
jksoft 0:8c643bfe55b7 144 UNKNOWN = 0, /**< Unknown of unspecified appearance type */
jksoft 0:8c643bfe55b7 145 GENERIC_PHONE = 64, /**< Generic Phone */
jksoft 0:8c643bfe55b7 146 GENERIC_COMPUTER = 128, /**< Generic Computer */
jksoft 0:8c643bfe55b7 147 GENERIC_WATCH = 192, /**< Generic Watch */
jksoft 0:8c643bfe55b7 148 WATCH_SPORTS_WATCH = 193, /**< Sports Watch */
jksoft 0:8c643bfe55b7 149 GENERIC_CLOCK = 256, /**< Generic Clock */
jksoft 0:8c643bfe55b7 150 GENERIC_DISPLAY = 320, /**< Generic Display */
jksoft 0:8c643bfe55b7 151 GENERIC_REMOTE_CONTROL = 384, /**< Generic Remote Control */
jksoft 0:8c643bfe55b7 152 GENERIC_EYE_GLASSES = 448, /**< Generic Eye Glasses */
jksoft 0:8c643bfe55b7 153 GENERIC_TAG = 512, /**< Generic Tag */
jksoft 0:8c643bfe55b7 154 GENERIC_KEYRING = 576, /**< Generic Keyring */
jksoft 0:8c643bfe55b7 155 GENERIC_MEDIA_PLAYER = 640, /**< Generic Media Player */
jksoft 0:8c643bfe55b7 156 GENERIC_BARCODE_SCANNER = 704, /**< Generic Barcode Scanner */
jksoft 0:8c643bfe55b7 157 GENERIC_THERMOMETER = 768, /**< Generic Thermometer */
jksoft 0:8c643bfe55b7 158 THERMOMETER_EAR = 769, /**< Ear Thermometer */
jksoft 0:8c643bfe55b7 159 GENERIC_HEART_RATE_SENSOR = 832, /**< Generic Heart Rate Sensor */
jksoft 0:8c643bfe55b7 160 HEART_RATE_SENSOR_HEART_RATE_BELT = 833, /**< Belt Heart Rate Sensor */
jksoft 0:8c643bfe55b7 161 GENERIC_BLOOD_PRESSURE = 896, /**< Generic Blood Pressure */
jksoft 0:8c643bfe55b7 162 BLOOD_PRESSURE_ARM = 897, /**< Arm Blood Pressure */
jksoft 0:8c643bfe55b7 163 BLOOD_PRESSURE_WRIST = 898, /**< Wrist Blood Pressure */
jksoft 0:8c643bfe55b7 164 HUMAN_INTERFACE_DEVICE_HID = 960, /**< Human Interface Device (HID) */
jksoft 0:8c643bfe55b7 165 KEYBOARD = 961, /**< Keyboard */
jksoft 0:8c643bfe55b7 166 MOUSE = 962, /**< Mouse */
jksoft 0:8c643bfe55b7 167 JOYSTICK = 963, /**< Joystick */
jksoft 0:8c643bfe55b7 168 GAMEPAD = 964, /**< Gamepad */
jksoft 0:8c643bfe55b7 169 DIGITIZER_TABLET = 965, /**< Digitizer Tablet */
jksoft 0:8c643bfe55b7 170 CARD_READER = 966, /**< Card Read */
jksoft 0:8c643bfe55b7 171 DIGITAL_PEN = 967, /**< Digital Pen */
jksoft 0:8c643bfe55b7 172 BARCODE_SCANNER = 968, /**< Barcode Scanner */
jksoft 0:8c643bfe55b7 173 GENERIC_GLUCOSE_METER = 1024, /**< Generic Glucose Meter */
jksoft 0:8c643bfe55b7 174 GENERIC_RUNNING_WALKING_SENSOR = 1088, /**< Generic Running/Walking Sensor */
jksoft 0:8c643bfe55b7 175 RUNNING_WALKING_SENSOR_IN_SHOE = 1089, /**< In Shoe Running/Walking Sensor */
jksoft 0:8c643bfe55b7 176 RUNNING_WALKING_SENSOR_ON_SHOE = 1090, /**< On Shoe Running/Walking Sensor */
jksoft 0:8c643bfe55b7 177 RUNNING_WALKING_SENSOR_ON_HIP = 1091, /**< On Hip Running/Walking Sensor */
jksoft 0:8c643bfe55b7 178 GENERIC_CYCLING = 1152, /**< Generic Cycling */
jksoft 0:8c643bfe55b7 179 CYCLING_CYCLING_COMPUTER = 1153, /**< Cycling Computer */
jksoft 0:8c643bfe55b7 180 CYCLING_SPEED_SENSOR = 1154, /**< Cycling Speed Senspr */
jksoft 0:8c643bfe55b7 181 CYCLING_CADENCE_SENSOR = 1155, /**< Cycling Cadence Sensor */
jksoft 0:8c643bfe55b7 182 CYCLING_POWER_SENSOR = 1156, /**< Cycling Power Sensor */
jksoft 0:8c643bfe55b7 183 CYCLING_SPEED_AND_CADENCE_SENSOR = 1157, /**< Cycling Speed and Cadence Sensor */
jksoft 0:8c643bfe55b7 184 PULSE_OXIMETER_GENERIC = 3136, /**< Generic Pulse Oximeter */
jksoft 0:8c643bfe55b7 185 PULSE_OXIMETER_FINGERTIP = 3137, /**< Fingertip Pulse Oximeter */
jksoft 0:8c643bfe55b7 186 PULSE_OXIMETER_WRIST_WORN = 3138, /**< Wrist Worn Pulse Oximeter */
jksoft 0:8c643bfe55b7 187 OUTDOOR_GENERIC = 5184, /**< Generic Outdoor */
jksoft 0:8c643bfe55b7 188 OUTDOOR_LOCATION_DISPLAY_DEVICE = 5185, /**< Outdoor Location Display Device */
jksoft 0:8c643bfe55b7 189 OUTDOOR_LOCATION_AND_NAVIGATION_DISPLAY_DEVICE = 5186, /**< Outdoor Location and Navigation Display Device */
jksoft 0:8c643bfe55b7 190 OUTDOOR_LOCATION_POD = 5187, /**< Outdoor Location Pod */
jksoft 0:8c643bfe55b7 191 OUTDOOR_LOCATION_AND_NAVIGATION_POD = 5188 /**< Outdoor Location and Navigation Pod */
jksoft 0:8c643bfe55b7 192 };
jksoft 0:8c643bfe55b7 193
jksoft 0:8c643bfe55b7 194 GapAdvertisingData(void);
jksoft 0:8c643bfe55b7 195 virtual ~GapAdvertisingData(void);
jksoft 0:8c643bfe55b7 196
jksoft 0:8c643bfe55b7 197 ble_error_t addData(DataType, uint8_t *, uint8_t);
jksoft 0:8c643bfe55b7 198 ble_error_t addAppearance(Appearance appearance = GENERIC_TAG);
jksoft 0:8c643bfe55b7 199 ble_error_t addFlags(Flags flag = LE_GENERAL_DISCOVERABLE);
jksoft 0:8c643bfe55b7 200 ble_error_t addTxPower(int8_t txPower);
jksoft 0:8c643bfe55b7 201 void clear(void);
jksoft 0:8c643bfe55b7 202 uint8_t * getPayload(void);
jksoft 0:8c643bfe55b7 203 uint8_t getPayloadLen(void);
jksoft 0:8c643bfe55b7 204 uint16_t getAppearance(void);
jksoft 0:8c643bfe55b7 205
jksoft 0:8c643bfe55b7 206 private:
jksoft 0:8c643bfe55b7 207 uint8_t _payload[GAP_ADVERTISING_DATA_MAX_PAYLOAD];
jksoft 0:8c643bfe55b7 208 uint8_t _payloadLen;
jksoft 0:8c643bfe55b7 209 uint16_t _appearance;
jksoft 0:8c643bfe55b7 210 };
jksoft 0:8c643bfe55b7 211
jksoft 0:8c643bfe55b7 212 #endif