Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
my-ble.cpp@0:72ab2fd9994b, 2018-05-25 (annotated)
- Committer:
- rikita
- Date:
- Fri May 25 01:34:23 2018 +0000
- Revision:
- 0:72ab2fd9994b
First commit.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| rikita | 0:72ab2fd9994b | 1 | /****************************************************************************** |
| rikita | 0:72ab2fd9994b | 2 | * |
| rikita | 0:72ab2fd9994b | 3 | * Copyright 2018 ASAHI KASEI MICRODEVICES CORPORATION, Japan |
| rikita | 0:72ab2fd9994b | 4 | * |
| rikita | 0:72ab2fd9994b | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| rikita | 0:72ab2fd9994b | 6 | * you may not use this file except in compliance with the License. |
| rikita | 0:72ab2fd9994b | 7 | * You may obtain a copy of the License at |
| rikita | 0:72ab2fd9994b | 8 | * |
| rikita | 0:72ab2fd9994b | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| rikita | 0:72ab2fd9994b | 10 | * |
| rikita | 0:72ab2fd9994b | 11 | * Unless required by applicable law or agreed to in writing, software |
| rikita | 0:72ab2fd9994b | 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| rikita | 0:72ab2fd9994b | 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| rikita | 0:72ab2fd9994b | 14 | * See the License for the specific language governing permissions and |
| rikita | 0:72ab2fd9994b | 15 | * limitations under the License. |
| rikita | 0:72ab2fd9994b | 16 | * |
| rikita | 0:72ab2fd9994b | 17 | ******************************************************************************/ |
| rikita | 0:72ab2fd9994b | 18 | #include <mbed.h> |
| rikita | 0:72ab2fd9994b | 19 | #include "my-ble-definition.h" |
| rikita | 0:72ab2fd9994b | 20 | |
| rikita | 0:72ab2fd9994b | 21 | /** @brief Initialize device. |
| rikita | 0:72ab2fd9994b | 22 | * @return MY_SUCCESS when device is successfully initialized. |
| rikita | 0:72ab2fd9994b | 23 | * @return Other when device is not initialized. |
| rikita | 0:72ab2fd9994b | 24 | */ |
| rikita | 0:72ab2fd9994b | 25 | uint32_t my_ble_init(void) { |
| rikita | 0:72ab2fd9994b | 26 | DPRINTF("my init\r\n"); |
| rikita | 0:72ab2fd9994b | 27 | return MY_SUCCESS; |
| rikita | 0:72ab2fd9994b | 28 | } |
| rikita | 0:72ab2fd9994b | 29 | |
| rikita | 0:72ab2fd9994b | 30 | /** @brief This function is called when timer period is elapsed. |
| rikita | 0:72ab2fd9994b | 31 | * The timer interval is defined as #MY_TIMER_INTERVAL. |
| rikita | 0:72ab2fd9994b | 32 | */ |
| rikita | 0:72ab2fd9994b | 33 | void my_ble_timer(void) { |
| rikita | 0:72ab2fd9994b | 34 | /* get current time |
| rikita | 0:72ab2fd9994b | 35 | * this time is elapsed time since the board boots up. |
| rikita | 0:72ab2fd9994b | 36 | */ |
| rikita | 0:72ab2fd9994b | 37 | uint32_t tm = (uint32_t)time(NULL); |
| rikita | 0:72ab2fd9994b | 38 | |
| rikita | 0:72ab2fd9994b | 39 | /** send data to BLE module */ |
| rikita | 0:72ab2fd9994b | 40 | MY_BLE->update_data1(tm); |
| rikita | 0:72ab2fd9994b | 41 | |
| rikita | 0:72ab2fd9994b | 42 | DPRINTF("my timer (%d)\r\n", tm); |
| rikita | 0:72ab2fd9994b | 43 | } |
| rikita | 0:72ab2fd9994b | 44 | |
| rikita | 0:72ab2fd9994b | 45 | /** @brief This function is called when INT1 pin changes |
| rikita | 0:72ab2fd9994b | 46 | * from LOW to HIGH. In case of BUTTON1, the button 1 is released. |
| rikita | 0:72ab2fd9994b | 47 | */ |
| rikita | 0:72ab2fd9994b | 48 | void my_ble_int1_rise(void) { |
| rikita | 0:72ab2fd9994b | 49 | /* do something */ |
| rikita | 0:72ab2fd9994b | 50 | DPRINTF("my int1 rise\r\n"); |
| rikita | 0:72ab2fd9994b | 51 | } |
| rikita | 0:72ab2fd9994b | 52 | |
| rikita | 0:72ab2fd9994b | 53 | /** @brief This function is called when INT1 pin changes |
| rikita | 0:72ab2fd9994b | 54 | * from HIGH to LOW. In case of BUTTON1, the button 1 is pressed. |
| rikita | 0:72ab2fd9994b | 55 | */ |
| rikita | 0:72ab2fd9994b | 56 | void my_ble_int1_fall(void) { |
| rikita | 0:72ab2fd9994b | 57 | /* do something */ |
| rikita | 0:72ab2fd9994b | 58 | DPRINTF("my int1 fall\r\n"); |
| rikita | 0:72ab2fd9994b | 59 | } |
| rikita | 0:72ab2fd9994b | 60 | |
| rikita | 0:72ab2fd9994b | 61 | void my_ble_int2_rise(void) { |
| rikita | 0:72ab2fd9994b | 62 | /* do something */ |
| rikita | 0:72ab2fd9994b | 63 | DPRINTF("my int2 rise\r\n"); |
| rikita | 0:72ab2fd9994b | 64 | } |
| rikita | 0:72ab2fd9994b | 65 | |
| rikita | 0:72ab2fd9994b | 66 | void my_ble_int2_fall(void) { |
| rikita | 0:72ab2fd9994b | 67 | /* do something */ |
| rikita | 0:72ab2fd9994b | 68 | DPRINTF("my int2 fall\r\n"); |
| rikita | 0:72ab2fd9994b | 69 | } |
| rikita | 0:72ab2fd9994b | 70 | |
| rikita | 0:72ab2fd9994b | 71 | void my_ble_received(const uint32_t data) { |
| rikita | 0:72ab2fd9994b | 72 | /* do something */ |
| rikita | 0:72ab2fd9994b | 73 | DPRINTF("Data received (%d)\r\n", data); |
| rikita | 0:72ab2fd9994b | 74 | } |