Initial (buggy) version

Dependencies:   BLE_API mbed nRF51822

Fork of nRF51822_SimpleControls by RedBearLab

Committer:
MarkSPA
Date:
Mon Nov 28 15:38:58 2016 +0000
Revision:
4:c8515fbd2e44
Parent:
3:823f105078c7
Child:
5:1f6311e0fc14
Initial (buggy) version

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 4:c8515fbd2e44 56 #define PATTERN_ICE 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);
RedBearLab 0:dfcebc1e442a 102
MarkSPA 4:c8515fbd2e44 103 extern uint32_t ble_radio_notification_init(nrf_app_irq_priority_t irq_priority,
MarkSPA 4:c8515fbd2e44 104 nrf_radio_notification_distance_t distance,
MarkSPA 4:c8515fbd2e44 105 ble_radio_notification_evt_handler_t evt_handler);
MarkSPA 4:c8515fbd2e44 106
MarkSPA 4:c8515fbd2e44 107 void connectionCallback(const Gap::ConnectionCallbackParams_t *params)
MarkSPA 4:c8515fbd2e44 108 {
MarkSPA 4:c8515fbd2e44 109 neopixel_init(&m_strip, dig_pin_num, NUM_LEDS);
MarkSPA 4:c8515fbd2e44 110 neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 111 }
RedBearLab 0:dfcebc1e442a 112
RedBearLab 3:823f105078c7 113 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
RedBearLab 0:dfcebc1e442a 114 {
MarkSPA 4:c8515fbd2e44 115 //pc.printf("Disconnected \r\n");
MarkSPA 4:c8515fbd2e44 116 //pc.printf("Restart advertising \r\n");
MarkSPA 4:c8515fbd2e44 117 //clear and remove strip
MarkSPA 4:c8515fbd2e44 118 //neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 119 //neopixel_destroy(&m_strip);
RedBearLab 0:dfcebc1e442a 120 ble.startAdvertising();
RedBearLab 0:dfcebc1e442a 121 }
RedBearLab 0:dfcebc1e442a 122
RedBearLab 2:bbcdd23ba9ba 123 void WrittenHandler(const GattWriteCallbackParams *Handler)
MarkSPA 4:c8515fbd2e44 124 {
RedBearLab 0:dfcebc1e442a 125 uint8_t buf[TXRX_BUF_LEN];
MarkSPA 4:c8515fbd2e44 126 uint16_t bytesRead;
MarkSPA 4:c8515fbd2e44 127
MarkSPA 4:c8515fbd2e44 128 if (Handler->handle == txCharacteristic.getValueAttribute().getHandle()) {
RedBearLab 0:dfcebc1e442a 129 ble.readCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(), buf, &bytesRead);
RedBearLab 0:dfcebc1e442a 130 memset(txPayload, 0, TXRX_BUF_LEN);
MarkSPA 4:c8515fbd2e44 131 memcpy(txPayload, buf, TXRX_BUF_LEN);
MarkSPA 4:c8515fbd2e44 132
MarkSPA 4:c8515fbd2e44 133 //for(index=0; index<bytesRead; index++)
MarkSPA 4:c8515fbd2e44 134 //pc.putc(buf[index]);
RedBearLab 0:dfcebc1e442a 135
MarkSPA 4:c8515fbd2e44 136 if(buf[0] == ONOFF_HEADER) {
MarkSPA 4:c8515fbd2e44 137 //pc.printf("LED value received \r\n");
MarkSPA 4:c8515fbd2e44 138 if(buf[1] == LEDS_ON) {
MarkSPA 4:c8515fbd2e44 139 LEDS_ON_FLAG = 1;
MarkSPA 4:c8515fbd2e44 140 //neopixel_init(&m_strip, dig_pin_num, NUM_LEDS);
MarkSPA 4:c8515fbd2e44 141 //neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 142 } else if(buf[1] == LEDS_OFF) {
MarkSPA 4:c8515fbd2e44 143 LEDS_ON_FLAG = 0;
MarkSPA 4:c8515fbd2e44 144 neopixel_init(&m_strip, dig_pin_num, NUM_LEDS);
MarkSPA 4:c8515fbd2e44 145 neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 146 }
MarkSPA 4:c8515fbd2e44 147 } else if(buf[0] == COLOR_HEADER) {
MarkSPA 4:c8515fbd2e44 148 red = buf[1];
MarkSPA 4:c8515fbd2e44 149 green = buf[2];
MarkSPA 4:c8515fbd2e44 150 blue = buf[3];
MarkSPA 4:c8515fbd2e44 151 pattern = buf[5];
RedBearLab 0:dfcebc1e442a 152 }
RedBearLab 0:dfcebc1e442a 153 }
RedBearLab 0:dfcebc1e442a 154 }
MarkSPA 4:c8515fbd2e44 155
RedBearLab 0:dfcebc1e442a 156 void m_status_check_handle(void)
MarkSPA 4:c8515fbd2e44 157 {
RedBearLab 0:dfcebc1e442a 158 uint8_t buf[3];
MarkSPA 4:c8515fbd2e44 159
RedBearLab 0:dfcebc1e442a 160 // If digital in changes, report the state
MarkSPA 4:c8515fbd2e44 161 if (BUTTON != old_state) {
RedBearLab 0:dfcebc1e442a 162 old_state = BUTTON;
MarkSPA 4:c8515fbd2e44 163
MarkSPA 4:c8515fbd2e44 164 if (BUTTON == 1) {
RedBearLab 0:dfcebc1e442a 165 buf[0] = (0x0A);
RedBearLab 0:dfcebc1e442a 166 buf[1] = (0x01);
MarkSPA 4:c8515fbd2e44 167 buf[2] = (0x00);
MarkSPA 4:c8515fbd2e44 168 ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 3);
MarkSPA 4:c8515fbd2e44 169 } else {
RedBearLab 0:dfcebc1e442a 170 buf[0] = (0x0A);
RedBearLab 0:dfcebc1e442a 171 buf[1] = (0x00);
RedBearLab 0:dfcebc1e442a 172 buf[2] = (0x00);
MarkSPA 4:c8515fbd2e44 173 ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 3);
RedBearLab 0:dfcebc1e442a 174 }
RedBearLab 0:dfcebc1e442a 175 }
RedBearLab 0:dfcebc1e442a 176 }
RedBearLab 0:dfcebc1e442a 177
MarkSPA 4:c8515fbd2e44 178 void ble_on_radio_active_evt(bool radio_active)
MarkSPA 4:c8515fbd2e44 179 {
MarkSPA 4:c8515fbd2e44 180 if ((radio_active == false) && (LEDS_ON_FLAG == 1)) {
MarkSPA 4:c8515fbd2e44 181 if (pattern == PATTERN_ON) {
MarkSPA 4:c8515fbd2e44 182 for (uint8_t i = 0; i < NUM_LEDS; i++)
MarkSPA 4:c8515fbd2e44 183 neopixel_set_color(&m_strip, i, red, green, blue);
MarkSPA 4:c8515fbd2e44 184 neopixel_show(&m_strip);
MarkSPA 4:c8515fbd2e44 185
MarkSPA 4:c8515fbd2e44 186 } else if (pattern == PATTERN_FAST) {
MarkSPA 4:c8515fbd2e44 187 neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 188 if (led_to_enable > NUM_LEDS)
MarkSPA 4:c8515fbd2e44 189 led_to_enable = 0;
MarkSPA 4:c8515fbd2e44 190
MarkSPA 4:c8515fbd2e44 191 neopixel_set_color(&m_strip, led_to_enable, red, green, blue);
MarkSPA 4:c8515fbd2e44 192 neopixel_show(&m_strip);
MarkSPA 4:c8515fbd2e44 193 led_to_enable++;
MarkSPA 4:c8515fbd2e44 194 } else if (pattern == PATTERN_SLOW) {
MarkSPA 4:c8515fbd2e44 195 if (slow_count > 20) {
MarkSPA 4:c8515fbd2e44 196 slow_count = 0;
MarkSPA 4:c8515fbd2e44 197 neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 198 if (led_to_enable > NUM_LEDS)
MarkSPA 4:c8515fbd2e44 199 led_to_enable = 0;
MarkSPA 4:c8515fbd2e44 200
MarkSPA 4:c8515fbd2e44 201 neopixel_set_color(&m_strip, led_to_enable, red, green, blue);
MarkSPA 4:c8515fbd2e44 202 neopixel_show(&m_strip);
MarkSPA 4:c8515fbd2e44 203 led_to_enable++;
MarkSPA 4:c8515fbd2e44 204 }
MarkSPA 4:c8515fbd2e44 205 slow_count++;
MarkSPA 4:c8515fbd2e44 206 } else if (pattern == PATTERN_CHASE) {
MarkSPA 4:c8515fbd2e44 207 for (uint8_t i = 0; i < NUM_LEDS; i++)
MarkSPA 4:c8515fbd2e44 208 neopixel_set_color(&m_strip, i, red, green, blue);
MarkSPA 4:c8515fbd2e44 209 neopixel_show(&m_strip);
MarkSPA 4:c8515fbd2e44 210 } else if (pattern == PATTERN_MRB) {
MarkSPA 4:c8515fbd2e44 211 neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 212 led_to_enable = rand()%NUM_LEDS;
MarkSPA 4:c8515fbd2e44 213
MarkSPA 4:c8515fbd2e44 214 neopixel_set_color(&m_strip, led_to_enable, red, green, blue);
MarkSPA 4:c8515fbd2e44 215 neopixel_show(&m_strip);
MarkSPA 4:c8515fbd2e44 216
MarkSPA 4:c8515fbd2e44 217 led_to_enable++;
MarkSPA 4:c8515fbd2e44 218 }
MarkSPA 4:c8515fbd2e44 219
MarkSPA 4:c8515fbd2e44 220 else if (pattern == PATTERN_RAINBOW)
MarkSPA 4:c8515fbd2e44 221 rainbowCycle(20, NUM_LEDS, m_strip);
MarkSPA 4:c8515fbd2e44 222
MarkSPA 4:c8515fbd2e44 223 else if (pattern == PATTERN_CANDY)
MarkSPA 4:c8515fbd2e44 224 candyChase(100, NUM_LEDS, m_strip);
MarkSPA 4:c8515fbd2e44 225
MarkSPA 4:c8515fbd2e44 226 else if (pattern == PATTERN_SNOW)
MarkSPA 4:c8515fbd2e44 227 snowflakes(100, NUM_LEDS, m_strip);
MarkSPA 4:c8515fbd2e44 228
MarkSPA 4:c8515fbd2e44 229 else if (pattern == PATTERN_ICE)
MarkSPA 4:c8515fbd2e44 230 iceflakes(100, NUM_LEDS, m_strip);
MarkSPA 4:c8515fbd2e44 231
MarkSPA 4:c8515fbd2e44 232 }
MarkSPA 4:c8515fbd2e44 233 }
MarkSPA 4:c8515fbd2e44 234
MarkSPA 4:c8515fbd2e44 235 static void radio_notification_init(void)
MarkSPA 4:c8515fbd2e44 236 {
MarkSPA 4:c8515fbd2e44 237 //uint32_t err_code;
MarkSPA 4:c8515fbd2e44 238 ble_radio_notification_init(NRF_APP_PRIORITY_LOW,
MarkSPA 4:c8515fbd2e44 239 NRF_RADIO_NOTIFICATION_DISTANCE_800US,
MarkSPA 4:c8515fbd2e44 240 ble_on_radio_active_evt);
MarkSPA 4:c8515fbd2e44 241 //APP_ERROR_CHECK(err_code);
MarkSPA 4:c8515fbd2e44 242 }
RedBearLab 0:dfcebc1e442a 243
RedBearLab 0:dfcebc1e442a 244 int main(void)
MarkSPA 4:c8515fbd2e44 245 {
MarkSPA 4:c8515fbd2e44 246 //uint8_t led_error;
MarkSPA 4:c8515fbd2e44 247
RedBearLab 0:dfcebc1e442a 248 Ticker ticker;
RedBearLab 0:dfcebc1e442a 249 ticker.attach_us(m_status_check_handle, 200000);
MarkSPA 4:c8515fbd2e44 250
MarkSPA 4:c8515fbd2e44 251 //pc.printf("neoPixel Init \r\n");
MarkSPA 4:c8515fbd2e44 252 neopixel_init(&m_strip, dig_pin_num, NUM_LEDS);
MarkSPA 4:c8515fbd2e44 253 neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 254
RedBearLab 0:dfcebc1e442a 255 ble.init();
RedBearLab 0:dfcebc1e442a 256 ble.onDisconnection(disconnectionCallback);
MarkSPA 4:c8515fbd2e44 257 ble.onConnection(connectionCallback);
MarkSPA 4:c8515fbd2e44 258 ble.onDataWritten(WrittenHandler);
MarkSPA 4:c8515fbd2e44 259 radio_notification_init();
MarkSPA 4:c8515fbd2e44 260 //pc.baud(9600);
MarkSPA 4:c8515fbd2e44 261 //pc.format(8, SerialBase::None, 1);
MarkSPA 4:c8515fbd2e44 262 //pc.printf("rbChromaBand Init \r\n");
MarkSPA 4:c8515fbd2e44 263 //pc.attach( uartCB , pc.RxIrq);
RedBearLab 0:dfcebc1e442a 264
MarkSPA 4:c8515fbd2e44 265 // setup advertising
RedBearLab 0:dfcebc1e442a 266 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
RedBearLab 0:dfcebc1e442a 267 ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
RedBearLab 0:dfcebc1e442a 268 ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
MarkSPA 4:c8515fbd2e44 269 (const uint8_t *)"rbCBand", sizeof("rbCBand") - 1);
RedBearLab 0:dfcebc1e442a 270 ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
MarkSPA 4:c8515fbd2e44 271 (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid));
MarkSPA 4:c8515fbd2e44 272 // 100ms; in multiples of 0.625ms.
MarkSPA 4:c8515fbd2e44 273 //ble.setAdvertisingInterval(160);
MarkSPA 4:c8515fbd2e44 274 ble.setAdvertisingInterval(80);
RedBearLab 0:dfcebc1e442a 275 ble.addService(uartService);
MarkSPA 4:c8515fbd2e44 276 ble.startAdvertising();
MarkSPA 4:c8515fbd2e44 277 //pc.printf("Advertising Start \r\n");
MarkSPA 4:c8515fbd2e44 278
MarkSPA 4:c8515fbd2e44 279 while(1) {
MarkSPA 4:c8515fbd2e44 280 //pc.putc(pc.getc());
MarkSPA 4:c8515fbd2e44 281 ble.waitForEvent();
RedBearLab 0:dfcebc1e442a 282 }
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