-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
50 lines (47 loc) · 1.31 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "serio.h"
#include "crc16.h"
#include "joystick.h"
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include <time.h>
#include "ui.h"
void packet_crc(packet_t *p){
p->cksum = htons(compute_crc((char *)p,sizeof(packet_t)-sizeof(uint16_t)));
}
int main(int argc, char ** argv){
char msg[RECVBUF];
if(argc != 3){
printf("Usage: ./serialctl <serial port> <joystick_num>\n");
return 3;
}
short loop=1;
connection_t c;
packet_t ctl;
if(serio_init(&c, argv[1]))
return 2;
if(joystick_init(atoi(argv[2])) != 0)
return 1;
if(joystick_wait_safe() != 0)
return 1;
init_ui();
while(loop){
int overflow = 0;
if(serio_recv(&c, msg) < 0){
printf("Error reading data!\n");
return 2;
}
if(joystick_update(&ctl) != 0){
return 1;
}
packet_crc(&ctl);
if(serio_send(&c, &ctl, sizeof(packet_t)) < 0){
printf("Unable to send data!\n");
return 2;
}
//printf("X: %i, Y: %i, CRC: %i, Resp: %s\n", ctl.stickX, ctl.stickY, ctl.cksum, msg);
refresh_ui(&ctl, msg, overflow);
// usleep(150E3);
}
return 0;
}