AndroidのBLEラジコンプロポアプリ「BLEPropo」と接続し、RCサーボとDCモータを制御するプログラムです。 mbed HRM1017で動作を確認しています。 BLEPropo → https://github.com/lipoyang/BLEPropo

Dependencies:   BLE_API mbed

Fork of BLE_RCBController2 by Junichi Katsu

BLEを使ったAndroid用ラジコンプロポアプリ「BLEPropo」に対応するmbed HRM1017用ファームウェアです。
BLEPropoは、GitHubにて公開中。
https://github.com/lipoyang/BLEPropo
/media/uploads/lipoyang/blepropo_ui.png
ラジコンは、mbed HRM1017とRCサーボやDCモータを組み合わせて作ります。
/media/uploads/lipoyang/ble_wiring.png

Committer:
jksoft
Date:
Wed Aug 20 13:41:01 2014 +0000
Revision:
4:ebda47d22091
Parent:
nRF51822/btle/btle_gap.cpp@1:48f6e08a3ac2
?????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 1:48f6e08a3ac2 1 /* mbed Microcontroller Library
jksoft 1:48f6e08a3ac2 2 * Copyright (c) 2006-2013 ARM Limited
jksoft 1:48f6e08a3ac2 3 *
jksoft 1:48f6e08a3ac2 4 * Licensed under the Apache License, Version 2.0 (the "License");
jksoft 1:48f6e08a3ac2 5 * you may not use this file except in compliance with the License.
jksoft 1:48f6e08a3ac2 6 * You may obtain a copy of the License at
jksoft 1:48f6e08a3ac2 7 *
jksoft 1:48f6e08a3ac2 8 * http://www.apache.org/licenses/LICENSE-2.0
jksoft 1:48f6e08a3ac2 9 *
jksoft 1:48f6e08a3ac2 10 * Unless required by applicable law or agreed to in writing, software
jksoft 1:48f6e08a3ac2 11 * distributed under the License is distributed on an "AS IS" BASIS,
jksoft 1:48f6e08a3ac2 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
jksoft 1:48f6e08a3ac2 13 * See the License for the specific language governing permissions and
jksoft 1:48f6e08a3ac2 14 * limitations under the License.
jksoft 1:48f6e08a3ac2 15 */
jksoft 1:48f6e08a3ac2 16 #include "common/common.h"
jksoft 1:48f6e08a3ac2 17
jksoft 1:48f6e08a3ac2 18 #include "app_timer.h"
jksoft 1:48f6e08a3ac2 19 #include "ble_gap.h"
jksoft 1:48f6e08a3ac2 20 #include "ble_conn_params.h"
jksoft 1:48f6e08a3ac2 21
jksoft 1:48f6e08a3ac2 22 static inline uint32_t msec_to_1_25msec(uint32_t interval_ms) ATTR_ALWAYS_INLINE ATTR_CONST;
jksoft 1:48f6e08a3ac2 23 static void error_callback(uint32_t nrf_error);
jksoft 1:48f6e08a3ac2 24
jksoft 1:48f6e08a3ac2 25 /**************************************************************************/
jksoft 1:48f6e08a3ac2 26 /*!
jksoft 1:48f6e08a3ac2 27 @brief Initialise GAP in the underlying SoftDevice
jksoft 1:48f6e08a3ac2 28
jksoft 1:48f6e08a3ac2 29 @returns
jksoft 1:48f6e08a3ac2 30 */
jksoft 1:48f6e08a3ac2 31 /**************************************************************************/
jksoft 1:48f6e08a3ac2 32 error_t btle_gap_init(void)
jksoft 1:48f6e08a3ac2 33 {
jksoft 1:48f6e08a3ac2 34 ble_gap_conn_params_t gap_conn_params = {0};
jksoft 1:48f6e08a3ac2 35
jksoft 1:48f6e08a3ac2 36 gap_conn_params.min_conn_interval = msec_to_1_25msec(CFG_GAP_CONNECTION_MIN_INTERVAL_MS); // in 1.25ms units
jksoft 1:48f6e08a3ac2 37 gap_conn_params.max_conn_interval = msec_to_1_25msec(CFG_GAP_CONNECTION_MAX_INTERVAL_MS); // in 1.25ms unit
jksoft 1:48f6e08a3ac2 38 gap_conn_params.slave_latency = CFG_GAP_CONNECTION_SLAVE_LATENCY;
jksoft 1:48f6e08a3ac2 39 gap_conn_params.conn_sup_timeout = CFG_GAP_CONNECTION_SUPERVISION_TIMEOUT_MS / 10; // in 10ms unit
jksoft 1:48f6e08a3ac2 40
jksoft 1:48f6e08a3ac2 41 ble_gap_conn_sec_mode_t sec_mode;
jksoft 1:48f6e08a3ac2 42 BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); // no security is needed
jksoft 1:48f6e08a3ac2 43
jksoft 1:48f6e08a3ac2 44 ASSERT_STATUS( sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *) CFG_GAP_LOCAL_NAME, strlen(CFG_GAP_LOCAL_NAME)));
jksoft 1:48f6e08a3ac2 45 ASSERT_STATUS( sd_ble_gap_appearance_set(CFG_GAP_APPEARANCE));
jksoft 1:48f6e08a3ac2 46 ASSERT_STATUS( sd_ble_gap_ppcp_set(&gap_conn_params));
jksoft 1:48f6e08a3ac2 47 ASSERT_STATUS( sd_ble_gap_tx_power_set(CFG_BLE_TX_POWER_LEVEL));
jksoft 1:48f6e08a3ac2 48
jksoft 1:48f6e08a3ac2 49 /* Connection Parameters */
jksoft 1:48f6e08a3ac2 50 enum {
jksoft 1:48f6e08a3ac2 51 FIRST_UPDATE_DELAY = APP_TIMER_TICKS(5000, CFG_TIMER_PRESCALER),
jksoft 1:48f6e08a3ac2 52 NEXT_UPDATE_DELAY = APP_TIMER_TICKS(5000, CFG_TIMER_PRESCALER),
jksoft 1:48f6e08a3ac2 53 MAX_UPDATE_COUNT = 3
jksoft 1:48f6e08a3ac2 54 };
jksoft 1:48f6e08a3ac2 55
jksoft 1:48f6e08a3ac2 56 ble_conn_params_init_t cp_init = {0};
jksoft 1:48f6e08a3ac2 57
jksoft 1:48f6e08a3ac2 58 cp_init.p_conn_params = NULL;
jksoft 1:48f6e08a3ac2 59 cp_init.first_conn_params_update_delay = FIRST_UPDATE_DELAY;
jksoft 1:48f6e08a3ac2 60 cp_init.next_conn_params_update_delay = NEXT_UPDATE_DELAY;
jksoft 1:48f6e08a3ac2 61 cp_init.max_conn_params_update_count = MAX_UPDATE_COUNT;
jksoft 1:48f6e08a3ac2 62 cp_init.start_on_notify_cccd_handle = BLE_GATT_HANDLE_INVALID;
jksoft 1:48f6e08a3ac2 63 cp_init.disconnect_on_fail = true;
jksoft 1:48f6e08a3ac2 64 cp_init.evt_handler = NULL;
jksoft 1:48f6e08a3ac2 65 cp_init.error_handler = error_callback;
jksoft 1:48f6e08a3ac2 66
jksoft 1:48f6e08a3ac2 67 ASSERT_STATUS ( ble_conn_params_init(&cp_init));
jksoft 1:48f6e08a3ac2 68
jksoft 1:48f6e08a3ac2 69 return ERROR_NONE;
jksoft 1:48f6e08a3ac2 70 }
jksoft 1:48f6e08a3ac2 71
jksoft 1:48f6e08a3ac2 72 /**************************************************************************/
jksoft 1:48f6e08a3ac2 73 /*!
jksoft 1:48f6e08a3ac2 74 @brief Converts msecs to an integer representing 1.25ms units
jksoft 1:48f6e08a3ac2 75
jksoft 1:48f6e08a3ac2 76 @param[in] ms
jksoft 1:48f6e08a3ac2 77 The number of milliseconds to conver to 1.25ms units
jksoft 1:48f6e08a3ac2 78
jksoft 1:48f6e08a3ac2 79 @returns The number of 1.25ms units in the supplied number of ms
jksoft 1:48f6e08a3ac2 80 */
jksoft 1:48f6e08a3ac2 81 /**************************************************************************/
jksoft 1:48f6e08a3ac2 82 static inline uint32_t msec_to_1_25msec(uint32_t interval_ms)
jksoft 1:48f6e08a3ac2 83 {
jksoft 1:48f6e08a3ac2 84 return (interval_ms * 4) / 5;
jksoft 1:48f6e08a3ac2 85 }
jksoft 1:48f6e08a3ac2 86
jksoft 1:48f6e08a3ac2 87 static void error_callback(uint32_t nrf_error)
jksoft 1:48f6e08a3ac2 88 {
jksoft 1:48f6e08a3ac2 89 ASSERT_STATUS_RET_VOID( nrf_error );
jksoft 1:48f6e08a3ac2 90 }