aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/linux/src/java/net/java/games/input/LinuxJoystickPOV.java
blob: 2ae5dc2c2e520db8cb42279472ba052d98c91a10 (plain)
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
package net.java.games.input;

import java.io.IOException;

public class LinuxJoystickPOV extends LinuxJoystickAxis {

	private LinuxJoystickAxis hatX;
	private LinuxJoystickAxis hatY;

	LinuxJoystickPOV(Component.Identifier.Axis id, LinuxJoystickAxis hatX, LinuxJoystickAxis hatY) {
		super(id, false);
		this.hatX = hatX;
		this.hatY = hatY;
	}
	
	protected LinuxJoystickAxis getXAxis() {
		return hatX;
	}
	
	protected LinuxJoystickAxis getYAxis() {
		return hatY;
	}
	
	
	
	protected void updateValue() {
		LinuxEnvironmentPlugin.logln("Updating pov " + hatX.getName() + ", " + hatY.getName());
		float last_x = hatX.getPollData();
		float last_y = hatY.getPollData();
		
		resetHasPolled();
		if (last_x == -1 && last_y == -1)
			setValue(Component.POV.UP_LEFT);
		else if (last_x == -1 && last_y == 0)
			setValue(Component.POV.LEFT);
		else if (last_x == -1 && last_y == 1)
			setValue(Component.POV.DOWN_LEFT);
		else if (last_x == 0 && last_y == -1)
			setValue(Component.POV.UP);
		else if (last_x == 0 && last_y == 0)
			setValue(Component.POV.OFF);
		else if (last_x == 0 && last_y == 1)
			setValue(Component.POV.DOWN);
		else if (last_x == 1 && last_y == -1)
			setValue(Component.POV.UP_RIGHT);
		else if (last_x == 1 && last_y == 0)
			setValue(Component.POV.RIGHT);
		else if (last_x == 1 && last_y == 1)
			setValue(Component.POV.DOWN_RIGHT);
		else {
			LinuxEnvironmentPlugin.logln("Unknown values x = " + last_x + " | y = " + last_y);
			setValue(Component.POV.OFF);
		}
	}
}