share for RS

Fork of rbVectorIQ by Mark @RRVA

Committer:
MarkSPA
Date:
Mon Jun 19 18:12:42 2017 +0000
Revision:
16:4fca60460b7e
Parent:
main.cpp@14:459081f9f70b
Child:
17:123883bbf391
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RedBearLab 1:f03072e32ed3 1 /*
RedBearLab 1:f03072e32ed3 2
MarkSPA 13:047bbd59f351 3 Copyright (c) 2017 Radiant RVA
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 */
MarkSPA 16:4fca60460b7e 19 //#define DK_52
MarkSPA 16:4fca60460b7e 20
MarkSPA 16:4fca60460b7e 21 #include <events/mbed_events.h>
MarkSPA 13:047bbd59f351 22 #include "vector_iq.h"
RedBearLab 0:dfcebc1e442a 23
MarkSPA 16:4fca60460b7e 24 #ifdef DK_52
MarkSPA 16:4fca60460b7e 25 DigitalOut led1(LED1, 1);
MarkSPA 16:4fca60460b7e 26 #endif
MarkSPA 16:4fca60460b7e 27
MarkSPA 16:4fca60460b7e 28 static EventQueue eventQueue(/* event count */ 16 * EVENTS_EVENT_SIZE);
MarkSPA 4:c8515fbd2e44 29
MarkSPA 4:c8515fbd2e44 30 void connectionCallback(const Gap::ConnectionCallbackParams_t *params)
MarkSPA 4:c8515fbd2e44 31 {
MarkSPA 16:4fca60460b7e 32 #ifdef VIQ
MarkSPA 4:c8515fbd2e44 33 neopixel_init(&m_strip, dig_pin_num, NUM_LEDS);
MarkSPA 4:c8515fbd2e44 34 neopixel_clear(&m_strip);
MarkSPA 7:0db51a3107fc 35 LEDS_ON_FLAG = 0;
MarkSPA 16:4fca60460b7e 36 #endif
MarkSPA 4:c8515fbd2e44 37 }
RedBearLab 0:dfcebc1e442a 38
RedBearLab 3:823f105078c7 39 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
RedBearLab 0:dfcebc1e442a 40 {
MarkSPA 16:4fca60460b7e 41 BLE::Instance().gap().startAdvertising(); // restart advertising
RedBearLab 0:dfcebc1e442a 42 }
RedBearLab 0:dfcebc1e442a 43
RedBearLab 2:bbcdd23ba9ba 44 void WrittenHandler(const GattWriteCallbackParams *Handler)
MarkSPA 4:c8515fbd2e44 45 {
MarkSPA 16:4fca60460b7e 46 #ifdef VIQ
RedBearLab 0:dfcebc1e442a 47 uint8_t buf[TXRX_BUF_LEN];
MarkSPA 4:c8515fbd2e44 48 uint16_t bytesRead;
MarkSPA 4:c8515fbd2e44 49
MarkSPA 4:c8515fbd2e44 50 if (Handler->handle == txCharacteristic.getValueAttribute().getHandle()) {
RedBearLab 0:dfcebc1e442a 51 ble.readCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(), buf, &bytesRead);
RedBearLab 0:dfcebc1e442a 52 memset(txPayload, 0, TXRX_BUF_LEN);
MarkSPA 4:c8515fbd2e44 53 memcpy(txPayload, buf, TXRX_BUF_LEN);
MarkSPA 4:c8515fbd2e44 54
MarkSPA 4:c8515fbd2e44 55 //for(index=0; index<bytesRead; index++)
MarkSPA 4:c8515fbd2e44 56 //pc.putc(buf[index]);
RedBearLab 0:dfcebc1e442a 57
MarkSPA 4:c8515fbd2e44 58 if(buf[0] == ONOFF_HEADER) {
MarkSPA 4:c8515fbd2e44 59 //pc.printf("LED value received \r\n");
MarkSPA 4:c8515fbd2e44 60 if(buf[1] == LEDS_ON) {
MarkSPA 4:c8515fbd2e44 61 LEDS_ON_FLAG = 1;
MarkSPA 4:c8515fbd2e44 62 } else if(buf[1] == LEDS_OFF) {
MarkSPA 4:c8515fbd2e44 63 LEDS_ON_FLAG = 0;
MarkSPA 4:c8515fbd2e44 64 neopixel_init(&m_strip, dig_pin_num, NUM_LEDS);
MarkSPA 4:c8515fbd2e44 65 neopixel_clear(&m_strip);
MarkSPA 4:c8515fbd2e44 66 }
MarkSPA 4:c8515fbd2e44 67 } else if(buf[0] == COLOR_HEADER) {
MarkSPA 4:c8515fbd2e44 68 red = buf[1];
MarkSPA 4:c8515fbd2e44 69 green = buf[2];
MarkSPA 4:c8515fbd2e44 70 blue = buf[3];
MarkSPA 4:c8515fbd2e44 71 pattern = buf[5];
MarkSPA 13:047bbd59f351 72 } else if(buf[0] == PIEZO_HEADER) {
MarkSPA 13:047bbd59f351 73 mPiezoOn = buf[1];
MarkSPA 14:459081f9f70b 74 //mPiezoDur = buf[2];
MarkSPA 14:459081f9f70b 75 mPiezoPattern = buf[2];
MarkSPA 13:047bbd59f351 76 } else if(buf[0] == HAPTIC_HEADER) {
MarkSPA 13:047bbd59f351 77 mHapticOn = buf[1];
MarkSPA 13:047bbd59f351 78 mHapticDur = buf[2];
MarkSPA 13:047bbd59f351 79 mHapticPattern = buf[3];
MarkSPA 14:459081f9f70b 80 } else if(buf[0] == ALARM_HEADER) {
MarkSPA 14:459081f9f70b 81 mAlarmOn = buf[1];
MarkSPA 14:459081f9f70b 82 //mAlarmStart = buf[2];
MarkSPA 14:459081f9f70b 83 mAlarmDur = buf[2];
MarkSPA 14:459081f9f70b 84 mAlarmPiezoOn = buf[4];
MarkSPA 14:459081f9f70b 85 mAlarmTone = buf[5];
MarkSPA 14:459081f9f70b 86 mAlarmPattern = buf[6];
MarkSPA 14:459081f9f70b 87 pattern = mAlarmPattern;
MarkSPA 14:459081f9f70b 88 if (mAlarmOn == ALARM_ON) {
MarkSPA 14:459081f9f70b 89 // Setup the timer
MarkSPA 14:459081f9f70b 90 t_alarm.start();
MarkSPA 14:459081f9f70b 91 mBeginAlarm = t_alarm.read();
MarkSPA 14:459081f9f70b 92 mEndAlarm = mBeginAlarm + mAlarmDur;
MarkSPA 14:459081f9f70b 93 mPiezoOn = mAlarmPiezoOn;
MarkSPA 14:459081f9f70b 94 LEDS_ON_FLAG = 1;
MarkSPA 14:459081f9f70b 95 } else if (mAlarmOn == ALARM_OFF) {
MarkSPA 14:459081f9f70b 96 // Stop the timer
MarkSPA 14:459081f9f70b 97 t_alarm.stop();
MarkSPA 14:459081f9f70b 98 // Kill all the effects
MarkSPA 14:459081f9f70b 99 mHapticOn = HAPTIC_OFF;
MarkSPA 14:459081f9f70b 100 mPiezoOn = PIEZO_OFF;
MarkSPA 14:459081f9f70b 101 LEDS_ON_FLAG = 0;
MarkSPA 14:459081f9f70b 102 }
MarkSPA 13:047bbd59f351 103 }
MarkSPA 6:074f5ec7428c 104 else
MarkSPA 6:074f5ec7428c 105 {
MarkSPA 6:074f5ec7428c 106 LEDS_ON_FLAG = 1;
MarkSPA 6:074f5ec7428c 107 red = buf[1];
MarkSPA 6:074f5ec7428c 108 green = buf[2];
MarkSPA 6:074f5ec7428c 109 blue = buf[3];
MarkSPA 6:074f5ec7428c 110 pattern = buf[5];
MarkSPA 6:074f5ec7428c 111 }
RedBearLab 0:dfcebc1e442a 112 }
MarkSPA 16:4fca60460b7e 113 #endif
RedBearLab 0:dfcebc1e442a 114 }
MarkSPA 4:c8515fbd2e44 115
MarkSPA 14:459081f9f70b 116 // pb Interrupt routine - is interrupt activated by a falling edge of pb input
MarkSPA 14:459081f9f70b 117 void pb_hit_interrupt (void) {
MarkSPA 14:459081f9f70b 118 pattern++;
MarkSPA 14:459081f9f70b 119 if (pattern >= PATTERN_MEM)
MarkSPA 14:459081f9f70b 120 pattern = PATTERN_ON;
MarkSPA 14:459081f9f70b 121 }
MarkSPA 14:459081f9f70b 122
RedBearLab 0:dfcebc1e442a 123 void m_status_check_handle(void)
MarkSPA 4:c8515fbd2e44 124 {
MarkSPA 13:047bbd59f351 125 //uint8_t buf[3];
MarkSPA 14:459081f9f70b 126
MarkSPA 14:459081f9f70b 127 //if (BUTTON == 1) {
MarkSPA 14:459081f9f70b 128 // Cycle through display patterns
MarkSPA 16:4fca60460b7e 129 //pattern++;
MarkSPA 16:4fca60460b7e 130 //if (pattern >= PATTERN_MEM)
MarkSPA 16:4fca60460b7e 131 // pattern = PATTERN_NONE;
MarkSPA 14:459081f9f70b 132 //}
RedBearLab 0:dfcebc1e442a 133 }
RedBearLab 0:dfcebc1e442a 134
MarkSPA 16:4fca60460b7e 135 void updateLEDs()
MarkSPA 4:c8515fbd2e44 136 {
MarkSPA 16:4fca60460b7e 137 #ifdef VIQ
MarkSPA 14:459081f9f70b 138 if (mAlarmOn == ALARM_ON) {
MarkSPA 14:459081f9f70b 139 if (t_alarm.read() > mEndAlarm) {
MarkSPA 14:459081f9f70b 140 // end alarm
MarkSPA 14:459081f9f70b 141 t_alarm.stop();
MarkSPA 14:459081f9f70b 142 mHapticOn = HAPTIC_OFF;
MarkSPA 14:459081f9f70b 143 mPiezoOn = PIEZO_OFF;
MarkSPA 14:459081f9f70b 144 LEDS_ON_FLAG = 0;
MarkSPA 14:459081f9f70b 145 }
MarkSPA 14:459081f9f70b 146 }
MarkSPA 13:047bbd59f351 147 if (mHapticOn == HAPTIC_ON) {
MarkSPA 13:047bbd59f351 148 BUZZER = 1;
MarkSPA 14:459081f9f70b 149 wait_ms(1000);
MarkSPA 13:047bbd59f351 150 } else {
MarkSPA 13:047bbd59f351 151 BUZZER = 0;
MarkSPA 13:047bbd59f351 152 //wait_ms(1000);
MarkSPA 13:047bbd59f351 153 }
MarkSPA 13:047bbd59f351 154 if (mPiezoOn == PIEZO_ON) {
MarkSPA 13:047bbd59f351 155 for (int i = 0; i < (sizeof(freq_coll) / sizeof(int)); i++) {
MarkSPA 14:459081f9f70b 156 // Keep checking for an "Off"
MarkSPA 14:459081f9f70b 157 //if (mPiezoOn == PIEZO_OFF)
MarkSPA 14:459081f9f70b 158 //break;
MarkSPA 13:047bbd59f351 159 PIEZO.period(1.0 / freq_coll[i]);
MarkSPA 14:459081f9f70b 160 PIEZO.write(0.9);
MarkSPA 13:047bbd59f351 161 wait(1.0 / beat_coll[i]);
MarkSPA 13:047bbd59f351 162 PIEZO.write(0);
MarkSPA 13:047bbd59f351 163 wait(0.05);
MarkSPA 13:047bbd59f351 164 }
MarkSPA 14:459081f9f70b 165 wait_ms(500);
MarkSPA 14:459081f9f70b 166 }
MarkSPA 13:047bbd59f351 167 if (LEDS_ON_FLAG == 1) {
MarkSPA 13:047bbd59f351 168 if (pattern == PATTERN_ON) {
MarkSPA 13:047bbd59f351 169 for (uint8_t i = 0; i <= NUM_LEDS; i++)
MarkSPA 13:047bbd59f351 170 neopixel_set_color(&m_strip, i, red, green, blue);
MarkSPA 13:047bbd59f351 171 neopixel_show(&m_strip);
MarkSPA 13:047bbd59f351 172
MarkSPA 13:047bbd59f351 173 } else if (pattern == PATTERN_FAST) {
MarkSPA 13:047bbd59f351 174 //neopixel_clear(&m_strip);
MarkSPA 13:047bbd59f351 175 for (uint8_t i = 0; i <= NUM_LEDS; i++)
MarkSPA 13:047bbd59f351 176 neopixel_set_color(&m_strip, i, 0, 0, 0);
MarkSPA 13:047bbd59f351 177 if (led_to_enable > NUM_LEDS)
MarkSPA 13:047bbd59f351 178 led_to_enable = 0;
MarkSPA 13:047bbd59f351 179 neopixel_set_color(&m_strip, led_to_enable, red, green, blue);
MarkSPA 13:047bbd59f351 180 neopixel_show(&m_strip);
MarkSPA 13:047bbd59f351 181 led_to_enable++;
MarkSPA 13:047bbd59f351 182 } else if (pattern == PATTERN_SLOW) {
MarkSPA 13:047bbd59f351 183 for (uint8_t i = 0; i <= NUM_LEDS; i++)
MarkSPA 13:047bbd59f351 184 neopixel_set_color(&m_strip, i, 0, 0, 0);
MarkSPA 13:047bbd59f351 185 if (led_to_enable > NUM_LEDS)
MarkSPA 13:047bbd59f351 186 led_to_enable = 0;
MarkSPA 13:047bbd59f351 187 neopixel_set_color(&m_strip, led_to_enable, red, green, blue);
MarkSPA 13:047bbd59f351 188 neopixel_show(&m_strip);
MarkSPA 13:047bbd59f351 189 led_to_enable++;
MarkSPA 13:047bbd59f351 190 wait_ms(1000);
MarkSPA 13:047bbd59f351 191
MarkSPA 13:047bbd59f351 192 } else if (pattern == PATTERN_CHASE) {
MarkSPA 14:459081f9f70b 193 for (uint8_t i = 0; i <= NUM_LEDS; i++)
MarkSPA 14:459081f9f70b 194 neopixel_set_color(&m_strip, i, 0, 0, 0);
MarkSPA 14:459081f9f70b 195 if (led_to_enable > NUM_LEDS)
MarkSPA 14:459081f9f70b 196 led_to_enable = 0;
MarkSPA 14:459081f9f70b 197 for (uint8_t i = 0; i <= NUM_LEDS; i++)
MarkSPA 14:459081f9f70b 198 neopixel_set_color(&m_strip, led_to_enable, red, green, blue);
MarkSPA 13:047bbd59f351 199 neopixel_show(&m_strip);
MarkSPA 14:459081f9f70b 200 led_to_enable++;
MarkSPA 14:459081f9f70b 201 wait_ms(100);
MarkSPA 13:047bbd59f351 202
MarkSPA 13:047bbd59f351 203 } else if (pattern == PATTERN_MRB) {
MarkSPA 13:047bbd59f351 204 //neopixel_clear(&m_strip);
MarkSPA 13:047bbd59f351 205 for (uint8_t i = 0; i <= NUM_LEDS; i++)
MarkSPA 13:047bbd59f351 206 neopixel_set_color(&m_strip, i, 0, 0, 0);
MarkSPA 13:047bbd59f351 207 led_to_enable = rand()%NUM_LEDS;
MarkSPA 13:047bbd59f351 208 neopixel_set_color(&m_strip, led_to_enable, red, green, blue);
MarkSPA 13:047bbd59f351 209 neopixel_show(&m_strip);
MarkSPA 13:047bbd59f351 210 }
MarkSPA 13:047bbd59f351 211
MarkSPA 13:047bbd59f351 212 else if (pattern == PATTERN_RAINBOW)
MarkSPA 13:047bbd59f351 213 rainbowCycle(20, NUM_LEDS, m_strip);
MarkSPA 13:047bbd59f351 214
MarkSPA 13:047bbd59f351 215 else if (pattern == PATTERN_CANDY)
MarkSPA 13:047bbd59f351 216 candyChase(100, NUM_LEDS, m_strip);
MarkSPA 13:047bbd59f351 217
MarkSPA 13:047bbd59f351 218 else if (pattern == PATTERN_SNOW)
MarkSPA 13:047bbd59f351 219 snowflakes(250, NUM_LEDS, m_strip);
MarkSPA 13:047bbd59f351 220
MarkSPA 13:047bbd59f351 221 else if (pattern == PATTERN_ICE)
MarkSPA 13:047bbd59f351 222 iceflakes(150, NUM_LEDS, m_strip);
MarkSPA 13:047bbd59f351 223
MarkSPA 13:047bbd59f351 224 else if (pattern == PATTERN_XMAS)
MarkSPA 13:047bbd59f351 225 xmas(200, NUM_LEDS, m_strip);
MarkSPA 13:047bbd59f351 226
MarkSPA 13:047bbd59f351 227 else if (pattern == PATTERN_COL)
MarkSPA 13:047bbd59f351 228 collegiate(100, NUM_LEDS, m_strip);
MarkSPA 13:047bbd59f351 229
MarkSPA 13:047bbd59f351 230 else if (pattern == PATTERN_IRON)
MarkSPA 13:047bbd59f351 231 irondude(250, NUM_LEDS, m_strip);
MarkSPA 13:047bbd59f351 232
MarkSPA 13:047bbd59f351 233 else if (pattern == PATTERN_EASTER)
MarkSPA 13:047bbd59f351 234 easter(250, NUM_LEDS, m_strip);
MarkSPA 13:047bbd59f351 235
MarkSPA 13:047bbd59f351 236 else if (pattern == PATTERN_SPRING)
MarkSPA 13:047bbd59f351 237 spring(250, NUM_LEDS, m_strip);
MarkSPA 13:047bbd59f351 238
MarkSPA 13:047bbd59f351 239 else if (pattern == PATTERN_MEM)
MarkSPA 13:047bbd59f351 240 memorial(250, NUM_LEDS, m_strip);
MarkSPA 13:047bbd59f351 241
MarkSPA 13:047bbd59f351 242 else
MarkSPA 13:047bbd59f351 243 neopixel_clear(&m_strip);
MarkSPA 13:047bbd59f351 244 }
MarkSPA 16:4fca60460b7e 245 #endif
MarkSPA 16:4fca60460b7e 246 }
MarkSPA 16:4fca60460b7e 247
MarkSPA 16:4fca60460b7e 248 void periodicCallback(void)
MarkSPA 16:4fca60460b7e 249 {
MarkSPA 16:4fca60460b7e 250 #ifdef DK_52
MarkSPA 16:4fca60460b7e 251 led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */
MarkSPA 16:4fca60460b7e 252 #endif
MarkSPA 16:4fca60460b7e 253 if (BLE::Instance().getGapState().connected) {
MarkSPA 16:4fca60460b7e 254 eventQueue.call(updateLEDs);
MarkSPA 4:c8515fbd2e44 255 }
MarkSPA 4:c8515fbd2e44 256 }
MarkSPA 4:c8515fbd2e44 257
MarkSPA 16:4fca60460b7e 258 void onBleInitError(BLE &ble, ble_error_t error)
MarkSPA 4:c8515fbd2e44 259 {
MarkSPA 16:4fca60460b7e 260 (void)ble;
MarkSPA 16:4fca60460b7e 261 (void)error;
MarkSPA 16:4fca60460b7e 262 /* Initialization error handling should go here */
MarkSPA 4:c8515fbd2e44 263 }
RedBearLab 0:dfcebc1e442a 264
MarkSPA 13:047bbd59f351 265 void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
MarkSPA 7:0db51a3107fc 266 {
MarkSPA 16:4fca60460b7e 267
MarkSPA 16:4fca60460b7e 268 BLE& ble = params->ble;
MarkSPA 13:047bbd59f351 269 ble_error_t error = params->error;
MarkSPA 16:4fca60460b7e 270
MarkSPA 13:047bbd59f351 271 if (error != BLE_ERROR_NONE) {
MarkSPA 16:4fca60460b7e 272 onBleInitError(ble, error);
MarkSPA 13:047bbd59f351 273 return;
MarkSPA 13:047bbd59f351 274 }
MarkSPA 16:4fca60460b7e 275
MarkSPA 16:4fca60460b7e 276 if (ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
MarkSPA 16:4fca60460b7e 277 return;
MarkSPA 16:4fca60460b7e 278 }
MarkSPA 16:4fca60460b7e 279
MarkSPA 16:4fca60460b7e 280 ble.gap().onDisconnection(disconnectionCallback);
MarkSPA 7:0db51a3107fc 281
MarkSPA 13:047bbd59f351 282 /* Setup primary (UART) service */
MarkSPA 13:047bbd59f351 283 ble.gattServer().addService(uartService);
MarkSPA 13:047bbd59f351 284
MarkSPA 13:047bbd59f351 285 /* Setup auxiliary service. */
MarkSPA 13:047bbd59f351 286 deviceInfo = new DeviceInformationService(ble, "RRVA", "VectorIQ", "SN1", "hw-rev1", "fw-rev1-1-0", "soft-rev1");
MarkSPA 13:047bbd59f351 287 //deviceInfo = new DeviceInformationService(ble, "RRVA", "VIQ", "", "", "1-0-0", "");
MarkSPA 13:047bbd59f351 288
MarkSPA 7:0db51a3107fc 289 // setup advertising
MarkSPA 13:047bbd59f351 290 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); // | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
MarkSPA 13:047bbd59f351 291 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS,
MarkSPA 13:047bbd59f351 292 (uint8_t *)uuid16_list, sizeof(uuid16_list));
MarkSPA 13:047bbd59f351 293 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
MarkSPA 13:047bbd59f351 294 (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid));
MarkSPA 7:0db51a3107fc 295 ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
MarkSPA 13:047bbd59f351 296 (const uint8_t *)&mDeviceName, mLength);
MarkSPA 13:047bbd59f351 297 ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
MarkSPA 13:047bbd59f351 298 ble.gap().setAdvertisingInterval(500); /* ms */
MarkSPA 13:047bbd59f351 299 ble.gap().startAdvertising();
MarkSPA 13:047bbd59f351 300 //ble.startAdvertising();
MarkSPA 7:0db51a3107fc 301 //pc.printf("Advertising Start \r\n");
MarkSPA 7:0db51a3107fc 302 }
MarkSPA 7:0db51a3107fc 303
MarkSPA 16:4fca60460b7e 304 void scheduleBleEventsProcessing(BLE::OnEventsToProcessCallbackContext* context) {
MarkSPA 16:4fca60460b7e 305 BLE &ble = BLE::Instance();
MarkSPA 16:4fca60460b7e 306 eventQueue.call(Callback<void()>(&ble, &BLE::processEvents));
MarkSPA 16:4fca60460b7e 307 }
MarkSPA 16:4fca60460b7e 308
RedBearLab 0:dfcebc1e442a 309 int main(void)
MarkSPA 16:4fca60460b7e 310 {
MarkSPA 14:459081f9f70b 311 set_time(1256729737 ); // Set RTC time to Wed, 28 Oct 2009 11:35:37
MarkSPA 13:047bbd59f351 312
MarkSPA 13:047bbd59f351 313 strcpy(mDeviceName, "VIQ");
MarkSPA 13:047bbd59f351 314 mLength = strlen(mDeviceName);
MarkSPA 4:c8515fbd2e44 315
MarkSPA 4:c8515fbd2e44 316 //pc.printf("neoPixel Init \r\n");
MarkSPA 16:4fca60460b7e 317 #ifdef VIQ
MarkSPA 4:c8515fbd2e44 318 neopixel_init(&m_strip, dig_pin_num, NUM_LEDS);
MarkSPA 4:c8515fbd2e44 319 neopixel_clear(&m_strip);
MarkSPA 16:4fca60460b7e 320 #endif
MarkSPA 16:4fca60460b7e 321 eventQueue.call_every(500, periodicCallback);
RedBearLab 0:dfcebc1e442a 322
MarkSPA 16:4fca60460b7e 323 BLE &ble = BLE::Instance();
MarkSPA 16:4fca60460b7e 324 ble.onEventsToProcess(scheduleBleEventsProcessing);
MarkSPA 16:4fca60460b7e 325 ble.init(bleInitComplete);
RedBearLab 0:dfcebc1e442a 326
MarkSPA 16:4fca60460b7e 327 eventQueue.dispatch_forever();
MarkSPA 16:4fca60460b7e 328 }