Initial (buggy) version

Dependencies:   BLE_API mbed nRF51822

Fork of nRF51822_SimpleControls by RedBearLab

Committer:
MarkSPA
Date:
Fri Dec 02 14:33:16 2016 +0000
Revision:
5:1f6311e0fc14
Parent:
4:c8515fbd2e44
Child:
6:074f5ec7428c
Minor updates to light algorithms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RedBearLab 1:f03072e32ed3 1 /*
RedBearLab 1:f03072e32ed3 2
RedBearLab 1:f03072e32ed3 3 Copyright (c) 2012-2014 RedBearLab
RedBearLab 1:f03072e32ed3 4
MarkSPA 4:c8515fbd2e44 5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software
MarkSPA 4:c8515fbd2e44 6 and associated documentation files (the "Software"), to deal in the Software without restriction,
MarkSPA 4:c8515fbd2e44 7 including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
MarkSPA 4:c8515fbd2e44 8 and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
RedBearLab 1:f03072e32ed3 9 subject to the following conditions:
RedBearLab 1:f03072e32ed3 10 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
RedBearLab 1:f03072e32ed3 11
MarkSPA 4:c8515fbd2e44 12 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
MarkSPA 4:c8515fbd2e44 13 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
MarkSPA 4:c8515fbd2e44 14 PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
MarkSPA 4:c8515fbd2e44 15 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
RedBearLab 1:f03072e32ed3 16 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
RedBearLab 1:f03072e32ed3 17
RedBearLab 1:f03072e32ed3 18 */
RedBearLab 0:dfcebc1e442a 19
RedBearLab 0:dfcebc1e442a 20 #include "mbed.h"
MarkSPA 4:c8515fbd2e44 21 #include "neopixel.h"
RedBearLab 2:bbcdd23ba9ba 22 #include "ble/BLE.h"
RedBearLab 2:bbcdd23ba9ba 23 #include "GattCallbackParamTypes.h"
MarkSPA 4:c8515fbd2e44 24 extern "C" {
MarkSPA 4:c8515fbd2e44 25 #include "ble_radio_notification.h"
MarkSPA 4:c8515fbd2e44 26 }
RedBearLab 0:dfcebc1e442a 27 #define BLE_UUID_TXRX_SERVICE 0x0000 /**< The UUID of the Nordic UART Service. */
RedBearLab 0:dfcebc1e442a 28 #define BLE_UUID_TX_CHARACTERISTIC 0x0002 /**< The UUID of the TX Characteristic. */
RedBearLab 0:dfcebc1e442a 29 #define BLE_UUIDS_RX_CHARACTERISTIC 0x0003 /**< The UUID of the RX Characteristic. */
RedBearLab 0:dfcebc1e442a 30
RedBearLab 0:dfcebc1e442a 31 #define TXRX_BUF_LEN 20
RedBearLab 0:dfcebc1e442a 32
RedBearLab 0:dfcebc1e442a 33 #define DIGITAL_OUT_PIN P0_17 //D7
MarkSPA 4:c8515fbd2e44 34 #define BOARD_LED P0_19 //
RedBearLab 0:dfcebc1e442a 35 #define DIGITAL_IN_PIN P0_5 //A4
RedBearLab 0:dfcebc1e442a 36 #define PWM_PIN P0_16 //D6
RedBearLab 0:dfcebc1e442a 37 #define SERVO_PIN P0_14 //D10
RedBearLab 0:dfcebc1e442a 38 #define ANALOG_IN_PIN P0_6 //A5
MarkSPA 4:c8515fbd2e44 39 #define BB_DIG_OUT_PIN P0_9 //D1
MarkSPA 4:c8515fbd2e44 40
MarkSPA 4:c8515fbd2e44 41 #define LED_HEADER 0x01
MarkSPA 4:c8515fbd2e44 42 #define ONOFF_HEADER 0x11
MarkSPA 4:c8515fbd2e44 43 #define COLOR_HEADER 0x22
MarkSPA 4:c8515fbd2e44 44 #define PATTERN_HEADER 0x33
MarkSPA 4:c8515fbd2e44 45
MarkSPA 4:c8515fbd2e44 46 #define NUM_LEDS 12
MarkSPA 4:c8515fbd2e44 47
MarkSPA 4:c8515fbd2e44 48 #define PATTERN_ON 0x01
MarkSPA 4:c8515fbd2e44 49 #define PATTERN_FAST 0x02
MarkSPA 4:c8515fbd2e44 50 #define PATTERN_SLOW 0x03
MarkSPA 4:c8515fbd2e44 51 #define PATTERN_CHASE 0x04
MarkSPA 4:c8515fbd2e44 52 #define PATTERN_MRB 0x05
MarkSPA 4:c8515fbd2e44 53 #define PATTERN_RAINBOW 0x06
MarkSPA 4:c8515fbd2e44 54 #define PATTERN_CANDY 0x07
MarkSPA 4:c8515fbd2e44 55 #define PATTERN_SNOW 0x08
MarkSPA 5:1f6311e0fc14 56 #define PATTERN_XMAS 0x09
MarkSPA 4:c8515fbd2e44 57 #define LEDS_ON 0x01
MarkSPA 4:c8515fbd2e44 58 #define LEDS_OFF 0x02
RedBearLab 0:dfcebc1e442a 59
RedBearLab 2:bbcdd23ba9ba 60 BLE ble;
RedBearLab 0:dfcebc1e442a 61
MarkSPA 4:c8515fbd2e44 62 //DigitalOut LED_SET(DIGITAL_OUT_PIN);
MarkSPA 4:c8515fbd2e44 63 DigitalOut LED_SET(BOARD_LED);
RedBearLab 0:dfcebc1e442a 64 DigitalIn BUTTON(DIGITAL_IN_PIN);
MarkSPA 4:c8515fbd2e44 65 //PwmOut PWM(PWM_PIN);
MarkSPA 4:c8515fbd2e44 66 //AnalogIn ANALOG(ANALOG_IN_PIN);
RedBearLab 0:dfcebc1e442a 67
MarkSPA 4:c8515fbd2e44 68 //Serial pc(USBTX, USBRX);
MarkSPA 4:c8515fbd2e44 69 static uint8_t old_state = 0;
MarkSPA 4:c8515fbd2e44 70 neopixel_strip_t m_strip;
MarkSPA 4:c8515fbd2e44 71 //uint8_t dig_pin_num = BB_DIG_OUT_PIN; //DIGITAL_OUT_PIN; //6;
MarkSPA 4:c8515fbd2e44 72 uint8_t dig_pin_num = P0_8;
MarkSPA 4:c8515fbd2e44 73 //uint8_t leds_per_strip = 4; //24;
MarkSPA 4:c8515fbd2e44 74 uint8_t slow_count = 0;
MarkSPA 4:c8515fbd2e44 75 //uint8_t error;
MarkSPA 4:c8515fbd2e44 76 uint8_t led_to_enable = 2; //10;
MarkSPA 4:c8515fbd2e44 77 uint8_t red = 255;
MarkSPA 4:c8515fbd2e44 78 uint8_t green = 128;
MarkSPA 4:c8515fbd2e44 79 uint8_t blue = 159;
MarkSPA 4:c8515fbd2e44 80 uint8_t pattern = 0;
RedBearLab 0:dfcebc1e442a 81
MarkSPA 4:c8515fbd2e44 82 uint8_t LEDS_ON_FLAG = 0;
RedBearLab 0:dfcebc1e442a 83
RedBearLab 0:dfcebc1e442a 84 // The Nordic UART Service
RedBearLab 0:dfcebc1e442a 85 static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
RedBearLab 0:dfcebc1e442a 86 static const uint8_t uart_tx_uuid[] = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
RedBearLab 0:dfcebc1e442a 87 static const uint8_t uart_rx_uuid[] = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
RedBearLab 0:dfcebc1e442a 88 static const uint8_t uart_base_uuid_rev[] = {0x1E, 0x94, 0x8D, 0xF1, 0x48, 0x31, 0x94, 0xBA, 0x75, 0x4C, 0x3E, 0x50, 0, 0, 0x3D, 0x71};
RedBearLab 0:dfcebc1e442a 89
RedBearLab 0:dfcebc1e442a 90 uint8_t txPayload[TXRX_BUF_LEN] = {0,};
RedBearLab 0:dfcebc1e442a 91 uint8_t rxPayload[TXRX_BUF_LEN] = {0,};
RedBearLab 0:dfcebc1e442a 92
RedBearLab 0:dfcebc1e442a 93 GattCharacteristic txCharacteristic (uart_tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);
RedBearLab 0:dfcebc1e442a 94 GattCharacteristic rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
RedBearLab 0:dfcebc1e442a 95 GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic};
RedBearLab 0:dfcebc1e442a 96 GattService uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *));
RedBearLab 0:dfcebc1e442a 97
MarkSPA 4:c8515fbd2e44 98 void rainbowCycle(int wait, uint8_t numLEDs, neopixel_strip_t m_strip);
MarkSPA 4:c8515fbd2e44 99 void candyChase(int wait, uint8_t numLEDs, neopixel_strip_t m_strip);
MarkSPA 4:c8515fbd2e44 100 void snowflakes(int wait, uint8_t numLEDs, neopixel_strip_t m_strip);
MarkSPA 4:c8515fbd2e44 101 void iceflakes(int delay, uint8_t numLEDs, neopixel_strip_t m_strip);
MarkSPA 5:1f6311e0fc14 102 void xmas(int delay, uint8_t numLEDs, neopixel_strip_t m_strip);
RedBearLab 0:dfcebc1e442a 103
MarkSPA 4:c8515fbd2e44 104 extern uint32_t ble_radio_notification_init(nrf_app_irq_priority_t irq_priority,
MarkSPA 4:c8515fbd2e44 105 nrf_radio_notification_distance_t distance,
MarkSPA 4:c8515fbd2e44 106 ble_radio_notification_evt_handler_t evt_handler);
MarkSPA 4:c8515fbd2e44 107
MarkSPA 4:c8515fbd2e44 108 void connectionCallback(const Gap::ConnectionCallbackParams_t *params)
MarkSPA 4:c8515fbd2e44 109 {
MarkSPA 4:c8515fbd2e44 110 neopixel_init(&m_strip, dig_pin_num, NUM_LEDS);
MarkSPA 4:c8515fbd2e44 111 neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 112 }
RedBearLab 0:dfcebc1e442a 113
RedBearLab 3:823f105078c7 114 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
RedBearLab 0:dfcebc1e442a 115 {
MarkSPA 4:c8515fbd2e44 116 //pc.printf("Disconnected \r\n");
MarkSPA 4:c8515fbd2e44 117 //pc.printf("Restart advertising \r\n");
MarkSPA 4:c8515fbd2e44 118 //clear and remove strip
MarkSPA 4:c8515fbd2e44 119 //neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 120 //neopixel_destroy(&m_strip);
RedBearLab 0:dfcebc1e442a 121 ble.startAdvertising();
RedBearLab 0:dfcebc1e442a 122 }
RedBearLab 0:dfcebc1e442a 123
RedBearLab 2:bbcdd23ba9ba 124 void WrittenHandler(const GattWriteCallbackParams *Handler)
MarkSPA 4:c8515fbd2e44 125 {
RedBearLab 0:dfcebc1e442a 126 uint8_t buf[TXRX_BUF_LEN];
MarkSPA 4:c8515fbd2e44 127 uint16_t bytesRead;
MarkSPA 4:c8515fbd2e44 128
MarkSPA 4:c8515fbd2e44 129 if (Handler->handle == txCharacteristic.getValueAttribute().getHandle()) {
RedBearLab 0:dfcebc1e442a 130 ble.readCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(), buf, &bytesRead);
RedBearLab 0:dfcebc1e442a 131 memset(txPayload, 0, TXRX_BUF_LEN);
MarkSPA 4:c8515fbd2e44 132 memcpy(txPayload, buf, TXRX_BUF_LEN);
MarkSPA 4:c8515fbd2e44 133
MarkSPA 4:c8515fbd2e44 134 //for(index=0; index<bytesRead; index++)
MarkSPA 4:c8515fbd2e44 135 //pc.putc(buf[index]);
RedBearLab 0:dfcebc1e442a 136
MarkSPA 4:c8515fbd2e44 137 if(buf[0] == ONOFF_HEADER) {
MarkSPA 4:c8515fbd2e44 138 //pc.printf("LED value received \r\n");
MarkSPA 4:c8515fbd2e44 139 if(buf[1] == LEDS_ON) {
MarkSPA 4:c8515fbd2e44 140 LEDS_ON_FLAG = 1;
MarkSPA 4:c8515fbd2e44 141 //neopixel_init(&m_strip, dig_pin_num, NUM_LEDS);
MarkSPA 4:c8515fbd2e44 142 //neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 143 } else if(buf[1] == LEDS_OFF) {
MarkSPA 4:c8515fbd2e44 144 LEDS_ON_FLAG = 0;
MarkSPA 4:c8515fbd2e44 145 neopixel_init(&m_strip, dig_pin_num, NUM_LEDS);
MarkSPA 4:c8515fbd2e44 146 neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 147 }
MarkSPA 4:c8515fbd2e44 148 } else if(buf[0] == COLOR_HEADER) {
MarkSPA 4:c8515fbd2e44 149 red = buf[1];
MarkSPA 4:c8515fbd2e44 150 green = buf[2];
MarkSPA 4:c8515fbd2e44 151 blue = buf[3];
MarkSPA 4:c8515fbd2e44 152 pattern = buf[5];
RedBearLab 0:dfcebc1e442a 153 }
RedBearLab 0:dfcebc1e442a 154 }
RedBearLab 0:dfcebc1e442a 155 }
MarkSPA 4:c8515fbd2e44 156
RedBearLab 0:dfcebc1e442a 157 void m_status_check_handle(void)
MarkSPA 4:c8515fbd2e44 158 {
RedBearLab 0:dfcebc1e442a 159 uint8_t buf[3];
MarkSPA 4:c8515fbd2e44 160
RedBearLab 0:dfcebc1e442a 161 // If digital in changes, report the state
MarkSPA 4:c8515fbd2e44 162 if (BUTTON != old_state) {
RedBearLab 0:dfcebc1e442a 163 old_state = BUTTON;
MarkSPA 4:c8515fbd2e44 164
MarkSPA 4:c8515fbd2e44 165 if (BUTTON == 1) {
RedBearLab 0:dfcebc1e442a 166 buf[0] = (0x0A);
RedBearLab 0:dfcebc1e442a 167 buf[1] = (0x01);
MarkSPA 4:c8515fbd2e44 168 buf[2] = (0x00);
MarkSPA 4:c8515fbd2e44 169 ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 3);
MarkSPA 4:c8515fbd2e44 170 } else {
RedBearLab 0:dfcebc1e442a 171 buf[0] = (0x0A);
RedBearLab 0:dfcebc1e442a 172 buf[1] = (0x00);
RedBearLab 0:dfcebc1e442a 173 buf[2] = (0x00);
MarkSPA 4:c8515fbd2e44 174 ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 3);
RedBearLab 0:dfcebc1e442a 175 }
RedBearLab 0:dfcebc1e442a 176 }
RedBearLab 0:dfcebc1e442a 177 }
RedBearLab 0:dfcebc1e442a 178
MarkSPA 4:c8515fbd2e44 179 void ble_on_radio_active_evt(bool radio_active)
MarkSPA 4:c8515fbd2e44 180 {
MarkSPA 4:c8515fbd2e44 181 if ((radio_active == false) && (LEDS_ON_FLAG == 1)) {
MarkSPA 4:c8515fbd2e44 182 if (pattern == PATTERN_ON) {
MarkSPA 4:c8515fbd2e44 183 for (uint8_t i = 0; i < NUM_LEDS; i++)
MarkSPA 4:c8515fbd2e44 184 neopixel_set_color(&m_strip, i, red, green, blue);
MarkSPA 4:c8515fbd2e44 185 neopixel_show(&m_strip);
MarkSPA 4:c8515fbd2e44 186
MarkSPA 4:c8515fbd2e44 187 } else if (pattern == PATTERN_FAST) {
MarkSPA 4:c8515fbd2e44 188 neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 189 if (led_to_enable > NUM_LEDS)
MarkSPA 4:c8515fbd2e44 190 led_to_enable = 0;
MarkSPA 4:c8515fbd2e44 191
MarkSPA 4:c8515fbd2e44 192 neopixel_set_color(&m_strip, led_to_enable, red, green, blue);
MarkSPA 4:c8515fbd2e44 193 neopixel_show(&m_strip);
MarkSPA 4:c8515fbd2e44 194 led_to_enable++;
MarkSPA 4:c8515fbd2e44 195 } else if (pattern == PATTERN_SLOW) {
MarkSPA 4:c8515fbd2e44 196 if (slow_count > 20) {
MarkSPA 4:c8515fbd2e44 197 slow_count = 0;
MarkSPA 4:c8515fbd2e44 198 neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 199 if (led_to_enable > NUM_LEDS)
MarkSPA 4:c8515fbd2e44 200 led_to_enable = 0;
MarkSPA 4:c8515fbd2e44 201
MarkSPA 4:c8515fbd2e44 202 neopixel_set_color(&m_strip, led_to_enable, red, green, blue);
MarkSPA 4:c8515fbd2e44 203 neopixel_show(&m_strip);
MarkSPA 4:c8515fbd2e44 204 led_to_enable++;
MarkSPA 4:c8515fbd2e44 205 }
MarkSPA 4:c8515fbd2e44 206 slow_count++;
MarkSPA 4:c8515fbd2e44 207 } else if (pattern == PATTERN_CHASE) {
MarkSPA 4:c8515fbd2e44 208 for (uint8_t i = 0; i < NUM_LEDS; i++)
MarkSPA 4:c8515fbd2e44 209 neopixel_set_color(&m_strip, i, red, green, blue);
MarkSPA 4:c8515fbd2e44 210 neopixel_show(&m_strip);
MarkSPA 4:c8515fbd2e44 211 } else if (pattern == PATTERN_MRB) {
MarkSPA 4:c8515fbd2e44 212 neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 213 led_to_enable = rand()%NUM_LEDS;
MarkSPA 4:c8515fbd2e44 214
MarkSPA 4:c8515fbd2e44 215 neopixel_set_color(&m_strip, led_to_enable, red, green, blue);
MarkSPA 4:c8515fbd2e44 216 neopixel_show(&m_strip);
MarkSPA 4:c8515fbd2e44 217
MarkSPA 4:c8515fbd2e44 218 led_to_enable++;
MarkSPA 4:c8515fbd2e44 219 }
MarkSPA 4:c8515fbd2e44 220
MarkSPA 4:c8515fbd2e44 221 else if (pattern == PATTERN_RAINBOW)
MarkSPA 4:c8515fbd2e44 222 rainbowCycle(20, NUM_LEDS, m_strip);
MarkSPA 4:c8515fbd2e44 223
MarkSPA 4:c8515fbd2e44 224 else if (pattern == PATTERN_CANDY)
MarkSPA 4:c8515fbd2e44 225 candyChase(100, NUM_LEDS, m_strip);
MarkSPA 4:c8515fbd2e44 226
MarkSPA 4:c8515fbd2e44 227 else if (pattern == PATTERN_SNOW)
MarkSPA 4:c8515fbd2e44 228 snowflakes(100, NUM_LEDS, m_strip);
MarkSPA 4:c8515fbd2e44 229
MarkSPA 5:1f6311e0fc14 230 else if (pattern == PATTERN_XMAS)
MarkSPA 5:1f6311e0fc14 231 xmas(200, NUM_LEDS, m_strip);
MarkSPA 4:c8515fbd2e44 232
MarkSPA 4:c8515fbd2e44 233 }
MarkSPA 4:c8515fbd2e44 234 }
MarkSPA 4:c8515fbd2e44 235
MarkSPA 4:c8515fbd2e44 236 static void radio_notification_init(void)
MarkSPA 4:c8515fbd2e44 237 {
MarkSPA 4:c8515fbd2e44 238 //uint32_t err_code;
MarkSPA 4:c8515fbd2e44 239 ble_radio_notification_init(NRF_APP_PRIORITY_LOW,
MarkSPA 4:c8515fbd2e44 240 NRF_RADIO_NOTIFICATION_DISTANCE_800US,
MarkSPA 4:c8515fbd2e44 241 ble_on_radio_active_evt);
MarkSPA 4:c8515fbd2e44 242 //APP_ERROR_CHECK(err_code);
MarkSPA 4:c8515fbd2e44 243 }
RedBearLab 0:dfcebc1e442a 244
RedBearLab 0:dfcebc1e442a 245 int main(void)
MarkSPA 4:c8515fbd2e44 246 {
MarkSPA 4:c8515fbd2e44 247 //uint8_t led_error;
MarkSPA 4:c8515fbd2e44 248
RedBearLab 0:dfcebc1e442a 249 Ticker ticker;
RedBearLab 0:dfcebc1e442a 250 ticker.attach_us(m_status_check_handle, 200000);
MarkSPA 4:c8515fbd2e44 251
MarkSPA 4:c8515fbd2e44 252 //pc.printf("neoPixel Init \r\n");
MarkSPA 4:c8515fbd2e44 253 neopixel_init(&m_strip, dig_pin_num, NUM_LEDS);
MarkSPA 4:c8515fbd2e44 254 neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 255
RedBearLab 0:dfcebc1e442a 256 ble.init();
RedBearLab 0:dfcebc1e442a 257 ble.onDisconnection(disconnectionCallback);
MarkSPA 4:c8515fbd2e44 258 ble.onConnection(connectionCallback);
MarkSPA 4:c8515fbd2e44 259 ble.onDataWritten(WrittenHandler);
MarkSPA 4:c8515fbd2e44 260 radio_notification_init();
MarkSPA 4:c8515fbd2e44 261 //pc.baud(9600);
MarkSPA 4:c8515fbd2e44 262 //pc.format(8, SerialBase::None, 1);
MarkSPA 4:c8515fbd2e44 263 //pc.printf("rbChromaBand Init \r\n");
MarkSPA 4:c8515fbd2e44 264 //pc.attach( uartCB , pc.RxIrq);
RedBearLab 0:dfcebc1e442a 265
MarkSPA 4:c8515fbd2e44 266 // setup advertising
RedBearLab 0:dfcebc1e442a 267 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
RedBearLab 0:dfcebc1e442a 268 ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
RedBearLab 0:dfcebc1e442a 269 ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
MarkSPA 5:1f6311e0fc14 270 (const uint8_t *)"rbCtrl02", sizeof("rbCtrl02") - 1);
RedBearLab 0:dfcebc1e442a 271 ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
MarkSPA 4:c8515fbd2e44 272 (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid));
MarkSPA 4:c8515fbd2e44 273 // 100ms; in multiples of 0.625ms.
MarkSPA 4:c8515fbd2e44 274 //ble.setAdvertisingInterval(160);
MarkSPA 4:c8515fbd2e44 275 ble.setAdvertisingInterval(80);
RedBearLab 0:dfcebc1e442a 276 ble.addService(uartService);
MarkSPA 4:c8515fbd2e44 277 ble.startAdvertising();
MarkSPA 4:c8515fbd2e44 278 //pc.printf("Advertising Start \r\n");
MarkSPA 4:c8515fbd2e44 279
MarkSPA 4:c8515fbd2e44 280 while(1) {
MarkSPA 4:c8515fbd2e44 281 //pc.putc(pc.getc());
MarkSPA 4:c8515fbd2e44 282 ble.waitForEvent();
RedBearLab 0:dfcebc1e442a 283 }
RedBearLab 0:dfcebc1e442a 284 }
RedBearLab 0:dfcebc1e442a 285
RedBearLab 0:dfcebc1e442a 286
RedBearLab 0:dfcebc1e442a 287
RedBearLab 0:dfcebc1e442a 288
RedBearLab 0:dfcebc1e442a 289
RedBearLab 0:dfcebc1e442a 290
RedBearLab 0:dfcebc1e442a 291
RedBearLab 0:dfcebc1e442a 292
RedBearLab 0:dfcebc1e442a 293
RedBearLab 0:dfcebc1e442a 294
RedBearLab 0:dfcebc1e442a 295
RedBearLab 0:dfcebc1e442a 296
RedBearLab 0:dfcebc1e442a 297
RedBearLab 0:dfcebc1e442a 298
RedBearLab 0:dfcebc1e442a 299
RedBearLab 0:dfcebc1e442a 300
RedBearLab 0:dfcebc1e442a 301
RedBearLab 0:dfcebc1e442a 302
RedBearLab 0:dfcebc1e442a 303
RedBearLab 0:dfcebc1e442a 304
RedBearLab 0:dfcebc1e442a 305
RedBearLab 0:dfcebc1e442a 306
RedBearLab 0:dfcebc1e442a 307
RedBearLab 0:dfcebc1e442a 308
RedBearLab 0:dfcebc1e442a 309
RedBearLab 0:dfcebc1e442a 310
RedBearLab 0:dfcebc1e442a 311
RedBearLab 0:dfcebc1e442a 312
RedBearLab 0:dfcebc1e442a 313
RedBearLab 0:dfcebc1e442a 314
RedBearLab 0:dfcebc1e442a 315
RedBearLab 0:dfcebc1e442a 316