Home Programmering Floppy styrt web kamera - Styreprogram
Floppy styrt web kamera - Styreprogram PDF Skriv ut E-post
Skrevet av Jens Christoffersen   
torsdag 17. september 2009 12:01
Artikkelindeks
Floppy styrt web kamera
Mekanisk
Kabler
Styreprogram
Video
Alle sider

 

C-programmet som styrer.

Følgende listing er programmet som styrer floppystasjonene. Kan sikkert med fordel lages bedre.

#include
#include
#include
#include
#include
#include
#include

// Definitions
#define BASEPORT 0x3bc // LPT0 or first parallel port on system

// Function Prototyping
int turnOffPort();
int resetCamera();
int mainMenu();
int moveCamera(int);


// Global variables
int giDirection;
int giCameraXPosition;
int giCameraYPosition;
char *strCameraXPosition[2] = {0};
char *strCameraYPosition[2] = {0};


// Functions
int resetCamera() // this function move camera to the LEFT UP position
{
int liSteps;
system ("clear");
printf ("Resetting...\n");

if (giCameraXPosition != 0) // check if camera is allready in LEFT position
{
// Moving cam left
liSteps = 0;
giDirection = 0;
giCameraXPosition = 0;
do {
system ("clear");
moveCamera(giDirection);
liSteps++;
} while (liSteps < 9);
}

if (giCameraYPosition != 0) // check if camera is already in UP position
{
// Moving cam up    
liSteps = 0;
giDirection = 2;
giCameraYPosition = 0;
do {
system ("clear");
moveCamera(giDirection);
liSteps++;
} while (liSteps < 9);
}
return 0;
} // end resetCamera()

int turnOffPort()
{
/* Get access to the ports */
if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);}

/* Set the data signals (D0-7) of the port to all low (0) */
outb(0, BASEPORT);
return 0;
} // turnOffPort()

int moveCamera(giDirection)
{
int liTemp;
int liDirection;
int y,x;
char *strDirection[4] = {0};

strDirection[0] = "LEFT";
strDirection[1] = "RIGHT";
strDirection[2] = "UP";
strDirection[3] = "DOWN";

printf ("Moving camera in %s direction...\n\n",strDirection[giDirection]);

if (giDirection == 0)
{
liDirection = 1;
}
if (giDirection == 1)
{
liDirection = 3;
}
if (giDirection == 2)
{
liDirection = 4;
}
if (giDirection == 3)
{
liDirection = 12;
}

y=0;

do
{
ioperm(BASEPORT, 3, 1);

liTemp = fcntl(0, F_GETFL, 1);
fcntl (0, F_SETFL, (liTemp | O_NDELAY));

for (x=0;x<8;x++) {
outb(liDirection, BASEPORT); // sending correct HIGH/LOW to the right pin
usleep(1000);
}

fcntl(0, F_SETFL, liTemp);
outb(0, BASEPORT);

if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}
y++;
} while (y<9);

return 0;

} // end moveCamera(giDirection)


int mainMenu()
{
int iMenuChoice = 0;
int steps;
while (iMenuChoice != 1)
{
system ("clear");
printf ("*******************************************************************\n");
printf ("*    Simple program to control my customized fdd driven web cam   *\n");
printf ("*******************************************************************\n\n");
printf ("Cameraposition:%s - %s\n\n",strCameraXPosition[giCameraXPosition], strCameraYPosition[giCameraYPosition]);
printf ("\t\t1.\tExit program.\n");
printf ("\t\t2.\tReset camera.\n");
printf ("\t\t3.\tMove camera left.\n");
printf ("\t\t4.\tMove camera right.\n");
printf ("\t\t5.\tMove camera up.\n");
printf ("\t\t6.\tMove camera down.\n");
printf ("\n\tEnter choice: ");
scanf ("%d", &iMenuChoice);

switch (iMenuChoice)
{
case 2:
resetCamera();
break;
case 3:
if (giCameraXPosition == 0) // stop camera from moving LEFT if its already in LEFT position
{
break;
}
steps = 0;
giDirection = 0;
giCameraXPosition = 0;
do {
system ("clear");
moveCamera(giDirection);
steps++;
} while (steps < 9);
turnOffPort();

break;
case 4:
if (giCameraXPosition == 1) // stop camera from moving RIGHT if its already in RIGHT position
{
break;
}
steps = 0;
giDirection = 1;
giCameraXPosition = 1;
do {
system ("clear");
moveCamera(giDirection);
steps++;
} while (steps < 9);
turnOffPort();

break;
case 5:
if (giCameraYPosition == 0) // stop camera from moving UP if its already in UP position
{
break;
}
steps = 0;
giDirection = 2;
giCameraYPosition = 0;
do {
system ("clear");
moveCamera(giDirection);
steps++;
} while (steps < 9);
turnOffPort();

break;
case 6:
if (giCameraYPosition == 1) // stop camera from moving DOWN if its already in DOWN position
{
break;
}
steps = 0;
giDirection = 3;
giCameraYPosition = 1;
do {
system ("clear");
moveCamera(giDirection);
steps++;
} while (steps < 9);
turnOffPort();

break;
} // end switch
} // end while
return 0;
} // end mainMenu()




int main()
{
strCameraXPosition[0] = "LEFT";
strCameraXPosition[1] = "RIGHT";

strCameraYPosition[0] = "UP";
strCameraYPosition[1] = "DOWN";

turnOffPort();

mainMenu();
turnOffPort();
resetCamera();

printf ("\n\nQuitting...bye bye\n\n");
printf ("*******************************************************************\n");
printf ("* This small program is made in the c programming language.       *\n");
printf ("* Written in gedit on an Ubuntu 9.04 installation. With           *\n");
printf ("* build-essentials package installed, and the ncurses library     *\n");
printf ("* installed.                                                      *\n");
printf ("* Compile command:                                                *\n");
printf ("* clear && gcc -Wall -lncurses cam-control.c -o cam-control       *\n");
printf ("*                                            nerdegutta.org 2009  *\n");
printf ("*******************************************************************\n\n\n");

return 0;
}

 

Brukergrensesnittet kan med fordel bli mye bedre.

 

Kompilert med:

gcc cam-control.c -lncurses -o cam-control

 

 



Comments (0)
Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:D:):(:0:shock::confused:8):lol::x:P:oops::cry:
:evil::twisted::roll::wink::!::?::idea::arrow:
Sist oppdatert onsdag 10. mars 2010 20:28
 
Kopirett © 2010 nerdegutta.org. Alle rettigheter reservert.
Joomla! er fri programvare utgitt under GNU/GPL License.