RadiantRVA
/
rbVectorIQ
share for RS
Fork of rbVectorIQ by
source/vector_iq.h@16:4fca60460b7e, 2017-06-19 (annotated)
- Committer:
- MarkSPA
- Date:
- Mon Jun 19 18:12:42 2017 +0000
- Revision:
- 16:4fca60460b7e
- Child:
- 17:123883bbf391
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MarkSPA | 16:4fca60460b7e | 1 | /* |
MarkSPA | 16:4fca60460b7e | 2 | |
MarkSPA | 16:4fca60460b7e | 3 | Copyright (c) 2017 Radiant RVA |
MarkSPA | 16:4fca60460b7e | 4 | |
MarkSPA | 16:4fca60460b7e | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
MarkSPA | 16:4fca60460b7e | 6 | and associated documentation files (the "Software"), to deal in the Software without restriction, |
MarkSPA | 16:4fca60460b7e | 7 | including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, |
MarkSPA | 16:4fca60460b7e | 8 | and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, |
MarkSPA | 16:4fca60460b7e | 9 | subject to the following conditions: |
MarkSPA | 16:4fca60460b7e | 10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
MarkSPA | 16:4fca60460b7e | 11 | |
MarkSPA | 16:4fca60460b7e | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
MarkSPA | 16:4fca60460b7e | 13 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
MarkSPA | 16:4fca60460b7e | 14 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE |
MarkSPA | 16:4fca60460b7e | 15 | FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
MarkSPA | 16:4fca60460b7e | 16 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
MarkSPA | 16:4fca60460b7e | 17 | |
MarkSPA | 16:4fca60460b7e | 18 | */ |
MarkSPA | 16:4fca60460b7e | 19 | |
MarkSPA | 16:4fca60460b7e | 20 | #include "mbed.h" |
MarkSPA | 16:4fca60460b7e | 21 | #include "neopixel.h" |
MarkSPA | 16:4fca60460b7e | 22 | #include "ble/BLE.h" |
MarkSPA | 16:4fca60460b7e | 23 | #include "GattCallbackParamTypes.h" |
MarkSPA | 16:4fca60460b7e | 24 | #include "DFUService.h" |
MarkSPA | 16:4fca60460b7e | 25 | #include "pitches.h" |
MarkSPA | 16:4fca60460b7e | 26 | #include <DeviceInformationService.h> |
MarkSPA | 16:4fca60460b7e | 27 | extern "C" { |
MarkSPA | 16:4fca60460b7e | 28 | #include "ble_radio_notification.h" |
MarkSPA | 16:4fca60460b7e | 29 | } |
MarkSPA | 16:4fca60460b7e | 30 | #define BLE_UUID_TXRX_SERVICE 0x0000 /**< The UUID of the Nordic UART Service. */ |
MarkSPA | 16:4fca60460b7e | 31 | #define BLE_UUID_TX_CHARACTERISTIC 0x0002 /**< The UUID of the TX Characteristic. */ |
MarkSPA | 16:4fca60460b7e | 32 | #define BLE_UUIDS_RX_CHARACTERISTIC 0x0003 /**< The UUID of the RX Characteristic. */ |
MarkSPA | 16:4fca60460b7e | 33 | |
MarkSPA | 16:4fca60460b7e | 34 | #define TXRX_BUF_LEN 20 |
MarkSPA | 16:4fca60460b7e | 35 | #ifdef VIQ |
MarkSPA | 16:4fca60460b7e | 36 | #define DIGITAL_OUT_PIN P0_17 |
MarkSPA | 16:4fca60460b7e | 37 | #define BOARD_LED P0_19 |
MarkSPA | 16:4fca60460b7e | 38 | #define DIGITAL_IN_PIN P0_9 |
MarkSPA | 16:4fca60460b7e | 39 | #define PWM_PIN P0_16 |
MarkSPA | 16:4fca60460b7e | 40 | #define SERVO_PIN P0_14 |
MarkSPA | 16:4fca60460b7e | 41 | #define ANALOG_IN_PIN P0_6 |
MarkSPA | 16:4fca60460b7e | 42 | #define LED_DIG_OUT_PIN P0_8 //RTS |
MarkSPA | 16:4fca60460b7e | 43 | #define HAPTIC_PIN P0_5 |
MarkSPA | 16:4fca60460b7e | 44 | #define PIEZO_PIN P0_4 |
MarkSPA | 16:4fca60460b7e | 45 | #endif |
MarkSPA | 16:4fca60460b7e | 46 | #define LED_HEADER 0x01 |
MarkSPA | 16:4fca60460b7e | 47 | #define ONOFF_HEADER 0x11 |
MarkSPA | 16:4fca60460b7e | 48 | #define COLOR_HEADER 0x22 |
MarkSPA | 16:4fca60460b7e | 49 | #define PATTERN_HEADER 0x33 |
MarkSPA | 16:4fca60460b7e | 50 | #define HAPTIC_HEADER 0x44 |
MarkSPA | 16:4fca60460b7e | 51 | #define PIEZO_HEADER 0x55 |
MarkSPA | 16:4fca60460b7e | 52 | #define ALARM_HEADER 0x66 |
MarkSPA | 16:4fca60460b7e | 53 | |
MarkSPA | 16:4fca60460b7e | 54 | #define NUM_LEDS 7 |
MarkSPA | 16:4fca60460b7e | 55 | |
MarkSPA | 16:4fca60460b7e | 56 | #define PATTERN_NONE 0x00 |
MarkSPA | 16:4fca60460b7e | 57 | #define PATTERN_ON 0x01 |
MarkSPA | 16:4fca60460b7e | 58 | #define PATTERN_FAST 0x02 |
MarkSPA | 16:4fca60460b7e | 59 | #define PATTERN_SLOW 0x03 |
MarkSPA | 16:4fca60460b7e | 60 | #define PATTERN_CHASE 0x04 |
MarkSPA | 16:4fca60460b7e | 61 | #define PATTERN_MRB 0x05 |
MarkSPA | 16:4fca60460b7e | 62 | #define PATTERN_RAINBOW 0x06 |
MarkSPA | 16:4fca60460b7e | 63 | #define PATTERN_CANDY 0x07 |
MarkSPA | 16:4fca60460b7e | 64 | #define PATTERN_SNOW 0x08 |
MarkSPA | 16:4fca60460b7e | 65 | #define PATTERN_XMAS 0x09 |
MarkSPA | 16:4fca60460b7e | 66 | #define PATTERN_ICE 0x0A |
MarkSPA | 16:4fca60460b7e | 67 | #define PATTERN_COL 0x0B |
MarkSPA | 16:4fca60460b7e | 68 | #define PATTERN_IRON 0x0C |
MarkSPA | 16:4fca60460b7e | 69 | #define PATTERN_SPRING 0x0D |
MarkSPA | 16:4fca60460b7e | 70 | #define PATTERN_EASTER 0x0E |
MarkSPA | 16:4fca60460b7e | 71 | #define PATTERN_MEM 0x0F |
MarkSPA | 16:4fca60460b7e | 72 | |
MarkSPA | 16:4fca60460b7e | 73 | #define LEDS_ON 0x01 |
MarkSPA | 16:4fca60460b7e | 74 | #define LEDS_OFF 0x02 |
MarkSPA | 16:4fca60460b7e | 75 | #define PIEZO_ON 0x01 |
MarkSPA | 16:4fca60460b7e | 76 | #define PIEZO_OFF 0x02 |
MarkSPA | 16:4fca60460b7e | 77 | #define ALARM_ON 0x01 |
MarkSPA | 16:4fca60460b7e | 78 | #define ALARM_OFF 0x02 |
MarkSPA | 16:4fca60460b7e | 79 | #define HAPTIC_ON 0x01 |
MarkSPA | 16:4fca60460b7e | 80 | #define HAPTIC_OFF 0x02 |
MarkSPA | 16:4fca60460b7e | 81 | |
MarkSPA | 16:4fca60460b7e | 82 | #define RINGTONE_COL 0x70 |
MarkSPA | 16:4fca60460b7e | 83 | #define RINGTONE_ONE 0x71 |
MarkSPA | 16:4fca60460b7e | 84 | #define RINGTONE_TWO 0x72 |
MarkSPA | 16:4fca60460b7e | 85 | #define RINGTONE_THREE 0x73 |
MarkSPA | 16:4fca60460b7e | 86 | #define RINGTONE_NONE 0x74 |
MarkSPA | 16:4fca60460b7e | 87 | |
MarkSPA | 16:4fca60460b7e | 88 | #define HAPTIC_10 0x10 |
MarkSPA | 16:4fca60460b7e | 89 | #define HAPTIC_30 0x30 |
MarkSPA | 16:4fca60460b7e | 90 | #define HAPTIC_60 0x60 |
MarkSPA | 16:4fca60460b7e | 91 | #define BUZZ_LEVEL1 0x51 |
MarkSPA | 16:4fca60460b7e | 92 | #define BUZZ_LEVEL2 0x52 |
MarkSPA | 16:4fca60460b7e | 93 | #define BUZZ_LEVEL3 0x53 |
MarkSPA | 16:4fca60460b7e | 94 | |
MarkSPA | 16:4fca60460b7e | 95 | BLE ble; |
MarkSPA | 16:4fca60460b7e | 96 | #ifdef VIQ |
MarkSPA | 16:4fca60460b7e | 97 | DigitalOut LED_SET(BOARD_LED); |
MarkSPA | 16:4fca60460b7e | 98 | DigitalIn BUTTON(DIGITAL_IN_PIN); |
MarkSPA | 16:4fca60460b7e | 99 | DigitalOut BUZZER(HAPTIC_PIN); |
MarkSPA | 16:4fca60460b7e | 100 | PwmOut PIEZO(PIEZO_PIN); |
MarkSPA | 16:4fca60460b7e | 101 | PwmOut PWM(PWM_PIN); |
MarkSPA | 16:4fca60460b7e | 102 | AnalogIn ANALOG(ANALOG_IN_PIN); |
MarkSPA | 16:4fca60460b7e | 103 | |
MarkSPA | 16:4fca60460b7e | 104 | InterruptIn pb(DIGITAL_IN_PIN); |
MarkSPA | 16:4fca60460b7e | 105 | uint8_t dig_pin_num = LED_DIG_OUT_PIN; |
MarkSPA | 16:4fca60460b7e | 106 | #endif |
MarkSPA | 16:4fca60460b7e | 107 | //Serial pc(USBTX, USBRX); |
MarkSPA | 16:4fca60460b7e | 108 | static uint8_t old_state = 0; |
MarkSPA | 16:4fca60460b7e | 109 | neopixel_strip_t m_strip; |
MarkSPA | 16:4fca60460b7e | 110 | |
MarkSPA | 16:4fca60460b7e | 111 | uint8_t slow_count = 0; |
MarkSPA | 16:4fca60460b7e | 112 | //uint8_t error; |
MarkSPA | 16:4fca60460b7e | 113 | uint8_t led_to_enable = 2; //10; |
MarkSPA | 16:4fca60460b7e | 114 | uint8_t red = 255; |
MarkSPA | 16:4fca60460b7e | 115 | uint8_t green = 0; |
MarkSPA | 16:4fca60460b7e | 116 | uint8_t blue = 0; |
MarkSPA | 16:4fca60460b7e | 117 | uint8_t pattern = 0; |
MarkSPA | 16:4fca60460b7e | 118 | uint8_t mPiezoOn = 0; |
MarkSPA | 16:4fca60460b7e | 119 | uint8_t mHapticOn = 0; |
MarkSPA | 16:4fca60460b7e | 120 | uint8_t mAlarmOn = 0; |
MarkSPA | 16:4fca60460b7e | 121 | uint8_t mHapticDur, mHapticPattern; |
MarkSPA | 16:4fca60460b7e | 122 | uint8_t mPiezoDur, mPiezoPattern; |
MarkSPA | 16:4fca60460b7e | 123 | uint8_t mAlarmDur, mAlarmPiezoOn, mAlarmTone, mAlarmPattern; |
MarkSPA | 16:4fca60460b7e | 124 | |
MarkSPA | 16:4fca60460b7e | 125 | char mDeviceName[128]; |
MarkSPA | 16:4fca60460b7e | 126 | int mLength; |
MarkSPA | 16:4fca60460b7e | 127 | |
MarkSPA | 16:4fca60460b7e | 128 | uint8_t LEDS_ON_FLAG = 0; |
MarkSPA | 16:4fca60460b7e | 129 | |
MarkSPA | 16:4fca60460b7e | 130 | Timer t_alarm; |
MarkSPA | 16:4fca60460b7e | 131 | float mBeginAlarm, mEndAlarm; |
MarkSPA | 16:4fca60460b7e | 132 | |
MarkSPA | 16:4fca60460b7e | 133 | /* Setup auxiliary services. */ |
MarkSPA | 16:4fca60460b7e | 134 | //const static char DEVICE_NAME[] = "RRVA BLE"; |
MarkSPA | 16:4fca60460b7e | 135 | static const uint16_t uuid16_list[] = {GattService::UUID_DEVICE_INFORMATION_SERVICE}; |
MarkSPA | 16:4fca60460b7e | 136 | DeviceInformationService *deviceInfo; |
MarkSPA | 16:4fca60460b7e | 137 | |
MarkSPA | 16:4fca60460b7e | 138 | // The Nordic UART Service |
MarkSPA | 16:4fca60460b7e | 139 | static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; |
MarkSPA | 16:4fca60460b7e | 140 | static const uint8_t uart_tx_uuid[] = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; |
MarkSPA | 16:4fca60460b7e | 141 | static const uint8_t uart_rx_uuid[] = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; |
MarkSPA | 16:4fca60460b7e | 142 | static const uint8_t uart_base_uuid_rev[] = {0x1E, 0x94, 0x8D, 0xF1, 0x48, 0x31, 0x94, 0xBA, 0x75, 0x4C, 0x3E, 0x50, 0, 0, 0x3D, 0x71}; |
MarkSPA | 16:4fca60460b7e | 143 | |
MarkSPA | 16:4fca60460b7e | 144 | int freq_shave[] = {NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 1, NOTE_B3, NOTE_C4}; |
MarkSPA | 16:4fca60460b7e | 145 | int beat_shave[] = {4, 8, 8, 4, 4, 4, 4, 4 }; |
MarkSPA | 16:4fca60460b7e | 146 | int freq_coll[] = {NOTE_C4, NOTE_B4, NOTE_B4, NOTE_A4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_G4, |
MarkSPA | 16:4fca60460b7e | 147 | NOTE_F4, NOTE_E4, NOTE_D3, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_F4, |
MarkSPA | 16:4fca60460b7e | 148 | NOTE_D4, NOTE_C3, NOTE_E4, NOTE_G4, NOTE_C4, NOTE_E5, NOTE_D4, NOTE_C4, |
MarkSPA | 16:4fca60460b7e | 149 | NOTE_G4, NOTE_G4, NOTE_C4, NOTE_G4}; |
MarkSPA | 16:4fca60460b7e | 150 | int beat_coll[] = {6, 2, 2, 2, 4, 6, 2, 2, 2, 4, 4, 2, 2, 2, |
MarkSPA | 16:4fca60460b7e | 151 | 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 2}; |
MarkSPA | 16:4fca60460b7e | 152 | |
MarkSPA | 16:4fca60460b7e | 153 | uint8_t txPayload[TXRX_BUF_LEN] = {0,}; |
MarkSPA | 16:4fca60460b7e | 154 | uint8_t rxPayload[TXRX_BUF_LEN] = {0,}; |
MarkSPA | 16:4fca60460b7e | 155 | |
MarkSPA | 16:4fca60460b7e | 156 | GattCharacteristic txCharacteristic (uart_tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE); |
MarkSPA | 16:4fca60460b7e | 157 | GattCharacteristic rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); |
MarkSPA | 16:4fca60460b7e | 158 | GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic}; |
MarkSPA | 16:4fca60460b7e | 159 | GattService uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *)); |
MarkSPA | 16:4fca60460b7e | 160 | void setup_advertising(void); |
MarkSPA | 16:4fca60460b7e | 161 | |
MarkSPA | 16:4fca60460b7e | 162 | void rainbowCycle(int wait, uint8_t numLEDs, neopixel_strip_t m_strip); |
MarkSPA | 16:4fca60460b7e | 163 | void candyChase(int wait, uint8_t numLEDs, neopixel_strip_t m_strip); |
MarkSPA | 16:4fca60460b7e | 164 | void snowflakes(int wait, uint8_t numLEDs, neopixel_strip_t m_strip); |
MarkSPA | 16:4fca60460b7e | 165 | void iceflakes(int delay, uint8_t numLEDs, neopixel_strip_t m_strip); |
MarkSPA | 16:4fca60460b7e | 166 | void xmas(int delay, uint8_t numLEDs, neopixel_strip_t m_strip); |
MarkSPA | 16:4fca60460b7e | 167 | void collegiate(int wait, uint8_t numLEDs, neopixel_strip_t m_strip); |
MarkSPA | 16:4fca60460b7e | 168 | void irondude(int wait, uint8_t numLEDs, neopixel_strip_t m_strip); |
MarkSPA | 16:4fca60460b7e | 169 | void easter(int wait, uint8_t numLEDs, neopixel_strip_t m_strip); |
MarkSPA | 16:4fca60460b7e | 170 | void spring(int wait, uint8_t numLEDs, neopixel_strip_t m_strip); |
MarkSPA | 16:4fca60460b7e | 171 | void memorial(int wait, uint8_t numLEDs, neopixel_strip_t m_strip); |
MarkSPA | 16:4fca60460b7e | 172 | |
MarkSPA | 16:4fca60460b7e | 173 | //extern uint32_t ble_radio_notification_init(nrf_app_irq_priority_t irq_priority, |
MarkSPA | 16:4fca60460b7e | 174 | // nrf_radio_notification_distance_t distance, |
MarkSPA | 16:4fca60460b7e | 175 | // ble_radio_notification_evt_handler_t evt_handler); |