Test for mike
Dependencies: mbed DevInterfaces MCP4728 MCP4728setaddr I2Cinterfaces
main.cpp@10:bf195171d850, 2019-05-20 (annotated)
- Committer:
- kstokely
- Date:
- Mon May 20 17:05:29 2019 +0000
- Revision:
- 10:bf195171d850
- Parent:
- 9:2d70aa45f16e
- Child:
- 11:4367b8eefa6c
5/20/19 New Allignment;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kstokely | 10:bf195171d850 | 1 | |
wbeaumont | 1:d175631a5803 | 2 | /** example program for the use of the MCP4728 class and DACInterface.h classes |
wbeaumont | 1:d175631a5803 | 3 | * |
wbeaumont | 1:d175631a5803 | 4 | * V 1.0 : tested on the KL05z but without the MCP4728 connected \ |
wbeaumont | 1:d175631a5803 | 5 | * (C) Wim Beaumont Universiteit Antwerpen 2016 |
wbeaumont | 1:d175631a5803 | 6 | */ |
wbeaumont | 1:d175631a5803 | 7 | |
wbeaumont | 3:e12e21dcd16a | 8 | #define MCP4728EXAMPLEVER "2.04" |
kstokely | 7:e649bb2b6187 | 9 | #define TARGET_MBED 1 |
wbeaumont | 1:d175631a5803 | 10 | |
wbeaumont | 0:5bc0f4bd5aa0 | 11 | #include "mbed.h" |
kstokely | 7:e649bb2b6187 | 12 | #include <string> |
kstokely | 10:bf195171d850 | 13 | #include <cstring> |
wbeaumont | 0:5bc0f4bd5aa0 | 14 | |
wbeaumont | 0:5bc0f4bd5aa0 | 15 | #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) |
wbeaumont | 0:5bc0f4bd5aa0 | 16 | PinName const SDA = PTE25; |
wbeaumont | 0:5bc0f4bd5aa0 | 17 | PinName const SCL = PTE24; |
wbeaumont | 0:5bc0f4bd5aa0 | 18 | #elif defined (TARGET_KL05Z) |
wbeaumont | 0:5bc0f4bd5aa0 | 19 | PinName const SDA = PTB4; |
wbeaumont | 0:5bc0f4bd5aa0 | 20 | PinName const SCL = PTB3; |
wbeaumont | 0:5bc0f4bd5aa0 | 21 | #elif defined (TARGET_K20D50M) |
wbeaumont | 0:5bc0f4bd5aa0 | 22 | PinName const SDA = PTB1; |
wbeaumont | 0:5bc0f4bd5aa0 | 23 | PinName const SCL = PTB0; |
kstokely | 7:e649bb2b6187 | 24 | #elif defined (TARGET_MBED) |
kstokely | 7:e649bb2b6187 | 25 | PinName const SDA = p28; |
kstokely | 7:e649bb2b6187 | 26 | PinName const SCL = p27; |
wbeaumont | 0:5bc0f4bd5aa0 | 27 | #else |
wbeaumont | 0:5bc0f4bd5aa0 | 28 | #error TARGET NOT DEFINED |
wbeaumont | 0:5bc0f4bd5aa0 | 29 | #endif |
wbeaumont | 0:5bc0f4bd5aa0 | 30 | |
wbeaumont | 0:5bc0f4bd5aa0 | 31 | |
wbeaumont | 0:5bc0f4bd5aa0 | 32 | #include "I2C.h" |
wbeaumont | 0:5bc0f4bd5aa0 | 33 | #include "I2CInterface.h" |
wbeaumont | 0:5bc0f4bd5aa0 | 34 | #include "MBEDI2CInterface.h" |
wbeaumont | 0:5bc0f4bd5aa0 | 35 | #include "DACInterface.h" |
wbeaumont | 0:5bc0f4bd5aa0 | 36 | #include "dev_interface_def.h" |
wbeaumont | 3:e12e21dcd16a | 37 | #include "MCP4728setaddr.h" |
wbeaumont | 0:5bc0f4bd5aa0 | 38 | #include "mcp4728.h" |
wbeaumont | 0:5bc0f4bd5aa0 | 39 | |
kstokely | 7:e649bb2b6187 | 40 | #include "shutter.h" |
kstokely | 7:e649bb2b6187 | 41 | |
wbeaumont | 0:5bc0f4bd5aa0 | 42 | MBEDI2CInterface mbedi2c( SDA, SCL); |
wbeaumont | 0:5bc0f4bd5aa0 | 43 | MBEDI2CInterface* mbedi2cp= &mbedi2c ; |
wbeaumont | 0:5bc0f4bd5aa0 | 44 | I2CInterface* i2cdev= mbedi2cp; |
kstokely | 7:e649bb2b6187 | 45 | const float Vdd = 4.97; |
wbeaumont | 3:e12e21dcd16a | 46 | |
wbeaumont | 0:5bc0f4bd5aa0 | 47 | |
wbeaumont | 0:5bc0f4bd5aa0 | 48 | Serial pc(USBTX, USBRX); |
wbeaumont | 0:5bc0f4bd5aa0 | 49 | |
kstokely | 10:bf195171d850 | 50 | DigitalOut CameraTrig(p29); |
kstokely | 7:e649bb2b6187 | 51 | |
kstokely | 7:e649bb2b6187 | 52 | //Pins for 4x4 Module |
kstokely | 7:e649bb2b6187 | 53 | |
kstokely | 7:e649bb2b6187 | 54 | DigitalOut m4x4TTL1(p21); |
kstokely | 7:e649bb2b6187 | 55 | DigitalOut m4x4TTL2(p22); |
kstokely | 7:e649bb2b6187 | 56 | DigitalOut m4x4TTL3(p23); |
kstokely | 7:e649bb2b6187 | 57 | DigitalOut m4x4TTL4(p24); |
kstokely | 7:e649bb2b6187 | 58 | DigitalOut m4x4TTL5(p25); |
kstokely | 7:e649bb2b6187 | 59 | |
kstokely | 7:e649bb2b6187 | 60 | DigitalOut m4x4CLK(p26); //CLk for triggering after new input |
kstokely | 7:e649bb2b6187 | 61 | |
kstokely | 7:e649bb2b6187 | 62 | |
kstokely | 7:e649bb2b6187 | 63 | //Pins for 4x5 Module |
kstokely | 7:e649bb2b6187 | 64 | |
kstokely | 7:e649bb2b6187 | 65 | DigitalOut m4x5TTL1(p7); |
kstokely | 7:e649bb2b6187 | 66 | DigitalOut m4x5TTL2(p8); |
kstokely | 7:e649bb2b6187 | 67 | DigitalOut m4x5TTL3(p9); |
kstokely | 7:e649bb2b6187 | 68 | DigitalOut m4x5TTL4(p10); |
kstokely | 7:e649bb2b6187 | 69 | DigitalOut m4x5TTL5(p11); |
kstokely | 7:e649bb2b6187 | 70 | |
kstokely | 7:e649bb2b6187 | 71 | //Shutter Pins |
kstokely | 7:e649bb2b6187 | 72 | DigitalOut SH1_1(p12); |
kstokely | 7:e649bb2b6187 | 73 | DigitalOut SH1_2(p13); |
kstokely | 7:e649bb2b6187 | 74 | DigitalOut SH2_1(p14); |
kstokely | 7:e649bb2b6187 | 75 | DigitalOut SH2_2(p15); |
kstokely | 7:e649bb2b6187 | 76 | DigitalOut SH3_1(p16); |
kstokely | 7:e649bb2b6187 | 77 | DigitalOut SH3_2(p17); |
kstokely | 7:e649bb2b6187 | 78 | DigitalOut SH4_1(p18); |
kstokely | 7:e649bb2b6187 | 79 | DigitalOut SH4_2(p19); |
kstokely | 7:e649bb2b6187 | 80 | |
kstokely | 7:e649bb2b6187 | 81 | DigitalOut m4x5CLK(p20); |
kstokely | 7:e649bb2b6187 | 82 | |
kstokely | 9:2d70aa45f16e | 83 | DigitalOut mRefShutters(p5); |
kstokely | 8:abdd660056fb | 84 | |
kstokely | 8:abdd660056fb | 85 | bool Shut1 = 0; |
kstokely | 8:abdd660056fb | 86 | bool Shut2 = 0; |
kstokely | 8:abdd660056fb | 87 | bool Shut3 = 0; |
kstokely | 8:abdd660056fb | 88 | bool Shut4 = 0; |
kstokely | 8:abdd660056fb | 89 | |
kstokely | 10:bf195171d850 | 90 | string pcstr; |
kstokely | 10:bf195171d850 | 91 | string seqstr; |
kstokely | 10:bf195171d850 | 92 | Timer t; |
kstokely | 8:abdd660056fb | 93 | |
kstokely | 8:abdd660056fb | 94 | |
kstokely | 10:bf195171d850 | 95 | void trigSH( Shutter SH, int nimg ) |
kstokely | 10:bf195171d850 | 96 | { |
kstokely | 10:bf195171d850 | 97 | for(int i = 0; i<nimg; i++) |
kstokely | 10:bf195171d850 | 98 | { |
kstokely | 10:bf195171d850 | 99 | SH.writeShutters(1,1,1,1);//Turn on Shutters |
kstokely | 10:bf195171d850 | 100 | |
kstokely | 10:bf195171d850 | 101 | wait_us(92);//Wait for shutter to go high |
kstokely | 10:bf195171d850 | 102 | wait_us(120);//Wait to trigger until middle of Shutter Opening |
kstokely | 10:bf195171d850 | 103 | |
kstokely | 10:bf195171d850 | 104 | CameraTrig = 1;//Trigger Camera to turn on |
kstokely | 10:bf195171d850 | 105 | wait_us(38);//Wait for rest of 250 us |
kstokely | 10:bf195171d850 | 106 | |
kstokely | 10:bf195171d850 | 107 | //wait_us(16417); //DEBUG: Added extra delay to slow down trigger |
kstokely | 10:bf195171d850 | 108 | |
kstokely | 10:bf195171d850 | 109 | //Turn off shutters and Camera Trigger |
kstokely | 10:bf195171d850 | 110 | SH.writeShutters(0,0,0,0); |
kstokely | 10:bf195171d850 | 111 | |
kstokely | 10:bf195171d850 | 112 | CameraTrig = 0; |
kstokely | 10:bf195171d850 | 113 | |
kstokely | 10:bf195171d850 | 114 | wait_us(16417); //Wait to run at 60 Hz |
kstokely | 10:bf195171d850 | 115 | |
kstokely | 10:bf195171d850 | 116 | //wait_us(16417); //DEBUG: Added extra delay to slow down trigger |
kstokely | 10:bf195171d850 | 117 | } |
kstokely | 10:bf195171d850 | 118 | } |
kstokely | 10:bf195171d850 | 119 | |
kstokely | 10:bf195171d850 | 120 | |
kstokely | 10:bf195171d850 | 121 | void trigNotEyeSafe( Shutter SH, int nimg ) |
kstokely | 10:bf195171d850 | 122 | { |
kstokely | 10:bf195171d850 | 123 | for(int i = 0; i<nimg; i++) |
kstokely | 10:bf195171d850 | 124 | { |
kstokely | 10:bf195171d850 | 125 | //SH.writeShutters(1,1,1,1);//Turn on Shutters |
kstokely | 10:bf195171d850 | 126 | |
kstokely | 10:bf195171d850 | 127 | wait_us(92);//Wait for shutter to go high |
kstokely | 10:bf195171d850 | 128 | wait_us(120);//Wait to trigger until middle of Shutter Opening |
kstokely | 10:bf195171d850 | 129 | |
kstokely | 10:bf195171d850 | 130 | CameraTrig = 1;//Trigger Camera to turn on |
kstokely | 10:bf195171d850 | 131 | wait_us(38);//Wait for rest of 250 us |
kstokely | 10:bf195171d850 | 132 | |
kstokely | 10:bf195171d850 | 133 | //wait_us(16417);//DEBUG: Added extra delay to slow down trigger |
kstokely | 10:bf195171d850 | 134 | |
kstokely | 10:bf195171d850 | 135 | //Turn off shutters and Camera Trigger |
kstokely | 10:bf195171d850 | 136 | //SH.writeShutters(0,0,0,0); |
kstokely | 10:bf195171d850 | 137 | CameraTrig = 0; |
kstokely | 10:bf195171d850 | 138 | |
kstokely | 10:bf195171d850 | 139 | wait_us(16417); //Wait to run at 60 Hz |
kstokely | 10:bf195171d850 | 140 | |
kstokely | 10:bf195171d850 | 141 | // wait_us(16417);//DEBUG: Added extra delay to slow down trigger |
kstokely | 10:bf195171d850 | 142 | } |
kstokely | 10:bf195171d850 | 143 | } |
kstokely | 10:bf195171d850 | 144 | |
kstokely | 10:bf195171d850 | 145 | |
kstokely | 10:bf195171d850 | 146 | |
kstokely | 10:bf195171d850 | 147 | int DACSetChannel( int chan, MCP4728* dac, int counts) |
kstokely | 8:abdd660056fb | 148 | { |
kstokely | 8:abdd660056fb | 149 | int ret = 0; |
kstokely | 10:bf195171d850 | 150 | int z = 0; |
kstokely | 10:bf195171d850 | 151 | int CHcnt; |
kstokely | 10:bf195171d850 | 152 | int voltCount = counts; |
kstokely | 8:abdd660056fb | 153 | string instr; |
kstokely | 8:abdd660056fb | 154 | |
kstokely | 10:bf195171d850 | 155 | if( voltCount > 4095 || voltCount < 0) |
kstokely | 10:bf195171d850 | 156 | { |
kstokely | 10:bf195171d850 | 157 | voltCount = 4095; |
kstokely | 10:bf195171d850 | 158 | } |
kstokely | 10:bf195171d850 | 159 | |
kstokely | 10:bf195171d850 | 160 | while(ret == 0 && z < 10) |
kstokely | 8:abdd660056fb | 161 | { |
kstokely | 10:bf195171d850 | 162 | //t.start(); |
kstokely | 10:bf195171d850 | 163 | dac->update(); |
kstokely | 10:bf195171d850 | 164 | //t.stop(); |
kstokely | 10:bf195171d850 | 165 | //t.reset(); |
kstokely | 10:bf195171d850 | 166 | //pc.printf("DAC update took %f seconds \n\r",t.read()); |
kstokely | 10:bf195171d850 | 167 | (void)dac->getDACvalue(CHcnt,chan); |
kstokely | 8:abdd660056fb | 168 | |
kstokely | 10:bf195171d850 | 169 | if(CHcnt == counts) |
kstokely | 10:bf195171d850 | 170 | { |
kstokely | 10:bf195171d850 | 171 | ret = 1; |
kstokely | 10:bf195171d850 | 172 | } |
kstokely | 10:bf195171d850 | 173 | else |
kstokely | 10:bf195171d850 | 174 | { |
kstokely | 10:bf195171d850 | 175 | //t.start(); |
kstokely | 10:bf195171d850 | 176 | dac->setDACvalue(voltCount,chan); |
kstokely | 10:bf195171d850 | 177 | //t.stop(); |
kstokely | 10:bf195171d850 | 178 | //pc.printf("DAC setting took %f seconds \n\r",t.read()); |
kstokely | 10:bf195171d850 | 179 | z++; |
kstokely | 10:bf195171d850 | 180 | } |
kstokely | 8:abdd660056fb | 181 | |
kstokely | 8:abdd660056fb | 182 | |
kstokely | 10:bf195171d850 | 183 | } |
kstokely | 10:bf195171d850 | 184 | |
kstokely | 10:bf195171d850 | 185 | /* |
kstokely | 8:abdd660056fb | 186 | if( z == 13 ) |
kstokely | 8:abdd660056fb | 187 | { |
kstokely | 10:bf195171d850 | 188 | voltCount = counts; |
kstokely | 8:abdd660056fb | 189 | |
kstokely | 9:2d70aa45f16e | 190 | if( voltCount > 4095 || voltCount < 0) |
kstokely | 8:abdd660056fb | 191 | { |
kstokely | 9:2d70aa45f16e | 192 | //////pc.printf("\n\r Voltage Entered Higher than Vdd Setting Voltage to Maximum\n\r"); |
kstokely | 9:2d70aa45f16e | 193 | dac->setDACvalue(4095,chan); |
kstokely | 8:abdd660056fb | 194 | } |
kstokely | 8:abdd660056fb | 195 | else |
kstokely | 8:abdd660056fb | 196 | { |
kstokely | 9:2d70aa45f16e | 197 | if ( dac->setDACvalue(voltCount,chan) ) |
kstokely | 8:abdd660056fb | 198 | { |
kstokely | 9:2d70aa45f16e | 199 | //printf("failed to set dac value %f for channel %d\n\r",voltCount,chan); |
kstokely | 8:abdd660056fb | 200 | } |
kstokely | 9:2d70aa45f16e | 201 | ////////pc.printf("Voltage set to %3fV\n\r", voltage); |
kstokely | 8:abdd660056fb | 202 | if( dac->update() ) |
kstokely | 8:abdd660056fb | 203 | { |
kstokely | 9:2d70aa45f16e | 204 | //printf("\n\rfailed to readback channel info \n\r"); |
kstokely | 8:abdd660056fb | 205 | } |
kstokely | 8:abdd660056fb | 206 | |
kstokely | 8:abdd660056fb | 207 | } |
kstokely | 8:abdd660056fb | 208 | |
kstokely | 8:abdd660056fb | 209 | } |
kstokely | 10:bf195171d850 | 210 | */ |
kstokely | 10:bf195171d850 | 211 | |
kstokely | 8:abdd660056fb | 212 | return 1; |
kstokely | 8:abdd660056fb | 213 | } |
kstokely | 8:abdd660056fb | 214 | |
kstokely | 10:bf195171d850 | 215 | void set4x4Piping(DigitalOut** Arr_4x4, char z1, char z2, char z3, char z4, char z5) |
kstokely | 10:bf195171d850 | 216 | { |
kstokely | 10:bf195171d850 | 217 | /* |
kstokely | 10:bf195171d850 | 218 | //Get 5 1's or 0's for binary number |
kstokely | 10:bf195171d850 | 219 | int count = 0; |
kstokely | 10:bf195171d850 | 220 | char c; |
kstokely | 10:bf195171d850 | 221 | ////pc.printf("4x4 Control: Enter 5 digit binary number\n\r"); |
kstokely | 10:bf195171d850 | 222 | while ( count < 5 ) |
kstokely | 10:bf195171d850 | 223 | { |
kstokely | 10:bf195171d850 | 224 | c = pc.getc(); |
kstokely | 10:bf195171d850 | 225 | |
kstokely | 10:bf195171d850 | 226 | if( c == '1' || c=='0' ) |
kstokely | 10:bf195171d850 | 227 | { |
kstokely | 10:bf195171d850 | 228 | *Arr_4x4[count] = atoi(&c); |
kstokely | 10:bf195171d850 | 229 | count++; |
kstokely | 10:bf195171d850 | 230 | } |
kstokely | 10:bf195171d850 | 231 | } |
kstokely | 10:bf195171d850 | 232 | */ |
kstokely | 10:bf195171d850 | 233 | |
kstokely | 10:bf195171d850 | 234 | *Arr_4x4[0] = atoi(&z1); |
kstokely | 10:bf195171d850 | 235 | *Arr_4x4[1] = atoi(&z2); |
kstokely | 10:bf195171d850 | 236 | *Arr_4x4[2] = atoi(&z3); |
kstokely | 10:bf195171d850 | 237 | *Arr_4x4[3] = atoi(&z4); |
kstokely | 10:bf195171d850 | 238 | *Arr_4x4[4] = atoi(&z5); |
kstokely | 10:bf195171d850 | 239 | |
kstokely | 10:bf195171d850 | 240 | for( int k = 0; k<2; k++) //Trigger clocking to change values |
kstokely | 10:bf195171d850 | 241 | { |
kstokely | 10:bf195171d850 | 242 | m4x4CLK = 1; |
kstokely | 10:bf195171d850 | 243 | wait_us(200); |
kstokely | 10:bf195171d850 | 244 | m4x4CLK = 0; |
kstokely | 10:bf195171d850 | 245 | } |
kstokely | 10:bf195171d850 | 246 | |
kstokely | 10:bf195171d850 | 247 | //pc.printf("Optical Path set to : %d%d%d%d%d\n\r", m4x4TTL1.read(), m4x4TTL2.read(), m4x4TTL3.read(), m4x4TTL4.read(), m4x4TTL5.read() ); //Confirm the correct output is set |
kstokely | 10:bf195171d850 | 248 | } |
kstokely | 7:e649bb2b6187 | 249 | |
kstokely | 10:bf195171d850 | 250 | void set4x5Piping(DigitalOut** Arr_4x5, char z1, char z2, char z3, char z4, char z5) |
kstokely | 10:bf195171d850 | 251 | { |
kstokely | 10:bf195171d850 | 252 | /* |
kstokely | 10:bf195171d850 | 253 | //Get 5 1's or 0's for binary number |
kstokely | 10:bf195171d850 | 254 | int count = 0; |
kstokely | 10:bf195171d850 | 255 | char c; |
kstokely | 10:bf195171d850 | 256 | ////pc.printf("4x5 Control: Enter 5 digit binary number\n\r"); |
kstokely | 10:bf195171d850 | 257 | while ( count < 5 ) |
kstokely | 10:bf195171d850 | 258 | { |
kstokely | 10:bf195171d850 | 259 | c = pc.getc(); |
kstokely | 10:bf195171d850 | 260 | |
kstokely | 10:bf195171d850 | 261 | if( c == '1' || c=='0' ) |
kstokely | 10:bf195171d850 | 262 | { |
kstokely | 10:bf195171d850 | 263 | *Arr_4x5[count] = atoi(&c); |
kstokely | 10:bf195171d850 | 264 | count++; |
kstokely | 10:bf195171d850 | 265 | } |
kstokely | 10:bf195171d850 | 266 | } |
kstokely | 10:bf195171d850 | 267 | */ |
kstokely | 10:bf195171d850 | 268 | |
kstokely | 10:bf195171d850 | 269 | *Arr_4x5[0] = atoi(&z1); |
kstokely | 10:bf195171d850 | 270 | *Arr_4x5[1] = atoi(&z2); |
kstokely | 10:bf195171d850 | 271 | *Arr_4x5[2] = atoi(&z3); |
kstokely | 10:bf195171d850 | 272 | *Arr_4x5[3] = atoi(&z4); |
kstokely | 10:bf195171d850 | 273 | *Arr_4x5[4] = atoi(&z5); |
kstokely | 10:bf195171d850 | 274 | |
kstokely | 10:bf195171d850 | 275 | for( int k = 0; k<2; k++) //Trigger clocking to change values |
kstokely | 10:bf195171d850 | 276 | { |
kstokely | 10:bf195171d850 | 277 | m4x5CLK = 1; |
kstokely | 10:bf195171d850 | 278 | wait_us(200); |
kstokely | 10:bf195171d850 | 279 | m4x5CLK = 0; |
kstokely | 10:bf195171d850 | 280 | } |
kstokely | 10:bf195171d850 | 281 | |
kstokely | 10:bf195171d850 | 282 | //pc.printf("Optical Path set to : %d%d%d%d%d\n\r", m4x5TTL1.read(), m4x5TTL2.read(), m4x5TTL3.read(), m4x5TTL4.read(), m4x5TTL5.read() ); //Confirm the correct output is set |
kstokely | 10:bf195171d850 | 283 | } |
kstokely | 7:e649bb2b6187 | 284 | |
kstokely | 7:e649bb2b6187 | 285 | |
kstokely | 7:e649bb2b6187 | 286 | |
kstokely | 10:bf195171d850 | 287 | void toggleShut1(Shutter SH) |
kstokely | 10:bf195171d850 | 288 | { |
kstokely | 10:bf195171d850 | 289 | Shut1 = !Shut1; |
kstokely | 10:bf195171d850 | 290 | SH.writeShutters(Shut1,Shut2,Shut3,Shut4); |
kstokely | 10:bf195171d850 | 291 | } |
kstokely | 10:bf195171d850 | 292 | |
kstokely | 10:bf195171d850 | 293 | |
kstokely | 10:bf195171d850 | 294 | void toggleShut2(Shutter SH) |
kstokely | 10:bf195171d850 | 295 | { |
kstokely | 10:bf195171d850 | 296 | Shut2 = !Shut2; |
kstokely | 10:bf195171d850 | 297 | SH.writeShutters(Shut1,Shut2,Shut3,Shut4); |
kstokely | 10:bf195171d850 | 298 | } |
kstokely | 10:bf195171d850 | 299 | |
kstokely | 10:bf195171d850 | 300 | |
kstokely | 10:bf195171d850 | 301 | void toggleShut3(Shutter SH) |
kstokely | 10:bf195171d850 | 302 | { |
kstokely | 10:bf195171d850 | 303 | Shut3 = !Shut3; |
kstokely | 10:bf195171d850 | 304 | SH.writeShutters(Shut1,Shut2,Shut3,Shut4); |
kstokely | 10:bf195171d850 | 305 | } |
kstokely | 10:bf195171d850 | 306 | |
kstokely | 10:bf195171d850 | 307 | |
kstokely | 10:bf195171d850 | 308 | void toggleShut4(Shutter SH) |
kstokely | 10:bf195171d850 | 309 | { |
kstokely | 10:bf195171d850 | 310 | Shut4 = !Shut4; |
kstokely | 10:bf195171d850 | 311 | SH.writeShutters(Shut1,Shut2,Shut3,Shut4); |
kstokely | 10:bf195171d850 | 312 | } |
kstokely | 10:bf195171d850 | 313 | |
kstokely | 10:bf195171d850 | 314 | void closeRef() |
kstokely | 10:bf195171d850 | 315 | { |
kstokely | 10:bf195171d850 | 316 | mRefShutters = 0; |
kstokely | 10:bf195171d850 | 317 | } |
kstokely | 10:bf195171d850 | 318 | |
kstokely | 10:bf195171d850 | 319 | void openRef() |
kstokely | 10:bf195171d850 | 320 | { |
kstokely | 10:bf195171d850 | 321 | mRefShutters = 1; |
kstokely | 10:bf195171d850 | 322 | } |
kstokely | 10:bf195171d850 | 323 | |
kstokely | 10:bf195171d850 | 324 | void openAllHP(Shutter SH) |
kstokely | 10:bf195171d850 | 325 | { |
kstokely | 10:bf195171d850 | 326 | Shut1 = 1; |
kstokely | 10:bf195171d850 | 327 | Shut2 = 1; |
kstokely | 10:bf195171d850 | 328 | Shut3 = 1; |
kstokely | 10:bf195171d850 | 329 | Shut4 = 1; |
kstokely | 10:bf195171d850 | 330 | SH.writeShutters(1,1,1,1); |
kstokely | 10:bf195171d850 | 331 | } |
kstokely | 10:bf195171d850 | 332 | |
kstokely | 10:bf195171d850 | 333 | void closeAllHP(Shutter SH) |
kstokely | 10:bf195171d850 | 334 | { |
kstokely | 10:bf195171d850 | 335 | Shut1 = 0; |
kstokely | 10:bf195171d850 | 336 | Shut2 = 0; |
kstokely | 10:bf195171d850 | 337 | Shut3 = 0; |
kstokely | 10:bf195171d850 | 338 | Shut4 = 0; |
kstokely | 10:bf195171d850 | 339 | SH.writeShutters(0,0,0,0); |
kstokely | 10:bf195171d850 | 340 | } |
kstokely | 10:bf195171d850 | 341 | |
kstokely | 10:bf195171d850 | 342 | void setAllShutters(Shutter SH,char z1, char z2, char z3, char z4) |
kstokely | 10:bf195171d850 | 343 | { |
kstokely | 10:bf195171d850 | 344 | /* |
kstokely | 10:bf195171d850 | 345 | //Writes to all 4x5 shutters a specific state |
kstokely | 10:bf195171d850 | 346 | int inarr[4]; |
kstokely | 10:bf195171d850 | 347 | for(int i=0; i<4; i++) |
kstokely | 10:bf195171d850 | 348 | { |
kstokely | 10:bf195171d850 | 349 | char z = pc.getc(); |
kstokely | 10:bf195171d850 | 350 | if( z == '1') |
kstokely | 10:bf195171d850 | 351 | { |
kstokely | 10:bf195171d850 | 352 | inarr[i] = 1; |
kstokely | 10:bf195171d850 | 353 | } |
kstokely | 10:bf195171d850 | 354 | else if( z == '0') |
kstokely | 10:bf195171d850 | 355 | { |
kstokely | 10:bf195171d850 | 356 | inarr[i] = 0; |
kstokely | 10:bf195171d850 | 357 | } |
kstokely | 10:bf195171d850 | 358 | else |
kstokely | 10:bf195171d850 | 359 | { |
kstokely | 10:bf195171d850 | 360 | inarr[i] = 0; |
kstokely | 10:bf195171d850 | 361 | } |
kstokely | 10:bf195171d850 | 362 | } |
kstokely | 10:bf195171d850 | 363 | */ |
kstokely | 10:bf195171d850 | 364 | Shut1 = atoi(&z1); |
kstokely | 10:bf195171d850 | 365 | Shut2 = atoi(&z2); |
kstokely | 10:bf195171d850 | 366 | Shut3 = atoi(&z3); |
kstokely | 10:bf195171d850 | 367 | Shut4 = atoi(&z4); |
kstokely | 10:bf195171d850 | 368 | SH.writeShutters(Shut1,Shut2,Shut3,Shut4); |
kstokely | 10:bf195171d850 | 369 | } |
kstokely | 10:bf195171d850 | 370 | |
kstokely | 10:bf195171d850 | 371 | void queryDAC(MCP4728* dac) |
kstokely | 10:bf195171d850 | 372 | { |
kstokely | 10:bf195171d850 | 373 | int CH1cnt; |
kstokely | 10:bf195171d850 | 374 | int CH2cnt; |
kstokely | 10:bf195171d850 | 375 | int CH3cnt; |
kstokely | 10:bf195171d850 | 376 | int CH4cnt; |
kstokely | 10:bf195171d850 | 377 | //Print State of DAC |
kstokely | 10:bf195171d850 | 378 | if( dac->update() == 0) |
kstokely | 10:bf195171d850 | 379 | { |
kstokely | 10:bf195171d850 | 380 | (void)dac->getDACvalue(CH1cnt,0); |
kstokely | 10:bf195171d850 | 381 | (void)dac->getDACvalue(CH2cnt,1); |
kstokely | 10:bf195171d850 | 382 | (void)dac->getDACvalue(CH3cnt,2); |
kstokely | 10:bf195171d850 | 383 | (void)dac->getDACvalue(CH4cnt,3); |
kstokely | 10:bf195171d850 | 384 | pc.printf("CH1:%4d CH2:%4d CH3:%4d CH4:%4d\n\r",CH1cnt,CH2cnt,CH3cnt,CH4cnt); |
kstokely | 10:bf195171d850 | 385 | } |
kstokely | 10:bf195171d850 | 386 | |
kstokely | 10:bf195171d850 | 387 | else |
kstokely | 10:bf195171d850 | 388 | { |
kstokely | 10:bf195171d850 | 389 | pc.printf("Error: No readback from DAC\n\r"); |
kstokely | 10:bf195171d850 | 390 | } |
kstokely | 10:bf195171d850 | 391 | } |
kstokely | 10:bf195171d850 | 392 | |
kstokely | 10:bf195171d850 | 393 | void queryShutters() |
kstokely | 10:bf195171d850 | 394 | { |
kstokely | 10:bf195171d850 | 395 | //Print State of Shutters |
kstokely | 10:bf195171d850 | 396 | pc.printf("SH1:%d SH2:%d SH3:%d SH4:%d SHRef:%d\n\r",Shut1,Shut2,Shut3,Shut4,mRefShutters.read()); |
kstokely | 10:bf195171d850 | 397 | } |
kstokely | 10:bf195171d850 | 398 | |
wbeaumont | 0:5bc0f4bd5aa0 | 399 | int main(void) { |
wbeaumont | 0:5bc0f4bd5aa0 | 400 | |
kstokely | 10:bf195171d850 | 401 | //get the version of getVersion |
kstokely | 10:bf195171d850 | 402 | getVersion gv; |
kstokely | 10:bf195171d850 | 403 | int addr; |
kstokely | 10:bf195171d850 | 404 | //Timer m; |
kstokely | 10:bf195171d850 | 405 | addr = 0; |
kstokely | 10:bf195171d850 | 406 | MCP4728 dac( i2cdev ,addr, Vdd); // assuming the address of the MCP4728 is set to 0 factory default |
kstokely | 10:bf195171d850 | 407 | |
kstokely | 10:bf195171d850 | 408 | wait(1); |
kstokely | 7:e649bb2b6187 | 409 | |
kstokely | 10:bf195171d850 | 410 | int cnt=0; |
kstokely | 10:bf195171d850 | 411 | pc.baud(921600); |
kstokely | 10:bf195171d850 | 412 | mRefShutters = 1; |
kstokely | 7:e649bb2b6187 | 413 | |
kstokely | 7:e649bb2b6187 | 414 | //Set up dac for external voltage |
kstokely | 10:bf195171d850 | 415 | dac.setRefExtern(); |
kstokely | 10:bf195171d850 | 416 | dac.update(); |
kstokely | 7:e649bb2b6187 | 417 | |
kstokely | 7:e649bb2b6187 | 418 | //Intialize shutters |
kstokely | 7:e649bb2b6187 | 419 | Shutter SH; |
kstokely | 7:e649bb2b6187 | 420 | SH.init( &SH1_1, &SH1_2, &SH2_1, &SH2_2, &SH3_1, &SH3_2, &SH4_1, &SH4_2 ); |
kstokely | 8:abdd660056fb | 421 | |
kstokely | 7:e649bb2b6187 | 422 | SH.writeShutters(Shut1,Shut2,Shut3,Shut4); |
kstokely | 7:e649bb2b6187 | 423 | |
kstokely | 7:e649bb2b6187 | 424 | |
kstokely | 7:e649bb2b6187 | 425 | //TTL pin arrays |
kstokely | 7:e649bb2b6187 | 426 | DigitalOut* Arr_4x4[5] = {&m4x4TTL1, &m4x4TTL2, &m4x4TTL3, &m4x4TTL4, &m4x4TTL5 }; |
kstokely | 7:e649bb2b6187 | 427 | DigitalOut* Arr_4x5[5] = {&m4x5TTL1, &m4x5TTL2, &m4x5TTL3, &m4x5TTL4, &m4x5TTL5 }; |
kstokely | 7:e649bb2b6187 | 428 | |
kstokely | 7:e649bb2b6187 | 429 | |
kstokely | 8:abdd660056fb | 430 | //Set straight pipes initial state |
kstokely | 7:e649bb2b6187 | 431 | m4x5TTL1 = 1; |
kstokely | 10:bf195171d850 | 432 | m4x4TTL1 = 1; |
kstokely | 7:e649bb2b6187 | 433 | |
kstokely | 7:e649bb2b6187 | 434 | float voltage = 0; |
kstokely | 9:2d70aa45f16e | 435 | int voltCount = 0; |
kstokely | 7:e649bb2b6187 | 436 | string instr; |
kstokely | 10:bf195171d850 | 437 | |
kstokely | 10:bf195171d850 | 438 | seqstr = "d010c010r010i010"; |
kstokely | 10:bf195171d850 | 439 | |
kstokely | 10:bf195171d850 | 440 | pcstr.resize(200); |
kstokely | 10:bf195171d850 | 441 | |
kstokely | 7:e649bb2b6187 | 442 | while(1) |
kstokely | 7:e649bb2b6187 | 443 | { |
kstokely | 10:bf195171d850 | 444 | //m.stop(); |
kstokely | 10:bf195171d850 | 445 | //pc.printf("Main loop took %f seconds \n\r",m.read()); |
kstokely | 10:bf195171d850 | 446 | pc.scanf("%s", pcstr.c_str() ); |
kstokely | 10:bf195171d850 | 447 | //m.reset(); |
kstokely | 10:bf195171d850 | 448 | //m.start(); |
kstokely | 10:bf195171d850 | 449 | //DEBUG |
kstokely | 10:bf195171d850 | 450 | //pc.printf( "String Entered: %s String Size:%d\n\r",pcstr.c_str(),pcstr.size() ); |
kstokely | 10:bf195171d850 | 451 | |
kstokely | 10:bf195171d850 | 452 | |
kstokely | 10:bf195171d850 | 453 | |
kstokely | 10:bf195171d850 | 454 | int indexArr[100]; |
kstokely | 10:bf195171d850 | 455 | int indexSize = 0; |
kstokely | 10:bf195171d850 | 456 | |
kstokely | 10:bf195171d850 | 457 | |
kstokely | 10:bf195171d850 | 458 | //Find all commas in string |
kstokely | 10:bf195171d850 | 459 | /* |
kstokely | 10:bf195171d850 | 460 | for(int i = 0; i < pcstr.size(); i++) |
kstokely | 10:bf195171d850 | 461 | { |
kstokely | 10:bf195171d850 | 462 | if( pcstr[i] == ',') |
kstokely | 10:bf195171d850 | 463 | { |
kstokely | 10:bf195171d850 | 464 | indexArr[indexSize] = i; |
kstokely | 10:bf195171d850 | 465 | indexSize++; |
kstokely | 10:bf195171d850 | 466 | } |
kstokely | 10:bf195171d850 | 467 | |
kstokely | 10:bf195171d850 | 468 | } |
kstokely | 10:bf195171d850 | 469 | */ |
kstokely | 10:bf195171d850 | 470 | |
kstokely | 10:bf195171d850 | 471 | //had to change as string does not resize |
kstokely | 10:bf195171d850 | 472 | int i =0; |
kstokely | 10:bf195171d850 | 473 | while( pcstr.c_str()[i] != 0 && pcstr.c_str()[i] != ' ' && pcstr.c_str()[i] != '\0') |
kstokely | 10:bf195171d850 | 474 | { |
kstokely | 10:bf195171d850 | 475 | if( pcstr[i] == ',') |
kstokely | 10:bf195171d850 | 476 | { |
kstokely | 10:bf195171d850 | 477 | indexArr[indexSize] = i; |
kstokely | 10:bf195171d850 | 478 | indexSize++; |
kstokely | 10:bf195171d850 | 479 | } |
kstokely | 10:bf195171d850 | 480 | i++; |
kstokely | 10:bf195171d850 | 481 | } |
kstokely | 10:bf195171d850 | 482 | |
kstokely | 10:bf195171d850 | 483 | //DEBUG |
kstokely | 10:bf195171d850 | 484 | //pc.printf( "Commas Found %d\n\r",indexSize ); |
kstokely | 10:bf195171d850 | 485 | |
kstokely | 10:bf195171d850 | 486 | |
kstokely | 10:bf195171d850 | 487 | |
kstokely | 10:bf195171d850 | 488 | //Interpret commands |
kstokely | 10:bf195171d850 | 489 | for(int i =0; i<indexSize; i++) |
kstokely | 10:bf195171d850 | 490 | { |
kstokely | 10:bf195171d850 | 491 | //DEBUG |
kstokely | 10:bf195171d850 | 492 | //pc.printf( "Loop #%d of %d\n\r",i,indexSize-1 ); |
kstokely | 10:bf195171d850 | 493 | |
kstokely | 10:bf195171d850 | 494 | char c; |
kstokely | 10:bf195171d850 | 495 | //command must begin with a comma |
kstokely | 10:bf195171d850 | 496 | c = pcstr.c_str()[ indexArr[i] +1 ]; |
kstokely | 10:bf195171d850 | 497 | |
kstokely | 10:bf195171d850 | 498 | |
kstokely | 10:bf195171d850 | 499 | |
kstokely | 10:bf195171d850 | 500 | |
kstokely | 10:bf195171d850 | 501 | //DEBUG |
kstokely | 10:bf195171d850 | 502 | //pc.printf( "Cmd is %c\n\r",c ); |
kstokely | 10:bf195171d850 | 503 | |
kstokely | 7:e649bb2b6187 | 504 | |
kstokely | 7:e649bb2b6187 | 505 | if( c == '1') //Toggle Shutter 1 |
kstokely | 7:e649bb2b6187 | 506 | { |
kstokely | 10:bf195171d850 | 507 | char z1 = pcstr[ indexArr[i] +2 ]; |
kstokely | 10:bf195171d850 | 508 | Shut1 = atoi(&z1); |
kstokely | 7:e649bb2b6187 | 509 | SH.writeShutters(Shut1,Shut2,Shut3,Shut4); |
kstokely | 7:e649bb2b6187 | 510 | } |
kstokely | 7:e649bb2b6187 | 511 | |
kstokely | 7:e649bb2b6187 | 512 | else if( c == '2') //Toggle Shutter 2 |
kstokely | 7:e649bb2b6187 | 513 | { |
kstokely | 10:bf195171d850 | 514 | char z1 = pcstr[ indexArr[i] +2 ]; |
kstokely | 10:bf195171d850 | 515 | Shut2 = atoi(&z1); |
kstokely | 7:e649bb2b6187 | 516 | SH.writeShutters(Shut1,Shut2,Shut3,Shut4); |
kstokely | 7:e649bb2b6187 | 517 | } |
kstokely | 7:e649bb2b6187 | 518 | |
kstokely | 7:e649bb2b6187 | 519 | else if( c == '3') //Toggle Shutter 3 |
kstokely | 7:e649bb2b6187 | 520 | { |
kstokely | 10:bf195171d850 | 521 | char z1 = pcstr[ indexArr[i] +2 ]; |
kstokely | 10:bf195171d850 | 522 | Shut3 = atoi(&z1); |
kstokely | 7:e649bb2b6187 | 523 | SH.writeShutters(Shut1,Shut2,Shut3,Shut4); |
kstokely | 7:e649bb2b6187 | 524 | } |
kstokely | 7:e649bb2b6187 | 525 | |
kstokely | 7:e649bb2b6187 | 526 | else if( c == '4') //Toggle Shutter 4 |
kstokely | 7:e649bb2b6187 | 527 | { |
kstokely | 10:bf195171d850 | 528 | char z1 = pcstr[ indexArr[i] +2 ]; |
kstokely | 10:bf195171d850 | 529 | Shut4 = atoi(&z1); |
kstokely | 7:e649bb2b6187 | 530 | SH.writeShutters(Shut1,Shut2,Shut3,Shut4); |
kstokely | 7:e649bb2b6187 | 531 | } |
kstokely | 7:e649bb2b6187 | 532 | |
kstokely | 8:abdd660056fb | 533 | else if( c == 'u') |
kstokely | 8:abdd660056fb | 534 | { |
kstokely | 10:bf195171d850 | 535 | closeRef(); |
kstokely | 8:abdd660056fb | 536 | } |
kstokely | 7:e649bb2b6187 | 537 | |
kstokely | 8:abdd660056fb | 538 | else if( c == 'y') |
kstokely | 8:abdd660056fb | 539 | { |
kstokely | 10:bf195171d850 | 540 | openRef(); |
kstokely | 8:abdd660056fb | 541 | } |
kstokely | 8:abdd660056fb | 542 | |
kstokely | 8:abdd660056fb | 543 | else if(c == 'o') //Open All Shutters |
kstokely | 8:abdd660056fb | 544 | { |
kstokely | 10:bf195171d850 | 545 | openAllHP(SH); |
kstokely | 8:abdd660056fb | 546 | } |
kstokely | 8:abdd660056fb | 547 | |
kstokely | 8:abdd660056fb | 548 | else if(c == 'r') //Close All Shutters |
kstokely | 8:abdd660056fb | 549 | { |
kstokely | 10:bf195171d850 | 550 | closeAllHP(SH); |
kstokely | 10:bf195171d850 | 551 | } |
kstokely | 10:bf195171d850 | 552 | |
kstokely | 10:bf195171d850 | 553 | else if( c == 'm') |
kstokely | 10:bf195171d850 | 554 | { |
kstokely | 10:bf195171d850 | 555 | //string sub = pcstr.substr( indexArr[i]+2 , 4 );//Used for DAC |
kstokely | 10:bf195171d850 | 556 | char z1 = pcstr[ indexArr[i] +2 ]; |
kstokely | 10:bf195171d850 | 557 | char z2 = pcstr[ indexArr[i] +3 ]; |
kstokely | 10:bf195171d850 | 558 | char z3 = pcstr[ indexArr[i] +4 ]; |
kstokely | 10:bf195171d850 | 559 | char z4 = pcstr[ indexArr[i] +5 ]; |
kstokely | 10:bf195171d850 | 560 | setAllShutters(SH,z1,z2,z3,z4); |
kstokely | 8:abdd660056fb | 561 | } |
kstokely | 8:abdd660056fb | 562 | |
kstokely | 8:abdd660056fb | 563 | else if( c == 91 ) //Left square bracket [ 4x4 Control |
kstokely | 7:e649bb2b6187 | 564 | { |
kstokely | 10:bf195171d850 | 565 | //get inputs for 4x4 |
kstokely | 10:bf195171d850 | 566 | char z1 = pcstr[ indexArr[i] +2 ]; |
kstokely | 10:bf195171d850 | 567 | char z2 = pcstr[ indexArr[i] +3 ]; |
kstokely | 10:bf195171d850 | 568 | char z3 = pcstr[ indexArr[i] +4 ]; |
kstokely | 10:bf195171d850 | 569 | char z4 = pcstr[ indexArr[i] +5 ]; |
kstokely | 10:bf195171d850 | 570 | char z5 = pcstr[ indexArr[i] +6 ]; |
kstokely | 10:bf195171d850 | 571 | set4x4Piping(Arr_4x4,z1,z2,z3,z4,z5); |
kstokely | 7:e649bb2b6187 | 572 | } |
kstokely | 7:e649bb2b6187 | 573 | |
kstokely | 7:e649bb2b6187 | 574 | |
kstokely | 8:abdd660056fb | 575 | else if( c == 93 ) //Right square bracket ] 4x5 Control |
kstokely | 7:e649bb2b6187 | 576 | { |
kstokely | 10:bf195171d850 | 577 | char z1 = pcstr[ indexArr[i] +2 ]; |
kstokely | 10:bf195171d850 | 578 | char z2 = pcstr[ indexArr[i] +3 ]; |
kstokely | 10:bf195171d850 | 579 | char z3 = pcstr[ indexArr[i] +4 ]; |
kstokely | 10:bf195171d850 | 580 | char z4 = pcstr[ indexArr[i] +5 ]; |
kstokely | 10:bf195171d850 | 581 | char z5 = pcstr[ indexArr[i] +6 ]; |
kstokely | 10:bf195171d850 | 582 | set4x5Piping(Arr_4x5,z1,z2,z3,z4,z5); |
kstokely | 7:e649bb2b6187 | 583 | } |
kstokely | 7:e649bb2b6187 | 584 | |
kstokely | 9:2d70aa45f16e | 585 | |
kstokely | 9:2d70aa45f16e | 586 | else if( c == 'd') |
kstokely | 9:2d70aa45f16e | 587 | { |
kstokely | 10:bf195171d850 | 588 | queryDAC(&dac); |
kstokely | 9:2d70aa45f16e | 589 | } |
kstokely | 9:2d70aa45f16e | 590 | |
kstokely | 9:2d70aa45f16e | 591 | else if( c == 'a') |
kstokely | 9:2d70aa45f16e | 592 | { |
kstokely | 10:bf195171d850 | 593 | queryShutters(); |
kstokely | 9:2d70aa45f16e | 594 | } |
kstokely | 9:2d70aa45f16e | 595 | |
kstokely | 8:abdd660056fb | 596 | else if( c == '.' ) //Single Channel DAC Control |
kstokely | 8:abdd660056fb | 597 | { |
kstokely | 9:2d70aa45f16e | 598 | ////pc.printf("Single Channel DAC Control Press Channel Number\n\r"); |
kstokely | 10:bf195171d850 | 599 | |
kstokely | 10:bf195171d850 | 600 | |
kstokely | 10:bf195171d850 | 601 | char achan = pcstr[ indexArr[i] + 2 ]; |
kstokely | 10:bf195171d850 | 602 | int ichan = atoi(&achan); |
kstokely | 10:bf195171d850 | 603 | |
kstokely | 10:bf195171d850 | 604 | char acount[5]; |
kstokely | 10:bf195171d850 | 605 | acount[0] = pcstr[ indexArr[i] + 3 ]; |
kstokely | 10:bf195171d850 | 606 | acount[1] = pcstr[ indexArr[i] + 4 ]; |
kstokely | 10:bf195171d850 | 607 | acount[2] = pcstr[ indexArr[i] + 5 ]; |
kstokely | 10:bf195171d850 | 608 | acount[3] = pcstr[ indexArr[i] + 6 ]; |
kstokely | 10:bf195171d850 | 609 | acount[4] = '\0'; |
kstokely | 10:bf195171d850 | 610 | int icount = atoi(acount);//Get 4 digit Count |
kstokely | 10:bf195171d850 | 611 | //icount = icount / 10; |
kstokely | 10:bf195171d850 | 612 | //DEBUG |
kstokely | 10:bf195171d850 | 613 | //pc.printf("DAC Channel: %d DAC Counts: %d Acount:\n\r",ichan,icount); |
kstokely | 10:bf195171d850 | 614 | |
kstokely | 10:bf195171d850 | 615 | |
kstokely | 10:bf195171d850 | 616 | if( achan == '1' || achan== '2' || achan == '3' || achan == '0' ) |
kstokely | 8:abdd660056fb | 617 | { |
kstokely | 9:2d70aa45f16e | 618 | //////////pc.printf("Channel %c Selected",z); |
kstokely | 10:bf195171d850 | 619 | DACSetChannel( ichan , &dac, icount); |
kstokely | 8:abdd660056fb | 620 | } |
kstokely | 7:e649bb2b6187 | 621 | else |
kstokely | 7:e649bb2b6187 | 622 | { |
kstokely | 9:2d70aa45f16e | 623 | ////pc.printf("ERROR"); |
wbeaumont | 1:d175631a5803 | 624 | } |
kstokely | 7:e649bb2b6187 | 625 | } |
kstokely | 10:bf195171d850 | 626 | |
kstokely | 10:bf195171d850 | 627 | else if( c == 't') |
kstokely | 10:bf195171d850 | 628 | { |
kstokely | 10:bf195171d850 | 629 | /* |
kstokely | 10:bf195171d850 | 630 | //Contours Hologran |
kstokely | 10:bf195171d850 | 631 | DACSetChannel( 0 , &dac, 0); |
kstokely | 10:bf195171d850 | 632 | DACSetChannel( 1 , &dac, 0); |
kstokely | 10:bf195171d850 | 633 | DACSetChannel( 2 , &dac, 0); |
kstokely | 10:bf195171d850 | 634 | DACSetChannel( 3 , &dac, 0); |
kstokely | 10:bf195171d850 | 635 | wait_ms(100); |
kstokely | 10:bf195171d850 | 636 | trigSH( SH, 1 ); |
kstokely | 10:bf195171d850 | 637 | wait_ms(100); |
kstokely | 10:bf195171d850 | 638 | |
kstokely | 10:bf195171d850 | 639 | |
kstokely | 10:bf195171d850 | 640 | //Illums |
kstokely | 10:bf195171d850 | 641 | DACSetChannel( 0 , &dac, 4095); |
kstokely | 10:bf195171d850 | 642 | DACSetChannel( 1 , &dac, 4095); |
kstokely | 10:bf195171d850 | 643 | DACSetChannel( 2 , &dac, 4095); |
kstokely | 10:bf195171d850 | 644 | DACSetChannel( 3 , &dac, 4095); |
kstokely | 10:bf195171d850 | 645 | SH.writeShutters(1,1,1,1); |
kstokely | 10:bf195171d850 | 646 | wait_ms(100); |
kstokely | 10:bf195171d850 | 647 | trigSH( SH, 10 ); |
kstokely | 10:bf195171d850 | 648 | wait_ms(100); |
kstokely | 10:bf195171d850 | 649 | |
kstokely | 10:bf195171d850 | 650 | |
kstokely | 10:bf195171d850 | 651 | //Reference |
kstokely | 10:bf195171d850 | 652 | DACSetChannel( 0 , &dac, 0); |
kstokely | 10:bf195171d850 | 653 | DACSetChannel( 1 , &dac, 0); |
kstokely | 10:bf195171d850 | 654 | DACSetChannel( 2 , &dac, 0); |
kstokely | 10:bf195171d850 | 655 | DACSetChannel( 3 , &dac, 0); |
kstokely | 10:bf195171d850 | 656 | SH.writeShutters(0,0,0,0); |
kstokely | 10:bf195171d850 | 657 | wait_ms(100); |
kstokely | 10:bf195171d850 | 658 | trigNotEyeSafe( SH, 10 ); |
kstokely | 10:bf195171d850 | 659 | wait_ms(100); |
kstokely | 10:bf195171d850 | 660 | |
kstokely | 10:bf195171d850 | 661 | //Darks |
kstokely | 10:bf195171d850 | 662 | SH.writeShutters(0,0,0,0); |
kstokely | 10:bf195171d850 | 663 | DACSetChannel( 0 , &dac, 4095); |
kstokely | 10:bf195171d850 | 664 | DACSetChannel( 1 , &dac, 4095); |
kstokely | 10:bf195171d850 | 665 | DACSetChannel( 2 , &dac, 4095); |
kstokely | 10:bf195171d850 | 666 | DACSetChannel( 3 , &dac, 4095); |
kstokely | 10:bf195171d850 | 667 | |
kstokely | 10:bf195171d850 | 668 | wait_ms(100); |
kstokely | 10:bf195171d850 | 669 | trigNotEyeSafe( SH, 10 ); |
kstokely | 10:bf195171d850 | 670 | wait_ms(100); |
kstokely | 10:bf195171d850 | 671 | */ |
kstokely | 10:bf195171d850 | 672 | |
kstokely | 10:bf195171d850 | 673 | int i; |
kstokely | 10:bf195171d850 | 674 | int nimgs = 0; |
kstokely | 10:bf195171d850 | 675 | for(i = 0; i<seqstr.size(); i++) |
kstokely | 10:bf195171d850 | 676 | { |
kstokely | 10:bf195171d850 | 677 | //Find characters and then grab next three digits as the number of times to trigger |
kstokely | 10:bf195171d850 | 678 | |
kstokely | 10:bf195171d850 | 679 | if( seqstr[i] == 'i') |
kstokely | 10:bf195171d850 | 680 | { |
kstokely | 10:bf195171d850 | 681 | nimgs = atoi( seqstr.substr(i+1, i+3).c_str() ); |
kstokely | 10:bf195171d850 | 682 | DACSetChannel( 0 , &dac, 4095); |
kstokely | 10:bf195171d850 | 683 | DACSetChannel( 1 , &dac, 4095); |
kstokely | 10:bf195171d850 | 684 | DACSetChannel( 2 , &dac, 4095); |
kstokely | 10:bf195171d850 | 685 | DACSetChannel( 3 , &dac, 4095); |
kstokely | 10:bf195171d850 | 686 | trigSH( SH, nimgs ); |
kstokely | 10:bf195171d850 | 687 | //pc.printf("Num Illums: %d\n",nimgs); |
kstokely | 10:bf195171d850 | 688 | } |
kstokely | 10:bf195171d850 | 689 | else if( seqstr[i] == 'd') |
kstokely | 10:bf195171d850 | 690 | { |
kstokely | 10:bf195171d850 | 691 | nimgs = atoi( seqstr.substr(i+1, i+3).c_str() ); |
kstokely | 10:bf195171d850 | 692 | SH.writeShutters(0,0,0,0); |
kstokely | 10:bf195171d850 | 693 | DACSetChannel( 0 , &dac, 4095); |
kstokely | 10:bf195171d850 | 694 | DACSetChannel( 1 , &dac, 4095); |
kstokely | 10:bf195171d850 | 695 | DACSetChannel( 2 , &dac, 4095); |
kstokely | 10:bf195171d850 | 696 | DACSetChannel( 3 , &dac, 4095); |
kstokely | 10:bf195171d850 | 697 | trigNotEyeSafe( SH, nimgs ); |
kstokely | 10:bf195171d850 | 698 | //pc.printf("Num Darks: %d\n",nimgs); |
kstokely | 10:bf195171d850 | 699 | } |
kstokely | 10:bf195171d850 | 700 | else if( seqstr[i] == 'c') |
kstokely | 10:bf195171d850 | 701 | { |
kstokely | 10:bf195171d850 | 702 | nimgs = atoi( seqstr.substr(i+1, i+3).c_str() ); |
kstokely | 10:bf195171d850 | 703 | DACSetChannel( 0 , &dac, 0); |
kstokely | 10:bf195171d850 | 704 | DACSetChannel( 1 , &dac, 0); |
kstokely | 10:bf195171d850 | 705 | DACSetChannel( 2 , &dac, 0); |
kstokely | 10:bf195171d850 | 706 | DACSetChannel( 3 , &dac, 0); |
kstokely | 10:bf195171d850 | 707 | trigSH( SH, nimgs ); |
kstokely | 10:bf195171d850 | 708 | |
kstokely | 10:bf195171d850 | 709 | //pc.printf("Num Contours: %d\n",nimgs); |
kstokely | 10:bf195171d850 | 710 | } |
kstokely | 10:bf195171d850 | 711 | else if( seqstr[i] == 'r') |
kstokely | 10:bf195171d850 | 712 | { |
kstokely | 10:bf195171d850 | 713 | nimgs = atoi( seqstr.substr(i+1, i+3).c_str() ); |
kstokely | 10:bf195171d850 | 714 | DACSetChannel( 0 , &dac, 0); |
kstokely | 10:bf195171d850 | 715 | DACSetChannel( 1 , &dac, 0); |
kstokely | 10:bf195171d850 | 716 | DACSetChannel( 2 , &dac, 0); |
kstokely | 10:bf195171d850 | 717 | DACSetChannel( 3 , &dac, 0); |
kstokely | 10:bf195171d850 | 718 | SH.writeShutters(0,0,0,0); |
kstokely | 10:bf195171d850 | 719 | trigNotEyeSafe( SH, nimgs ); |
kstokely | 10:bf195171d850 | 720 | //pc.printf("Num Refs: %d\n",nimgs); |
kstokely | 10:bf195171d850 | 721 | } |
wbeaumont | 1:d175631a5803 | 722 | |
kstokely | 10:bf195171d850 | 723 | } |
kstokely | 10:bf195171d850 | 724 | |
kstokely | 10:bf195171d850 | 725 | } |
kstokely | 10:bf195171d850 | 726 | |
kstokely | 10:bf195171d850 | 727 | else if( c == 's' ) |
kstokely | 10:bf195171d850 | 728 | { |
kstokely | 10:bf195171d850 | 729 | seqstr = pcstr.substr( indexArr[i] +2, indexArr[i+1] -1 ); |
kstokely | 10:bf195171d850 | 730 | pc.printf("String is %s \n",seqstr.c_str()); |
kstokely | 10:bf195171d850 | 731 | } |
kstokely | 10:bf195171d850 | 732 | |
kstokely | 10:bf195171d850 | 733 | |
kstokely | 10:bf195171d850 | 734 | else if( c == ';') |
kstokely | 10:bf195171d850 | 735 | { |
kstokely | 10:bf195171d850 | 736 | //Dumb states of everything out |
kstokely | 10:bf195171d850 | 737 | //All on one line |
kstokely | 10:bf195171d850 | 738 | |
kstokely | 10:bf195171d850 | 739 | //Shutters |
kstokely | 10:bf195171d850 | 740 | pc.printf("SH1:%d SH2:%d SH3:%d SH4:%d SHRef:%d",Shut1,Shut2,Shut3,Shut4,mRefShutters.read()); |
kstokely | 10:bf195171d850 | 741 | |
kstokely | 10:bf195171d850 | 742 | //DAC |
kstokely | 10:bf195171d850 | 743 | int CH1cnt; |
kstokely | 10:bf195171d850 | 744 | int CH2cnt; |
kstokely | 10:bf195171d850 | 745 | int CH3cnt; |
kstokely | 10:bf195171d850 | 746 | int CH4cnt; |
kstokely | 10:bf195171d850 | 747 | |
kstokely | 10:bf195171d850 | 748 | //Print State of DAC |
kstokely | 10:bf195171d850 | 749 | int sts = dac.update(); |
kstokely | 10:bf195171d850 | 750 | int updatecnt = 0; |
kstokely | 10:bf195171d850 | 751 | |
kstokely | 10:bf195171d850 | 752 | |
kstokely | 10:bf195171d850 | 753 | while( sts != 0 && updatecnt < 5) |
kstokely | 10:bf195171d850 | 754 | { |
kstokely | 10:bf195171d850 | 755 | if(sts != 0) |
kstokely | 10:bf195171d850 | 756 | { |
kstokely | 10:bf195171d850 | 757 | sts = dac.update(); |
kstokely | 10:bf195171d850 | 758 | updatecnt++; |
kstokely | 10:bf195171d850 | 759 | |
kstokely | 10:bf195171d850 | 760 | } |
kstokely | 10:bf195171d850 | 761 | } |
kstokely | 10:bf195171d850 | 762 | |
kstokely | 10:bf195171d850 | 763 | if( updatecnt >= 5) |
kstokely | 10:bf195171d850 | 764 | { |
kstokely | 10:bf195171d850 | 765 | pc.printf("CH1:xxxx CH2:xxxx CH3:xxxx CH4:xxxx"); |
kstokely | 10:bf195171d850 | 766 | } |
kstokely | 10:bf195171d850 | 767 | else |
kstokely | 10:bf195171d850 | 768 | { |
kstokely | 10:bf195171d850 | 769 | (void)dac.getDACvalue(CH1cnt,0); |
kstokely | 10:bf195171d850 | 770 | (void)dac.getDACvalue(CH2cnt,1); |
kstokely | 10:bf195171d850 | 771 | (void)dac.getDACvalue(CH3cnt,2); |
kstokely | 10:bf195171d850 | 772 | (void)dac.getDACvalue(CH4cnt,3); |
kstokely | 10:bf195171d850 | 773 | pc.printf("CH1:%4d CH2:%4d CH3:%4d CH4:%4d",CH1cnt,CH2cnt,CH3cnt,CH4cnt); |
kstokely | 10:bf195171d850 | 774 | } |
kstokely | 10:bf195171d850 | 775 | |
kstokely | 10:bf195171d850 | 776 | //Piping |
kstokely | 10:bf195171d850 | 777 | pc.printf("4x4:%d%d%d%d%d", m4x4TTL1.read(), m4x4TTL2.read(), m4x4TTL3.read(), m4x4TTL4.read(), m4x4TTL5.read() ); |
kstokely | 10:bf195171d850 | 778 | pc.printf("4x5:%d%d%d%d%d\n", m4x5TTL1.read(), m4x5TTL2.read(), m4x5TTL3.read(), m4x5TTL4.read(), m4x5TTL5.read() ); |
kstokely | 10:bf195171d850 | 779 | } |
kstokely | 10:bf195171d850 | 780 | |
kstokely | 10:bf195171d850 | 781 | else if( c == '+' ) |
kstokely | 10:bf195171d850 | 782 | { |
kstokely | 10:bf195171d850 | 783 | pc.printf(",[%d%d%d%d%d,]%d%d%d%d%d", m4x4TTL1.read(), m4x4TTL2.read(), m4x4TTL3.read(), m4x4TTL4.read(), m4x4TTL5.read(), m4x5TTL1.read(), m4x5TTL2.read(), m4x5TTL3.read(), m4x5TTL4.read(), m4x5TTL5.read() ); |
kstokely | 10:bf195171d850 | 784 | pc.printf(",m%d%d%d%d",Shut1,Shut2,Shut3,Shut4); |
kstokely | 10:bf195171d850 | 785 | int CH1cnt; |
kstokely | 10:bf195171d850 | 786 | int CH2cnt; |
kstokely | 10:bf195171d850 | 787 | int CH3cnt; |
kstokely | 10:bf195171d850 | 788 | int CH4cnt; |
kstokely | 10:bf195171d850 | 789 | |
kstokely | 10:bf195171d850 | 790 | int sts = dac.update(); |
kstokely | 10:bf195171d850 | 791 | int updatecnt = 0; |
kstokely | 10:bf195171d850 | 792 | |
kstokely | 10:bf195171d850 | 793 | |
kstokely | 10:bf195171d850 | 794 | while( sts != 0 && updatecnt < 5) |
kstokely | 10:bf195171d850 | 795 | { |
kstokely | 10:bf195171d850 | 796 | |
kstokely | 10:bf195171d850 | 797 | if(sts != 0) |
kstokely | 10:bf195171d850 | 798 | { |
kstokely | 10:bf195171d850 | 799 | sts = dac.update(); |
kstokely | 10:bf195171d850 | 800 | updatecnt++; |
kstokely | 10:bf195171d850 | 801 | |
kstokely | 10:bf195171d850 | 802 | } |
kstokely | 10:bf195171d850 | 803 | |
kstokely | 10:bf195171d850 | 804 | } |
kstokely | 10:bf195171d850 | 805 | if( updatecnt >= 5 && sts != 0) |
kstokely | 10:bf195171d850 | 806 | { |
kstokely | 10:bf195171d850 | 807 | pc.printf(",.0xxxx,.1xxxx,.2xxxx,.3xxxx\n"); |
kstokely | 10:bf195171d850 | 808 | } |
kstokely | 10:bf195171d850 | 809 | else |
kstokely | 10:bf195171d850 | 810 | { |
kstokely | 10:bf195171d850 | 811 | (void)dac.getDACvalue(CH1cnt,0); |
kstokely | 10:bf195171d850 | 812 | (void)dac.getDACvalue(CH2cnt,1); |
kstokely | 10:bf195171d850 | 813 | (void)dac.getDACvalue(CH3cnt,2); |
kstokely | 10:bf195171d850 | 814 | (void)dac.getDACvalue(CH4cnt,3); |
kstokely | 10:bf195171d850 | 815 | pc.printf(",.0%04d,.1%04d,.2%04d,.3%04d\n",CH1cnt,CH2cnt,CH3cnt,CH4cnt); |
kstokely | 10:bf195171d850 | 816 | } |
kstokely | 10:bf195171d850 | 817 | |
kstokely | 10:bf195171d850 | 818 | } |
kstokely | 10:bf195171d850 | 819 | |
kstokely | 10:bf195171d850 | 820 | |
kstokely | 10:bf195171d850 | 821 | } |
kstokely | 10:bf195171d850 | 822 | |
kstokely | 7:e649bb2b6187 | 823 | } |
kstokely | 8:abdd660056fb | 824 | //Never Reach This |
kstokely | 8:abdd660056fb | 825 | return 1; |
kstokely | 8:abdd660056fb | 826 | } |
kstokely | 8:abdd660056fb | 827 |