Jason Chang
/
9v1
Add I2CSlave to ov580 master.
main.cpp@10:c757bd889ed1, 2018-11-12 (annotated)
- Committer:
- claytonk
- Date:
- Mon Nov 12 00:13:30 2018 +0000
- Revision:
- 10:c757bd889ed1
- Parent:
- 9:69e0bbfdb62b
- Child:
- 11:236d223ba3bc
Considered Frozen;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
claytonk | 7:9c77eaad5102 | 1 | #define TWIS1_ENABLED 1 |
claytonk | 7:9c77eaad5102 | 2 | #define TWIS0_ENABLED 0 |
claytonk | 7:9c77eaad5102 | 3 | #define TWIS_ENABLED 1 |
claytonk | 7:9c77eaad5102 | 4 | #define TWI0_ENABLED 1 |
claytonk | 7:9c77eaad5102 | 5 | #define TWI1_ENABLED 0 |
claytonk | 7:9c77eaad5102 | 6 | #define TWI0_USE_EASY_DMA 1 |
claytonk | 7:9c77eaad5102 | 7 | #define TWI1_USE_EASY_DMA 1 |
claytonk | 7:9c77eaad5102 | 8 | #define TWI_DEFAULT_CONFIG_FREQUENCY 104857600 |
claytonk | 7:9c77eaad5102 | 9 | #define ARDUINO_A4_PIN 14 |
claytonk | 7:9c77eaad5102 | 10 | #define ARDUINO_A5_PIN 15 |
claytonk | 7:9c77eaad5102 | 11 | |
claytonk | 7:9c77eaad5102 | 12 | |
claytonk | 0:605fe136b7ea | 13 | #include "mbed.h" |
claytonk | 7:9c77eaad5102 | 14 | //#include <nrfx_config.h> need SDK config instead |
claytonk | 7:9c77eaad5102 | 15 | //#include "sdk_config.h" not needed now |
claytonk | 0:605fe136b7ea | 16 | |
claytonk | 0:605fe136b7ea | 17 | /* |
claytonk | 0:605fe136b7ea | 18 | FEATURE REQUIREMENTS |
claytonk | 0:605fe136b7ea | 19 | |
claytonk | 3:6b14862f5f51 | 20 | - I2C write occurs on falling edge of strobe pulse to prevent unknown states |
claytonk | 3:6b14862f5f51 | 21 | |
claytonk | 3:6b14862f5f51 | 22 | - Stack check occurs on leading edge of strobe pulse to ensure strobes are |
claytonk | 3:6b14862f5f51 | 23 | set correctly |
claytonk | 0:605fe136b7ea | 24 | |
claytonk | 3:6b14862f5f51 | 25 | - Reoccuring enable from app that will prevent the emitters from remaining |
claytonk | 3:6b14862f5f51 | 26 | on if the app crashes and a turn off command isn't sent |
claytonk | 0:605fe136b7ea | 27 | - Can be a counter on the emitter enable > threshold |
claytonk | 3:6b14862f5f51 | 28 | - Better if it's a counter based on reads from the fault register |
claytonk | 0:605fe136b7ea | 29 | |
claytonk | 9:69e0bbfdb62b | 30 | -Flood/Dot tagging indicated on GPIO3 / PWM0 |
claytonk | 0:605fe136b7ea | 31 | - 0 Flood |
claytonk | 0:605fe136b7ea | 32 | - 1 DOT |
claytonk | 0:605fe136b7ea | 33 | |
claytonk | 9:69e0bbfdb62b | 34 | -Fault indication on GPIO4 / PWM1 to indicate to app to reboot |
claytonk | 0:605fe136b7ea | 35 | - 0 OK |
claytonk | 0:605fe136b7ea | 36 | - 1 Fault/Reboot |
claytonk | 0:605fe136b7ea | 37 | |
claytonk | 0:605fe136b7ea | 38 | I2C write commands |
claytonk | 0:605fe136b7ea | 39 | Reg: Information Condition |
claytonk | 4:fc0c93cb0197 | 40 | 0x0000 Emitter enable 0x00 Emitters off |
claytonk | 0:605fe136b7ea | 41 | 0x01 Dot on |
claytonk | 0:605fe136b7ea | 42 | 0x10 Flood on |
claytonk | 0:605fe136b7ea | 43 | 0x11 Flood / Dot on |
claytonk | 0:605fe136b7ea | 44 | |
claytonk | 4:fc0c93cb0197 | 45 | 0x0001 Dot fault Read from LM36011 |
claytonk | 0:605fe136b7ea | 46 | |
claytonk | 4:fc0c93cb0197 | 47 | 0x0002 Dot Current 0x00 - level_dot_max |
claytonk | 3:6b14862f5f51 | 48 | |
claytonk | 4:fc0c93cb0197 | 49 | 0x0003 Flood Fault Read from LM36011 |
claytonk | 3:6b14862f5f51 | 50 | |
claytonk | 4:fc0c93cb0197 | 51 | 0x0004 Flood Current 0x00 - level_flood_max |
claytonk | 0:605fe136b7ea | 52 | |
claytonk | 4:fc0c93cb0197 | 53 | 0x0005 Fault register bit[0] KILL_VCSEL fault |
claytonk | 3:6b14862f5f51 | 54 | bit[1] dot fault |
claytonk | 3:6b14862f5f51 | 55 | bit[2] flood fault |
claytonk | 3:6b14862f5f51 | 56 | bit[3] unstacked fault |
claytonk | 3:6b14862f5f51 | 57 | bit[4] ?not in app fault? |
claytonk | 3:6b14862f5f51 | 58 | bit[5-7] unused |
claytonk | 3:6b14862f5f51 | 59 | |
claytonk | 3:6b14862f5f51 | 60 | |
claytonk | 4:fc0c93cb0197 | 61 | 0x0006 Version number 0x70 = version 7.0 |
claytonk | 0:605fe136b7ea | 62 | |
claytonk | 9:69e0bbfdb62b | 63 | */ |
claytonk | 9:69e0bbfdb62b | 64 | /* ERROR CHECKING */ |
claytonk | 0:605fe136b7ea | 65 | |
claytonk | 7:9c77eaad5102 | 66 | #if (TWIS0_ENABLED == 1) |
claytonk | 7:9c77eaad5102 | 67 | #error TWIS0 is congigured wrong |
claytonk | 7:9c77eaad5102 | 68 | #endif |
claytonk | 7:9c77eaad5102 | 69 | |
claytonk | 7:9c77eaad5102 | 70 | #if (TWIS1_ENABLED == 0) |
claytonk | 7:9c77eaad5102 | 71 | #error TWIS1 is off |
claytonk | 7:9c77eaad5102 | 72 | #endif |
claytonk | 6:85d9ad912c14 | 73 | |
claytonk | 7:9c77eaad5102 | 74 | #if (TWIS_ENABLED == 0) |
claytonk | 7:9c77eaad5102 | 75 | #error TWIS is off |
claytonk | 7:9c77eaad5102 | 76 | #endif |
claytonk | 6:85d9ad912c14 | 77 | |
claytonk | 7:9c77eaad5102 | 78 | #if (TWI0_ENABLED == 0) |
claytonk | 7:9c77eaad5102 | 79 | #error TWI0 is off |
claytonk | 7:9c77eaad5102 | 80 | #endif |
claytonk | 7:9c77eaad5102 | 81 | |
claytonk | 7:9c77eaad5102 | 82 | #if (TWI1_ENABLED == 1) |
claytonk | 7:9c77eaad5102 | 83 | #error TWI1 is congigured wrong |
claytonk | 7:9c77eaad5102 | 84 | #endif |
claytonk | 6:85d9ad912c14 | 85 | |
claytonk | 3:6b14862f5f51 | 86 | /* DEFINES */ |
claytonk | 3:6b14862f5f51 | 87 | |
claytonk | 3:6b14862f5f51 | 88 | #define version_number 0x70 |
claytonk | 3:6b14862f5f51 | 89 | |
claytonk | 0:605fe136b7ea | 90 | // define pins for I2C |
claytonk | 0:605fe136b7ea | 91 | #define dot_sda p2 |
claytonk | 0:605fe136b7ea | 92 | #define dot_scl p4 |
claytonk | 0:605fe136b7ea | 93 | #define flood_sda p28 |
claytonk | 0:605fe136b7ea | 94 | #define flood_scl p3 |
claytonk | 0:605fe136b7ea | 95 | #define ov580_sda p30 |
claytonk | 0:605fe136b7ea | 96 | #define ov580_scl p31 |
claytonk | 3:6b14862f5f51 | 97 | |
claytonk | 3:6b14862f5f51 | 98 | // define strobe pins |
claytonk | 9:69e0bbfdb62b | 99 | #define strobe_flood p23 // strobe0 |
claytonk | 9:69e0bbfdb62b | 100 | #define strobe_dot p24 // strobe1 |
claytonk | 3:6b14862f5f51 | 101 | |
claytonk | 3:6b14862f5f51 | 102 | // define pmw pins |
claytonk | 0:605fe136b7ea | 103 | #define pwm_1_pin p29 |
claytonk | 0:605fe136b7ea | 104 | #define pwm_0_pin p5 |
claytonk | 0:605fe136b7ea | 105 | |
claytonk | 0:605fe136b7ea | 106 | // define LED pins |
claytonk | 0:605fe136b7ea | 107 | #define ledRed p12 |
claytonk | 0:605fe136b7ea | 108 | #define ledGreen p17 |
claytonk | 0:605fe136b7ea | 109 | #define ledBlue p13 |
claytonk | 0:605fe136b7ea | 110 | |
claytonk | 4:fc0c93cb0197 | 111 | /* THREAD */ |
claytonk | 4:fc0c93cb0197 | 112 | EventQueue queue; |
claytonk | 4:fc0c93cb0197 | 113 | |
claytonk | 6:85d9ad912c14 | 114 | /* TIMOUT */ |
claytonk | 8:10ffd42a3921 | 115 | Timeout dot_timeout; |
claytonk | 8:10ffd42a3921 | 116 | Timeout flood_timeout; |
claytonk | 9:69e0bbfdb62b | 117 | Timeout app_timeout; |
claytonk | 6:85d9ad912c14 | 118 | |
claytonk | 4:fc0c93cb0197 | 119 | /* INTERRUPTS */ |
claytonk | 4:fc0c93cb0197 | 120 | //create interupts |
claytonk | 4:fc0c93cb0197 | 121 | InterruptIn int_strobe_dot(strobe_dot); |
claytonk | 9:69e0bbfdb62b | 122 | InterruptIn int_strobe_flood(strobe_flood); |
claytonk | 3:6b14862f5f51 | 123 | |
claytonk | 3:6b14862f5f51 | 124 | /* I/O */ |
claytonk | 0:605fe136b7ea | 125 | // initialize LEDs |
claytonk | 0:605fe136b7ea | 126 | DigitalOut red(ledRed,1); |
claytonk | 0:605fe136b7ea | 127 | DigitalOut green(ledGreen,1); |
claytonk | 0:605fe136b7ea | 128 | DigitalOut blue(ledBlue,1); |
claytonk | 0:605fe136b7ea | 129 | |
claytonk | 0:605fe136b7ea | 130 | // Initialize outputs |
claytonk | 3:6b14862f5f51 | 131 | DigitalOut pwm_0_output(pwm_0_pin,0); // GPIO 3 |
claytonk | 3:6b14862f5f51 | 132 | DigitalOut pwm_1_output(pwm_1_pin,0); // GPIO 4 |
claytonk | 0:605fe136b7ea | 133 | |
claytonk | 0:605fe136b7ea | 134 | // Initialize inputs |
claytonk | 7:9c77eaad5102 | 135 | DigitalIn strobe0(strobe_flood,PullNone); |
claytonk | 7:9c77eaad5102 | 136 | DigitalIn strobe1(strobe_dot,PullNone); |
claytonk | 9:69e0bbfdb62b | 137 | DigitalIn vcselFault(p25,PullNone); // vcselFault is 1V8 instead of 3V3 |
claytonk | 9:69e0bbfdb62b | 138 | DigitalIn killVcsel(p26,PullNone); |
claytonk | 0:605fe136b7ea | 139 | |
claytonk | 7:9c77eaad5102 | 140 | |
claytonk | 3:6b14862f5f51 | 141 | /* REGISTERS */ |
claytonk | 0:605fe136b7ea | 142 | static uint8_t LM36011_addr = 0x64 << 1; //0xC8 |
claytonk | 0:605fe136b7ea | 143 | |
claytonk | 0:605fe136b7ea | 144 | // register names |
claytonk | 0:605fe136b7ea | 145 | static uint8_t enable_reg = 0x01; |
claytonk | 0:605fe136b7ea | 146 | static uint8_t configuration_reg = 0x02; |
claytonk | 0:605fe136b7ea | 147 | static uint8_t brightness_reg = 0x03; |
claytonk | 3:6b14862f5f51 | 148 | //static uint8_t torch_reg = 0x04; |
claytonk | 3:6b14862f5f51 | 149 | //static uint8_t flags_reg = 0x05; |
claytonk | 3:6b14862f5f51 | 150 | //static uint8_t device_id_reset_reg = 0x06; |
claytonk | 0:605fe136b7ea | 151 | |
claytonk | 0:605fe136b7ea | 152 | // register settings |
claytonk | 0:605fe136b7ea | 153 | static uint8_t enable_ir = 0x05; |
claytonk | 0:605fe136b7ea | 154 | static uint8_t disable_ir = 0x20; |
claytonk | 0:605fe136b7ea | 155 | static uint8_t enable_flash_timeout = 0x01; |
claytonk | 0:605fe136b7ea | 156 | |
claytonk | 0:605fe136b7ea | 157 | // level settings |
claytonk | 0:605fe136b7ea | 158 | static uint8_t level_flood_max = 0x66; // = 1.2 A |
claytonk | 10:c757bd889ed1 | 159 | //static uint8_t level_dot_max = 0x5F; // = 1.03 A |
claytonk | 0:605fe136b7ea | 160 | //static uint8_t level_dot_max = 0x3F; // = 0.75 A |
claytonk | 0:605fe136b7ea | 161 | //static uint8_t level_dot_max = 0x3C; // = 0.70 A |
claytonk | 0:605fe136b7ea | 162 | //static uint8_t level_dot_max = 0x15 //0.257 A |
claytonk | 10:c757bd889ed1 | 163 | static uint8_t level_dot_max = 0x1F; // = 352mA |
claytonk | 0:605fe136b7ea | 164 | |
claytonk | 3:6b14862f5f51 | 165 | char lm_on[2] = {enable_reg,enable_ir}; |
claytonk | 3:6b14862f5f51 | 166 | char lm_off[2] = {enable_reg,disable_ir}; |
claytonk | 0:605fe136b7ea | 167 | char lmSafety[2] = {configuration_reg,enable_flash_timeout}; |
claytonk | 0:605fe136b7ea | 168 | |
claytonk | 0:605fe136b7ea | 169 | char flashBrightness_dot[2] = {brightness_reg,level_dot_max}; |
claytonk | 0:605fe136b7ea | 170 | char flashBrightness_flood[2] = {brightness_reg,level_flood_max}; |
claytonk | 0:605fe136b7ea | 171 | |
claytonk | 3:6b14862f5f51 | 172 | /* I2C */ |
claytonk | 9:69e0bbfdb62b | 173 | //I2CSlave ov_I2C(ov580_sda,ov580_scl); |
claytonk | 0:605fe136b7ea | 174 | I2C flood_I2C(flood_sda,flood_scl); |
claytonk | 0:605fe136b7ea | 175 | I2C dot_I2C(dot_sda,dot_scl); |
claytonk | 6:85d9ad912c14 | 176 | |
claytonk | 0:605fe136b7ea | 177 | |
claytonk | 3:6b14862f5f51 | 178 | /* VARIABLES */ |
claytonk | 3:6b14862f5f51 | 179 | bool stacked = false; |
claytonk | 3:6b14862f5f51 | 180 | bool emitter_status_dot = false; |
claytonk | 7:9c77eaad5102 | 181 | char rcv_buffer[3] = {0,0,0}; |
claytonk | 8:10ffd42a3921 | 182 | int dot_counter = 0; |
claytonk | 6:85d9ad912c14 | 183 | bool dot_on = false; |
claytonk | 8:10ffd42a3921 | 184 | int flood_counter = 0; |
claytonk | 6:85d9ad912c14 | 185 | bool flood_on = false; |
claytonk | 6:85d9ad912c14 | 186 | bool once = false; |
claytonk | 8:10ffd42a3921 | 187 | bool in_app = false; |
claytonk | 8:10ffd42a3921 | 188 | int app_counts_required = 10; |
claytonk | 8:10ffd42a3921 | 189 | int stacked_counter = 0; |
claytonk | 3:6b14862f5f51 | 190 | |
claytonk | 3:6b14862f5f51 | 191 | /* FUNCTIONS */ |
claytonk | 1:ffffa383ba7e | 192 | |
claytonk | 6:85d9ad912c14 | 193 | // WAI |
claytonk | 6:85d9ad912c14 | 194 | void write_off() |
claytonk | 6:85d9ad912c14 | 195 | { |
claytonk | 6:85d9ad912c14 | 196 | dot_I2C.write(LM36011_addr,lm_off,2,false); |
claytonk | 6:85d9ad912c14 | 197 | flood_I2C.write(LM36011_addr,lm_off,2,false); |
claytonk | 6:85d9ad912c14 | 198 | } |
claytonk | 6:85d9ad912c14 | 199 | |
claytonk | 8:10ffd42a3921 | 200 | // WAI |
claytonk | 6:85d9ad912c14 | 201 | void write_dot() |
claytonk | 1:ffffa383ba7e | 202 | { |
claytonk | 6:85d9ad912c14 | 203 | flood_I2C.write(LM36011_addr,lm_off,2,false); |
claytonk | 6:85d9ad912c14 | 204 | dot_I2C.write(LM36011_addr,lm_on,2,false); |
claytonk | 6:85d9ad912c14 | 205 | } |
claytonk | 6:85d9ad912c14 | 206 | |
claytonk | 8:10ffd42a3921 | 207 | // WAI |
claytonk | 6:85d9ad912c14 | 208 | void write_flood() |
claytonk | 6:85d9ad912c14 | 209 | { |
claytonk | 6:85d9ad912c14 | 210 | dot_I2C.write(LM36011_addr,lm_off,2,false); |
claytonk | 6:85d9ad912c14 | 211 | flood_I2C.write(LM36011_addr,lm_on,2,false); |
claytonk | 6:85d9ad912c14 | 212 | } |
claytonk | 6:85d9ad912c14 | 213 | |
claytonk | 8:10ffd42a3921 | 214 | // WAI |
claytonk | 6:85d9ad912c14 | 215 | void write_pulsed() |
claytonk | 6:85d9ad912c14 | 216 | { |
claytonk | 6:85d9ad912c14 | 217 | if(emitter_status_dot) { |
claytonk | 6:85d9ad912c14 | 218 | write_dot(); |
claytonk | 6:85d9ad912c14 | 219 | } else { |
claytonk | 6:85d9ad912c14 | 220 | write_flood(); |
claytonk | 6:85d9ad912c14 | 221 | } |
claytonk | 1:ffffa383ba7e | 222 | } |
claytonk | 1:ffffa383ba7e | 223 | |
claytonk | 8:10ffd42a3921 | 224 | // WAI |
claytonk | 4:fc0c93cb0197 | 225 | void write_once() |
claytonk | 4:fc0c93cb0197 | 226 | { |
claytonk | 8:10ffd42a3921 | 227 | if(in_app) { |
claytonk | 8:10ffd42a3921 | 228 | if(stacked_counter > app_counts_required) { |
claytonk | 8:10ffd42a3921 | 229 | write_pulsed(); |
claytonk | 8:10ffd42a3921 | 230 | write_pulsed(); |
claytonk | 4:fc0c93cb0197 | 231 | } else { |
claytonk | 8:10ffd42a3921 | 232 | if(dot_on) { |
claytonk | 8:10ffd42a3921 | 233 | write_dot(); |
claytonk | 8:10ffd42a3921 | 234 | write_dot(); |
claytonk | 8:10ffd42a3921 | 235 | } else if(flood_on) { |
claytonk | 8:10ffd42a3921 | 236 | write_flood(); |
claytonk | 8:10ffd42a3921 | 237 | write_flood(); |
claytonk | 8:10ffd42a3921 | 238 | } else { |
claytonk | 8:10ffd42a3921 | 239 | write_off(); |
claytonk | 8:10ffd42a3921 | 240 | write_off(); |
claytonk | 8:10ffd42a3921 | 241 | } |
claytonk | 4:fc0c93cb0197 | 242 | } |
claytonk | 8:10ffd42a3921 | 243 | } else { |
claytonk | 8:10ffd42a3921 | 244 | write_off(); |
claytonk | 8:10ffd42a3921 | 245 | write_off(); |
claytonk | 6:85d9ad912c14 | 246 | } |
claytonk | 6:85d9ad912c14 | 247 | } |
claytonk | 6:85d9ad912c14 | 248 | |
claytonk | 8:10ffd42a3921 | 249 | void dot_watchdog() |
claytonk | 6:85d9ad912c14 | 250 | { |
claytonk | 8:10ffd42a3921 | 251 | dot_on = false; |
claytonk | 8:10ffd42a3921 | 252 | dot_counter = 0; |
claytonk | 8:10ffd42a3921 | 253 | stacked_counter = 0; |
claytonk | 8:10ffd42a3921 | 254 | stacked = false; |
claytonk | 8:10ffd42a3921 | 255 | queue.call(&write_once); |
claytonk | 8:10ffd42a3921 | 256 | } |
claytonk | 8:10ffd42a3921 | 257 | |
claytonk | 8:10ffd42a3921 | 258 | void flood_watchdog() |
claytonk | 8:10ffd42a3921 | 259 | { |
claytonk | 8:10ffd42a3921 | 260 | flood_on = false; |
claytonk | 8:10ffd42a3921 | 261 | flood_counter = 0; |
claytonk | 8:10ffd42a3921 | 262 | stacked_counter = 0; |
claytonk | 8:10ffd42a3921 | 263 | stacked = false; |
claytonk | 8:10ffd42a3921 | 264 | queue.call(&write_once); |
claytonk | 8:10ffd42a3921 | 265 | } |
claytonk | 8:10ffd42a3921 | 266 | |
claytonk | 9:69e0bbfdb62b | 267 | void app_watchdog() |
claytonk | 9:69e0bbfdb62b | 268 | { |
claytonk | 9:69e0bbfdb62b | 269 | in_app = false; |
claytonk | 9:69e0bbfdb62b | 270 | dot_watchdog(); |
claytonk | 9:69e0bbfdb62b | 271 | flood_watchdog(); |
claytonk | 9:69e0bbfdb62b | 272 | } |
claytonk | 9:69e0bbfdb62b | 273 | |
claytonk | 8:10ffd42a3921 | 274 | void dot_falling_edge() |
claytonk | 8:10ffd42a3921 | 275 | { |
claytonk | 6:85d9ad912c14 | 276 | |
claytonk | 6:85d9ad912c14 | 277 | if(stacked) { |
claytonk | 6:85d9ad912c14 | 278 | emitter_status_dot = !emitter_status_dot; |
claytonk | 4:fc0c93cb0197 | 279 | } else { |
claytonk | 6:85d9ad912c14 | 280 | emitter_status_dot = dot_on; |
claytonk | 4:fc0c93cb0197 | 281 | } |
claytonk | 8:10ffd42a3921 | 282 | // indicate status dot |
claytonk | 8:10ffd42a3921 | 283 | pwm_0_output = emitter_status_dot; |
claytonk | 8:10ffd42a3921 | 284 | // indicate VCSEL fault if it exists |
claytonk | 8:10ffd42a3921 | 285 | pwm_1_output = !vcselFault.read(); |
claytonk | 8:10ffd42a3921 | 286 | |
claytonk | 8:10ffd42a3921 | 287 | // write once |
claytonk | 8:10ffd42a3921 | 288 | queue.call(&write_once); |
claytonk | 8:10ffd42a3921 | 289 | |
claytonk | 9:69e0bbfdb62b | 290 | // timeout for dot |
claytonk | 8:10ffd42a3921 | 291 | dot_timeout.attach(&dot_watchdog,.05); |
claytonk | 9:69e0bbfdb62b | 292 | // timout for app |
claytonk | 9:69e0bbfdb62b | 293 | app_timeout.detach(); |
claytonk | 9:69e0bbfdb62b | 294 | app_timeout.attach(&app_watchdog,1); |
claytonk | 4:fc0c93cb0197 | 295 | } |
claytonk | 4:fc0c93cb0197 | 296 | |
claytonk | 8:10ffd42a3921 | 297 | void flood_falling_edge() |
claytonk | 4:fc0c93cb0197 | 298 | { |
claytonk | 8:10ffd42a3921 | 299 | if (!stacked) { |
claytonk | 8:10ffd42a3921 | 300 | emitter_status_dot = dot_on; |
claytonk | 6:85d9ad912c14 | 301 | } |
claytonk | 8:10ffd42a3921 | 302 | // indicate status dot |
claytonk | 8:10ffd42a3921 | 303 | pwm_0_output = emitter_status_dot; |
claytonk | 8:10ffd42a3921 | 304 | // indicate VCSEL fault if it exists |
claytonk | 8:10ffd42a3921 | 305 | pwm_1_output = !vcselFault.read(); |
claytonk | 8:10ffd42a3921 | 306 | // timeout for app exit |
claytonk | 8:10ffd42a3921 | 307 | //timeout.attach(&write_off,.5); |
claytonk | 8:10ffd42a3921 | 308 | // write once |
claytonk | 8:10ffd42a3921 | 309 | queue.call(&write_once); |
claytonk | 4:fc0c93cb0197 | 310 | |
claytonk | 9:69e0bbfdb62b | 311 | // timeout for flood |
claytonk | 8:10ffd42a3921 | 312 | flood_timeout.attach(&flood_watchdog,.05); |
claytonk | 9:69e0bbfdb62b | 313 | // timout for app |
claytonk | 9:69e0bbfdb62b | 314 | app_timeout.detach(); |
claytonk | 9:69e0bbfdb62b | 315 | app_timeout.attach(&app_watchdog,1); |
claytonk | 8:10ffd42a3921 | 316 | } |
claytonk | 4:fc0c93cb0197 | 317 | |
claytonk | 6:85d9ad912c14 | 318 | void dot_check() |
claytonk | 6:85d9ad912c14 | 319 | { |
claytonk | 8:10ffd42a3921 | 320 | dot_timeout.detach(); |
claytonk | 6:85d9ad912c14 | 321 | |
claytonk | 8:10ffd42a3921 | 322 | dot_counter ++; |
claytonk | 8:10ffd42a3921 | 323 | if(dot_counter > app_counts_required) { |
claytonk | 8:10ffd42a3921 | 324 | dot_on = true; |
claytonk | 10:c757bd889ed1 | 325 | in_app = true; |
claytonk | 8:10ffd42a3921 | 326 | } else { |
claytonk | 8:10ffd42a3921 | 327 | dot_on = false; |
claytonk | 8:10ffd42a3921 | 328 | } |
claytonk | 8:10ffd42a3921 | 329 | stacked = strobe0.read(); |
claytonk | 8:10ffd42a3921 | 330 | if(stacked) { |
claytonk | 8:10ffd42a3921 | 331 | stacked_counter++; |
claytonk | 8:10ffd42a3921 | 332 | } else { |
claytonk | 8:10ffd42a3921 | 333 | stacked_counter = 0; |
claytonk | 8:10ffd42a3921 | 334 | flood_counter = 0; |
claytonk | 8:10ffd42a3921 | 335 | flood_on = false; |
claytonk | 8:10ffd42a3921 | 336 | } |
claytonk | 8:10ffd42a3921 | 337 | if(!in_app) { |
claytonk | 8:10ffd42a3921 | 338 | if (stacked_counter > app_counts_required) { |
claytonk | 8:10ffd42a3921 | 339 | in_app = true; |
claytonk | 8:10ffd42a3921 | 340 | } |
claytonk | 8:10ffd42a3921 | 341 | } |
claytonk | 6:85d9ad912c14 | 342 | } |
claytonk | 6:85d9ad912c14 | 343 | |
claytonk | 6:85d9ad912c14 | 344 | |
claytonk | 6:85d9ad912c14 | 345 | void flood_check() |
claytonk | 6:85d9ad912c14 | 346 | { |
claytonk | 8:10ffd42a3921 | 347 | flood_timeout.detach(); |
claytonk | 6:85d9ad912c14 | 348 | |
claytonk | 8:10ffd42a3921 | 349 | flood_counter ++; |
claytonk | 8:10ffd42a3921 | 350 | if(flood_counter > app_counts_required) { |
claytonk | 8:10ffd42a3921 | 351 | flood_on = true; |
claytonk | 10:c757bd889ed1 | 352 | in_app = true; |
claytonk | 8:10ffd42a3921 | 353 | } else { |
claytonk | 8:10ffd42a3921 | 354 | flood_on = false; |
claytonk | 8:10ffd42a3921 | 355 | } |
claytonk | 8:10ffd42a3921 | 356 | stacked = strobe1.read(); |
claytonk | 8:10ffd42a3921 | 357 | if(stacked) { |
claytonk | 8:10ffd42a3921 | 358 | stacked_counter++; |
claytonk | 8:10ffd42a3921 | 359 | } else { |
claytonk | 8:10ffd42a3921 | 360 | stacked_counter = 0; |
claytonk | 8:10ffd42a3921 | 361 | dot_counter = 0; |
claytonk | 8:10ffd42a3921 | 362 | dot_on = false; |
claytonk | 8:10ffd42a3921 | 363 | } |
claytonk | 8:10ffd42a3921 | 364 | if(!in_app) { |
claytonk | 8:10ffd42a3921 | 365 | if (stacked_counter > app_counts_required) { |
claytonk | 8:10ffd42a3921 | 366 | in_app = true; |
claytonk | 8:10ffd42a3921 | 367 | } |
claytonk | 8:10ffd42a3921 | 368 | } |
claytonk | 6:85d9ad912c14 | 369 | } |
claytonk | 6:85d9ad912c14 | 370 | |
claytonk | 6:85d9ad912c14 | 371 | // TODOS // |
claytonk | 7:9c77eaad5102 | 372 | // DONE P0 Get illumination working |
claytonk | 8:10ffd42a3921 | 373 | // P0 Get OV580 I2C to look correct. Suspect open drain culprit |
claytonk | 9:69e0bbfdb62b | 374 | // DONE P0 Ensure that current implementation meets the needs of data collection |
claytonk | 8:10ffd42a3921 | 375 | // DONE P0 Get in app working |
claytonk | 8:10ffd42a3921 | 376 | // DONE P0 Get watchdog time working |
claytonk | 8:10ffd42a3921 | 377 | // DONE P0 Check watchdog for working on dot and flood |
claytonk | 6:85d9ad912c14 | 378 | // P1 Bluetooth OTA updates |
claytonk | 6:85d9ad912c14 | 379 | // P2 Get writing working |
claytonk | 6:85d9ad912c14 | 380 | // P2 Get reading working |
claytonk | 6:85d9ad912c14 | 381 | // |
claytonk | 6:85d9ad912c14 | 382 | |
claytonk | 0:605fe136b7ea | 383 | // main() runs in its own thread in the OS |
claytonk | 1:ffffa383ba7e | 384 | int main() |
claytonk | 1:ffffa383ba7e | 385 | { |
claytonk | 4:fc0c93cb0197 | 386 | Thread eventThread(osPriorityHigh);; |
claytonk | 4:fc0c93cb0197 | 387 | eventThread.start(callback(&queue, &EventQueue::dispatch_forever)); |
claytonk | 4:fc0c93cb0197 | 388 | |
claytonk | 4:fc0c93cb0197 | 389 | // set interrupts |
claytonk | 6:85d9ad912c14 | 390 | int_strobe_dot.rise(&dot_check); |
claytonk | 6:85d9ad912c14 | 391 | int_strobe_flood.rise(&flood_check); |
claytonk | 8:10ffd42a3921 | 392 | int_strobe_dot.fall(&dot_falling_edge); |
claytonk | 8:10ffd42a3921 | 393 | int_strobe_flood.fall(&flood_falling_edge); |
claytonk | 8:10ffd42a3921 | 394 | |
claytonk | 8:10ffd42a3921 | 395 | while(!in_app) { |
claytonk | 9:69e0bbfdb62b | 396 | wait(.1); |
claytonk | 8:10ffd42a3921 | 397 | } |
claytonk | 1:ffffa383ba7e | 398 | |
claytonk | 0:605fe136b7ea | 399 | // write safety |
claytonk | 0:605fe136b7ea | 400 | flood_I2C.write(LM36011_addr,lmSafety,2,false); |
claytonk | 0:605fe136b7ea | 401 | dot_I2C.write(LM36011_addr,lmSafety,2,false); |
claytonk | 3:6b14862f5f51 | 402 | |
claytonk | 1:ffffa383ba7e | 403 | // write brightness |
claytonk | 1:ffffa383ba7e | 404 | flood_I2C.write(LM36011_addr,flashBrightness_flood,2,false); |
claytonk | 3:6b14862f5f51 | 405 | dot_I2C.write(LM36011_addr,flashBrightness_dot,2,false); |
claytonk | 1:ffffa383ba7e | 406 | |
claytonk | 0:605fe136b7ea | 407 | while (true) { |
claytonk | 9:69e0bbfdb62b | 408 | wait(.1); |
claytonk | 0:605fe136b7ea | 409 | } |
claytonk | 0:605fe136b7ea | 410 | } |
claytonk | 0:605fe136b7ea | 411 |