diff options
Diffstat (limited to 'test-mvmt.c')
-rw-r--r-- | test-mvmt.c | 65 |
1 files changed, 49 insertions, 16 deletions
diff --git a/test-mvmt.c b/test-mvmt.c index 27f0aa3..e3bdb06 100644 --- a/test-mvmt.c +++ b/test-mvmt.c @@ -71,13 +71,13 @@ int startpipe(char *path, char *input , char *output, ssize_t *size) { exit(EXIT_FAILURE); } if (WIFEXITED(status)) { - printf("\033[10;1H\033[2Kchild exited, status=%d", WEXITSTATUS(status)); + /*printf("\033[24;1H\033[2Kchild exited, status=%d", WEXITSTATUS(status));*/ } else if (WIFSIGNALED(status)) { - printf("\033[10;1H\033[2Kchild killed (signal %d)", WTERMSIG(status)); + printf("\033[24;1H\033[2Kchild killed (signal %d)", WTERMSIG(status)); } else if (WIFSTOPPED(status)) { - printf("\033[10;1H\033[2Kchild stopped (signal %d)", WSTOPSIG(status)); + printf("\033[24;1H\033[2Kchild stopped (signal %d)", WSTOPSIG(status)); } else { - printf("\033[10;1H\033[2KUnexpected status (0x%x)", status); + printf("\033[24;1H\033[2KUnexpected status (0x%x)", status); } } close(fd0[1]); @@ -88,7 +88,7 @@ int startpipe(char *path, char *input , char *output, ssize_t *size) { return 0; } -void split(char *str, char **splitstr) { +int split(char *str, char **splitstr) { char *p; int i=0; p = strtok(str,"\n"); @@ -99,22 +99,26 @@ void split(char *str, char **splitstr) { i++; p = strtok (NULL, "\n"); } + return i; } int main (int argc, char **argv) { - uint8_t u = 0, d = 0, l = 0; - uint8_t r = 0; + uint8_t u = 0, u2 = 0; + uint8_t d = 0, d2 = 0; + uint8_t l = 0, l2 = 0; + uint8_t r = 0, r2 = 0; int frame = 0; double x1 = 224, y1 = 128; int w1 = 16, h1 = 16; double xvel = 0, yvel = 0; int x2 = 256, y2 = 256; int w2 = 64, h2 = 64; + double xvel2 = 0, yvel2 = 0; int stat; char *keys; char *buf = malloc(8193); FILE *fp; - fp = popen("actkbd -Ps", "r"); + fp = popen("actkbd -PsN -d /dev/input/by-path/platform-i8042-serio-0-event-kbd", "r"); printf("\033[2J"); if (fp == NULL) { fprintf(stderr, "Error occured when trying to run actkbd.\n"); @@ -126,44 +130,73 @@ int main (int argc, char **argv) { char *tmp = malloc(4096); char *input = malloc(2049); char *path = malloc(4102); - char ln[129]; + char ln[2049]; + int lines = 0; frame = atoi(strtok(buf, " ")); keys = strtok(NULL, " "); for(int ch = 0; ch<sizeof(ln); ch++) ln[ch] = '\0'; sprintf(path, "%s/clld", getcwd(tmp, 4096)); - sprintf(input, "1\n%i,%i\n%i,%i\n%07.06f,%07.06f\n%i,%i\n%i,%i\n", w1, h1, (int)x1, (int)y1, xvel, yvel, w2, h2, x2, y2); + sprintf(input, "1\n%i,%i\n%i,%i\n%07.06f,%07.06f\n%i,%i\n%i,%i\n%07.06f,%07.06f\n", w1, h1, (int)x1, (int)y1, xvel, yvel, w2, h2, x2, y2, xvel2, yvel2); startpipe(path, input, &ln, &size); char *line[65] = {NULL}; - split(ln, line); + lines = split(ln, line); x1 = atof(strtok(line[2], ",")); y1 = atof(strtok(NULL, "\0")); xvel = atof(strtok(line[3], ",")); yvel = atof(strtok(NULL, "\0")); - u = match(keys, "KEY_W"); - d = (match(keys, "KEY_S") && !match(keys, "KEY_(SHIFT|SLASH|SPACE|SEMICOLON)")); - l = match(keys, "KEY_A") && !match(keys,"KEY_APOSTROPHE"); - r = (match(keys, "KEY_D") && !match(keys, "KEY_(DOWN|DELETE|DOT)")); + x2 = atof(strtok(line[6], ",")); + y2 = atof(strtok(NULL, "\0")); + /*xvel2 = atof(strtok(line[7], ",")); + yvel2 = atof(strtok(NULL, "\0"));*/ + + u = match(keys, "17"); + d = match(keys, "31"); + l = match(keys, "30"); + r = match(keys, "32"); + + u2 = match(keys, "72"); + d2 = match(keys, "80"); + l2 = match(keys, "75"); + r2 = match(keys, "77"); (u) ? (yvel-=0.25) : ((yvel < 0) ? (d ? (yvel+=0.5) : (yvel+=0.25)) : (yvel=yvel)); (d) ? (yvel+=0.25) : ((yvel > 0) ? (u ? (yvel-=0.5) : (yvel-=0.25)) : (yvel=yvel)); (l) ? (xvel-=0.25) : ((xvel < 0) ? (r ? (xvel+=0.5) : (xvel+=0.25)) : (xvel=xvel)); (r) ? (xvel+=0.25) : ((xvel > 0) ? (l ? (xvel-=0.5) : (xvel-=0.25)) : (xvel=xvel)); + yvel = (yvel > 5) ? 5 : (yvel < -5 ? -5 : yvel); xvel = (xvel > 5) ? 5 : (xvel < -5 ? -5 : xvel); + x1+=xvel; y1+=yvel; + (u2) ? (yvel2-=0.25) : ((yvel2 < 0) ? (d2 ? (yvel2+=0.5) : (yvel2+=0.25)) : (yvel2=yvel2)); + (d2) ? (yvel2+=0.25) : ((yvel2 > 0) ? (u2 ? (yvel2-=0.5) : (yvel2-=0.25)) : (yvel2=yvel2)); + (l2) ? (xvel2-=0.25) : ((xvel2 < 0) ? (r2 ? (xvel2+=0.5) : (xvel2+=0.25)) : (xvel2=xvel2)); + (r2) ? (xvel2+=0.25) : ((xvel2 > 0) ? (l2 ? (xvel2-=0.5) : (xvel2-=0.25)) : (xvel2=xvel2)); + + yvel2 = (yvel2 > 5) ? 5 : (yvel2 < -5 ? -5 : yvel2); + xvel2 = (xvel2 > 5) ? 5 : (xvel2 < -5 ? -5 : xvel2); + + x2+=xvel2; + y2+=yvel2; + printf("\033[1;1H\033[2K%s", keys); printf( "\033[E\033[2Kframe: %i, u: %u, d: %u, l: %u, r: %u" "\033[E\033[2Kx1: %i, y1: %i" "\033[E\033[2Kxvel: %07.06f, yvel: %07.06f" "\n\033[2K", frame, u, d, l, r, (int)x1, (int)y1, xvel, yvel); + printf( + "\033[E\033[2Ku2: %u, d2: %u, l2: %u, r2: %u" + "\033[E\033[2Kx2: %i, y2: %i" + "\033[E\033[2Kxvel2: %07.06f, yvel2: %07.06f" + "\n\033[2K", u2, d2, l2, r2, (int)x2, (int)y2, xvel2, yvel2); - if (match(keys, "KEY_Q")) { + if (match(keys, "16")) { printf("\033[2J\033[1;1H"); free(buf); free(tmp); |