<commit_before>// GamePadController.java
// <NAME>, October 2006, <EMAIL>

/* This controller supports a game pad with two
 analog sticks with axes (x,y) and (z,rz), 12 buttons, a 
 D-Pad acting as a point-of-view (POV) hat, and a 
 single rumbler.

 The sticks are assumed to be absolute and analog, while the 
 hat and buttons are absolute and digital.

 -----
 The sticks and hat data are accessed as compass directions
 (e.g. NW, NORTH). The compass constants are public so they can be 
 used in the rest of the application.

 The buttons values (booleans) can be accessed individually, or 
 together in an array. 

 The rumbler can be switched on/off, and its current status retrieved.

 created by <NAME>, appreciated & hacked up by GroG :)
 */

package org.myrobotlab.service;

import java.util.HashMap;
import java.util.TreeMap;

import net.java.games.input.Component;
import net.java.games.input.Component.Identifier;
import net.java.games.input.Component.POV;
import net.java.games.input.Controller;
import net.java.games.input.Controller.Type;
import net.java.games.input.ControllerEnvironment;
import net.java.games.input.Rumbler;

import org.myrobotlab.framework.Service;
import org.myrobotlab.framework.Status;
import org.myrobotlab.logging.Level;
import org.myrobotlab.logging.LoggerFactory;
import org.myrobotlab.logging.Logging;
import org.myrobotlab.logging.LoggingFactory;
import org.myrobotlab.math.Mapper;
import org.myrobotlab.service.interfaces.ServoControl;
import org.slf4j.Logger;

public class Joystick extends Service {

	private static final long serialVersionUID = 1L;

	public static final int NUM_BUTTONS = 12;
	public static final int BUTTON_OFF = 0;
	public static final int BUTTON_ON = 1;

	// public stick and hat compass positions
	public static final int NUM_COMPASS_DIRS = 9;

	public static final int NW = 0;
	public static final int NORTH = 1;
	public static final int NE = 2;
	public static final int WEST = 3;
	public static final int NONE = 4; // default value
	public static final int EAST = 5;
	public static final int SW = 6;
	public static final int SOUTH = 7;
	public static final int SE = 8;

	public final static Logger log = LoggerFactory.getLogger(Joystick.class.getCanonicalName());

	transient Controller[] controllers;
	TreeMap<String, Integer> controllerNames = new TreeMap<String, Integer>();

	InputPollingThread pollingThread = null;
	int myDeviceIndex = -1;
	transient Controller controller = null;
	HashMap<String, Float> lastValues = new HashMap<String, Float>();

	private Component[] comps; // holds the components
	private int xAxisIdx, yAxisIdx, zAxisIdx, rzAxisIdx;
	// indices for the analog sticks axes
	private int povIdx; // index for the POV hat
	private int buttonsIdx[]; // indices for the buttons

	private Rumbler[] rumblers;
	private int rumblerIdx; // index for the rumbler being used
	private boolean rumblerOn = false; // whether rumbler is on or off

	private HashMap<String, Mapper> mappers = new HashMap<String, Mapper>();

	public void setMapper(String name, float x0, float x1, float y0, float y1) {
		Mapper mapper = new Mapper(x0, x1, y0, y1);
		mappers.put(name, mapper);
	}

	public class InputPollingThread extends Thread {
		public boolean isPolling = false;

		public InputPollingThread(String name) {
			super(name);
		}

		public void run() {

			if (controller == null) {
				error("controller is null - can not poll");<commit_msg>joystick now serializable<commit_after>// GamePadController.java
// <NAME>, October 2006, <EMAIL>

/* This controller supports a game pad with two
 analog sticks with axes (x,y) and (z,rz), 12 buttons, a 
 D-Pad acting as a point-of-view (POV) hat, and a 
 single rumbler.

 The sticks are assumed to be absolute and analog, while the 
 hat and buttons are absolute and digital.

 -----
 The sticks and hat data are accessed as compass directions
 (e.g. NW, NORTH). The compass constants are public so they can be 
 used in the rest of the application.

 The buttons values (booleans) can be accessed individually, or 
 together in an array. 

 The rumbler can be switched on/off, and its current status retrieved.

 created by <NAME>, appreciated & hacked up by GroG :)
 */

package org.myrobotlab.service;

import java.util.HashMap;
import java.util.TreeMap;

import net.java.games.input.Component;
import net.java.games.input.Component.Identifier;
import net.java.games.input.Component.POV;
import net.java.games.input.Controller;
import net.java.games.input.Controller.Type;
import net.java.games.input.ControllerEnvironment;
import net.java.games.input.Rumbler;

import org.myrobotlab.framework.Service;
import org.myrobotlab.framework.Status;
import org.myrobotlab.logging.Level;
import org.myrobotlab.logging.LoggerFactory;
import org.myrobotlab.logging.Logging;
import org.myrobotlab.logging.LoggingFactory;
import org.myrobotlab.math.Mapper;
import org.myrobotlab.service.interfaces.ServoControl;
import org.slf4j.Logger;

public class Joystick extends Service {

	private static final long serialVersionUID = 1L;

	public static final int NUM_BUTTONS = 12;
	public static final int BUTTON_OFF = 0;
	public static final int BUTTON_ON = 1;

	// public stick and hat compass positions
	public static final int NUM_COMPASS_DIRS = 9;

	public static final int NW = 0;
	public static final int NORTH = 1;
	public static final int NE = 2;
	public static final int WEST = 3;
	public static final int NONE = 4; // default value
	public static final int EAST = 5;
	public static final int SW = 6;
	public static final int SOUTH = 7;
	public static final int SE = 8;

	public final static Logger log = LoggerFactory.getLogger(Joystick.class.getCanonicalName());

	transient Controller[] controllers;
	transient Component[] comps; // holds the components

	TreeMap<String, Integer> controllerNames = new TreeMap<String, Integer>();

	transient InputPollingThread pollingThread = null;
	int myDeviceIndex = -1;
	transient Controller controller = null;
	HashMap<String, Float> lastValues = new HashMap<String, Float>();

	// TODO - remove - direction and any details (e.g. index) - should be published
	private int xAxisIdx, yAxisIdx, zAxisIdx, rzAxisIdx;
	// indices for the analog sticks axes
	private int povIdx; // index for the POV hat
	private int buttonsIdx[]; // indices for the buttons

	transient Rumbler[] rumblers;
	int rumblerIdx; // index for the rumbler being used
	boolean rumblerOn = false; // whether rumbler is on or off

	private HashMap<String, Mapper> mappers = new HashMap<String, Mapper>();

	public void setMapper(String name, float x0, float x1, float y0, float y1) {
		Mapper mapper = new Mapper(x0, x1, y0, y1);
		mappers.put(name, mapper);
	}

	public class InputPollingThread extends Thread {
		public boolean isPolling = false;

		public InputPollingThread(String name) {
			super(name);
		}

		public void run() {

			if (controller == null) {
				error("controller is null - can not poll");
{'fraction_non_alphanumeric': 0.08710048949035416, 'fraction_numerical': 0.008926000575871005, 'mean_word_length': 4.262878787878788, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '119104', 'n_tokens_mistral': 2205, 'n_tokens_neox': 2044, 'n_words': 787}