main.cpp

The main code of the program

In this part of the program all modules defined in ctrl.cpp are compiled to a program. Also there are some general things done before. The main program is an endless loop that waits for user input and after input starts an according action, and - when finished that action - returns to the loop again..
Here's the code:
First a comment header with information about the author, license, and coresponding files.
//=================================================================================================
//
// ProjektNAME: BlueIO
// FileName: main.cpp
//
// Corresponding files:
// myIncludes.h - central list of used includes
// myio.h, - DAQ class declaration
// fio.h - FIO class declaration
// ctrl.h - header for control class
// LED.h - header for visual stimulus class
// myIO.cpp - class DAQ (analog I/O)
// fio.cpp - class FIO (disk I/O operation)
// crtl.cpp - class CTRL (program control)
// LED.cpp - class LED (visual stimulus)
//
// AUTHOR: [ujb] ulrich.beckers1@uni-bielefeld.de
//
// LICENSE: Free to use, free to modify for own use. No publication of the binary nor the sources
// by a 3rd party allowed!
// No commercial use without permission from the original author.
// Author must be noted when program is used publically.
//
// HOMEPAGE: http://via.i-networx.de/BlueIO/about.htm

Note the following important information: Never ever forget to adjust the date and version string in ctrl.cpp!!
//
// DATE: 12-Aug-2009
//
// VERSION: 1.7.1
//
// NOTE: Whenever changes are made, backup the previous version and change the *date* and version
// in ctrl.cpp CTRL::startup()
//
The rest of the comment header is rather trivial, it's just some history stuff.
// HISTORY: 0.1 - 1.0 see MyIO, last release has been 0.8.3.1 (14-09-06)
// V 1.1 spin off to new version, changed current output to 2s in random order (B3 and B2),
[...]
//=================================================================================================
#include "myIncludes.h"
This include directive calls a central include file that cares for *all* required header files. After the include the actual program starts.
First action is to create an object of the class CTRL, because barely anything is not controlled by this class. The main programm is basically just a list of calls of functions of this class.
But first some other things are done:
//*** M A I N *** M A I N *** M A I N *** M A I N *** M A I N *** M A I N ***

