/
opengalax.h
131 lines (106 loc) · 2.54 KB
/
opengalax.h
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* opengalax touchscreen daemon
* Copyright 2012 Pau Oliva Fora <pof@eslack.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <signal.h>
#include <linux/uinput.h>
#include <sys/stat.h>
#define XA_MAX 0xF
#define YA_MAX 0xF
#define XB_MAX 0x7F
#define YB_MAX 0x7F
#define X_AXIS_MAX (XA_MAX+1)*(XB_MAX+1)
#define Y_AXIS_MAX (YA_MAX+1)*(YB_MAX+1)
#define CMD_OK 0xFA
#define CMD_ERR 0xFE
#define PRESS 0x81
#define RELEASE 0x80
#define BTN1_RELEASE 0
#define BTN1_PRESS 1
#define BTN2_RELEASE 2
#define BTN2_PRESS 3
#define DEBUG 0
#define die(str, args...) do { \
perror(str); \
exit(EXIT_FAILURE); \
} while(0)
/* config file */
typedef struct {
char serial_device[1024];
char uinput_device[1024];
int rightclick_enable;
int rightclick_duration;
int rightclick_range;
int direction;
int psmouse;
} conf_data;
typedef struct {
int xmin;
int xmax;
int ymin;
int ymax;
} calibration_data;
int fd_serial, fd_uinput;
struct uinput_user_dev uidev;
int use_psmouse;
/* configfile.c */
int create_config_file (char* file);
conf_data config_parse (void);
calibration_data calibration_parse (void);
/* functions.c */
int running_as_root (void);
int time_elapsed_ms (struct timeval *start, struct timeval *end, int ms);
int configure_uinput (void);
int setup_uinput (void);
int setup_uinput_dev (const char *ui_dev);
int open_serial_port (const char *fd_device);
int init_panel ();
void initialize_panel (int sig);
void signal_handler (int sig);
void signal_installer (void);
int file_exists (char *file);
char* default_pid_file (void);
int create_pid_file (void);
int remove_pid_file (void);
/* psmouse.c */
void uinput_open(const char *uinput_dev_name);
int psmouse_connect();
void uinput_create();
int phys_wait_for_input(int *ptimeout);
void psmouse_interrupt(unsigned char data);
void uinput_destroy();
void uinput_close();
void psmouse_disconnect();
/*
init sequence:
send: f5 f3 0a f3 64 f3 c8 f4
read: fa fa fa fa fa fa fa fa
return values:
0xFA == OK
0xFE == ERROR
Example PDUs:
81 0F 3D 05 06
80 0F 3D 05 06
byte 0:
0x80 == PRESS
0x81 == RELEASE
byte 1:
X axis value, from 0 to 0x0F
byte 2:
X axis value, from 0 to 0x7F
byte 3:
Y axis value, from 0 to 0x0F
byte 4:
Y axis value, from 0 to 0x7F
*/