PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Wer spricht C auf Linux?



carlitoco
24.10.2008, 14:38
Ich möchte mir in der linux Konsole bash auf Slackware mit Hilfe eines in C/C++ geschriebenen Programm die Mauskoordinaten ausgeben lassen.
Das Ganze soll dann Servos ansteuern, die an den RP6 Roboter angeschlossen sind.
Dieser code wurde mir von robocat gegeben, jedoch ist er für windows

gruss
carlitoco


// einfaches konsolenprogramm um mauskoordinaten anzuzeigen

#include <windows.h> // for API functions
#include <stdio.h> // for printf

int main()
{
CURSORINFO cursorinfo;
POINT p;

for(;;)
{
// structure wants to know its size
cursorinfo.cbSize=sizeof(CURSORINFO);

// fill the cursorinfo structure
GetCursorInfo(&cursorinfo);

// copy mouse coordinates to p
// not necessary; cursorinfo.ptScreenPos.x could be used directly
p=cursorinfo.ptScreenPos;

// output coordinates
printf("x:%d,y:%d\n",p.x,p.y);

// sleep for 100ms to keep cpu load low
Sleep(100);
}
return 0;
}

Mixxer
24.10.2008, 15:01
Hallo,

da hast du wohl noch n bisschen Arbeit, bis das auf Linux portiert ist. Hier mal die Fehler beim compilieren mit m g++:
mouse.cpp:3:43: error: windows.h: No such file or directory
mouse.cpp: In function ‘int main()’:
mouse.cpp:8: error: ‘CURSORINFO’ was not declared in this scope
mouse.cpp:8: error: expected `;' before ‘cursorinfo’
mouse.cpp:9: error: ‘POINT’ was not declared in this scope
mouse.cpp:9: error: expected `;' before ‘p’
mouse.cpp:14: error: ‘cursorinfo’ was not declared in this scope
mouse.cpp:17: error: ‘GetCursorInfo’ was not declared in this scope
mouse.cpp:21: error: ‘p’ was not declared in this scope
mouse.cpp:27: error: ‘Sleep’ was not declared in this scope


Die windows.h kannst du gleich mal komplett rauswerfen, dann würd ich mal schauen wie die Funktionen für die Mauspositionen bei Linux heißen!
Bin jetzt nicht so der C-freak sonnst würd ich dir mehr helfen (können)!

MFG Mixxer

geronet
24.10.2008, 15:49
Eventuell hilft dir da ein Tipp auf /dev/input/mice weiter..

carlitoco
27.10.2008, 08:28
Das hat ein bekannter "übersetzt".


#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>

#include <linux/input.h>

#define MOUSEFILE "/dev/input/event7"

/* oder wenn nicht usb mouse sondern trackpoint:
#define MOUSEFILE "/dev/input/event5"

*/

int main()
{
int fd;
struct input_event ie;

if((fd = open(MOUSEFILE, O_RDONLY)) == -1) {
perror("opening device");
exit(EXIT_FAILURE);
}

while(read(fd, &ie, sizeof(struct input_event))) {
printf("time %ld.%06ld\ttype %d\tcode %d\tvalue %d\n",
ie.time.tv_sec, ie.time.tv_usec, ie.type,
ie.code, ie.value); }

return 0;
}[/code]