int main()
{
CTRL myCTRL;
char ch=0;
bool UAE=false;
HANDLE hProcess=NULL;

cout<<"* This is the phreaky-phunky recording suite for tweaking and teasing VS/V1 *"< cout<<"* with some nice voltage clamp and other BIG FUN things using up 2 all 3 sub- *"< cout<<"* systems of the incredible PD2-MFS Board and 2304 B L U E ultrabright LEDs *"<

After a warm welcome the program looks whether WinUAE is started alredy or not. If not it alerts the user about that! This routine starts at BEGIN WinUAE and ends at END WinUAE. Then the task priority for this program is set to "high" (again indicated by BEGIN and END).
// BEGIN WinUAE finden
[...]
// END WinUAE finden
// BEGIN Programpriorität hoch
[...]
// END Programpriorität hoch
Now the actual program starts. The DAQ board is prepared by the myCTRL.startup() function. Then the main loop for user input is started with the while statement. Depending on the input the program switches by parsing the input in the if...else statements to the according action.
myCTRL.startup(); // DAQ, LED und SEC bereit machen

while (ch=true) // endless loop
{
cout< cout<<" l for LED functions"< cout<<" i for a card reset"< cout<<" o for analog out only"< cout<<" r for standard recordings menu"< cout<<" v for several VC tests (rectangle jumps or ramp w/ or w/o stripes)"< cout<<" b for current different pulse injections"< cout<<" k for prolonged visual stimuli in VC, bridged or both rec modes"< cout<<" f rm #13 MAN - AIN + stripes (pd endless)"< cout<<" p for preferences menu"< cout<<" c for list of current settings"< cout<<" a for about"< cout<<" q for ending this session"<
myCTRL.namefalse();
cin>>ch;
Most actions are just simple calls of myCTRL.*(). Exemplarily a few calls are reprinted here. I think this is rather self explaining. To look what these functions actually do, check the CTRL section.
if (ch=='q' || ch =='Q') // Leaving the loop and exit immediately
{
myCTRL.quit();
return 0; //... und Ende!
}
else
if (ch=='i' || ch =='I') // init card again
{
myCTRL.openclose();
}
else

Now we have some subloops to broaden the choice. It is quite similar to the main loop. The loop waits for some user input and parses the input and jumps to the according action. I used switch instead of if...else here.
if (ch=='l' || ch=='L') // Several recording options
{
char x=NULL;
while (x!=57) // LED menu
{
cout<<" Now chose your LED option:"< cout<<" 1 toogling LED on/off"< cout<<" 2 vertical stripes (pd nd)"< cout<<" 3 vert stripes (pd endless)"< cout<<" 4 vert stripes (nd endless)"< cout<<" 5 horiz stripes (pd nd)"< cout<<" 6 classification pattern test"< cout<<" 7 for an Oops!"< cout<<" 9 for going back to the mainmenu"<< endl;
cout<<" any other key to return to main menu"< cin>> x;
switch (x)
{
case 49: myCTRL.flash(); break; // 1=LED an/aus
case 50: myCTRL.stripeX(); break; // 2=Stripes vert
case 51: myCTRL.down(); break; // 3= Stripes down
case 52: myCTRL.up(); break; // 4= Stripes up
case 53: myCTRL.stripesH(); break; // 5= Stipes horiz
case 54: myCTRL.VStest(); break; // 6= VS classification
case 55: myCTRL.oops(); break;
case 57: cout<<"Okay - going back to main menu"; break;
default: cout<<"Sorry - "< }
}
}
else

[...]
if (ch=='r' || ch=='R') // Several recording options
{
char x=NULL;
cout<<" Now chose your recording option:"<<endl;

[...] skipped some console text. Now functions are called that require some parameters. The meaning of these parameters is to obtain from the CTRL header section.
cin>> x;
switch (x)
{
case 48: myCTRL.AIN(true, NULL, NULL); break; //0
case 49: myCTRL.AIN(false, NULL, NULL); break; //1
case 50: myCTRL.MT_AInStripes(true, NULL, NULL); break; //2
case 51: myCTRL.MT_AInAOutStri(false, NULL, NULL, true); break; //3
case 52: myCTRL.MT_AInAOut(false, NULL, NULL, true); break; //4
case 53: myCTRL.MT_AInAOutSetS(false, NULL, NULL); break; //5
case 54: myCTRL.MT_AInRandomStripes(true, NULL, NULL); break; //6
case 55: myCTRL.MT_AInAOutStri(true, NULL, NULL, false); break; //7
case 56: myCTRL.MT_AInAOut(true, NULL, NULL, false); break; //8
case 57: myCTRL.MT_AInVStest(true, NULL, NULL); break; //9

default: cout<<"Sorry - "< }
}
else

[...]
skipped some other subloops. Look into main.cpp for skipped part. It should be rather selfexplaining, no magic included.
The next subloop introduces even longer parameter lists, that are also kind of overloaded (this has nothing to do wih C++ overloading though..). i.e. depending from the other started threads some parameters are interpreted in a different way.
In this particular case this is true for the myCTRL.MT.AInLStripes(...) function: Prameter #2 & #3 get either interpreted as int values or boolean flags. I.e. the actual number set here gets overridden in many cases. Nevertheless it is wise to keep the numbers here for better readability and for correct timing if the function is called in another context (when the parameter doesn't get overridden).
NOTE: Check the CTRL section for details about the parameters.

if (ch=='k' || ch=='K') // list of *c*urrent settings
{
char x=NULL;
cout<<" VC vs. VC - BRI - VC"<
cout<<" 0 rm#14 - VC - prolonged stripe pattern (vert PD)"<
[...]
cout<<" 4 rm#14 - VC/BRI - BRI while stripes are moving (vert PD)"< cout<<" 5 rm#15 - VC/BRI - BRI while stripes are moving (vert ND)"<
[...]
cout<<" any other key to return to main menu"< cin>> x;
switch (x)
{
case 48: myCTRL.MT_AInLStripes(false, NULL, NULL, true, true); break;
case 49: myCTRL.MT_AInLStripes(false, NULL, NULL, true, false); break;
case 50: myCTRL.MT_AInLStripes(false, NULL, NULL, false, true); break;
case 51: myCTRL.MT_AInLStripes(false, NULL, NULL, false, false); break;

case 52: myCTRL.MT_AInLStripes(false, 2000, 4000, true, true); break;
case 53: myCTRL.MT_AInLStripes(false, 2000, 4000, true, false); break;
case 54: myCTRL.MT_AInLStripes(false, 2000, 4000, false, true); break;
case 55: myCTRL.MT_AInLStripes(false, 2000, 4000, false, false); break;

case 56: myCTRL.MT_AInLStripes(true, NULL, NULL, true, true); break;
case 57: myCTRL.MT_AInLStripes(true, NULL, NULL, true, false); break;
case 42: myCTRL.MT_AInLStripes(true, NULL, NULL, false, true); break;
case 43: myCTRL.MT_AInLStripes(true, NULL, NULL, false, false); break;

case 97: myCTRL.MT_AInLStripes(true, 2000, 4000, true, true); break;
case 98: myCTRL.MT_AInLStripes(true, 2000, 4000, true, false); break;
case 99: myCTRL.MT_AInLStripes(true, 2000, 4000, false, true); break;
case 100: myCTRL.MT_AInLStripes(true, 2000, 4000, false, false); break;

default: cout<<"Sorry - "< }
}

[...]
else
{
cout<<"Sorry mate, "< }
} // diese Klammer gehört zur while(ch=true) Bedingung"

// "Notaus" sollte ch = false eintreten.
cout<<"Exit now!";
myCTRL.quit();
return 0;
}

// T H E E N D ! ! !


back to the code manual page

back to the Blue IO main page

back to main page and contact information
--
latest change: 26-08-2009 -- (c) U. Beckers