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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
diff -ru audicle-1.0.0.6~/lang/chuck-1.2.1.1/src/util_hid.cpp audicle-1.0.0.6/lang/chuck-1.2.1.1/src/util_hid.cpp
--- audicle-1.0.0.6~/lang/chuck-1.2.1.1/src/util_hid.cpp 2008-03-30 00:29:37.000000000 +0100
+++ audicle-1.0.0.6/lang/chuck-1.2.1.1/src/util_hid.cpp 2008-03-30 00:33:08.000000000 +0100
@@ -7175,14 +7175,139 @@
int WiiRemote_send( const HidMsg * msg ){ return -1; }
const char * WiiRemote_name( int wr ){ return NULL; }
+#define SYSFS_TILTSENSOR_FILE "/sys/devices/platform/applesmc/position"
+#define TILTSENSOR_BUF_LEN 32
+
+static struct t_TiltSensor_data
+{
+ union
+ {
+ struct t_macbook
+ {
+ int x;
+ int y;
+ int z;
+ } macbook;
+ } data;
+ int dataType;
+ int detected;
+ int refcount;
+
+ t_TiltSensor_data()
+ {
+ refcount = 0;
+ dataType = -1;
+ detected = 0;
+ }
+
+} TiltSensor_data;
+enum
+{
+ linuxAppleSMCMacBookDataType
+};
+static int TiltSensor_detect()
+{
+ int fd;
+
+ fd = open(SYSFS_TILTSENSOR_FILE, O_RDONLY);
+
+ if (fd > 0)
+ {
+ TiltSensor_data.dataType = linuxAppleSMCMacBookDataType;
+ TiltSensor_data.detected = 1;
+ close(fd);
+ return 1;
+ }
+
+ TiltSensor_data.detected = -1;
+
+ return 0;
+}
+
+static int TiltSensor_do_read()
+{
+
+ switch(TiltSensor_data.dataType)
+ {
+ case linuxAppleSMCMacBookDataType:
+ char buf[TILTSENSOR_BUF_LEN];
+ int ret, fd;
+ fd = open(SYSFS_TILTSENSOR_FILE, O_RDONLY);
+
+ if (fd < 0) {
+ return -1;
+ }
+ ret = read(fd, buf, TILTSENSOR_BUF_LEN);
+ if (ret < 0) {
+ close(fd);
+ return -1;
+ }
+ if (sscanf(buf, "(%d,%d,%d)\n", &TiltSensor_data.data.macbook.x, &TiltSensor_data.data.macbook.y, &TiltSensor_data.data.macbook.z) != 3) {
+ close(fd);
+ return -1;
+ }
+ close(fd);
+ break;
+ default:
+ return 0;
+ }
+ return 1;
+}
void TiltSensor_init(){}
void TiltSensor_quit(){}
void TiltSensor_probe(){}
-int TiltSensor_count(){ return 0; }
-int TiltSensor_open( int ts ){ return -1; }
-int TiltSensor_close( int ts ){ return -1; }
-int TiltSensor_read( int ts, int type, int num, HidMsg * msg ){ return -1; }
-const char * TiltSensor_name( int ts ){ return NULL; }
+int TiltSensor_count()
+{
+ if(TiltSensor_data.detected == 0)
+ TiltSensor_detect();
+
+ if(TiltSensor_data.detected == -1)
+ return 0;
+ else if(TiltSensor_data.detected == 1)
+ return 1;
+
+ return 0;
+}
+int TiltSensor_open( int ts )
+{
+ if(TiltSensor_data.detected == 0)
+ TiltSensor_detect();
+
+ if(TiltSensor_data.detected == -1)
+ return -1;
+
+ TiltSensor_data.refcount++;
+
+ return 0;
+}
+int TiltSensor_close( int ts )
+{
+ TiltSensor_data.refcount--;
+
+ return 0;
+}
+int TiltSensor_read( int ts, int type, int num, HidMsg * msg )
+{
+
+ if(TiltSensor_data.detected == -1)
+ return -1;
+
+ if(!TiltSensor_do_read())
+ return -1;
+
+ if(TiltSensor_data.dataType == linuxAppleSMCMacBookDataType)
+ {
+ msg->idata[0] = TiltSensor_data.data.macbook.x;
+ msg->idata[1] = TiltSensor_data.data.macbook.y;
+ msg->idata[2] = TiltSensor_data.data.macbook.z;
+ }
+
+ return 0;
+}
+const char * TiltSensor_name( int ts )
+{
+ return "Apple Sudden Motion Sensor";
+}
#endif
|