TYBLE16 on os5 sample programs
Dependencies: BME280 TextLCD nRF51_Vdd
Fork of TYBLE16_mbedlized_os5_BASE by
Please refer following notebook.
/users/kenjiArai/notebook/tyble16-module-as-mbed-os-5-board-mbedlization/
2_EddyStoneBeacon/main.cpp@1:9011c83e4178, 2018-04-14 (annotated)
- Committer:
- kenjiArai
- Date:
- Sat Apr 14 04:56:34 2018 +0000
- Revision:
- 1:9011c83e4178
added samples
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 1:9011c83e4178 | 1 | /* mbed Microcontroller Library |
kenjiArai | 1:9011c83e4178 | 2 | * Copyright (c) 2006-2013 ARM Limited |
kenjiArai | 1:9011c83e4178 | 3 | * |
kenjiArai | 1:9011c83e4178 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kenjiArai | 1:9011c83e4178 | 5 | * you may not use this file except in compliance with the License. |
kenjiArai | 1:9011c83e4178 | 6 | * You may obtain a copy of the License at |
kenjiArai | 1:9011c83e4178 | 7 | * |
kenjiArai | 1:9011c83e4178 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kenjiArai | 1:9011c83e4178 | 9 | * |
kenjiArai | 1:9011c83e4178 | 10 | * Unless required by applicable law or agreed to in writing, software |
kenjiArai | 1:9011c83e4178 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kenjiArai | 1:9011c83e4178 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kenjiArai | 1:9011c83e4178 | 13 | * See the License for the specific language governing permissions and |
kenjiArai | 1:9011c83e4178 | 14 | * limitations under the License. |
kenjiArai | 1:9011c83e4178 | 15 | */ |
kenjiArai | 1:9011c83e4178 | 16 | |
kenjiArai | 1:9011c83e4178 | 17 | /* |
kenjiArai | 1:9011c83e4178 | 18 | * /////// Works well on TYBLE16 Module /////// |
kenjiArai | 1:9011c83e4178 | 19 | * Modified by Kenji Arai |
kenjiArai | 1:9011c83e4178 | 20 | * http://www.page.sannet.ne.jp/kenjia/index.html |
kenjiArai | 1:9011c83e4178 | 21 | * https://os.mbed.com/users/kenjiArai/ |
kenjiArai | 1:9011c83e4178 | 22 | * |
kenjiArai | 1:9011c83e4178 | 23 | * Started: Feburary 18th, 2018 |
kenjiArai | 1:9011c83e4178 | 24 | * Revised: April 14th, 2018 |
kenjiArai | 1:9011c83e4178 | 25 | * |
kenjiArai | 1:9011c83e4178 | 26 | * Original: |
kenjiArai | 1:9011c83e4178 | 27 | * nRF51822_SimpleControls |
kenjiArai | 1:9011c83e4178 | 28 | * https://developer.mbed.org/teams |
kenjiArai | 1:9011c83e4178 | 29 | * /Bluetooth-Low-Energy/code/BLE_EddystoneBeacon_Service/ |
kenjiArai | 1:9011c83e4178 | 30 | * Tested Controller Device: |
kenjiArai | 1:9011c83e4178 | 31 | * iPhone6 Physical Web (PhyWeb) By Viet Hoa Dinh |
kenjiArai | 1:9011c83e4178 | 32 | * https://itunes.apple.com/us/app/physical-web/id927653608?mt=8 |
kenjiArai | 1:9011c83e4178 | 33 | */ |
kenjiArai | 1:9011c83e4178 | 34 | |
kenjiArai | 1:9011c83e4178 | 35 | //#define EXAMPLE_2_EDDYSTONE_BEACON |
kenjiArai | 1:9011c83e4178 | 36 | #ifdef EXAMPLE_2_EDDYSTONE_BEACON |
kenjiArai | 1:9011c83e4178 | 37 | |
kenjiArai | 1:9011c83e4178 | 38 | // Include -------------------------------------------------------------------- |
kenjiArai | 1:9011c83e4178 | 39 | #include "mbed.h" |
kenjiArai | 1:9011c83e4178 | 40 | #include "TYBLE16_BASE.h" |
kenjiArai | 1:9011c83e4178 | 41 | #include "BLE.h" |
kenjiArai | 1:9011c83e4178 | 42 | //#include "EddystoneService.h" |
kenjiArai | 1:9011c83e4178 | 43 | #include "../Eddystone/EddystoneService.h" |
kenjiArai | 1:9011c83e4178 | 44 | |
kenjiArai | 1:9011c83e4178 | 45 | // Object --------------------------------------------------------------------- |
kenjiArai | 1:9011c83e4178 | 46 | DigitalOut led(P0_5); |
kenjiArai | 1:9011c83e4178 | 47 | Serial pc(USBTX, USBRX); |
kenjiArai | 1:9011c83e4178 | 48 | |
kenjiArai | 1:9011c83e4178 | 49 | // Definition ----------------------------------------------------------------- |
kenjiArai | 1:9011c83e4178 | 50 | |
kenjiArai | 1:9011c83e4178 | 51 | // RAM ------------------------------------------------------------------------ |
kenjiArai | 1:9011c83e4178 | 52 | EddystoneService *eddyServicePtr; |
kenjiArai | 1:9011c83e4178 | 53 | Gap::Address_t my_mac; |
kenjiArai | 1:9011c83e4178 | 54 | |
kenjiArai | 1:9011c83e4178 | 55 | // ROM / Constant data -------------------------------------------------------- |
kenjiArai | 1:9011c83e4178 | 56 | char *const opngmsg = |
kenjiArai | 1:9011c83e4178 | 57 | "\x1b[2J\x1b[H"__FILE__ "\r\n"__DATE__ " " __TIME__ " (UTC)\r\n""\r\n"; |
kenjiArai | 1:9011c83e4178 | 58 | |
kenjiArai | 1:9011c83e4178 | 59 | // Function prototypes -------------------------------------------------------- |
kenjiArai | 1:9011c83e4178 | 60 | int8_t check_dice(void); |
kenjiArai | 1:9011c83e4178 | 61 | uint16_t update_vdd(uint16_t x); |
kenjiArai | 1:9011c83e4178 | 62 | uint16_t update_temp(uint16_t x); |
kenjiArai | 1:9011c83e4178 | 63 | void onBleInitError(BLE::InitializationCompleteCallbackContext* initContext); |
kenjiArai | 1:9011c83e4178 | 64 | void bleInitComplete(BLE::InitializationCompleteCallbackContext* initContext); |
kenjiArai | 1:9011c83e4178 | 65 | |
kenjiArai | 1:9011c83e4178 | 66 | //------------------------------------------------------------------------------ |
kenjiArai | 1:9011c83e4178 | 67 | // Control Program |
kenjiArai | 1:9011c83e4178 | 68 | //------------------------------------------------------------------------------ |
kenjiArai | 1:9011c83e4178 | 69 | // !!!!!!!! Please select number of 0 to 6 !!!!!!!!!!!!!!!!! |
kenjiArai | 1:9011c83e4178 | 70 | int8_t check_dice(void) |
kenjiArai | 1:9011c83e4178 | 71 | { |
kenjiArai | 1:9011c83e4178 | 72 | return 5; |
kenjiArai | 1:9011c83e4178 | 73 | } |
kenjiArai | 1:9011c83e4178 | 74 | |
kenjiArai | 1:9011c83e4178 | 75 | void bleInitComplete(BLE::InitializationCompleteCallbackContext* initContext) |
kenjiArai | 1:9011c83e4178 | 76 | { |
kenjiArai | 1:9011c83e4178 | 77 | BLE &ble = initContext->ble; |
kenjiArai | 1:9011c83e4178 | 78 | ble_error_t error = initContext->error; |
kenjiArai | 1:9011c83e4178 | 79 | |
kenjiArai | 1:9011c83e4178 | 80 | if (error != BLE_ERROR_NONE) { |
kenjiArai | 1:9011c83e4178 | 81 | onBleInitError(initContext); |
kenjiArai | 1:9011c83e4178 | 82 | return; |
kenjiArai | 1:9011c83e4178 | 83 | } |
kenjiArai | 1:9011c83e4178 | 84 | // Set UID and TLM frame data |
kenjiArai | 1:9011c83e4178 | 85 | const UIDNamespaceID_t uidNamespaceID = |
kenjiArai | 1:9011c83e4178 | 86 | {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99}; |
kenjiArai | 1:9011c83e4178 | 87 | const UIDInstanceID_t uidInstanceID = |
kenjiArai | 1:9011c83e4178 | 88 | {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}; |
kenjiArai | 1:9011c83e4178 | 89 | uint8_t tlmVersion = 0x00; |
kenjiArai | 1:9011c83e4178 | 90 | |
kenjiArai | 1:9011c83e4178 | 91 | Gap::AddressType_t my_mac_type; |
kenjiArai | 1:9011c83e4178 | 92 | ble.gap().getAddress(&my_mac_type, my_mac); |
kenjiArai | 1:9011c83e4178 | 93 | // Initialize a EddystoneBeaconConfig service |
kenjiArai | 1:9011c83e4178 | 94 | // Values for ADV packets related to firmware levels, |
kenjiArai | 1:9011c83e4178 | 95 | // calibrated based on measured values at 1m |
kenjiArai | 1:9011c83e4178 | 96 | static const PowerLevels_t defaultAdvPowerLevels = {-47, -33, -21, -13}; |
kenjiArai | 1:9011c83e4178 | 97 | // Values for radio power levels, provided by manufacturer. |
kenjiArai | 1:9011c83e4178 | 98 | static const PowerLevels_t radioPowerLevels = {-30, -16, -4, 4}; |
kenjiArai | 1:9011c83e4178 | 99 | eddyServicePtr = new EddystoneService(ble, |
kenjiArai | 1:9011c83e4178 | 100 | defaultAdvPowerLevels, |
kenjiArai | 1:9011c83e4178 | 101 | radioPowerLevels); |
kenjiArai | 1:9011c83e4178 | 102 | // created short cut web addres by http://bitly.oshiire.org/ |
kenjiArai | 1:9011c83e4178 | 103 | switch (check_dice()) { |
kenjiArai | 1:9011c83e4178 | 104 | case 1: // Switch sience(mbed) |
kenjiArai | 1:9011c83e4178 | 105 | eddyServicePtr->setURLData("http://bit.ly/1oJh91B"); |
kenjiArai | 1:9011c83e4178 | 106 | break; |
kenjiArai | 1:9011c83e4178 | 107 | case 2: // switch sience(HP) |
kenjiArai | 1:9011c83e4178 | 108 | eddyServicePtr->setURLData("http://bit.ly/1oJhP7g"); |
kenjiArai | 1:9011c83e4178 | 109 | break; |
kenjiArai | 1:9011c83e4178 | 110 | case 3: // Taiyo Yuden BLE |
kenjiArai | 1:9011c83e4178 | 111 | eddyServicePtr->setURLData("http://bit.ly/1VvuCVr"); |
kenjiArai | 1:9011c83e4178 | 112 | break; |
kenjiArai | 1:9011c83e4178 | 113 | case 4: // Taiyo Yuden |
kenjiArai | 1:9011c83e4178 | 114 | eddyServicePtr->setURLData("http://bit.ly/1Vvtp0l"); |
kenjiArai | 1:9011c83e4178 | 115 | break; |
kenjiArai | 1:9011c83e4178 | 116 | case 5: // JH1PJL(mbed) |
kenjiArai | 1:9011c83e4178 | 117 | eddyServicePtr->setURLData("http://bit.ly/1Vvt51J"); |
kenjiArai | 1:9011c83e4178 | 118 | break; |
kenjiArai | 1:9011c83e4178 | 119 | case 6: // JH1PJL(HP) |
kenjiArai | 1:9011c83e4178 | 120 | eddyServicePtr->setURLData("http://bit.ly/1VvteT0"); |
kenjiArai | 1:9011c83e4178 | 121 | break; |
kenjiArai | 1:9011c83e4178 | 122 | case 0: |
kenjiArai | 1:9011c83e4178 | 123 | default: // Mbed |
kenjiArai | 1:9011c83e4178 | 124 | eddyServicePtr->setURLData("http://mbed.org"); |
kenjiArai | 1:9011c83e4178 | 125 | break; |
kenjiArai | 1:9011c83e4178 | 126 | } |
kenjiArai | 1:9011c83e4178 | 127 | eddyServicePtr->setUIDData(&uidNamespaceID, &uidInstanceID); |
kenjiArai | 1:9011c83e4178 | 128 | eddyServicePtr->setTLMData(tlmVersion); |
kenjiArai | 1:9011c83e4178 | 129 | // Start Eddystone in config mode |
kenjiArai | 1:9011c83e4178 | 130 | eddyServicePtr->startBeaconService(5, 5, 5); |
kenjiArai | 1:9011c83e4178 | 131 | } |
kenjiArai | 1:9011c83e4178 | 132 | |
kenjiArai | 1:9011c83e4178 | 133 | int main(void) |
kenjiArai | 1:9011c83e4178 | 134 | { |
kenjiArai | 1:9011c83e4178 | 135 | pc.puts(opngmsg); |
kenjiArai | 1:9011c83e4178 | 136 | led = 1; |
kenjiArai | 1:9011c83e4178 | 137 | // Check TYBLE-16 configuration |
kenjiArai | 1:9011c83e4178 | 138 | cpu_sys(); |
kenjiArai | 1:9011c83e4178 | 139 | if (compile_condition() == false) { |
kenjiArai | 1:9011c83e4178 | 140 | pc.printf("This is wrong configuration!!\r\n"); |
kenjiArai | 1:9011c83e4178 | 141 | while(true) { |
kenjiArai | 1:9011c83e4178 | 142 | led = !led; |
kenjiArai | 1:9011c83e4178 | 143 | wait(0.2); |
kenjiArai | 1:9011c83e4178 | 144 | } |
kenjiArai | 1:9011c83e4178 | 145 | } |
kenjiArai | 1:9011c83e4178 | 146 | BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE); |
kenjiArai | 1:9011c83e4178 | 147 | ble.init(bleInitComplete); |
kenjiArai | 1:9011c83e4178 | 148 | while (ble.hasInitialized() == false) { |
kenjiArai | 1:9011c83e4178 | 149 | ; |
kenjiArai | 1:9011c83e4178 | 150 | } |
kenjiArai | 1:9011c83e4178 | 151 | // |
kenjiArai | 1:9011c83e4178 | 152 | led = 0; |
kenjiArai | 1:9011c83e4178 | 153 | //pc.printf("line:%d\r\n", __LINE__); |
kenjiArai | 1:9011c83e4178 | 154 | while (true) { |
kenjiArai | 1:9011c83e4178 | 155 | ble.waitForEvent(); |
kenjiArai | 1:9011c83e4178 | 156 | } |
kenjiArai | 1:9011c83e4178 | 157 | } |
kenjiArai | 1:9011c83e4178 | 158 | |
kenjiArai | 1:9011c83e4178 | 159 | void onBleInitError(BLE::InitializationCompleteCallbackContext* initContext) |
kenjiArai | 1:9011c83e4178 | 160 | { |
kenjiArai | 1:9011c83e4178 | 161 | // Initialization error handling goes here... |
kenjiArai | 1:9011c83e4178 | 162 | (void) initContext; |
kenjiArai | 1:9011c83e4178 | 163 | } |
kenjiArai | 1:9011c83e4178 | 164 | |
kenjiArai | 1:9011c83e4178 | 165 | #endif |