- Timestamp:
- Dec 1, 2009, 10:51:51 PM (15 years ago)
- Location:
- liacs/mss/project
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
liacs/mss/project/Makefile
r15 r17 1 1 CFLAGS=-g 2 2 3 CFLAGS+= -I/usr/include/opencv -lcxcore -lcv -lhighgui -lcvaux -lml 3 CFLAGS+= -I/usr/include/opencv -lcxcore -lcv -lhighgui -lcvaux -lml -lX11 -lXtst 4 4 5 5 all: uinput … … 9 9 ./colour-tracking 1 10 10 11 colour-tracking: xdo.o 12 -
liacs/mss/project/colour-tracking.c
r15 r17 9 9 #include <highgui.h> 10 10 #include <stdio.h> 11 #include "xdo.h" 11 12 12 13 #define DEBUG 1 … … 15 16 #define GVALUE(x,y,step) (x*step+y*3+1) 16 17 #define BVALUE(x,y,step) (x*step+y*3+0) 18 19 /* XXX: Global variables */ 20 xdo_t *xdo; 17 21 18 22 /* Used for playing with bounderies, returned max value of the pair */ … … 67 71 int r, g, b; 68 72 int q; 73 int retval; 74 char arg1[4], arg2[4]; 69 75 70 76 … … 149 155 cvCopy(output,filter, NULL); 150 156 cvCircle(target, cvPoint(xmax, ymax), 10, CV_RGB(255,0,0),4, 8, 0); 157 xdo_mousemove(xdo,xmax,ymax); 151 158 152 159 … … 181 188 // Quick at 1.0.0, not needing in 2.0x anymore 182 189 int main(int argc, char *argv[]) { 183 return InitSystem(argc, argv); 190 int retval; 191 xdo = xdo_new(getenv("DISPLAY")); 192 retval = InitSystem(argc, argv); 193 xdo_free(xdo); 184 194 } -
liacs/mss/project/uinput.c
r16 r17 66 66 &event.xbutton.state); 67 67 68 //printf("Mouse Coordinates: %d %d\n", event.xbutton.x, event.xbutton.y);68 printf("Mouse Coordinates: %d %d\n", event.xbutton.x, event.xbutton.y); 69 69 XCloseDisplay( dsp ); 70 70 xy_current.x = event.xbutton.x; … … 90 90 device.id.version=UINPUT_VERSION; 91 91 92 for (i=0; i < ABS_MAX; i++) {93 device.absmax[i] = -1;94 device.absmin[i] = -1;95 device.absfuzz[i] = -1;96 device.absflat[i] = -1;97 }92 //for (i=0; i < ABS_MAX; i++) { 93 // device.absmax[i] = -1; 94 // device.absmin[i] = -1; 95 // device.absfuzz[i] = -1; 96 // device.absflat[i] = -1; 97 //} 98 98 99 99 if (write(fd,&device,sizeof(device)) != sizeof(device)) … … 109 109 * Also, mouse buttons have to send sync events. 110 110 */ 111 ioctl(fd, UI_SET_EVBIT, EV_KEY);111 //ioctl(fd, UI_SET_EVBIT, EV_KEY); 112 112 ioctl(fd, UI_SET_EVBIT, EV_REL); 113 113 ioctl(fd, UI_SET_EVBIT, EV_SYN); … … 115 115 ioctl(fd, UI_SET_RELBIT, REL_X); 116 116 ioctl(fd, UI_SET_RELBIT, REL_Y); 117 ioctl(fd, UI_SET_RELBIT, REL_WHEEL);117 //ioctl(fd, UI_SET_RELBIT, REL_WHEEL); 118 118 119 119 ioctl(fd, UI_SET_KEYBIT, BTN_LEFT); 120 ioctl(fd, UI_SET_KEYBIT, BTN_RIGHT);121 ioctl(fd, UI_SET_KEYBIT, BTN_MIDDLE);120 //ioctl(fd, UI_SET_KEYBIT, BTN_RIGHT); 121 //ioctl(fd, UI_SET_KEYBIT, BTN_MIDDLE); 122 122 123 for (i=0; i < 256; i++) {124 ioctl(fd, UI_SET_KEYBIT, i);125 }123 //for (i=0; i < 256; i++) { 124 // ioctl(fd, UI_SET_KEYBIT, i); 125 //} 126 126 127 127 ioctl(fd, UI_DEV_CREATE, NULL); … … 130 130 131 131 int set_pointer(const struct coords xy_target) { 132 struct coords xy_current, xy_diff; 132 struct coords xy_diff, xy_prev; 133 struct coords xy_current = { -1 , -1 }; // Bogus inital value 134 char c; 133 135 // Force pointer to absolute location on the screen 134 136 while ( 1 ) { 135 xy_current = get_coords(); 136 xy_diff.x = -(xy_current.x - xy_target.x); 137 xy_diff.y = -(xy_current.y - xy_target.y); 137 //XXX: Screen pointer get updated really slow 138 xy_prev.x = xy_current.x; 139 xy_prev.y = xy_current.y; 140 while ( 1 ) { 141 xy_current = get_coords(); 142 // Found ourself an update 143 printf("old->new coordinates %ix%i -> %ix%i\n", 144 xy_prev.x,xy_prev.y, 145 xy_current.x,xy_current.y); 146 if (xy_prev.x != xy_current.x || xy_prev.y != xy_current.y) { 147 //ex_program(1); 148 break; 149 } 150 usleep(200000); 151 } 152 153 xy_diff.x = (xy_target.x - xy_current.x); 154 xy_diff.y = (xy_target.y - xy_current.y); 138 155 if (xy_diff.x == 0 && xy_diff.y == 0) { 156 printf("Location %ix%i\n", xy_current.x, xy_current.y); 139 157 break; 140 158 } else { … … 146 164 send_event(fd, EV_REL, REL_Y, xy_diff.y); 147 165 send_event(fd, EV_SYN, SYN_REPORT, 0); 148 // Wait some small period of time to get it populated (and the screen get updated 149 usleep(2000000); 150 break; 166 // Wait some small period of time to get it populated (and the screen get updated) 167 usleep(200000); 151 168 } 152 169 } … … 155 172 int 156 173 main() { 157 struct coords xy_target = { 500,500 };174 struct coords xy_target = { 200,200 }; 158 175 init_pointer(); 159 176 set_pointer(xy_target); 160 xy_target.x = 700;161 xy_target.y = 700;177 xy_target.x = 500; 178 xy_target.y = 500; 162 179 set_pointer(xy_target); 163 180 close_pointer();
Note:
See TracChangeset
for help on using the changeset viewer.