RadiantRVA
/
rbVectorIQ
share for RS
Fork of rbVectorIQ by
main.cpp@15:daadb429b388, 2017-03-01 (annotated)
- Committer:
- MarkSPA
- Date:
- Wed Mar 01 21:10:07 2017 +0000
- Revision:
- 15:daadb429b388
- Parent:
- 12:99c81e757506
Cleaned up version for DRHS
Who changed what in which revision?
User | Revision | Line number | New 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 // |
MarkSPA | 10:eb100af346bf | 35 | #define DIGITAL_IN_PIN P0_9 //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 | 15:daadb429b388 | 39 | #define LED_DIG_OUT_PIN P0_8 //RTS |
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 | 8:e275405a431d | 59 | #define PATTERN_IRON 0x0C |
MarkSPA | 4:c8515fbd2e44 | 60 | #define LEDS_ON 0x01 |
MarkSPA | 4:c8515fbd2e44 | 61 | #define LEDS_OFF 0x02 |
RedBearLab | 0:dfcebc1e442a | 62 | |
RedBearLab | 2:bbcdd23ba9ba | 63 | BLE ble; |
RedBearLab | 0:dfcebc1e442a | 64 | |
MarkSPA | 4:c8515fbd2e44 | 65 | //DigitalOut LED_SET(DIGITAL_OUT_PIN); |
MarkSPA | 4:c8515fbd2e44 | 66 | DigitalOut LED_SET(BOARD_LED); |
RedBearLab | 0:dfcebc1e442a | 67 | DigitalIn BUTTON(DIGITAL_IN_PIN); |
MarkSPA | 4:c8515fbd2e44 | 68 | //PwmOut PWM(PWM_PIN); |
MarkSPA | 4:c8515fbd2e44 | 69 | //AnalogIn ANALOG(ANALOG_IN_PIN); |
RedBearLab | 0:dfcebc1e442a | 70 | |
MarkSPA | 4:c8515fbd2e44 | 71 | //Serial pc(USBTX, USBRX); |
MarkSPA | 4:c8515fbd2e44 | 72 | static uint8_t old_state = 0; |
MarkSPA | 4:c8515fbd2e44 | 73 | neopixel_strip_t m_strip; |
MarkSPA | 15:daadb429b388 | 74 | uint8_t dig_pin_num = LED_DIG_OUT_PIN; |
MarkSPA | 4:c8515fbd2e44 | 75 | uint8_t slow_count = 0; |
MarkSPA | 4:c8515fbd2e44 | 76 | //uint8_t error; |
MarkSPA | 15:daadb429b388 | 77 | uint8_t led_to_enable = 2; |
MarkSPA | 4:c8515fbd2e44 | 78 | uint8_t red = 255; |
MarkSPA | 15:daadb429b388 | 79 | uint8_t green = 0; |
MarkSPA | 15:daadb429b388 | 80 | uint8_t blue = 0; |
MarkSPA | 4:c8515fbd2e44 | 81 | uint8_t pattern = 0; |
RedBearLab | 0:dfcebc1e442a | 82 | |
MarkSPA | 7:0db51a3107fc | 83 | char mDeviceName[128]; |
MarkSPA | 7:0db51a3107fc | 84 | |
MarkSPA | 4:c8515fbd2e44 | 85 | uint8_t LEDS_ON_FLAG = 0; |
RedBearLab | 0:dfcebc1e442a | 86 | |
RedBearLab | 0:dfcebc1e442a | 87 | // The Nordic UART Service |
RedBearLab | 0:dfcebc1e442a | 88 | 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 | 89 | 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 | 90 | 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 | 91 | 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 | 92 | |
RedBearLab | 0:dfcebc1e442a | 93 | uint8_t txPayload[TXRX_BUF_LEN] = {0,}; |
RedBearLab | 0:dfcebc1e442a | 94 | uint8_t rxPayload[TXRX_BUF_LEN] = {0,}; |
RedBearLab | 0:dfcebc1e442a | 95 | |
RedBearLab | 0:dfcebc1e442a | 96 | 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 | 97 | GattCharacteristic rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); |
RedBearLab | 0:dfcebc1e442a | 98 | GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic}; |
RedBearLab | 0:dfcebc1e442a | 99 | GattService uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *)); |
MarkSPA | 7:0db51a3107fc | 100 | void setup_advertising(void); |
RedBearLab | 0:dfcebc1e442a | 101 | |
MarkSPA | 4:c8515fbd2e44 | 102 | void rainbowCycle(int wait, uint8_t numLEDs, neopixel_strip_t m_strip); |
MarkSPA | 4:c8515fbd2e44 | 103 | void candyChase(int wait, uint8_t numLEDs, neopixel_strip_t m_strip); |
MarkSPA | 4:c8515fbd2e44 | 104 | void snowflakes(int wait, uint8_t numLEDs, neopixel_strip_t m_strip); |
MarkSPA | 4:c8515fbd2e44 | 105 | void iceflakes(int delay, uint8_t numLEDs, neopixel_strip_t m_strip); |
MarkSPA | 5:1f6311e0fc14 | 106 | void xmas(int delay, uint8_t numLEDs, neopixel_strip_t m_strip); |
MarkSPA | 7:0db51a3107fc | 107 | void collegiate(int wait, uint8_t numLEDs, neopixel_strip_t m_strip); |
MarkSPA | 8:e275405a431d | 108 | void irondude(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 | 15:daadb429b388 | 125 | |
RedBearLab | 0:dfcebc1e442a | 126 | ble.startAdvertising(); |
RedBearLab | 0:dfcebc1e442a | 127 | } |
RedBearLab | 0:dfcebc1e442a | 128 | |
RedBearLab | 2:bbcdd23ba9ba | 129 | void WrittenHandler(const GattWriteCallbackParams *Handler) |
MarkSPA | 4:c8515fbd2e44 | 130 | { |
RedBearLab | 0:dfcebc1e442a | 131 | uint8_t buf[TXRX_BUF_LEN]; |
MarkSPA | 4:c8515fbd2e44 | 132 | uint16_t bytesRead; |
MarkSPA | 4:c8515fbd2e44 | 133 | |
MarkSPA | 4:c8515fbd2e44 | 134 | if (Handler->handle == txCharacteristic.getValueAttribute().getHandle()) { |
RedBearLab | 0:dfcebc1e442a | 135 | ble.readCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(), buf, &bytesRead); |
RedBearLab | 0:dfcebc1e442a | 136 | memset(txPayload, 0, TXRX_BUF_LEN); |
MarkSPA | 4:c8515fbd2e44 | 137 | memcpy(txPayload, buf, TXRX_BUF_LEN); |
MarkSPA | 4:c8515fbd2e44 | 138 | |
MarkSPA | 4:c8515fbd2e44 | 139 | //for(index=0; index<bytesRead; index++) |
MarkSPA | 4:c8515fbd2e44 | 140 | //pc.putc(buf[index]); |
RedBearLab | 0:dfcebc1e442a | 141 | |
MarkSPA | 4:c8515fbd2e44 | 142 | if(buf[0] == ONOFF_HEADER) { |
MarkSPA | 4:c8515fbd2e44 | 143 | //pc.printf("LED value received \r\n"); |
MarkSPA | 4:c8515fbd2e44 | 144 | if(buf[1] == LEDS_ON) { |
MarkSPA | 4:c8515fbd2e44 | 145 | LEDS_ON_FLAG = 1; |
MarkSPA | 4:c8515fbd2e44 | 146 | } else if(buf[1] == LEDS_OFF) { |
MarkSPA | 4:c8515fbd2e44 | 147 | LEDS_ON_FLAG = 0; |
MarkSPA | 4:c8515fbd2e44 | 148 | neopixel_init(&m_strip, dig_pin_num, NUM_LEDS); |
MarkSPA | 4:c8515fbd2e44 | 149 | neopixel_clear(&m_strip); |
MarkSPA | 4:c8515fbd2e44 | 150 | } |
MarkSPA | 4:c8515fbd2e44 | 151 | } else if(buf[0] == COLOR_HEADER) { |
MarkSPA | 4:c8515fbd2e44 | 152 | red = buf[1]; |
MarkSPA | 4:c8515fbd2e44 | 153 | green = buf[2]; |
MarkSPA | 4:c8515fbd2e44 | 154 | blue = buf[3]; |
MarkSPA | 4:c8515fbd2e44 | 155 | pattern = buf[5]; |
RedBearLab | 0:dfcebc1e442a | 156 | } |
MarkSPA | 6:074f5ec7428c | 157 | else |
MarkSPA | 6:074f5ec7428c | 158 | { |
MarkSPA | 6:074f5ec7428c | 159 | LEDS_ON_FLAG = 1; |
MarkSPA | 6:074f5ec7428c | 160 | red = buf[1]; |
MarkSPA | 6:074f5ec7428c | 161 | green = buf[2]; |
MarkSPA | 6:074f5ec7428c | 162 | blue = buf[3]; |
MarkSPA | 6:074f5ec7428c | 163 | pattern = buf[5]; |
MarkSPA | 6:074f5ec7428c | 164 | } |
RedBearLab | 0:dfcebc1e442a | 165 | } |
RedBearLab | 0:dfcebc1e442a | 166 | } |
MarkSPA | 4:c8515fbd2e44 | 167 | |
RedBearLab | 0:dfcebc1e442a | 168 | void m_status_check_handle(void) |
MarkSPA | 4:c8515fbd2e44 | 169 | { |
RedBearLab | 0:dfcebc1e442a | 170 | uint8_t buf[3]; |
MarkSPA | 4:c8515fbd2e44 | 171 | |
RedBearLab | 0:dfcebc1e442a | 172 | // If digital in changes, report the state |
MarkSPA | 4:c8515fbd2e44 | 173 | if (BUTTON != old_state) { |
RedBearLab | 0:dfcebc1e442a | 174 | old_state = BUTTON; |
MarkSPA | 10:eb100af346bf | 175 | if (LEDS_ON_FLAG) |
MarkSPA | 10:eb100af346bf | 176 | LEDS_ON_FLAG = 0; |
MarkSPA | 10:eb100af346bf | 177 | else |
MarkSPA | 10:eb100af346bf | 178 | LEDS_ON_FLAG = 1; |
MarkSPA | 10:eb100af346bf | 179 | |
MarkSPA | 4:c8515fbd2e44 | 180 | if (BUTTON == 1) { |
RedBearLab | 0:dfcebc1e442a | 181 | buf[0] = (0x0A); |
RedBearLab | 0:dfcebc1e442a | 182 | buf[1] = (0x01); |
MarkSPA | 4:c8515fbd2e44 | 183 | buf[2] = (0x00); |
MarkSPA | 4:c8515fbd2e44 | 184 | ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 3); |
MarkSPA | 4:c8515fbd2e44 | 185 | } else { |
RedBearLab | 0:dfcebc1e442a | 186 | buf[0] = (0x0A); |
RedBearLab | 0:dfcebc1e442a | 187 | buf[1] = (0x00); |
RedBearLab | 0:dfcebc1e442a | 188 | buf[2] = (0x00); |
MarkSPA | 4:c8515fbd2e44 | 189 | ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 3); |
RedBearLab | 0:dfcebc1e442a | 190 | } |
RedBearLab | 0:dfcebc1e442a | 191 | } |
RedBearLab | 0:dfcebc1e442a | 192 | } |
RedBearLab | 0:dfcebc1e442a | 193 | |
MarkSPA | 4:c8515fbd2e44 | 194 | void ble_on_radio_active_evt(bool radio_active) |
MarkSPA | 4:c8515fbd2e44 | 195 | { |
MarkSPA | 4:c8515fbd2e44 | 196 | if ((radio_active == false) && (LEDS_ON_FLAG == 1)) { |
MarkSPA | 4:c8515fbd2e44 | 197 | if (pattern == PATTERN_ON) { |
MarkSPA | 6:074f5ec7428c | 198 | for (uint8_t i = 0; i <= NUM_LEDS; i++) |
MarkSPA | 4:c8515fbd2e44 | 199 | neopixel_set_color(&m_strip, i, red, green, blue); |
MarkSPA | 4:c8515fbd2e44 | 200 | neopixel_show(&m_strip); |
MarkSPA | 4:c8515fbd2e44 | 201 | |
MarkSPA | 4:c8515fbd2e44 | 202 | } else if (pattern == PATTERN_FAST) { |
MarkSPA | 6:074f5ec7428c | 203 | //neopixel_clear(&m_strip); |
MarkSPA | 6:074f5ec7428c | 204 | for (uint8_t i = 0; i <= NUM_LEDS; i++) |
MarkSPA | 6:074f5ec7428c | 205 | neopixel_set_color(&m_strip, i, 0, 0, 0); |
MarkSPA | 4:c8515fbd2e44 | 206 | if (led_to_enable > NUM_LEDS) |
MarkSPA | 4:c8515fbd2e44 | 207 | led_to_enable = 0; |
MarkSPA | 4:c8515fbd2e44 | 208 | neopixel_set_color(&m_strip, led_to_enable, red, green, blue); |
MarkSPA | 4:c8515fbd2e44 | 209 | neopixel_show(&m_strip); |
MarkSPA | 4:c8515fbd2e44 | 210 | led_to_enable++; |
MarkSPA | 4:c8515fbd2e44 | 211 | } else if (pattern == PATTERN_SLOW) { |
MarkSPA | 6:074f5ec7428c | 212 | for (uint8_t i = 0; i <= NUM_LEDS; i++) |
MarkSPA | 6:074f5ec7428c | 213 | neopixel_set_color(&m_strip, i, 0, 0, 0); |
MarkSPA | 6:074f5ec7428c | 214 | if (led_to_enable > NUM_LEDS) |
MarkSPA | 6:074f5ec7428c | 215 | led_to_enable = 0; |
MarkSPA | 6:074f5ec7428c | 216 | neopixel_set_color(&m_strip, led_to_enable, red, green, blue); |
MarkSPA | 6:074f5ec7428c | 217 | neopixel_show(&m_strip); |
MarkSPA | 6:074f5ec7428c | 218 | led_to_enable++; |
MarkSPA | 6:074f5ec7428c | 219 | wait_ms(1000); |
MarkSPA | 6:074f5ec7428c | 220 | |
MarkSPA | 4:c8515fbd2e44 | 221 | } else if (pattern == PATTERN_CHASE) { |
MarkSPA | 4:c8515fbd2e44 | 222 | for (uint8_t i = 0; i < NUM_LEDS; i++) |
MarkSPA | 4:c8515fbd2e44 | 223 | neopixel_set_color(&m_strip, i, red, green, blue); |
MarkSPA | 4:c8515fbd2e44 | 224 | neopixel_show(&m_strip); |
MarkSPA | 6:074f5ec7428c | 225 | |
MarkSPA | 4:c8515fbd2e44 | 226 | } else if (pattern == PATTERN_MRB) { |
MarkSPA | 8:e275405a431d | 227 | //neopixel_clear(&m_strip); |
MarkSPA | 8:e275405a431d | 228 | for (uint8_t i = 0; i <= NUM_LEDS; i++) |
MarkSPA | 8:e275405a431d | 229 | neopixel_set_color(&m_strip, i, 0, 0, 0); |
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 | 11:45f76d2b5b8c | 245 | iceflakes(150, 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 | 8:e275405a431d | 253 | else if (pattern == PATTERN_IRON) |
MarkSPA | 8:e275405a431d | 254 | irondude(250, NUM_LEDS, m_strip); |
MarkSPA | 8:e275405a431d | 255 | |
MarkSPA | 6:074f5ec7428c | 256 | else |
MarkSPA | 6:074f5ec7428c | 257 | neopixel_clear(&m_strip); |
MarkSPA | 4:c8515fbd2e44 | 258 | |
MarkSPA | 4:c8515fbd2e44 | 259 | } |
MarkSPA | 4:c8515fbd2e44 | 260 | } |
MarkSPA | 4:c8515fbd2e44 | 261 | |
MarkSPA | 4:c8515fbd2e44 | 262 | static void radio_notification_init(void) |
MarkSPA | 4:c8515fbd2e44 | 263 | { |
MarkSPA | 4:c8515fbd2e44 | 264 | //uint32_t err_code; |
MarkSPA | 4:c8515fbd2e44 | 265 | ble_radio_notification_init(NRF_APP_PRIORITY_LOW, |
MarkSPA | 4:c8515fbd2e44 | 266 | NRF_RADIO_NOTIFICATION_DISTANCE_800US, |
MarkSPA | 4:c8515fbd2e44 | 267 | ble_on_radio_active_evt); |
MarkSPA | 4:c8515fbd2e44 | 268 | //APP_ERROR_CHECK(err_code); |
MarkSPA | 4:c8515fbd2e44 | 269 | } |
RedBearLab | 0:dfcebc1e442a | 270 | |
MarkSPA | 7:0db51a3107fc | 271 | void setup_advertising(void) |
MarkSPA | 7:0db51a3107fc | 272 | { |
MarkSPA | 7:0db51a3107fc | 273 | int length = strlen(mDeviceName); |
MarkSPA | 7:0db51a3107fc | 274 | |
MarkSPA | 7:0db51a3107fc | 275 | // setup advertising |
MarkSPA | 7:0db51a3107fc | 276 | ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); |
MarkSPA | 7:0db51a3107fc | 277 | ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
MarkSPA | 7:0db51a3107fc | 278 | ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, |
MarkSPA | 7:0db51a3107fc | 279 | (const uint8_t *)&mDeviceName, length); |
MarkSPA | 7:0db51a3107fc | 280 | ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, |
MarkSPA | 7:0db51a3107fc | 281 | (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid)); |
MarkSPA | 15:daadb429b388 | 282 | // In multiples of 0.625ms. |
MarkSPA | 7:0db51a3107fc | 283 | ble.setAdvertisingInterval(80); |
MarkSPA | 7:0db51a3107fc | 284 | ble.addService(uartService); |
MarkSPA | 7:0db51a3107fc | 285 | ble.startAdvertising(); |
MarkSPA | 7:0db51a3107fc | 286 | //pc.printf("Advertising Start \r\n"); |
MarkSPA | 7:0db51a3107fc | 287 | } |
MarkSPA | 7:0db51a3107fc | 288 | |
RedBearLab | 0:dfcebc1e442a | 289 | int main(void) |
MarkSPA | 4:c8515fbd2e44 | 290 | { |
MarkSPA | 4:c8515fbd2e44 | 291 | //uint8_t led_error; |
MarkSPA | 4:c8515fbd2e44 | 292 | |
RedBearLab | 0:dfcebc1e442a | 293 | Ticker ticker; |
RedBearLab | 0:dfcebc1e442a | 294 | ticker.attach_us(m_status_check_handle, 200000); |
MarkSPA | 4:c8515fbd2e44 | 295 | |
MarkSPA | 4:c8515fbd2e44 | 296 | //pc.printf("neoPixel Init \r\n"); |
MarkSPA | 4:c8515fbd2e44 | 297 | neopixel_init(&m_strip, dig_pin_num, NUM_LEDS); |
MarkSPA | 4:c8515fbd2e44 | 298 | neopixel_clear(&m_strip); |
MarkSPA | 4:c8515fbd2e44 | 299 | |
RedBearLab | 0:dfcebc1e442a | 300 | ble.init(); |
RedBearLab | 0:dfcebc1e442a | 301 | ble.onDisconnection(disconnectionCallback); |
MarkSPA | 4:c8515fbd2e44 | 302 | ble.onConnection(connectionCallback); |
MarkSPA | 4:c8515fbd2e44 | 303 | ble.onDataWritten(WrittenHandler); |
MarkSPA | 4:c8515fbd2e44 | 304 | radio_notification_init(); |
MarkSPA | 4:c8515fbd2e44 | 305 | //pc.baud(9600); |
MarkSPA | 4:c8515fbd2e44 | 306 | //pc.format(8, SerialBase::None, 1); |
MarkSPA | 4:c8515fbd2e44 | 307 | //pc.printf("rbChromaBand Init \r\n"); |
MarkSPA | 4:c8515fbd2e44 | 308 | //pc.attach( uartCB , pc.RxIrq); |
MarkSPA | 7:0db51a3107fc | 309 | |
MarkSPA | 7:0db51a3107fc | 310 | strcpy(mDeviceName, "RRVA BLE"); |
RedBearLab | 0:dfcebc1e442a | 311 | |
MarkSPA | 7:0db51a3107fc | 312 | setup_advertising(); |
MarkSPA | 4:c8515fbd2e44 | 313 | |
MarkSPA | 4:c8515fbd2e44 | 314 | while(1) { |
MarkSPA | 4:c8515fbd2e44 | 315 | //pc.putc(pc.getc()); |
MarkSPA | 4:c8515fbd2e44 | 316 | ble.waitForEvent(); |
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 | |
RedBearLab | 0:dfcebc1e442a | 349 | |
RedBearLab | 0:dfcebc1e442a | 350 |