RadiantRVA
/
rbVectorIQ
share for RS
Fork of rbVectorIQ by
main.cpp@14:459081f9f70b, 2017-04-19 (annotated)
- Committer:
- MarkSPA
- Date:
- Wed Apr 19 21:20:31 2017 +0000
- Revision:
- 14:459081f9f70b
- Parent:
- 13:047bbd59f351
4/19/2017 updates
Who changed what in which revision?
User | Revision | Line number | New 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 | 13:047bbd59f351 | 19 | #include "vector_iq.h" |
RedBearLab | 0:dfcebc1e442a | 20 | |
MarkSPA | 4:c8515fbd2e44 | 21 | |
MarkSPA | 4:c8515fbd2e44 | 22 | void connectionCallback(const Gap::ConnectionCallbackParams_t *params) |
MarkSPA | 4:c8515fbd2e44 | 23 | { |
MarkSPA | 4:c8515fbd2e44 | 24 | neopixel_init(&m_strip, dig_pin_num, NUM_LEDS); |
MarkSPA | 4:c8515fbd2e44 | 25 | neopixel_clear(&m_strip); |
MarkSPA | 7:0db51a3107fc | 26 | LEDS_ON_FLAG = 0; |
MarkSPA | 4:c8515fbd2e44 | 27 | } |
RedBearLab | 0:dfcebc1e442a | 28 | |
RedBearLab | 3:823f105078c7 | 29 | void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) |
RedBearLab | 0:dfcebc1e442a | 30 | { |
MarkSPA | 4:c8515fbd2e44 | 31 | //pc.printf("Disconnected \r\n"); |
MarkSPA | 4:c8515fbd2e44 | 32 | //pc.printf("Restart advertising \r\n"); |
MarkSPA | 4:c8515fbd2e44 | 33 | //clear and remove strip |
MarkSPA | 4:c8515fbd2e44 | 34 | //neopixel_clear(&m_strip); |
MarkSPA | 4:c8515fbd2e44 | 35 | //neopixel_destroy(&m_strip); |
MarkSPA | 7:0db51a3107fc | 36 | //strcpy(mDeviceName, "RRVA Cntd"); |
MarkSPA | 7:0db51a3107fc | 37 | //setup_advertising(); |
MarkSPA | 13:047bbd59f351 | 38 | BLE::Instance(BLE::DEFAULT_INSTANCE).gap().startAdvertising(); // restart advertising |
MarkSPA | 13:047bbd59f351 | 39 | //ble.startAdvertising(); |
RedBearLab | 0:dfcebc1e442a | 40 | } |
RedBearLab | 0:dfcebc1e442a | 41 | |
RedBearLab | 2:bbcdd23ba9ba | 42 | void WrittenHandler(const GattWriteCallbackParams *Handler) |
MarkSPA | 4:c8515fbd2e44 | 43 | { |
RedBearLab | 0:dfcebc1e442a | 44 | uint8_t buf[TXRX_BUF_LEN]; |
MarkSPA | 4:c8515fbd2e44 | 45 | uint16_t bytesRead; |
MarkSPA | 4:c8515fbd2e44 | 46 | |
MarkSPA | 4:c8515fbd2e44 | 47 | if (Handler->handle == txCharacteristic.getValueAttribute().getHandle()) { |
RedBearLab | 0:dfcebc1e442a | 48 | ble.readCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(), buf, &bytesRead); |
RedBearLab | 0:dfcebc1e442a | 49 | memset(txPayload, 0, TXRX_BUF_LEN); |
MarkSPA | 4:c8515fbd2e44 | 50 | memcpy(txPayload, buf, TXRX_BUF_LEN); |
MarkSPA | 4:c8515fbd2e44 | 51 | |
MarkSPA | 4:c8515fbd2e44 | 52 | //for(index=0; index<bytesRead; index++) |
MarkSPA | 4:c8515fbd2e44 | 53 | //pc.putc(buf[index]); |
RedBearLab | 0:dfcebc1e442a | 54 | |
MarkSPA | 4:c8515fbd2e44 | 55 | if(buf[0] == ONOFF_HEADER) { |
MarkSPA | 4:c8515fbd2e44 | 56 | //pc.printf("LED value received \r\n"); |
MarkSPA | 4:c8515fbd2e44 | 57 | if(buf[1] == LEDS_ON) { |
MarkSPA | 4:c8515fbd2e44 | 58 | LEDS_ON_FLAG = 1; |
MarkSPA | 4:c8515fbd2e44 | 59 | } else if(buf[1] == LEDS_OFF) { |
MarkSPA | 4:c8515fbd2e44 | 60 | LEDS_ON_FLAG = 0; |
MarkSPA | 4:c8515fbd2e44 | 61 | neopixel_init(&m_strip, dig_pin_num, NUM_LEDS); |
MarkSPA | 4:c8515fbd2e44 | 62 | neopixel_clear(&m_strip); |
MarkSPA | 4:c8515fbd2e44 | 63 | } |
MarkSPA | 4:c8515fbd2e44 | 64 | } else if(buf[0] == COLOR_HEADER) { |
MarkSPA | 4:c8515fbd2e44 | 65 | red = buf[1]; |
MarkSPA | 4:c8515fbd2e44 | 66 | green = buf[2]; |
MarkSPA | 4:c8515fbd2e44 | 67 | blue = buf[3]; |
MarkSPA | 4:c8515fbd2e44 | 68 | pattern = buf[5]; |
MarkSPA | 13:047bbd59f351 | 69 | } else if(buf[0] == PIEZO_HEADER) { |
MarkSPA | 13:047bbd59f351 | 70 | mPiezoOn = buf[1]; |
MarkSPA | 14:459081f9f70b | 71 | //mPiezoDur = buf[2]; |
MarkSPA | 14:459081f9f70b | 72 | mPiezoPattern = buf[2]; |
MarkSPA | 13:047bbd59f351 | 73 | } else if(buf[0] == HAPTIC_HEADER) { |
MarkSPA | 13:047bbd59f351 | 74 | mHapticOn = buf[1]; |
MarkSPA | 13:047bbd59f351 | 75 | mHapticDur = buf[2]; |
MarkSPA | 13:047bbd59f351 | 76 | mHapticPattern = buf[3]; |
MarkSPA | 14:459081f9f70b | 77 | } else if(buf[0] == ALARM_HEADER) { |
MarkSPA | 14:459081f9f70b | 78 | mAlarmOn = buf[1]; |
MarkSPA | 14:459081f9f70b | 79 | //mAlarmStart = buf[2]; |
MarkSPA | 14:459081f9f70b | 80 | mAlarmDur = buf[2]; |
MarkSPA | 14:459081f9f70b | 81 | mAlarmPiezoOn = buf[4]; |
MarkSPA | 14:459081f9f70b | 82 | mAlarmTone = buf[5]; |
MarkSPA | 14:459081f9f70b | 83 | mAlarmPattern = buf[6]; |
MarkSPA | 14:459081f9f70b | 84 | pattern = mAlarmPattern; |
MarkSPA | 14:459081f9f70b | 85 | if (mAlarmOn == ALARM_ON) { |
MarkSPA | 14:459081f9f70b | 86 | // Setup the timer |
MarkSPA | 14:459081f9f70b | 87 | t_alarm.start(); |
MarkSPA | 14:459081f9f70b | 88 | mBeginAlarm = t_alarm.read(); |
MarkSPA | 14:459081f9f70b | 89 | mEndAlarm = mBeginAlarm + mAlarmDur; |
MarkSPA | 14:459081f9f70b | 90 | mPiezoOn = mAlarmPiezoOn; |
MarkSPA | 14:459081f9f70b | 91 | LEDS_ON_FLAG = 1; |
MarkSPA | 14:459081f9f70b | 92 | } else if (mAlarmOn == ALARM_OFF) { |
MarkSPA | 14:459081f9f70b | 93 | // Stop the timer |
MarkSPA | 14:459081f9f70b | 94 | t_alarm.stop(); |
MarkSPA | 14:459081f9f70b | 95 | // Kill all the effects |
MarkSPA | 14:459081f9f70b | 96 | mHapticOn = HAPTIC_OFF; |
MarkSPA | 14:459081f9f70b | 97 | mPiezoOn = PIEZO_OFF; |
MarkSPA | 14:459081f9f70b | 98 | LEDS_ON_FLAG = 0; |
MarkSPA | 14:459081f9f70b | 99 | } |
MarkSPA | 13:047bbd59f351 | 100 | } |
MarkSPA | 6:074f5ec7428c | 101 | else |
MarkSPA | 6:074f5ec7428c | 102 | { |
MarkSPA | 6:074f5ec7428c | 103 | LEDS_ON_FLAG = 1; |
MarkSPA | 6:074f5ec7428c | 104 | red = buf[1]; |
MarkSPA | 6:074f5ec7428c | 105 | green = buf[2]; |
MarkSPA | 6:074f5ec7428c | 106 | blue = buf[3]; |
MarkSPA | 6:074f5ec7428c | 107 | pattern = buf[5]; |
MarkSPA | 6:074f5ec7428c | 108 | } |
RedBearLab | 0:dfcebc1e442a | 109 | } |
RedBearLab | 0:dfcebc1e442a | 110 | } |
MarkSPA | 4:c8515fbd2e44 | 111 | |
MarkSPA | 14:459081f9f70b | 112 | // pb Interrupt routine - is interrupt activated by a falling edge of pb input |
MarkSPA | 14:459081f9f70b | 113 | void pb_hit_interrupt (void) { |
MarkSPA | 14:459081f9f70b | 114 | pattern++; |
MarkSPA | 14:459081f9f70b | 115 | if (pattern >= PATTERN_MEM) |
MarkSPA | 14:459081f9f70b | 116 | pattern = PATTERN_ON; |
MarkSPA | 14:459081f9f70b | 117 | } |
MarkSPA | 14:459081f9f70b | 118 | |
RedBearLab | 0:dfcebc1e442a | 119 | void m_status_check_handle(void) |
MarkSPA | 4:c8515fbd2e44 | 120 | { |
MarkSPA | 13:047bbd59f351 | 121 | //uint8_t buf[3]; |
MarkSPA | 14:459081f9f70b | 122 | |
MarkSPA | 14:459081f9f70b | 123 | //if (BUTTON == 1) { |
MarkSPA | 14:459081f9f70b | 124 | // Cycle through display patterns |
MarkSPA | 14:459081f9f70b | 125 | pattern++; |
MarkSPA | 14:459081f9f70b | 126 | if (pattern >= PATTERN_MEM) |
MarkSPA | 14:459081f9f70b | 127 | pattern = PATTERN_NONE; |
MarkSPA | 14:459081f9f70b | 128 | //} |
MarkSPA | 4:c8515fbd2e44 | 129 | |
MarkSPA | 13:047bbd59f351 | 130 | /* if (BUTTON == 1) |
MarkSPA | 13:047bbd59f351 | 131 | LEDS_ON_FLAG = 0; |
MarkSPA | 13:047bbd59f351 | 132 | else if (BUTTON == 0) |
MarkSPA | 13:047bbd59f351 | 133 | LEDS_ON_FLAG = 1; */ |
MarkSPA | 13:047bbd59f351 | 134 | |
MarkSPA | 13:047bbd59f351 | 135 | /*if (BUTTON != old_state) { |
RedBearLab | 0:dfcebc1e442a | 136 | old_state = BUTTON; |
MarkSPA | 10:eb100af346bf | 137 | if (LEDS_ON_FLAG) |
MarkSPA | 13:047bbd59f351 | 138 | LEDS_ON_FLAG = 0; |
MarkSPA | 10:eb100af346bf | 139 | else |
MarkSPA | 13:047bbd59f351 | 140 | LEDS_ON_FLAG = 1; |
MarkSPA | 10:eb100af346bf | 141 | |
MarkSPA | 4:c8515fbd2e44 | 142 | if (BUTTON == 1) { |
RedBearLab | 0:dfcebc1e442a | 143 | buf[0] = (0x0A); |
RedBearLab | 0:dfcebc1e442a | 144 | buf[1] = (0x01); |
MarkSPA | 4:c8515fbd2e44 | 145 | buf[2] = (0x00); |
MarkSPA | 4:c8515fbd2e44 | 146 | ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 3); |
MarkSPA | 4:c8515fbd2e44 | 147 | } else { |
RedBearLab | 0:dfcebc1e442a | 148 | buf[0] = (0x0A); |
RedBearLab | 0:dfcebc1e442a | 149 | buf[1] = (0x00); |
RedBearLab | 0:dfcebc1e442a | 150 | buf[2] = (0x00); |
MarkSPA | 4:c8515fbd2e44 | 151 | ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 3); |
MarkSPA | 13:047bbd59f351 | 152 | } |
MarkSPA | 13:047bbd59f351 | 153 | } */ |
RedBearLab | 0:dfcebc1e442a | 154 | } |
RedBearLab | 0:dfcebc1e442a | 155 | |
MarkSPA | 4:c8515fbd2e44 | 156 | void ble_on_radio_active_evt(bool radio_active) |
MarkSPA | 4:c8515fbd2e44 | 157 | { |
MarkSPA | 13:047bbd59f351 | 158 | if (radio_active == false) { |
MarkSPA | 14:459081f9f70b | 159 | if (mAlarmOn == ALARM_ON) { |
MarkSPA | 14:459081f9f70b | 160 | if (t_alarm.read() > mEndAlarm) { |
MarkSPA | 14:459081f9f70b | 161 | // end alarm |
MarkSPA | 14:459081f9f70b | 162 | t_alarm.stop(); |
MarkSPA | 14:459081f9f70b | 163 | mHapticOn = HAPTIC_OFF; |
MarkSPA | 14:459081f9f70b | 164 | mPiezoOn = PIEZO_OFF; |
MarkSPA | 14:459081f9f70b | 165 | LEDS_ON_FLAG = 0; |
MarkSPA | 14:459081f9f70b | 166 | } |
MarkSPA | 14:459081f9f70b | 167 | } |
MarkSPA | 13:047bbd59f351 | 168 | if (mHapticOn == HAPTIC_ON) { |
MarkSPA | 13:047bbd59f351 | 169 | BUZZER = 1; |
MarkSPA | 14:459081f9f70b | 170 | wait_ms(1000); |
MarkSPA | 13:047bbd59f351 | 171 | } else { |
MarkSPA | 13:047bbd59f351 | 172 | BUZZER = 0; |
MarkSPA | 13:047bbd59f351 | 173 | //wait_ms(1000); |
MarkSPA | 13:047bbd59f351 | 174 | } |
MarkSPA | 13:047bbd59f351 | 175 | if (mPiezoOn == PIEZO_ON) { |
MarkSPA | 13:047bbd59f351 | 176 | for (int i = 0; i < (sizeof(freq_coll) / sizeof(int)); i++) { |
MarkSPA | 14:459081f9f70b | 177 | // Keep checking for an "Off" |
MarkSPA | 14:459081f9f70b | 178 | //if (mPiezoOn == PIEZO_OFF) |
MarkSPA | 14:459081f9f70b | 179 | //break; |
MarkSPA | 13:047bbd59f351 | 180 | PIEZO.period(1.0 / freq_coll[i]); |
MarkSPA | 14:459081f9f70b | 181 | PIEZO.write(0.9); |
MarkSPA | 13:047bbd59f351 | 182 | wait(1.0 / beat_coll[i]); |
MarkSPA | 13:047bbd59f351 | 183 | PIEZO.write(0); |
MarkSPA | 13:047bbd59f351 | 184 | wait(0.05); |
MarkSPA | 13:047bbd59f351 | 185 | } |
MarkSPA | 14:459081f9f70b | 186 | wait_ms(500); |
MarkSPA | 14:459081f9f70b | 187 | } |
MarkSPA | 13:047bbd59f351 | 188 | if (LEDS_ON_FLAG == 1) { |
MarkSPA | 13:047bbd59f351 | 189 | if (pattern == PATTERN_ON) { |
MarkSPA | 13:047bbd59f351 | 190 | for (uint8_t i = 0; i <= NUM_LEDS; i++) |
MarkSPA | 13:047bbd59f351 | 191 | neopixel_set_color(&m_strip, i, red, green, blue); |
MarkSPA | 13:047bbd59f351 | 192 | neopixel_show(&m_strip); |
MarkSPA | 13:047bbd59f351 | 193 | |
MarkSPA | 13:047bbd59f351 | 194 | } else if (pattern == PATTERN_FAST) { |
MarkSPA | 13:047bbd59f351 | 195 | //neopixel_clear(&m_strip); |
MarkSPA | 13:047bbd59f351 | 196 | for (uint8_t i = 0; i <= NUM_LEDS; i++) |
MarkSPA | 13:047bbd59f351 | 197 | neopixel_set_color(&m_strip, i, 0, 0, 0); |
MarkSPA | 13:047bbd59f351 | 198 | if (led_to_enable > NUM_LEDS) |
MarkSPA | 13:047bbd59f351 | 199 | led_to_enable = 0; |
MarkSPA | 13:047bbd59f351 | 200 | neopixel_set_color(&m_strip, led_to_enable, red, green, blue); |
MarkSPA | 13:047bbd59f351 | 201 | neopixel_show(&m_strip); |
MarkSPA | 13:047bbd59f351 | 202 | led_to_enable++; |
MarkSPA | 13:047bbd59f351 | 203 | } else if (pattern == PATTERN_SLOW) { |
MarkSPA | 13:047bbd59f351 | 204 | for (uint8_t i = 0; i <= NUM_LEDS; i++) |
MarkSPA | 13:047bbd59f351 | 205 | neopixel_set_color(&m_strip, i, 0, 0, 0); |
MarkSPA | 13:047bbd59f351 | 206 | if (led_to_enable > NUM_LEDS) |
MarkSPA | 13:047bbd59f351 | 207 | led_to_enable = 0; |
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 | led_to_enable++; |
MarkSPA | 13:047bbd59f351 | 211 | wait_ms(1000); |
MarkSPA | 13:047bbd59f351 | 212 | |
MarkSPA | 13:047bbd59f351 | 213 | } else if (pattern == PATTERN_CHASE) { |
MarkSPA | 14:459081f9f70b | 214 | for (uint8_t i = 0; i <= NUM_LEDS; i++) |
MarkSPA | 14:459081f9f70b | 215 | neopixel_set_color(&m_strip, i, 0, 0, 0); |
MarkSPA | 14:459081f9f70b | 216 | if (led_to_enable > NUM_LEDS) |
MarkSPA | 14:459081f9f70b | 217 | led_to_enable = 0; |
MarkSPA | 14:459081f9f70b | 218 | for (uint8_t i = 0; i <= NUM_LEDS; i++) |
MarkSPA | 14:459081f9f70b | 219 | neopixel_set_color(&m_strip, led_to_enable, red, green, blue); |
MarkSPA | 13:047bbd59f351 | 220 | neopixel_show(&m_strip); |
MarkSPA | 14:459081f9f70b | 221 | led_to_enable++; |
MarkSPA | 14:459081f9f70b | 222 | wait_ms(100); |
MarkSPA | 13:047bbd59f351 | 223 | |
MarkSPA | 13:047bbd59f351 | 224 | } else if (pattern == PATTERN_MRB) { |
MarkSPA | 13:047bbd59f351 | 225 | //neopixel_clear(&m_strip); |
MarkSPA | 13:047bbd59f351 | 226 | for (uint8_t i = 0; i <= NUM_LEDS; i++) |
MarkSPA | 13:047bbd59f351 | 227 | neopixel_set_color(&m_strip, i, 0, 0, 0); |
MarkSPA | 13:047bbd59f351 | 228 | led_to_enable = rand()%NUM_LEDS; |
MarkSPA | 13:047bbd59f351 | 229 | neopixel_set_color(&m_strip, led_to_enable, red, green, blue); |
MarkSPA | 13:047bbd59f351 | 230 | neopixel_show(&m_strip); |
MarkSPA | 13:047bbd59f351 | 231 | } |
MarkSPA | 13:047bbd59f351 | 232 | |
MarkSPA | 13:047bbd59f351 | 233 | else if (pattern == PATTERN_RAINBOW) |
MarkSPA | 13:047bbd59f351 | 234 | rainbowCycle(20, NUM_LEDS, m_strip); |
MarkSPA | 13:047bbd59f351 | 235 | |
MarkSPA | 13:047bbd59f351 | 236 | else if (pattern == PATTERN_CANDY) |
MarkSPA | 13:047bbd59f351 | 237 | candyChase(100, NUM_LEDS, m_strip); |
MarkSPA | 13:047bbd59f351 | 238 | |
MarkSPA | 13:047bbd59f351 | 239 | else if (pattern == PATTERN_SNOW) |
MarkSPA | 13:047bbd59f351 | 240 | snowflakes(250, NUM_LEDS, m_strip); |
MarkSPA | 13:047bbd59f351 | 241 | |
MarkSPA | 13:047bbd59f351 | 242 | else if (pattern == PATTERN_ICE) |
MarkSPA | 13:047bbd59f351 | 243 | iceflakes(150, NUM_LEDS, m_strip); |
MarkSPA | 13:047bbd59f351 | 244 | |
MarkSPA | 13:047bbd59f351 | 245 | else if (pattern == PATTERN_XMAS) |
MarkSPA | 13:047bbd59f351 | 246 | xmas(200, NUM_LEDS, m_strip); |
MarkSPA | 13:047bbd59f351 | 247 | |
MarkSPA | 13:047bbd59f351 | 248 | else if (pattern == PATTERN_COL) |
MarkSPA | 13:047bbd59f351 | 249 | collegiate(100, NUM_LEDS, m_strip); |
MarkSPA | 13:047bbd59f351 | 250 | |
MarkSPA | 13:047bbd59f351 | 251 | else if (pattern == PATTERN_IRON) |
MarkSPA | 13:047bbd59f351 | 252 | irondude(250, NUM_LEDS, m_strip); |
MarkSPA | 13:047bbd59f351 | 253 | |
MarkSPA | 13:047bbd59f351 | 254 | else if (pattern == PATTERN_EASTER) |
MarkSPA | 13:047bbd59f351 | 255 | easter(250, NUM_LEDS, m_strip); |
MarkSPA | 13:047bbd59f351 | 256 | |
MarkSPA | 13:047bbd59f351 | 257 | else if (pattern == PATTERN_SPRING) |
MarkSPA | 13:047bbd59f351 | 258 | spring(250, NUM_LEDS, m_strip); |
MarkSPA | 13:047bbd59f351 | 259 | |
MarkSPA | 13:047bbd59f351 | 260 | else if (pattern == PATTERN_MEM) |
MarkSPA | 13:047bbd59f351 | 261 | memorial(250, NUM_LEDS, m_strip); |
MarkSPA | 13:047bbd59f351 | 262 | |
MarkSPA | 13:047bbd59f351 | 263 | else |
MarkSPA | 13:047bbd59f351 | 264 | neopixel_clear(&m_strip); |
MarkSPA | 13:047bbd59f351 | 265 | } |
MarkSPA | 4:c8515fbd2e44 | 266 | } |
MarkSPA | 4:c8515fbd2e44 | 267 | } |
MarkSPA | 4:c8515fbd2e44 | 268 | |
MarkSPA | 4:c8515fbd2e44 | 269 | static void radio_notification_init(void) |
MarkSPA | 4:c8515fbd2e44 | 270 | { |
MarkSPA | 4:c8515fbd2e44 | 271 | //uint32_t err_code; |
MarkSPA | 4:c8515fbd2e44 | 272 | ble_radio_notification_init(NRF_APP_PRIORITY_LOW, |
MarkSPA | 4:c8515fbd2e44 | 273 | NRF_RADIO_NOTIFICATION_DISTANCE_800US, |
MarkSPA | 4:c8515fbd2e44 | 274 | ble_on_radio_active_evt); |
MarkSPA | 4:c8515fbd2e44 | 275 | //APP_ERROR_CHECK(err_code); |
MarkSPA | 4:c8515fbd2e44 | 276 | } |
RedBearLab | 0:dfcebc1e442a | 277 | |
MarkSPA | 13:047bbd59f351 | 278 | void bleInitComplete(BLE::InitializationCompleteCallbackContext *params) |
MarkSPA | 7:0db51a3107fc | 279 | { |
MarkSPA | 13:047bbd59f351 | 280 | BLE &ble = params->ble; |
MarkSPA | 13:047bbd59f351 | 281 | ble_error_t error = params->error; |
MarkSPA | 13:047bbd59f351 | 282 | |
MarkSPA | 13:047bbd59f351 | 283 | if (error != BLE_ERROR_NONE) { |
MarkSPA | 13:047bbd59f351 | 284 | return; |
MarkSPA | 13:047bbd59f351 | 285 | } |
MarkSPA | 7:0db51a3107fc | 286 | int length = strlen(mDeviceName); |
MarkSPA | 13:047bbd59f351 | 287 | |
MarkSPA | 13:047bbd59f351 | 288 | ble.gap().onDisconnection(disconnectionCallback); |
MarkSPA | 7:0db51a3107fc | 289 | |
MarkSPA | 13:047bbd59f351 | 290 | /* Setup primary (UART) service */ |
MarkSPA | 13:047bbd59f351 | 291 | ble.gattServer().addService(uartService); |
MarkSPA | 13:047bbd59f351 | 292 | |
MarkSPA | 13:047bbd59f351 | 293 | /* Setup auxiliary service. */ |
MarkSPA | 13:047bbd59f351 | 294 | deviceInfo = new DeviceInformationService(ble, "RRVA", "VectorIQ", "SN1", "hw-rev1", "fw-rev1-1-0", "soft-rev1"); |
MarkSPA | 13:047bbd59f351 | 295 | //deviceInfo = new DeviceInformationService(ble, "RRVA", "VIQ", "", "", "1-0-0", ""); |
MarkSPA | 13:047bbd59f351 | 296 | |
MarkSPA | 7:0db51a3107fc | 297 | // setup advertising |
MarkSPA | 13:047bbd59f351 | 298 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); // | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); |
MarkSPA | 13:047bbd59f351 | 299 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, |
MarkSPA | 13:047bbd59f351 | 300 | (uint8_t *)uuid16_list, sizeof(uuid16_list)); |
MarkSPA | 13:047bbd59f351 | 301 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, |
MarkSPA | 13:047bbd59f351 | 302 | (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid)); |
MarkSPA | 7:0db51a3107fc | 303 | ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, |
MarkSPA | 13:047bbd59f351 | 304 | (const uint8_t *)&mDeviceName, mLength); |
MarkSPA | 13:047bbd59f351 | 305 | ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
MarkSPA | 13:047bbd59f351 | 306 | ble.gap().setAdvertisingInterval(500); /* ms */ |
MarkSPA | 13:047bbd59f351 | 307 | ble.gap().startAdvertising(); |
MarkSPA | 13:047bbd59f351 | 308 | //ble.startAdvertising(); |
MarkSPA | 7:0db51a3107fc | 309 | //pc.printf("Advertising Start \r\n"); |
MarkSPA | 7:0db51a3107fc | 310 | } |
MarkSPA | 7:0db51a3107fc | 311 | |
RedBearLab | 0:dfcebc1e442a | 312 | int main(void) |
MarkSPA | 4:c8515fbd2e44 | 313 | { |
MarkSPA | 4:c8515fbd2e44 | 314 | //uint8_t led_error; |
MarkSPA | 14:459081f9f70b | 315 | //BUTTON.mode(PullDown); |
MarkSPA | 14:459081f9f70b | 316 | //Ticker ticker; |
MarkSPA | 14:459081f9f70b | 317 | //ticker.attach_us(m_status_check_handle, 200000); |
MarkSPA | 14:459081f9f70b | 318 | |
MarkSPA | 14:459081f9f70b | 319 | // Use internal pullup for pushbutton |
MarkSPA | 14:459081f9f70b | 320 | //pb.mode(PullDown); |
MarkSPA | 14:459081f9f70b | 321 | // Delay for initial pullup to take effect |
MarkSPA | 14:459081f9f70b | 322 | //wait(.01); |
MarkSPA | 14:459081f9f70b | 323 | // Attach the address of the interrupt handler routine for pushbutton |
MarkSPA | 14:459081f9f70b | 324 | //pb.fall(&pb_hit_interrupt); |
MarkSPA | 14:459081f9f70b | 325 | |
MarkSPA | 14:459081f9f70b | 326 | set_time(1256729737 ); // Set RTC time to Wed, 28 Oct 2009 11:35:37 |
MarkSPA | 13:047bbd59f351 | 327 | |
MarkSPA | 13:047bbd59f351 | 328 | strcpy(mDeviceName, "VIQ"); |
MarkSPA | 13:047bbd59f351 | 329 | mLength = strlen(mDeviceName); |
MarkSPA | 4:c8515fbd2e44 | 330 | |
MarkSPA | 4:c8515fbd2e44 | 331 | //pc.printf("neoPixel Init \r\n"); |
MarkSPA | 4:c8515fbd2e44 | 332 | neopixel_init(&m_strip, dig_pin_num, NUM_LEDS); |
MarkSPA | 4:c8515fbd2e44 | 333 | neopixel_clear(&m_strip); |
MarkSPA | 13:047bbd59f351 | 334 | |
MarkSPA | 13:047bbd59f351 | 335 | BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE); |
MarkSPA | 13:047bbd59f351 | 336 | ble.init(bleInitComplete); |
MarkSPA | 13:047bbd59f351 | 337 | |
MarkSPA | 13:047bbd59f351 | 338 | /* Explicitly enable over-the-air firmware updates. Instantiating DFUSservice introduces a |
MarkSPA | 13:047bbd59f351 | 339 | * control characteristic which can be used to trigger the application to |
MarkSPA | 13:047bbd59f351 | 340 | * handover control to a resident bootloader. */ |
MarkSPA | 13:047bbd59f351 | 341 | //DFUService dfu(ble); |
MarkSPA | 4:c8515fbd2e44 | 342 | |
MarkSPA | 13:047bbd59f351 | 343 | //ble.init(); |
MarkSPA | 13:047bbd59f351 | 344 | //ble.onDisconnection(disconnectionCallback); |
MarkSPA | 4:c8515fbd2e44 | 345 | ble.onConnection(connectionCallback); |
MarkSPA | 4:c8515fbd2e44 | 346 | ble.onDataWritten(WrittenHandler); |
MarkSPA | 4:c8515fbd2e44 | 347 | radio_notification_init(); |
MarkSPA | 4:c8515fbd2e44 | 348 | //pc.baud(9600); |
MarkSPA | 4:c8515fbd2e44 | 349 | //pc.format(8, SerialBase::None, 1); |
MarkSPA | 4:c8515fbd2e44 | 350 | //pc.printf("rbChromaBand Init \r\n"); |
MarkSPA | 4:c8515fbd2e44 | 351 | //pc.attach( uartCB , pc.RxIrq); |
MarkSPA | 7:0db51a3107fc | 352 | |
MarkSPA | 13:047bbd59f351 | 353 | /* SpinWait for initialization to complete. This is necessary because the |
MarkSPA | 13:047bbd59f351 | 354 | * BLE object is used in the main loop below. */ |
MarkSPA | 13:047bbd59f351 | 355 | //while (ble.hasInitialized() == false) { /* spin loop */ } |
RedBearLab | 0:dfcebc1e442a | 356 | |
MarkSPA | 13:047bbd59f351 | 357 | //setup_advertising(); |
MarkSPA | 4:c8515fbd2e44 | 358 | |
MarkSPA | 4:c8515fbd2e44 | 359 | while(1) { |
MarkSPA | 4:c8515fbd2e44 | 360 | //pc.putc(pc.getc()); |
MarkSPA | 4:c8515fbd2e44 | 361 | ble.waitForEvent(); |
RedBearLab | 0:dfcebc1e442a | 362 | } |
RedBearLab | 0:dfcebc1e442a | 363 | } |
RedBearLab | 0:dfcebc1e442a | 364 | |
RedBearLab | 0:dfcebc1e442a | 365 | |
RedBearLab | 0:dfcebc1e442a | 366 | |
RedBearLab | 0:dfcebc1e442a | 367 | |
RedBearLab | 0:dfcebc1e442a | 368 | |
RedBearLab | 0:dfcebc1e442a | 369 | |
RedBearLab | 0:dfcebc1e442a | 370 | |
RedBearLab | 0:dfcebc1e442a | 371 | |
RedBearLab | 0:dfcebc1e442a | 372 | |
RedBearLab | 0:dfcebc1e442a | 373 | |
RedBearLab | 0:dfcebc1e442a | 374 | |
RedBearLab | 0:dfcebc1e442a | 375 | |
RedBearLab | 0:dfcebc1e442a | 376 | |
RedBearLab | 0:dfcebc1e442a | 377 | |
RedBearLab | 0:dfcebc1e442a | 378 | |
RedBearLab | 0:dfcebc1e442a | 379 | |
RedBearLab | 0:dfcebc1e442a | 380 | |
RedBearLab | 0:dfcebc1e442a | 381 | |
RedBearLab | 0:dfcebc1e442a | 382 | |
RedBearLab | 0:dfcebc1e442a | 383 | |
RedBearLab | 0:dfcebc1e442a | 384 | |
RedBearLab | 0:dfcebc1e442a | 385 | |
RedBearLab | 0:dfcebc1e442a | 386 | |
RedBearLab | 0:dfcebc1e442a | 387 | |
RedBearLab | 0:dfcebc1e442a | 388 | |
RedBearLab | 0:dfcebc1e442a | 389 | |
RedBearLab | 0:dfcebc1e442a | 390 | |
RedBearLab | 0:dfcebc1e442a | 391 | |
RedBearLab | 0:dfcebc1e442a | 392 | |
RedBearLab | 0:dfcebc1e442a | 393 | |
RedBearLab | 0:dfcebc1e442a | 394 | |
RedBearLab | 0:dfcebc1e442a | 395 |