fork of shutter test program

Fork of test_shutter by james kain

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002  
00003 //are these actually used ??? - not used sg. Was for the inital LED's you had. Then I thought of the 4 into 16 while coding
00004 DigitalOut ext_led[8] = {p21,p22,p23,p24,p25,p26,p27,p28};
00005 //DigitalOut int_led[4] = {LED1, LED2, LED3, LED4};
00006  
00007 // from handbook for BusOut:  Flexible way to write multiple DigitalOut pins as one value
00008 BusOut int_led(LED1, LED2, LED3, LED4);  //four built-in LEDs used to display the counter from the trigger
00009  
00010 //original from Sam in Seaside
00011 //DigitalInOut fire(p20);     //connected to the tip of 2.5mm connector (T2i)
00012 //DigitalInOut pre_fire(p19); //connected to the mid-connection for 2.5mm connector (T2i)
00013  
00014 //modification to connect to the IMU carrier board
00015 DigitalInOut fire(p29);     //connected to the tip of 2.5mm connector (T2i)
00016 DigitalInOut pre_fire(p30); //connected to the mid-connection for 2.5mm connector (T2i)
00017  
00018 // using ADIS hardware
00019 //DigitalInOut fire(p29);     //connected to the tip of 2.5mm connector (T2i)
00020 //DigitalInOut pre_fire(p30); //connected to the mid-connection for 2.5mm connector (T2i)
00021  
00022 InterruptIn x(p18); 
00023 Serial pc(USBTX, USBRX);
00024  
00025  
00026 #define US_INTERVAL 500
00027     
00028 //set the resolution of the timing information
00029 #define MS_INTERVAL 1           //interval used to change the counter display 
00030 #define WAIT_KNOWN_MS   145     // known delay between trigger and shutter time (allows to better use 4 leds)
00031 #define TRIGGER_INTERVAL 7.5f   // amount of time between triggers
00032  
00033 void resetLed()
00034 {
00035     for(int i=0; i<8; i++)
00036     {
00037         ext_led[i] = 0;
00038     }
00039     int_led = 0;
00040 }
00041  
00042 //xFire procedure is not used in the logic in main. This was to test the accuracy of the hotshoe trigger and it was spot on sg
00043 void xFire()
00044 {
00045     for(int i=1; i<16; i++)
00046     {
00047         wait_us(US_INTERVAL);
00048         int_led = i;
00049     }
00050     return;
00051 }
00052  
00053 volatile bool trigger = 0;
00054 Ticker trig;
00055 void setTrig()
00056 {
00057     trigger = 1;
00058 }
00059  
00060 int main()
00061 {
00062     // try open drain driving (internal pullup in camera?)
00063     //x procedure not used below 
00064     x.mode(PullUp);
00065     x.fall(&xFire);   
00066     
00067     fire.output();  //set the fire pin as outoput
00068     pre_fire.output();  //set the pre-fire pin as output
00069     //fire.mode(OpenDrain);
00070     
00071     //set up for the first trigger
00072     fire = 1;
00073     pre_fire = 1;
00074     
00075     // reset the LED's
00076     resetLed();
00077     
00078     //trig is a ticker used to repeatedly fire a trigger at the interval (e.g., 7.5 secs)
00079     trig.attach(&setTrig, TRIGGER_INTERVAL);  //set ticker interval to 7.5secs
00080     
00081     // start the program
00082     while(1)
00083     {
00084 //        if(pc.readable())  //used to trigger from a keyboard click
00085 //        {
00086 //            char ch = pc.getc();  //read the keyboard click
00087  
00088           //below used for repeatedly triggering on a ticker
00089           if(trigger)  //is the ticker has fired the trigger, proceed ...
00090           {
00091             trigger = 0;  //reset the trigger to zero
00092             
00093             // turn all leds off to start the counter
00094             resetLed();
00095             
00096             // pre-fire the trigger using the mid-body 2.5mm connection (T2i)
00097             pre_fire = 0;
00098             
00099             wait(.25f);  //wait for 0.25 secs
00100             
00101             fire = 0; //fire the trigger using the tip connection
00102             
00103             wait_ms(WAIT_KNOWN_MS); // empirically known delay to get us to the range of the 4 timing LEDs 
00104             
00105             // maybe we need more or later just use these...
00106             //just count up to 16 diaplaying the results on the LEDs
00107             for(int i=1; i<16; i++)
00108             {
00109                 wait_ms(MS_INTERVAL);
00110                 int_led = i;  //write to the BusOut to display the counter on 4 LEDs
00111             }
00112             
00113             //reset for the next trigger
00114             // release the trigger
00115             fire = 1;
00116             pre_fire = 1;
00117         }
00118     }
00119 }