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
jksoft 0:8c643bfe55b7 18 #include <stdio.h>
jksoft 0:8c643bfe55b7 19 #include <string.h>
jksoft 0:8c643bfe55b7 20
jksoft 0:8c643bfe55b7 21 #include "GattService.h"
jksoft 0:8c643bfe55b7 22
jksoft 0:8c643bfe55b7 23 /**************************************************************************/
jksoft 0:8c643bfe55b7 24 /*!
jksoft 0:8c643bfe55b7 25 @brief Creates a new GattService using the specified 128-bit UUID
jksoft 0:8c643bfe55b7 26
jksoft 0:8c643bfe55b7 27 @note The UUID value must be unique on the device
jksoft 0:8c643bfe55b7 28
jksoft 0:8c643bfe55b7 29 @param[in] uuid
jksoft 0:8c643bfe55b7 30 The 16 byte (128-bit) UUID to use for this characteristic
jksoft 0:8c643bfe55b7 31
jksoft 0:8c643bfe55b7 32 @section EXAMPLE
jksoft 0:8c643bfe55b7 33
jksoft 0:8c643bfe55b7 34 @code
jksoft 0:8c643bfe55b7 35
jksoft 0:8c643bfe55b7 36 @endcode
jksoft 0:8c643bfe55b7 37 */
jksoft 0:8c643bfe55b7 38 /**************************************************************************/
jksoft 0:8c643bfe55b7 39 GattService::GattService(uint8_t base_uuid[16])
jksoft 0:8c643bfe55b7 40 {
jksoft 0:8c643bfe55b7 41 primaryServiceID.update(base_uuid);
jksoft 0:8c643bfe55b7 42 characteristicCount = 0;
jksoft 0:8c643bfe55b7 43 handle = 0;
jksoft 0:8c643bfe55b7 44 }
jksoft 0:8c643bfe55b7 45
jksoft 0:8c643bfe55b7 46 /**************************************************************************/
jksoft 0:8c643bfe55b7 47 /*!
jksoft 0:8c643bfe55b7 48 @brief Creates a new GattService using the specified 16-bit BLE UUID
jksoft 0:8c643bfe55b7 49
jksoft 0:8c643bfe55b7 50 @param[in] ble_uuid
jksoft 0:8c643bfe55b7 51 The standardised 16-bit (2 byte) BLE UUID to use for this
jksoft 0:8c643bfe55b7 52 characteristic
jksoft 0:8c643bfe55b7 53
jksoft 0:8c643bfe55b7 54 @section EXAMPLE
jksoft 0:8c643bfe55b7 55
jksoft 0:8c643bfe55b7 56 @code
jksoft 0:8c643bfe55b7 57
jksoft 0:8c643bfe55b7 58 @endcode
jksoft 0:8c643bfe55b7 59 */
jksoft 0:8c643bfe55b7 60 /**************************************************************************/
jksoft 0:8c643bfe55b7 61 GattService::GattService(uint16_t ble_uuid)
jksoft 0:8c643bfe55b7 62 {
jksoft 0:8c643bfe55b7 63 primaryServiceID.update( ble_uuid );
jksoft 0:8c643bfe55b7 64 characteristicCount = 0;
jksoft 0:8c643bfe55b7 65 handle = 0;
jksoft 0:8c643bfe55b7 66 }
jksoft 0:8c643bfe55b7 67
jksoft 0:8c643bfe55b7 68 /**************************************************************************/
jksoft 0:8c643bfe55b7 69 /*!
jksoft 0:8c643bfe55b7 70 @brief Destructor
jksoft 0:8c643bfe55b7 71 */
jksoft 0:8c643bfe55b7 72 /**************************************************************************/
jksoft 0:8c643bfe55b7 73 GattService::~GattService(void)
jksoft 0:8c643bfe55b7 74 {
jksoft 0:8c643bfe55b7 75 }
jksoft 0:8c643bfe55b7 76
jksoft 0:8c643bfe55b7 77 /**************************************************************************/
jksoft 0:8c643bfe55b7 78 /*!
jksoft 0:8c643bfe55b7 79 @brief Adds a GattCharacterisic to the service.
jksoft 0:8c643bfe55b7 80
jksoft 0:8c643bfe55b7 81 @note This function will not update the .handle field in the
jksoft 0:8c643bfe55b7 82 GattCharacteristic. This value is updated when the parent
jksoft 0:8c643bfe55b7 83 service is added via the radio driver.
jksoft 0:8c643bfe55b7 84
jksoft 0:8c643bfe55b7 85 @param[in] characteristic
jksoft 0:8c643bfe55b7 86 The GattCharacteristic object describing the characteristic
jksoft 0:8c643bfe55b7 87 to add to this service
jksoft 0:8c643bfe55b7 88
jksoft 0:8c643bfe55b7 89 @returns BLE_ERROR_NONE (0) if everything executed correctly, or an
jksoft 0:8c643bfe55b7 90 error code if there was a problem
jksoft 0:8c643bfe55b7 91 @retval BLE_ERROR_NONE
jksoft 0:8c643bfe55b7 92 Everything executed correctly
jksoft 0:8c643bfe55b7 93
jksoft 0:8c643bfe55b7 94 @section EXAMPLE
jksoft 0:8c643bfe55b7 95
jksoft 0:8c643bfe55b7 96 @code
jksoft 0:8c643bfe55b7 97
jksoft 0:8c643bfe55b7 98 @endcode
jksoft 0:8c643bfe55b7 99 */
jksoft 0:8c643bfe55b7 100 /**************************************************************************/
jksoft 0:8c643bfe55b7 101 ble_error_t GattService::addCharacteristic(GattCharacteristic & characteristic)
jksoft 0:8c643bfe55b7 102 {
jksoft 0:8c643bfe55b7 103 /* ToDo: Make sure we don't overflow the array, etc. */
jksoft 0:8c643bfe55b7 104 /* ToDo: Make sure this characteristic UUID doesn't already exist */
jksoft 0:8c643bfe55b7 105 /* ToDo: Basic validation */
jksoft 0:8c643bfe55b7 106
jksoft 0:8c643bfe55b7 107 characteristics[characteristicCount] = &characteristic;
jksoft 0:8c643bfe55b7 108 characteristicCount++;
jksoft 0:8c643bfe55b7 109
jksoft 0:8c643bfe55b7 110 return BLE_ERROR_NONE;
jksoft 0:8c643bfe55b7 111 }