'---------------------------------------------------- ' C o l l i s i o n S c r i p t '5/8/04 '---------------------------------------------------- const sMODE := 1, hHALFDUR := 2, hDEADDUR := 3, cLATENCY := 4, cINTERDUR := 5, tFILLER := 6, tCYCLES := 7, cTYPE := 10, cHALFDUR := 11, sBOOTH := 40, sTICKSPERSEC := 62, 'utility kError := -1, 'standard error code kEmpty := -1, kTrue := 1, kFalse := 0, kNAN := 999999, 'simulate not-a-number kPi := 3.141592654, kRadians := 360 / (2 * kPi), kMS := 1000, 'booths kRobinsonBooth := 0, kOKNbooth := 1, kLEDbooth := 2, kVisualBooth := 3, kGazeBooth := 4; var 'files gScriptDir$, 'path to script file gDataPlot%, 'handle of the data file gCollisionPlot%, 'handle of the collision file 'buttons gQuitButton := 1, gResetPlotButton := 2, gStopButton := 3, gStartButton := 4, gAcceptButton := 5, gPrevButton := 6, gNextButton := 7, gParametersButton := 8, gDecButton := 9, gIncButton := 10, gEditButton := 11, gCollisionButton := 12, gSearchButton := 13, 'channels gChUnit, gChHeye, gChVeye, gChHtarg1, gChVtarg1, gChEvents, gChKeyboard, 'not used, remove code related to these gChHtarg2, gChVtarg2, gChHvel, gChVvel, 'booth gWhichBooth := kLEDbooth, 'timing gTicksPerSec, gCollisionPlotLast := 0, gCollisionN, gChangeParam := 1, gSamplesPerMS := 100, 'unit gMSBefore := 1, gMSAfter := 5, gPointsBefore, gPointsAfter, gEditN, gEditPlot%, gBackwardAnchor, gCurrentAnchor, gForwardAnchor, gName$, gEditIndex, gPulseType%, gTrainDur$, gTrainFreq$; '-------------------------- 'G L O B A L 'I N I T I A L I Z A T I O N ' 'Can't declare and initialize 'variables with program contants '-------------------------- gScriptDir$ := FilePath$(); ToolbarVisible(1); 'Make toolbar visible always SetToolbar(); 'Setup the toolbar gTicksPerSec := SampleSeqVar(sTICKSPERSEC) * 10; 'why 10? (10/27/03) gPointsBefore := gMSBefore*gSamplesPerMS; gPointsAfter := gMSAfter*gSamplesPerMS; DialogStartup(); DoToolbar(); 'Setup the toolbar '---------------------------------------------------- ' SetToolbar '5/8/04 '---------------------------------------------------- proc SetToolbar() ToolbarClear(); 'eliminate all the buttons 'set up the basic buttons ToolbarSet(0,"",Idle%); 'Call Idle%() whenever there is free time ToolbarSet(gQuitButton,"Quit Program",Quit%); ToolbarSet(gResetPlotButton,"Reset Plot", ResetPlot%); ToolbarSet(gStopButton,"Stop", Stop%); ToolbarSet(gStartButton,"Start", Start%); ToolbarSet(gAcceptButton,"&Accept Trace", TraceAccept%); ToolbarSet(gPrevButton,"&Previous Trace", TracePrev%); ToolbarSet(gNextButton,"&Next Trace", TraceNext%); ToolbarSet(gParametersButton,"Set Parameters", DialogParameters%); ToolbarSet(gDecButton,"&Dec Latency", LatencyDecrease%); ToolbarSet(gIncButton,"&Inc Latency", LatencyIncrease%); ToolbarSet(gEditButton,"&Edit Mode", ModeEdit%); ToolbarSet(gCollisionButton,"&Collision Mode", ModeCollision%); ToolbarSet(gSearchButton,"&Search Mode", ModeSearch%); ToolbarEnable(gResetPlotButton,1); ToolbarEnable(gStopButton,0); ToolbarEnable(gEditButton,0); ToolbarEnable(gCollisionButton,1); ToolbarEnable(gSearchButton,0); end 'SetToolbar '---------------------------------------------------- ' DoToolbar '5/8/04 '---------------------------------------------------- proc DoToolbar() Toolbar("", 1023); 'Wait here until quit is pressed end 'DoToolbar '---------------------------------------------------- ' DialogStartup '5/13/04 '---------------------------------------------------- proc DialogStartup() var ok%, aRow%, aResponse; dlgcreate("Signal Connections"); aRow% := 2; dlgText("DIG IN ch 0 <--- Window Discriminator output",0,aRow%); aRow% := aRow% + 1; dlgText("DAC ch 0 ---> Stimulation Isolation Unit input\n",0,aRow%); aRow% := aRow% + 2; dlgText("ADC ch 0 <--- Unit",0,aRow%); aRow% := aRow% + 1; dlgText("ADC ch 1 <--- Horz Eye",0,aRow%); aRow% := aRow% + 2; dlgText("ADC ch 2 <--- Vert Eye",0,aRow%); aRow% := aRow% + 1; dlgText("ADC ch 3 <--- Horz Target",0,aRow%); aRow% := aRow% + 1; dlgText("ADC ch 4 <--- Vert Target",0,aRow%); aRow% := aRow% + 1; dlgText(" ",0,aRow%); 'dlgButton(0,""); dlgButton(1,"Connected"); ok% := dlgshow(); if ok% = 0 then halt; endif dlgcreate("Spike2 Preferences"); aRow% := 2; dlgText("You can LOSE YOUR COLLISION DATA unless you do the following:\n",0,aRow%); aRow% := aRow% + 2; dlgText("In the /Edit/Edit Preferences/ menu, indicate that you want to",0,aRow%); aRow% := aRow% + 1; dlgText("be prompted whenever closing Result and XY views.",0,aRow%); aRow% := aRow% + 6; dlgText(" ",0,aRow%); 'dlgButton(0,""); dlgButton(1,"Losing data iritates me"); ok% := dlgshow(); if ok% = 0 then halt; endif Start%(); end 'DialogStartup '---------------------------------------------------- ' Start '5/8/04 '---------------------------------------------------- func Start%() 'If "Start" is pressed New%(); 'Set up new sampling window SampleStart(); 'Start sampling ToolbarEnable(gIncButton,1); ToolbarEnable(gDecButton,1); ToolbarEnable(gAcceptButton,0); ToolbarEnable(gPrevButton,0); ToolbarEnable(gNextButton,0); ToolbarEnable(gSearchButton,0); ToolbarEnable(gCollisionButton,1); ToolbarEnable(gEditButton,0); ToolbarEnable(gQuitButton,0); ToolbarEnable(gParametersButton,1); ToolbarEnable(gStopButton,1); ToolbarEnable(gStartButton,0); ToolbarText("Press STOP to halt Sactrack"); return kTrue; 'Stay with toolbar end 'Start '---------------------------------------------------- ' New 'Open a data view create some memory channels and 'arrange all the channels. '5/8/04 '---------------------------------------------------- func New%() var dX1 := 0, dY1 := 0, dX2 := 100, dY2 := 50, logX1 := 0, logY1 := 50, logX2 := 25, logY2 := 100, plotX1 := 25, plotY1 := 50, plotX2 := 100, plotY2 := 100, ok%, aStr$, bStr$, aResult, aRow%; 'close down previous activity '---------------------------- MyFileClose(gDataPlot%, 0); 'close & query the last data file MyFileClose(gCollisionPlot%, 0); 'close & query the last collilsion file MyFileClose(gEditPlot%, 0); 'close & query the last edit file gChangeParam := 1; 'intialize variables 'declare traces gChUnit := 1; gChHeye := 2; gChVeye := 3; gChHtarg1 := 4; gChVtarg1 := 5; gChHvel := 6; gChVvel := 7; gChHtarg2 := 8; gChVtarg2 := 9; gChKeyboard := 31; gChEvents := 32; gCollisionPlotLast := 0; 'change the following default colors PaletteSet(22, 100, 40, 65); 'medium red 'create and label the sampling channels '-------------------------------------- SampleClear(); 'must preceed sequencer selection 'clear ALL the sampling settings 'select the sequencer aStr$ := gScriptDir$ + "collision_sequence.pls"; aResult := SampleSequencer(aStr$); 'identify the sequencer to use if aResult < 0 then dlgcreate("Sequencer Error"); dlgtext("The sequencer script was not found.", 0, 1); bStr$ := "Looking for " + aStr$; dlgtext(bStr$, 0, 2); dlgtext(" ", 0, 3); DlgButton(0,""); 'remove the CANCEL button ok% := dlgShow(); endif SampleWaveform(gChHeye, 1,1000); 'H Eye channel SampleTitle$(gChHeye, "H Eye"); SampleWaveform(gChVeye, 2,1000); 'V Eye channel SampleTitle$(gChVeye, "V Eye"); SampleWaveform(gChHtarg1,3,1000); 'H Target channel SampleTitle$(gChHtarg1, "H Targ"); SampleWaveform(gChVtarg1,4,1000); 'V Target channel SampleTitle$(gChVtarg1, "V Targ"); SampleDigMark(100); 'channel to record events SampleTitle$(gChEvents, "Events"); SampleWaveform(gChUnit, 0,100000); 'channel and sample at 100 kHz SampleTitle$(gChUnit, "Unit"); SampleOptimise(2,1,2); 'Full optimize, group channels, Power 1401 aResult := SampleEvent(69, 0, 1, 100); 'enter a name to use as the file gName$ := "MonkeyName"; dlgcreate("Name This Session"); aRow% := 2; dlgText(" ",0,aRow%); aRow% := aRow% + 1; dlgText("Enter a general name for this session. It will become part of filename of several output files.",0,aRow%); aRow% := aRow% + 1; dlgText(" ",0,aRow%); aRow% := aRow% + 1; dlgString(1,60,30,"a-zA-Z0-9",0,aRow%); aRow% := aRow% + 1; dlgText(" ",0,aRow%); aRow% := aRow% + 1; dlgText(" ",0,aRow%); aRow% := aRow% + 1; dlgText(" ",0,aRow%); aRow% := aRow% + 1; dlgText(" ",0,aRow%); aRow% := aRow% + 1; dlgText(" ",0,aRow%); aRow% := aRow% + 1; dlgText(" ",0,aRow%); 'dlgButton(0,""); dlgButton(1,"OK"); ok% := dlgshow(gName$); if ok% = 0 then halt; endif 'prepare a new data file and its window '-------------------------------------- gDataPlot% := FileNew(0,1); 'Open a new data file for sampling WindowTitle$(gName$); '----------------------------------------- 'CANNOT SET SEQUENCE VARIABLES BEFORE THIS 'POINT AS THE VALUES WILL BE INITIALIZED '----------------------------------------- SampleSeqVar(sBOOTH, gWhichBooth); 'inform sequencer which booth we are running 'prepare the log window '---------------------- FrontView(LogHandle()); 'Bring the Log view to the front EditSelectAll(); 'Select all text in log view EditClear(); 'Delete it Window(logX1,logY1,logX2,logY2); 'Display it at the bottom of the screen WindowVisible(1); 'Make it visbible aStr$ := "Collision Log"; WindowTitle$(aStr$); FrontView(gDataPlot%); 'Bring the data view to the front Window(dX1,dY1,dX2,dY2); 'Make data window in top bit of screen XRange(0,10); 'show ten seconds of data 'create the memory channels DrawMode(gChKeyboard,1); 'show as text not vertical lines DrawMode(gChEvents,1); 'reveal sequencer MARK stamps ChanTitle$(gChUnit,"Unit"); YRange(gChUnit, -7, 7); 'set the ±32k bit range represents 20 volts ChanScale(gChHeye, 20); YRange(gChHeye, -21, 21); ChanColour(gChHeye, 1, 0); 'black ChanUnits$(gChHeye,"deg"); ChanColour(gChHvel, 1, 0); 'black ChanUnits$(gChHvel,"deg/s"); ChanHide(gChHvel); ChanScale(gChVeye, 20); YRange(gChVeye, -21, 21); ChanColour(gChVeye, 1, 0); 'black ChanUnits$(gChVeye,"deg"); ChanColour(gChVvel, 1, 0); 'black ChanUnits$(gChVvel,"deg/s"); ChanHide(gChVvel); ChanScale(gChHtarg1, 20); YRange(gChHtarg1, -21, 21); ChanColour(gChHtarg1, 1, 16); 'red ChanUnits$(gChHtarg1,"deg"); ChanScale(gChVtarg1, 20); YRange(gChVtarg1, -21, 21); ChanColour(gChVtarg1, 1, 16); 'red ChanUnits$(gChVtarg1,"deg"); 'prepare the plot window '----------------------- gCollisionN := 0; gCollisionPlot% := FileNew(12,1); 'prepare to plot the spike traces Window(plotX1,plotY1,plotX2,plotY2); 'Make data window in top bit of screen WindowRange(gCollisionPlot%); '2.16.05 turn off auto-scaling 'XYDrawMode(1,5,1); 'auto axis range mode XYDrawMode(-1,5,0); 'auto axis range mode explicitly off XYDrawMode(1,2,2); 'small dots XYcolour(1,16); 'red 'XYjoin(1,1); SetCollisionTitle(); 'prepare the toolbar '------------------- ToolbarEnable(gQuitButton,1); ToolbarEnable(gParametersButton,1); ToolbarEnable(gStopButton,0); ToolbarEnable(gStartButton,1); ToolbarText("Press START to run Sactrack"); return 1; end 'New '---------------------------------------------------- ' WindowRange ' '5/17/04 '---------------------------------------------------- proc WindowRange(theWindow%) View(theWindow%); XRange(-gMSBefore/1000-0.0005, gMSAfter/1000+0.0005); 'loX,hiX end '---------------------------------------------------- ' SetCollisionTitle ' 'Updates information displayed in the collision plot 'title bar. '5/14/04 '---------------------------------------------------- proc SetCollisionTitle() var aStr$; View(gCollisionPlot%); aStr$ := gName$ + " --- Raw --- " + " N=" + Str$(gCollisionN) + " --- Time = " + Str$(gCollisionPlotLast); WindowTitle$(aStr$); end 'SetCollisionTitle '---------------------------------------------------- ' IncreaseLatency ' '5/14/04 '---------------------------------------------------- func LatencyIncrease%() var aLatency; aLatency := SampleSeqVar(cLATENCY); aLatency := aLatency + 10; '0.1 ms at 100kHz SampleSeqVar(cLATENCY, aLatency); LogUpdate(); return 1; end 'LatencyIncrease '---------------------------------------------------- ' DecreaseLatency ' '5/14/04 '---------------------------------------------------- func LatencyDecrease%() var aLatency; aLatency := SampleSeqVar(cLATENCY); aLatency := aLatency - 10; '0.1 ms at 100kHz SampleSeqVar(cLATENCY, aLatency); LogUpdate(); return 1; end 'LatencyDecrease '---------------------------------------------------- ' SearchMode ' '5/14/04 '---------------------------------------------------- func ModeSearch%() SampleSeqVar(sMODE, 0); MyFileClose(gEditPlot%, 0); 'close & query the last edit file View(gCollisionPlot%); XYDelete(2); ToolbarEnable(gIncButton,1); ToolbarEnable(gDecButton,1); ToolbarEnable(gAcceptButton,0); ToolbarEnable(gPrevButton,0); ToolbarEnable(gNextButton,0); ToolbarEnable(gSearchButton,0); ToolbarEnable(gCollisionButton,1); ToolbarEnable(gEditButton,0); gChangeParam := 1; return 1; end 'ModeSearch '---------------------------------------------------- ' CollisionMode ' '5/14/04 '---------------------------------------------------- func ModeCollision%() SampleSeqVar(sMODE, 1); MyFileClose(gEditPlot%, 0); 'close & query the last edit file View(gCollisionPlot%); XYDelete(2); ToolbarEnable(gIncButton,1); ToolbarEnable(gDecButton,1); ToolbarEnable(gAcceptButton,0); ToolbarEnable(gPrevButton,0); ToolbarEnable(gNextButton,0); ToolbarEnable(gSearchButton,1); ToolbarEnable(gCollisionButton,0); ToolbarEnable(gEditButton,1); gChangeParam := 1; return 1; end 'ModeCollision '---------------------------------------------------- ' EditMode ' '5/17/04 '---------------------------------------------------- func ModeEdit%() var aDataXdel[(gMSBefore+gMSAfter)*gSamplesPerMS+1], aDataYdel[(gMSBefore+gMSAfter)*gSamplesPerMS+1], plotX1 := 25, plotY1 := 0, plotX2 := 100, plotY2 := 50, aStr$; SampleSeqVar(sMODE, 2); ToolbarEnable(gIncButton,0); ToolbarEnable(gDecButton,0); ToolbarEnable(gAcceptButton,1); ToolbarEnable(gPrevButton,1); ToolbarEnable(gNextButton,1); ToolbarEnable(gSearchButton,1); ToolbarEnable(gCollisionButton,1); ToolbarEnable(gEditButton,0); 'create the edit window '----------------------- gEditN := 0; gEditPlot% := FileNew(12,1); 'prepare to plot the spike traces aStr$ := gName$ + " --- Select --- "; WindowTitle$(aStr$); Window(plotX1,plotY1,plotX2,plotY2); 'Make data window in top bit of screen WindowRange(gEditPlot%); '2.16.05 turn off auto-scaling 'XYDrawMode(1,5,1); 'auto axis range mode XYDrawMode(-1,5,0); 'auto axis range mode explicitly off XYDrawMode(1,2,0); 'no dots XYjoin(1,1); 'join with lines XYcolour(1,16); 'red 'prepare a channel for highlighting/deleting a trace view(gCollisionPlot%); XYsetChan(0); '2.16.05 turn off auto-scaling 'XYDrawMode(2,5,1); 'auto axis range mode XYDrawMode(-1,5,0); 'auto axis range mode explicitly off XYDrawMode(2,2,3); 'medium dots XYcolour(2,0); 'black gCurrentAnchor := 0; gBackwardAnchor := gCurrentAnchor - ((gMSBefore+gMSAfter)*gSamplesPerMS+1); gForwardAnchor := gCurrentAnchor + (gMSBefore+gMSAfter)*gSamplesPerMS+1; XYGetData(1, aDataXdel[], aDataYdel[], 0, (gMSBefore+gMSAfter)*gSamplesPerMS); XYAddData(2, aDataXdel[], aDataYdel[]); LogUpdate(); 'gChangeParam := 1; return 1; end 'ModeCollision '---------------------------------------------------- ' Updatelog ' '5/14/04 '---------------------------------------------------- proc LogUpdate() var aLatency, aMode, ahPulseWidth, aInterDur, acHALFDUR, aLoDur, aDeadTime, aType, aCycles; aMode := SampleSeqVar(sMODE); View(LogHandle()); 'Make log view the current view EditSelectAll(); 'Select all text in log view EditClear(); 'Delete it if aMode = 0 then 'hunt/search mode ahPulseWidth := (SampleSeqVar(hHALFDUR)*2.0)/100.0; aLoDur := SampleSeqVar(hDEADDUR)/100.0; PrintLog("S E A R C H M O D E\n"); PrintLog("Time zero = Stim Pulse\n"); 'PrintLog("Collision latency = ", aLatency, " ms (inactive)"); PrintLog("Biphasic Stim pulse dur = ", ahPulseWidth, " ms"); PrintLog("Inactive time = ", aLoDur, " ms"); PrintLog("\n"); PrintLog("Event Marks\n"); 'PrintLog(" .T = Incoming trigger detected\n"); PrintLog(" .S = Stimulation pulse sent\n"); endif if aMode = 1 then 'collision mode aType := SampleSeqVar(cTYPE); aLatency := SampleSeqVar(cLATENCY)/100.0; acHALFDUR := (SampleSeqVar(cHALFDUR)*2.0)/100.0; 'acPulseWidth := SampleSeqVar(tFILLER)/100.0; aInterDur := SampleSeqVar(cINTERDUR)/100.0; aCycles := SampleSeqVar(tCycles); PrintLog("C O L L I S I O N M O D E\n"); PrintLog("Time zero = Spontaneous Pulse\n"); PrintLog("Collision latency = ", aLatency, " ms"); PrintLog("Biphasic Stim pulse dur = ", acHALFDUR, " ms"); if aType = 1 then 'pulse train type PrintLog("Pulse train freq = ", gTrainFreq$, " Hz"); PrintLog("Stim cycles = ", aCycles); PrintLog("Pulse train dur = ", gTrainDur$, " ms"); endif PrintLog("Inactive time = ", aInterDur, " ms (minimum)"); PrintLog("\n"); PrintLog("Event Marks\n"); PrintLog(" .T = Incoming trigger detected\n"); PrintLog(" .S = Stimulation pulse sent\n"); endif if aMode = 2 then PrintLog("E D I T M O D E\n"); endif end 'LogUpdate '---------------------------------------------------- ' Idle ' 'Control comes here when Spike2 has nothing to do. '5/8/04 '---------------------------------------------------- func Idle%() var aCurrentTime, aMoveNow, aLatency, aMode, aHiDur, aLoDur, aDeadTime, aFreq, a,i, aDataX[(gMSBefore+gMSAfter)*gSamplesPerMS+1], aDataY[(gMSBefore+gMSAfter)*gSamplesPerMS+1], aDataXdel[(gMSBefore+gMSAfter)*gSamplesPerMS+1], aDataYdel[(gMSBefore+gMSAfter)*gSamplesPerMS+1], aTime, aCode%[4], aStr$, aResult; 'enter if the user has made a change if gChangeParam = 1 then gChangeParam := 0; gCollisionN := 0; 'divide by zero protection if aHiDur + aLoDur = 0 then aFreq := 0; else aFreq := (1/(aHiDur+aLoDur)) * 1000; endif LogUpdate(); View(gDataPlot%); gCollisionPlotLast := Maxtime(); if gCollisionPlotLast < 1.000 then gCollisionPlotLast := 1.000; endif WindowRange(gCollisionPlot%); ResetPlot%(); 'erase the plot endif 'skip when there is no collision plot is available if (ViewKind(gCollisionPlot%) >= 0) and (SampleSeqVar(sMODE)<=1) then View(gDataPlot%); 'exclude events too close to the right side of the screen if gCollisionPlotLast < MaxTime() - 2.00 then 'must protect gCollisionPlotLast from creeping past MaxTime aTime := NextTime(gChEvents, gCollisionPlotLast, aCode%[]); 'find the next event marker 'skip if no event marker was found if (aTime > 1) and (aTime < MaxTime()) then '(aTime > gCollisionPlotLast) and 'skip unless a marker representing stimulation was found 'line up on .S in Search Mode 'line up on .T in Collision Mode if ((SampleSeqVar(sMODE)=0) and (aCode%[0] = 83)) or ((SampleSeqVar(sMODE)=1) and (aCode%[0] = 84)) then gCollisionN := gCollisionN + 1; 'count the events found 'Prepare to get 10ms of data on either side of zero plus zero. 'At 100kHz, that is 1000+1000+1 data points View(gCollisionPlot%); a := -gMSBefore/1000; for i := 0 to (gMSBefore+gMSAfter)*gSamplesPerMS do '100kHz aDataX[i] := a; a := a + 0.00001; 'the interval in seconds at 100kHz next 'in search mode, only store/plot 5 traces if (SampleSeqVar(sMODE) = 0) and (gCollisionN > 5) then XYdelete(1,0,(gMSBefore+gMSAfter)*gSamplesPerMS); gCollisionN := gCollisionN - 1; endif View(gDataPlot%); 'aResult := ChanData(1, aDataY[], aTime-0.0100, aTime+0.0100); aResult := ChanData(1, aDataY[], aTime-gMSBefore/1000, aTime+gMSAfter/1000); view(gCollisionPlot%); aResult := XYAddData(1, aDataX[], aDataY[]); SetCollisionTitle(); endif gCollisionPlotLast := aTime; 'remember this time endif gCollisionPlotLast := gCollisionPlotLast + 0.0001; 'remember this time plus a little bit to avoid finding same location multiple times endif endif return kTrue; 'Stay in toolbar end 'Idle '---------------------------------------------------- ' Stop '5/8/04 '---------------------------------------------------- func Stop%() 'If "Stop" is pressed SampleStop(); 'Stop sampling SetToolbar(); ToolbarEnable(gIncButton,0); ToolbarEnable(gDecButton,0); ToolbarEnable(gAcceptButton,0); ToolbarEnable(gPrevButton,0); ToolbarEnable(gNextButton,0); ToolbarEnable(gSearchButton,1); ToolbarEnable(gCollisionButton,1); ToolbarEnable(gEditButton,0); ToolbarEnable(gQuitButton,1); ToolbarEnable(gParametersButton,1); ToolbarEnable(gStopButton,0); ToolbarEnable(gStartButton,1); ToolbarText("Press FILE NEW to capture another data file"); return kTrue; 'Stay in toolbar end 'Stop '---------------------------------------------------- ' AcceptTrace '5/18/04 '---------------------------------------------------- func TraceAccept%() var aDataXdel[(gMSBefore+gMSAfter)*gSamplesPerMS+1], aDataYdel[(gMSBefore+gMSAfter)*gSamplesPerMS+1]; 'copy it from the raw family of traces view(gCollisionPlot%); XYGetData(1, aDataXdel[], aDataYdel[], gCurrentAnchor, gForwardAnchor-1); 'paste it into the selected family of traces view(gEditPlot%); gEditIndex := gEditIndex + 1; XYsetChan(0); 'gimme another trace '2.16.05 turn off auto-scaling 'XYDrawMode(gEditIndex,5,1); 'auto axis range mode XYDrawMode(-1,5,0); 'auto axis range mode explicitly off XYDrawMode(gEditIndex,2,0); 'no dots XYjoin(gEditIndex,1); 'join with lines XYcolour(gEditIndex,16); 'red XYAddData(gEditIndex, aDataXdel[], aDataYdel[]); return kTrue; 'Stay in toolbar end '---------------------------------------------------- ' NextTrace '5/18/04 '---------------------------------------------------- func TraceNext%() var a, ok%, aDataXdel[(gMSBefore+gMSAfter)*gSamplesPerMS+1], aDataYdel[(gMSBefore+gMSAfter)*gSamplesPerMS+1]; gBackwardAnchor := gCurrentAnchor; gCurrentAnchor := gForwardAnchor; gForwardAnchor := gCurrentAnchor + (gMSBefore+gMSAfter)*gSamplesPerMS+1; view(gCollisionPlot%); a := XYcount(1); if gCurrentAnchor >= a then dlgcreate("Wrap Around"); dlgText("You just passed the last trial. Click OK and you will see the first trial.",0,2); dlgText(" ",0,3); dlgButton(0,""); dlgButton(1,"OK"); ok% := dlgshow(); gCurrentAnchor := 0; gBackwardAnchor := gCurrentAnchor - ((gMSBefore+gMSAfter)*gSamplesPerMS+1); gForwardAnchor := gCurrentAnchor + (gMSBefore+gMSAfter)*gSamplesPerMS+1; endif XYDelete(2); XYGetData(1, aDataXdel[], aDataYdel[], gCurrentAnchor, gForwardAnchor-1); XYAddData(2, aDataXdel[], aDataYdel[]); return kTrue; 'Stay in toolbar end 'nexttrace '---------------------------------------------------- ' PrevTrace '5/18/04 '---------------------------------------------------- func TracePrev%() var a, ok%, aDataXdel[(gMSBefore+gMSAfter)*gSamplesPerMS+1], aDataYdel[(gMSBefore+gMSAfter)*gSamplesPerMS+1]; gForwardAnchor := gCurrentAnchor; gCurrentAnchor := gBackwardAnchor; gBackwardAnchor := gBackwardAnchor - ((gMSBefore+gMSAfter)*gSamplesPerMS+1); view(gCollisionPlot%); a := XYcount(1); if gCurrentAnchor < 0 then dlgcreate("Wrap Around"); dlgText("You just passed the first trial. Click OK and you will see the last trial.",0,2); dlgText(" ",0,3); dlgButton(0,""); dlgButton(1,"OK"); ok% := dlgshow(); gCurrentAnchor := a - ((gMSBefore+gMSAfter)*gSamplesPerMS+1); gBackwardAnchor := gCurrentAnchor - ((gMSBefore+gMSAfter)*gSamplesPerMS+1); gForwardAnchor := a+1; endif XYDelete(2); XYGetData(1, aDataXdel[], aDataYdel[], gCurrentAnchor, gForwardAnchor-1); XYAddData(2, aDataXdel[], aDataYdel[]); return kTrue; 'Stay in toolbar end '---------------------------------------------------- ' ResetPlot '5/13/04 '---------------------------------------------------- func ResetPlot%() var aStr$; View(gCollisionPlot%); XYdelete(1); 'delete all points gCollisionN := 0; SetCollisionTitle(); return kTrue; 'Stay in toolbar end 'ResetPlot '---------------------------------------------------- ' MyFileClose '5/8/04 '---------------------------------------------------- proc MyFileClose(aWindow%, aQuery) 'aQuery: 0=query -1=no query if ViewKind(aWindow%) >= 0 then '-2=invalid, -1=unknown View(aWindow%); FileClose(0, aQuery); 'Close the window endif end 'MyFileClose '---------------------------------------------------- ' Quit '5/8/04 '---------------------------------------------------- func Quit%() 'If "Quit" is pressed var list%[100], i%; SampleStop(); 'Stop sampling MyFileClose(gDataPlot%, 0); 'Close & query i% := 4096; 'specify XY views ViewList(list%[], i%); 'get a list of the views that match for i% := 0 to list%[0] do if ViewKind(list%[i%]) >= 0 then View(list%[i%]); 'pull up those views FileClose(0, 0);'-1); 'close current, don't query endif next View(LogHandle()); 'Make log view the current view EditSelectAll(); 'Select all text in log view EditClear(); 'Delete it WindowVisible(0); 'Make it visbible return kFalse; 'leave toolbar end 'Quit '---------------------------------------------------- ' DialogParameters '5/8/04 '---------------------------------------------------- func DialogParameters%() var ok%, aStr$, aHigh, aLow, aFreq, aDelay, aDur, aDeadTime, item1$, item2$, item3$, item4$, item5$, aRow := 1, aTab0 := 0, aTab1 := 30, aTab2, aTab3 := 6, aTab4 := 50, aSearchOn$, aSearchOff$, aFreq$,aDur$, aTemp, aBefore$,aAfter$, aSingleDur$, aTrainFreq$, aTrainDur$, aDelay$, aTrainOff$, aOneCycleDur; aTab2 := aTab1 + 9; aBefore$ := Str$(gMSbefore); '1 aAfter$ := Str$(gMSafter); '2 aTemp := SampleSeqVar(hHALFDUR); aSearchOn$ := str$(SampleSeqVar(hHALFDUR)*2.0/100.0); '3 aTemp := SampleSeqVar(hDEADDUR); aSearchOff$ := str$(SampleSeqVar(hDEADDUR)/100.0); '4 aTemp := SampleSeqVar(cLATENCY); aDelay$ := Str$(SampleSeqVar(cLATENCY)/100.0); '5 'type 'type '6 aTemp := SampleSeqVar(cHALFDUR); aSingleDur$ := str$((SampleSeqVar(cHALFDUR)*2.0)/100.0); '7 aTemp := SampleSeqVar(cINTERDUR); aTrainOff$ := str$(SampleSeqVar(cINTERDUR)/100.0); '8 aTemp := SampleSeqVar(tFILLER); aTemp := (SampleSeqVar(cHALFDUR)*2.0)+SampleSeqVar(tFILLER); aTrainFreq$ := str$((1000.0*100.0)/((SampleSeqVar(cHALFDUR)*2.0)+SampleSeqVar(tFILLER))); '9 aTemp := SampleSeqVar(tCYCLES); aTrainDur$ := str$((SampleSeqVar(tCYCLES)*(((SampleSeqVar(cHALFDUR)*2.0)+SampleSeqVar(tFILLER)))/100.0)); '10 dlgcreate("Search & Collision Parameters"); aRow := 1; dlgText("S p i k e D i s p l a y P a r a m e t e r s :", aTab0, aRow); aRow := aRow + 1; dlgstring(1,"Time to Show Before Trigger",aTab3,".0123456789", aTab1, aRow); dlgText("ms", aTab2, aRow); aRow := aRow + 1; dlgstring(2,"Time to Show After Trigger",aTab3,".0123456789", aTab1, aRow); dlgText("ms", aTab2, aRow); aRow := aRow + 3; dlgText("S e a r c h P u l s e P a r a m e t e r s :", aTab0, aRow); aRow := aRow + 1; dlgstring(3,"Biphasic Pulse Width",aTab3,".0123456789", aTab1, aRow); dlgText("ms", aTab2, aRow); aRow := aRow + 1; dlgstring(4,"Interval Between Search Pulses",aTab3,".0123456789", aTab1, aRow); dlgText("ms", aTab2, aRow); aRow := aRow + 3; dlgText("C o l l i s i o n C o m m o n P a r a m e t e r s :", aTab0, aRow); aRow := aRow + 1; dlgstring(5,"Collision Pulse Latency",aTab3,".0123456789", aTab1, aRow); dlgText("ms", aTab2, aRow); aRow := aRow + 1; DlgList(6, "Collision Pulse Type", "Single Pulse|Pulse Train", 20, aTab1, aRow); aRow := aRow + 1; dlgstring(7,"Biphasic Pulse Width",aTab3,".0123456789", aTab1, aRow); dlgText("ms", aTab2, aRow); aRow := aRow + 1; dlgstring(8,"Minimum No-Trigger Interval",aTab3,".0123456789", aTab1, aRow); dlgText("ms", aTab2, aRow); aRow := aRow + 2; dlgText("C o l l i s i o n P u l s e T r a i n P a r a m e t e r s :", aTab0, aRow); aRow := aRow + 1; dlgstring(9,"Pulse Train Freq",aTab3,".0123456789", aTab1, aRow); dlgText("Hz", aTab2, aRow); aRow := aRow + 1; dlgstring(10,"Pulse Train Duration",aTab3,".0123456789", aTab1, aRow); dlgText("ms", aTab2, aRow); aRow := aRow + 1; dlgText("", aTab2, aRow); ok% := dlgshow(aBefore$, aAfter$, aSearchOn$, aSearchOff$, aDelay$, gPulseType%, aSingleDur$, aTrainOff$, aTrainFreq$, aTrainDur$); if ok% > 0 then aTemp := val(aBefore$); gMSbefore := val(aBefore$); '1 aTemp := val(aAfter$); gMSafter := val(aAfter$); '2 aTemp := val(aSearchOn$)*100.0; SampleSeqVar(hHALFDUR, (val(aSearchOn$)/2.0)*100.0); '3 aTemp := val(aSearchOff$)*100.0; SampleSeqVar(hDEADDUR, val(aSearchOff$)*100.0); '4 aTemp := val(aDelay$)*100.0; SampleSeqVar(cLATENCY, val(aDelay$)*100.0); '5 aTemp := gPulseType%; SampleSeqVar(cTYPE, gPulseType%); '6 aTemp := val(aSingleDur$)*100.0; SampleSeqVar(cHALFDUR, (val(aSingleDur$)/2)*100.0); '7 aTemp := val(aTrainOff$)*100.0; SampleSeqVar(cINTERDUR, val(aTrainOff$)*100.0); '8 aOneCycleDur := (1000.0*100.0)/val(aTrainFreq$); 'duration of one cycle aTemp := aOneCycleDur - (val(aSingleDur$))*100.0; 'time leftover after biphasic if aTemp < 0 then aTemp := 0; 'must protect from sending negative durations endif SampleSeqVar(tFILLER, aTemp); '9 gTrainFreq$ := aTrainFreq$; aTemp := (val(aTrainDur$)*100.0)/aOneCycleDur; SampleSeqVar(tCYCLES, (val(aTrainDur$)*100.0)/aOneCycleDur); '10 gTrainDur$ := aTrainDur$; gChangeParam := 1; endif return kTrue; 'Stay in toolbar end 'DialogParameters%