javaInterface: OswaldInterface.java

File OswaldInterface.java, 1.4 kB (added by goskab, 6 months ago)

Oswald abstraction layer

Line 
1 /**
2  * abstraction class for the OswaldInterface.
3  * runs on top of the Joystick class, will work
4  * with any joystick on a linux 2.6 kernel
5  * @author goskab
6  */
7 public class OswaldInterface {
8         Joystick js;
9        
10         /**
11          * Make a new oswald interface object, this
12          * will open the joystick and watch the values
13          * that come from it, ask the object for values
14          * to check the input from the user.
15          */
16         public OswaldInterface() {
17                 js = new Joystick("/dev/input/js0");
18         }
19        
20         /**
21          * get the X axis on the touchpad
22          * (not touchscreen)
23          * @return integer (+/- ~32000 max)
24          */
25         public int getTouchX() {
26                 return js.getAxis(0);
27         }
28        
29         /**
30          * get the Y axis on the touchpad
31          * (not touchscreen)
32          * @return integer (+/- ~32000 max)
33          */
34         public int getTouchY() {
35                 return js.getAxis(1);
36         }
37        
38         /**
39          * get the X axis on the accelerometer
40          * @return integer (+/- ~32000 max)
41          */
42         public int getAccelX() {
43                 return js.getAxis(2);
44         }
45
46         /**
47          * get the Y axis on the accelerometer
48          * @return integer (+/- ~32000 max)
49          */
50         public int getAccelY() {
51                 return js.getAxis(3);
52         }
53        
54         /**
55          * get the Z axis on the accelerometer
56          * @return integer (+/- ~32000 max)
57          */
58         public int getAccelZ() {
59                 return js.getAxis(4);
60         }
61        
62         /**
63          * get the value of a button (includes up,
64          * down, left, right).
65          * @param num button number
66          * @return true if pressed, false if not
67          */
68         public boolean getButton(int num) {
69                 return js.getButton(num);
70         }
71 }