Initial (buggy) version

Dependencies:   BLE_API mbed nRF51822

Fork of nRF51822_SimpleControls by RedBearLab

Committer:
MarkSPA
Date:
Thu Dec 15 23:25:16 2016 +0000
Revision:
7:0db51a3107fc
Parent:
6:074f5ec7428c
Child:
8:e275405a431d
Added a couple of patterns, changed behavior or connect/disconnect.

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 6:074f5ec7428c 57 #define PATTERN_ICE 0x0A
MarkSPA 7:0db51a3107fc 58 #define PATTERN_COL 0x0B
MarkSPA 4:c8515fbd2e44 59 #define LEDS_ON 0x01
MarkSPA 4:c8515fbd2e44 60 #define LEDS_OFF 0x02
RedBearLab 0:dfcebc1e442a 61
RedBearLab 2:bbcdd23ba9ba 62 BLE ble;
RedBearLab 0:dfcebc1e442a 63
MarkSPA 4:c8515fbd2e44 64 //DigitalOut LED_SET(DIGITAL_OUT_PIN);
MarkSPA 4:c8515fbd2e44 65 DigitalOut LED_SET(BOARD_LED);
RedBearLab 0:dfcebc1e442a 66 DigitalIn BUTTON(DIGITAL_IN_PIN);
MarkSPA 4:c8515fbd2e44 67 //PwmOut PWM(PWM_PIN);
MarkSPA 4:c8515fbd2e44 68 //AnalogIn ANALOG(ANALOG_IN_PIN);
RedBearLab 0:dfcebc1e442a 69
MarkSPA 4:c8515fbd2e44 70 //Serial pc(USBTX, USBRX);
MarkSPA 4:c8515fbd2e44 71 static uint8_t old_state = 0;
MarkSPA 4:c8515fbd2e44 72 neopixel_strip_t m_strip;
MarkSPA 4:c8515fbd2e44 73 //uint8_t dig_pin_num = BB_DIG_OUT_PIN; //DIGITAL_OUT_PIN; //6;
MarkSPA 4:c8515fbd2e44 74 uint8_t dig_pin_num = P0_8;
MarkSPA 4:c8515fbd2e44 75 //uint8_t leds_per_strip = 4; //24;
MarkSPA 4:c8515fbd2e44 76 uint8_t slow_count = 0;
MarkSPA 4:c8515fbd2e44 77 //uint8_t error;
MarkSPA 4:c8515fbd2e44 78 uint8_t led_to_enable = 2; //10;
MarkSPA 4:c8515fbd2e44 79 uint8_t red = 255;
MarkSPA 4:c8515fbd2e44 80 uint8_t green = 128;
MarkSPA 4:c8515fbd2e44 81 uint8_t blue = 159;
MarkSPA 4:c8515fbd2e44 82 uint8_t pattern = 0;
RedBearLab 0:dfcebc1e442a 83
MarkSPA 7:0db51a3107fc 84 char mDeviceName[128];
MarkSPA 7:0db51a3107fc 85
MarkSPA 4:c8515fbd2e44 86 uint8_t LEDS_ON_FLAG = 0;
RedBearLab 0:dfcebc1e442a 87
RedBearLab 0:dfcebc1e442a 88 // The Nordic UART Service
RedBearLab 0:dfcebc1e442a 89 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 90 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 91 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 92 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 93
RedBearLab 0:dfcebc1e442a 94 uint8_t txPayload[TXRX_BUF_LEN] = {0,};
RedBearLab 0:dfcebc1e442a 95 uint8_t rxPayload[TXRX_BUF_LEN] = {0,};
RedBearLab 0:dfcebc1e442a 96
RedBearLab 0:dfcebc1e442a 97 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 98 GattCharacteristic rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
RedBearLab 0:dfcebc1e442a 99 GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic};
RedBearLab 0:dfcebc1e442a 100 GattService uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *));
MarkSPA 7:0db51a3107fc 101 void setup_advertising(void);
RedBearLab 0:dfcebc1e442a 102
MarkSPA 4:c8515fbd2e44 103 void rainbowCycle(int wait, uint8_t numLEDs, neopixel_strip_t m_strip);
MarkSPA 4:c8515fbd2e44 104 void candyChase(int wait, uint8_t numLEDs, neopixel_strip_t m_strip);
MarkSPA 4:c8515fbd2e44 105 void snowflakes(int wait, uint8_t numLEDs, neopixel_strip_t m_strip);
MarkSPA 4:c8515fbd2e44 106 void iceflakes(int delay, uint8_t numLEDs, neopixel_strip_t m_strip);
MarkSPA 5:1f6311e0fc14 107 void xmas(int delay, uint8_t numLEDs, neopixel_strip_t m_strip);
MarkSPA 7:0db51a3107fc 108 void collegiate(int wait, uint8_t numLEDs, neopixel_strip_t m_strip);
RedBearLab 0:dfcebc1e442a 109
MarkSPA 4:c8515fbd2e44 110 extern uint32_t ble_radio_notification_init(nrf_app_irq_priority_t irq_priority,
MarkSPA 4:c8515fbd2e44 111 nrf_radio_notification_distance_t distance,
MarkSPA 4:c8515fbd2e44 112 ble_radio_notification_evt_handler_t evt_handler);
MarkSPA 4:c8515fbd2e44 113
MarkSPA 4:c8515fbd2e44 114 void connectionCallback(const Gap::ConnectionCallbackParams_t *params)
MarkSPA 4:c8515fbd2e44 115 {
MarkSPA 4:c8515fbd2e44 116 neopixel_init(&m_strip, dig_pin_num, NUM_LEDS);
MarkSPA 4:c8515fbd2e44 117 neopixel_clear(&m_strip);
MarkSPA 7:0db51a3107fc 118 LEDS_ON_FLAG = 0;
MarkSPA 4:c8515fbd2e44 119 }
RedBearLab 0:dfcebc1e442a 120
RedBearLab 3:823f105078c7 121 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
RedBearLab 0:dfcebc1e442a 122 {
MarkSPA 4:c8515fbd2e44 123 //pc.printf("Disconnected \r\n");
MarkSPA 4:c8515fbd2e44 124 //pc.printf("Restart advertising \r\n");
MarkSPA 4:c8515fbd2e44 125 //clear and remove strip
MarkSPA 4:c8515fbd2e44 126 //neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 127 //neopixel_destroy(&m_strip);
MarkSPA 7:0db51a3107fc 128 //strcpy(mDeviceName, "RRVA Cntd");
MarkSPA 7:0db51a3107fc 129 //setup_advertising();
RedBearLab 0:dfcebc1e442a 130 ble.startAdvertising();
RedBearLab 0:dfcebc1e442a 131 }
RedBearLab 0:dfcebc1e442a 132
RedBearLab 2:bbcdd23ba9ba 133 void WrittenHandler(const GattWriteCallbackParams *Handler)
MarkSPA 4:c8515fbd2e44 134 {
RedBearLab 0:dfcebc1e442a 135 uint8_t buf[TXRX_BUF_LEN];
MarkSPA 4:c8515fbd2e44 136 uint16_t bytesRead;
MarkSPA 4:c8515fbd2e44 137
MarkSPA 4:c8515fbd2e44 138 if (Handler->handle == txCharacteristic.getValueAttribute().getHandle()) {
RedBearLab 0:dfcebc1e442a 139 ble.readCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(), buf, &bytesRead);
RedBearLab 0:dfcebc1e442a 140 memset(txPayload, 0, TXRX_BUF_LEN);
MarkSPA 4:c8515fbd2e44 141 memcpy(txPayload, buf, TXRX_BUF_LEN);
MarkSPA 4:c8515fbd2e44 142
MarkSPA 4:c8515fbd2e44 143 //for(index=0; index<bytesRead; index++)
MarkSPA 4:c8515fbd2e44 144 //pc.putc(buf[index]);
RedBearLab 0:dfcebc1e442a 145
MarkSPA 4:c8515fbd2e44 146 if(buf[0] == ONOFF_HEADER) {
MarkSPA 4:c8515fbd2e44 147 //pc.printf("LED value received \r\n");
MarkSPA 4:c8515fbd2e44 148 if(buf[1] == LEDS_ON) {
MarkSPA 4:c8515fbd2e44 149 LEDS_ON_FLAG = 1;
MarkSPA 4:c8515fbd2e44 150 //neopixel_init(&m_strip, dig_pin_num, NUM_LEDS);
MarkSPA 4:c8515fbd2e44 151 //neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 152 } else if(buf[1] == LEDS_OFF) {
MarkSPA 4:c8515fbd2e44 153 LEDS_ON_FLAG = 0;
MarkSPA 4:c8515fbd2e44 154 neopixel_init(&m_strip, dig_pin_num, NUM_LEDS);
MarkSPA 4:c8515fbd2e44 155 neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 156 }
MarkSPA 4:c8515fbd2e44 157 } else if(buf[0] == COLOR_HEADER) {
MarkSPA 4:c8515fbd2e44 158 red = buf[1];
MarkSPA 4:c8515fbd2e44 159 green = buf[2];
MarkSPA 4:c8515fbd2e44 160 blue = buf[3];
MarkSPA 4:c8515fbd2e44 161 pattern = buf[5];
RedBearLab 0:dfcebc1e442a 162 }
MarkSPA 6:074f5ec7428c 163 else
MarkSPA 6:074f5ec7428c 164 {
MarkSPA 6:074f5ec7428c 165 LEDS_ON_FLAG = 1;
MarkSPA 6:074f5ec7428c 166 red = buf[1];
MarkSPA 6:074f5ec7428c 167 green = buf[2];
MarkSPA 6:074f5ec7428c 168 blue = buf[3];
MarkSPA 6:074f5ec7428c 169 pattern = buf[5];
MarkSPA 6:074f5ec7428c 170 }
RedBearLab 0:dfcebc1e442a 171 }
RedBearLab 0:dfcebc1e442a 172 }
MarkSPA 4:c8515fbd2e44 173
RedBearLab 0:dfcebc1e442a 174 void m_status_check_handle(void)
MarkSPA 4:c8515fbd2e44 175 {
RedBearLab 0:dfcebc1e442a 176 uint8_t buf[3];
MarkSPA 4:c8515fbd2e44 177
RedBearLab 0:dfcebc1e442a 178 // If digital in changes, report the state
MarkSPA 4:c8515fbd2e44 179 if (BUTTON != old_state) {
RedBearLab 0:dfcebc1e442a 180 old_state = BUTTON;
MarkSPA 4:c8515fbd2e44 181
MarkSPA 4:c8515fbd2e44 182 if (BUTTON == 1) {
RedBearLab 0:dfcebc1e442a 183 buf[0] = (0x0A);
RedBearLab 0:dfcebc1e442a 184 buf[1] = (0x01);
MarkSPA 4:c8515fbd2e44 185 buf[2] = (0x00);
MarkSPA 4:c8515fbd2e44 186 ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 3);
MarkSPA 4:c8515fbd2e44 187 } else {
RedBearLab 0:dfcebc1e442a 188 buf[0] = (0x0A);
RedBearLab 0:dfcebc1e442a 189 buf[1] = (0x00);
RedBearLab 0:dfcebc1e442a 190 buf[2] = (0x00);
MarkSPA 4:c8515fbd2e44 191 ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 3);
RedBearLab 0:dfcebc1e442a 192 }
RedBearLab 0:dfcebc1e442a 193 }
RedBearLab 0:dfcebc1e442a 194 }
RedBearLab 0:dfcebc1e442a 195
MarkSPA 4:c8515fbd2e44 196 void ble_on_radio_active_evt(bool radio_active)
MarkSPA 4:c8515fbd2e44 197 {
MarkSPA 4:c8515fbd2e44 198 if ((radio_active == false) && (LEDS_ON_FLAG == 1)) {
MarkSPA 4:c8515fbd2e44 199 if (pattern == PATTERN_ON) {
MarkSPA 6:074f5ec7428c 200 for (uint8_t i = 0; i <= NUM_LEDS; i++)
MarkSPA 4:c8515fbd2e44 201 neopixel_set_color(&m_strip, i, red, green, blue);
MarkSPA 4:c8515fbd2e44 202 neopixel_show(&m_strip);
MarkSPA 4:c8515fbd2e44 203
MarkSPA 4:c8515fbd2e44 204 } else if (pattern == PATTERN_FAST) {
MarkSPA 6:074f5ec7428c 205 //neopixel_clear(&m_strip);
MarkSPA 6:074f5ec7428c 206 for (uint8_t i = 0; i <= NUM_LEDS; i++)
MarkSPA 6:074f5ec7428c 207 neopixel_set_color(&m_strip, i, 0, 0, 0);
MarkSPA 4:c8515fbd2e44 208 if (led_to_enable > NUM_LEDS)
MarkSPA 4:c8515fbd2e44 209 led_to_enable = 0;
MarkSPA 4:c8515fbd2e44 210 neopixel_set_color(&m_strip, led_to_enable, red, green, blue);
MarkSPA 4:c8515fbd2e44 211 neopixel_show(&m_strip);
MarkSPA 4:c8515fbd2e44 212 led_to_enable++;
MarkSPA 4:c8515fbd2e44 213 } else if (pattern == PATTERN_SLOW) {
MarkSPA 6:074f5ec7428c 214 for (uint8_t i = 0; i <= NUM_LEDS; i++)
MarkSPA 6:074f5ec7428c 215 neopixel_set_color(&m_strip, i, 0, 0, 0);
MarkSPA 6:074f5ec7428c 216 if (led_to_enable > NUM_LEDS)
MarkSPA 6:074f5ec7428c 217 led_to_enable = 0;
MarkSPA 6:074f5ec7428c 218 neopixel_set_color(&m_strip, led_to_enable, red, green, blue);
MarkSPA 6:074f5ec7428c 219 neopixel_show(&m_strip);
MarkSPA 6:074f5ec7428c 220 led_to_enable++;
MarkSPA 6:074f5ec7428c 221 wait_ms(1000);
MarkSPA 6:074f5ec7428c 222
MarkSPA 4:c8515fbd2e44 223 } else if (pattern == PATTERN_CHASE) {
MarkSPA 4:c8515fbd2e44 224 for (uint8_t i = 0; i < NUM_LEDS; i++)
MarkSPA 4:c8515fbd2e44 225 neopixel_set_color(&m_strip, i, red, green, blue);
MarkSPA 4:c8515fbd2e44 226 neopixel_show(&m_strip);
MarkSPA 6:074f5ec7428c 227
MarkSPA 4:c8515fbd2e44 228 } else if (pattern == PATTERN_MRB) {
MarkSPA 4:c8515fbd2e44 229 neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 230 led_to_enable = rand()%NUM_LEDS;
MarkSPA 4:c8515fbd2e44 231 neopixel_set_color(&m_strip, led_to_enable, red, green, blue);
MarkSPA 4:c8515fbd2e44 232 neopixel_show(&m_strip);
MarkSPA 4:c8515fbd2e44 233 }
MarkSPA 4:c8515fbd2e44 234
MarkSPA 4:c8515fbd2e44 235 else if (pattern == PATTERN_RAINBOW)
MarkSPA 4:c8515fbd2e44 236 rainbowCycle(20, NUM_LEDS, m_strip);
MarkSPA 4:c8515fbd2e44 237
MarkSPA 4:c8515fbd2e44 238 else if (pattern == PATTERN_CANDY)
MarkSPA 4:c8515fbd2e44 239 candyChase(100, NUM_LEDS, m_strip);
MarkSPA 4:c8515fbd2e44 240
MarkSPA 4:c8515fbd2e44 241 else if (pattern == PATTERN_SNOW)
MarkSPA 6:074f5ec7428c 242 snowflakes(250, NUM_LEDS, m_strip);
MarkSPA 6:074f5ec7428c 243
MarkSPA 6:074f5ec7428c 244 else if (pattern == PATTERN_ICE)
MarkSPA 6:074f5ec7428c 245 iceflakes(250, NUM_LEDS, m_strip);
MarkSPA 4:c8515fbd2e44 246
MarkSPA 5:1f6311e0fc14 247 else if (pattern == PATTERN_XMAS)
MarkSPA 5:1f6311e0fc14 248 xmas(200, NUM_LEDS, m_strip);
MarkSPA 6:074f5ec7428c 249
MarkSPA 7:0db51a3107fc 250 else if (pattern == PATTERN_COL)
MarkSPA 7:0db51a3107fc 251 collegiate(100, NUM_LEDS, m_strip);
MarkSPA 7:0db51a3107fc 252
MarkSPA 6:074f5ec7428c 253 else
MarkSPA 6:074f5ec7428c 254 neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 255
MarkSPA 4:c8515fbd2e44 256 }
MarkSPA 4:c8515fbd2e44 257 }
MarkSPA 4:c8515fbd2e44 258
MarkSPA 4:c8515fbd2e44 259 static void radio_notification_init(void)
MarkSPA 4:c8515fbd2e44 260 {
MarkSPA 4:c8515fbd2e44 261 //uint32_t err_code;
MarkSPA 4:c8515fbd2e44 262 ble_radio_notification_init(NRF_APP_PRIORITY_LOW,
MarkSPA 4:c8515fbd2e44 263 NRF_RADIO_NOTIFICATION_DISTANCE_800US,
MarkSPA 4:c8515fbd2e44 264 ble_on_radio_active_evt);
MarkSPA 4:c8515fbd2e44 265 //APP_ERROR_CHECK(err_code);
MarkSPA 4:c8515fbd2e44 266 }
RedBearLab 0:dfcebc1e442a 267
MarkSPA 7:0db51a3107fc 268 void setup_advertising(void)
MarkSPA 7:0db51a3107fc 269 {
MarkSPA 7:0db51a3107fc 270 int length = strlen(mDeviceName);
MarkSPA 7:0db51a3107fc 271
MarkSPA 7:0db51a3107fc 272 // setup advertising
MarkSPA 7:0db51a3107fc 273 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
MarkSPA 7:0db51a3107fc 274 ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
MarkSPA 7:0db51a3107fc 275 ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
MarkSPA 7:0db51a3107fc 276 (const uint8_t *)&mDeviceName, length);
MarkSPA 7:0db51a3107fc 277 ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
MarkSPA 7:0db51a3107fc 278 (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid));
MarkSPA 7:0db51a3107fc 279 // 100ms; in multiples of 0.625ms.
MarkSPA 7:0db51a3107fc 280 //ble.setAdvertisingInterval(160);
MarkSPA 7:0db51a3107fc 281 ble.setAdvertisingInterval(80);
MarkSPA 7:0db51a3107fc 282 ble.addService(uartService);
MarkSPA 7:0db51a3107fc 283 ble.startAdvertising();
MarkSPA 7:0db51a3107fc 284 //pc.printf("Advertising Start \r\n");
MarkSPA 7:0db51a3107fc 285 }
MarkSPA 7:0db51a3107fc 286
RedBearLab 0:dfcebc1e442a 287 int main(void)
MarkSPA 4:c8515fbd2e44 288 {
MarkSPA 4:c8515fbd2e44 289 //uint8_t led_error;
MarkSPA 4:c8515fbd2e44 290
RedBearLab 0:dfcebc1e442a 291 Ticker ticker;
RedBearLab 0:dfcebc1e442a 292 ticker.attach_us(m_status_check_handle, 200000);
MarkSPA 4:c8515fbd2e44 293
MarkSPA 4:c8515fbd2e44 294 //pc.printf("neoPixel Init \r\n");
MarkSPA 4:c8515fbd2e44 295 neopixel_init(&m_strip, dig_pin_num, NUM_LEDS);
MarkSPA 4:c8515fbd2e44 296 neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 297
RedBearLab 0:dfcebc1e442a 298 ble.init();
RedBearLab 0:dfcebc1e442a 299 ble.onDisconnection(disconnectionCallback);
MarkSPA 4:c8515fbd2e44 300 ble.onConnection(connectionCallback);
MarkSPA 4:c8515fbd2e44 301 ble.onDataWritten(WrittenHandler);
MarkSPA 4:c8515fbd2e44 302 radio_notification_init();
MarkSPA 4:c8515fbd2e44 303 //pc.baud(9600);
MarkSPA 4:c8515fbd2e44 304 //pc.format(8, SerialBase::None, 1);
MarkSPA 4:c8515fbd2e44 305 //pc.printf("rbChromaBand Init \r\n");
MarkSPA 4:c8515fbd2e44 306 //pc.attach( uartCB , pc.RxIrq);
MarkSPA 7:0db51a3107fc 307
MarkSPA 7:0db51a3107fc 308 strcpy(mDeviceName, "RRVA BLE");
RedBearLab 0:dfcebc1e442a 309
MarkSPA 7:0db51a3107fc 310 setup_advertising();
MarkSPA 4:c8515fbd2e44 311
MarkSPA 4:c8515fbd2e44 312 while(1) {
MarkSPA 4:c8515fbd2e44 313 //pc.putc(pc.getc());
MarkSPA 4:c8515fbd2e44 314 ble.waitForEvent();
RedBearLab 0:dfcebc1e442a 315 }
RedBearLab 0:dfcebc1e442a 316 }
RedBearLab 0:dfcebc1e442a 317
RedBearLab 0:dfcebc1e442a 318
RedBearLab 0:dfcebc1e442a 319
RedBearLab 0:dfcebc1e442a 320
RedBearLab 0:dfcebc1e442a 321
RedBearLab 0:dfcebc1e442a 322
RedBearLab 0:dfcebc1e442a 323
RedBearLab 0:dfcebc1e442a 324
RedBearLab 0:dfcebc1e442a 325
RedBearLab 0:dfcebc1e442a 326
RedBearLab 0:dfcebc1e442a 327
RedBearLab 0:dfcebc1e442a 328
RedBearLab 0:dfcebc1e442a 329
RedBearLab 0:dfcebc1e442a 330
RedBearLab 0:dfcebc1e442a 331
RedBearLab 0:dfcebc1e442a 332
RedBearLab 0:dfcebc1e442a 333
RedBearLab 0:dfcebc1e442a 334
RedBearLab 0:dfcebc1e442a 335
RedBearLab 0:dfcebc1e442a 336
RedBearLab 0:dfcebc1e442a 337
RedBearLab 0:dfcebc1e442a 338
RedBearLab 0:dfcebc1e442a 339
RedBearLab 0:dfcebc1e442a 340
RedBearLab 0:dfcebc1e442a 341
RedBearLab 0:dfcebc1e442a 342
RedBearLab 0:dfcebc1e442a 343
RedBearLab 0:dfcebc1e442a 344
RedBearLab 0:dfcebc1e442a 345
RedBearLab 0:dfcebc1e442a 346
RedBearLab 0:dfcebc1e442a 347
RedBearLab 0:dfcebc1e442a 348