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