diff --git a/WiiUseJ/src/wiiusej/WiiUseApiRequestsManager.java b/WiiUseJ/src/wiiusej/WiiUseApiRequestsManager.java deleted file mode 100644 index b3ac993..0000000 --- a/WiiUseJ/src/wiiusej/WiiUseApiRequestsManager.java +++ /dev/null @@ -1,162 +0,0 @@ -package wiiusej; - -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.Semaphore; - -import wiiusej.wiiuseapirequest.FloatValueRequest; -import wiiusej.wiiuseapirequest.IntValueRequest; -import wiiusej.wiiuseapirequest.LedsRequest; -import wiiusej.wiiuseapirequest.TwoIntValueRequest; -import wiiusej.wiiuseapirequest.WiiUseApiRequest; - -/** - * This class is thread dedicated to send request to WiiUseApi. It is used only - * (and must be used only) by WiiUseApiManager. - * - * @author guiguito - * - */ -public class WiiUseApiRequestsManager extends Thread { - - //protected Semaphore semaphore = new Semaphore(0); - private WiiUseApi wiiuse = WiiUseApi.getInstance(); - private ConcurrentLinkedQueue requests = new ConcurrentLinkedQueue(); - private static WiiUseApiRequestsManager instance = new WiiUseApiRequestsManager(); - private boolean running = false; - - /** - * Default constructor. - */ - WiiUseApiRequestsManager() { - super(); - } - - public static WiiUseApiRequestsManager getInstance() { - return instance; - } - - public void addRequests(WiiUseApiRequest request) { - requests.add(request); - //semaphore.release(); - synchronized (requests) { - requests.notify(); - } - } - - public void run() { - running = true; - while (running) { - /* deal with requests done to wiiuse API */ - - /* - try { - semaphore.acquire(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - */ - if (requests.size()==0){ - synchronized (requests) { - try { - requests.wait(); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - - WiiUseApiRequest req = requests.poll(); - if (req != null) {// there is a request for the wiiuse api - int id = req.getId(); - synchronized (wiiuse) {// synchronized on wiiuseApi - if (req.getRequestType() == WiiUseApiRequest.WIIUSE_CLOSE_CONNECTION_REQUEST) { - /* Close connections requests */ - wiiuse.closeConnection(id); - if (WiiUseApiManager.getInstance() - .getNbConnectedWiimotes() <= 0) { - this.shutdown(); - } - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_STATUS_REQUEST) { - /* Status requests */ - wiiuse.getStatus(id); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ACTIVATE_RUMBLE_REQUEST) { - /* Activate Rumble requests */ - wiiuse.activateRumble(id); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_DEACTIVATE_RUMBLE_REQUEST) { - /* Deactivate Rumble requests */ - wiiuse.deactivateRumble(id); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ACTIVATE_IR_TRACKING_REQUEST) { - /* Activate IR Tracking requests */ - wiiuse.activateIRTracking(id); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_DEACTIVATE_IR_TRACKING_REQUEST) { - /* Deactivate IR Tracking requests */ - wiiuse.deactivateIRTracking(id); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ACTIVATE_MOTION_SENSING_REQUEST) { - /* Activate Motion sensing requests */ - wiiuse.activateMotionSensing(id); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_DEACTIVATE_MOTION_SENSING_REQUEST) { - /* Deactivate Motion sensing requests */ - wiiuse.deactivateMotionSensing(id); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_LEDS_REQUEST) { - /* leds requests */ - LedsRequest reqLed = (LedsRequest) req; - wiiuse.setLeds(id, reqLed.isLed1(), reqLed.isLed2(), - reqLed.isLed3(), reqLed.isLed4()); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ACTIVATE_SMOOTHING_REQUEST) { - /* Activate smoothing requests */ - wiiuse.activateSmoothing(id); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_DEACTIVATE_SMOOTHING_REQUEST) { - /* Deactivate smoothing requests */ - wiiuse.deactivateSmoothing(id); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ACTIVATE_CONTINUOUS_REQUEST) { - /* Activate continuous requests */ - wiiuse.activateContinuous(id); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_DEACTIVATE_CONTINUOUS_REQUEST) { - /* Deactivate continuous requests */ - wiiuse.deactivateContinuous(id); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ORIENT_THRESHOLHD_REQUEST) { - /* set orientation threshold request */ - wiiuse.setOrientThreshold(req.getId(), - ((FloatValueRequest) req).getFloatValue()); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ACCEL_THRESHOLHD_REQUEST) { - /* set acceleration threshold request */ - wiiuse.setAccelThreshold(req.getId(), - ((IntValueRequest) req).getIntValue()); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ALPHA_SMOOTHING_REQUEST) { - /* set alpha smoothing request */ - wiiuse.setAlphaSmoothing(req.getId(), - ((FloatValueRequest) req).getFloatValue()); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_RESYNC) { - /* set resync request */ - wiiuse.reSync(req.getId()); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ASPECT_RATIO_4_3) { - /* set screen aspect ratio to 4/3 */ - wiiuse.setScreenRatio43(req.getId()); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ASPECT_RATIO_16_9) { - /* set screen aspect ratio to 16/9 */ - wiiuse.setScreenRatio169(req.getId()); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_SENSOR_BAR_ABOVE) { - /* set sensor bar above the screen */ - wiiuse.setSensorBarAboveScreen(req.getId()); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_SENSOR_BAR_BELOW) { - /* set sensor bar above the screen */ - wiiuse.setSensorBarBelowScreen(req.getId()); - } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_SET_VIRTUAL_RESOLUTION) { - /* set virtual resolution */ - wiiuse.setVirtualScreenResolution(req.getId(), - ((TwoIntValueRequest) req).getIntValue(), - ((TwoIntValueRequest) req).getSecondIntValue()); - } else { - System.out.println("Bad request to Wiiuse API !!!!!"); - } - }// end synchronized on wiiuseApi - }//if (req != null) - }//end while(running) - } - - public void shutdown() { - running = false; - } - -} diff --git a/WiiUseJ/src/wiiusej/wiiuseapirequest/FloatValueRequest.java b/WiiUseJ/src/wiiusej/wiiuseapirequest/FloatValueRequest.java deleted file mode 100644 index a003239..0000000 --- a/WiiUseJ/src/wiiusej/wiiuseapirequest/FloatValueRequest.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * This file is part of WiiuseJ. - * - * WiiuseJ 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 3 of the License, or - * (at your option) any later version. - * - * WiiuseJ is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WiiuseJ. If not, see . - */ -package wiiusej.wiiuseapirequest; - -/** - * Represents a request with a float value to pass to wiiuse API. - * - * @author guiguito - */ -public class FloatValueRequest extends WiiUseApiRequest { - - private float floatValue; - - /** - * Constructor setting the id of the wiimote concerned. - * - * @param id - * the id of the wiimote concerned. - */ - public FloatValueRequest(int id, int type) { - super(id, type); - } - - /** - * Constructor setting the id of the wiimote concerned. - * - * @param id - * the id of the wiimote concerned. - * @param type - * type of the request - * @param th - * threshold in degrees - */ - public FloatValueRequest(int id, int type, float th) { - super(id, type); - floatValue = th; - } - - /** - * Get the float value. - * @return the float value - */ - public float getFloatValue() { - return floatValue; - } - - /** - * Set the float value. - * @param val the value to set - */ - public void setFloatValue(float val) { - this.floatValue = val; - } - - - -} diff --git a/WiiUseJ/src/wiiusej/wiiuseapirequest/IntValueRequest.java b/WiiUseJ/src/wiiusej/wiiuseapirequest/IntValueRequest.java deleted file mode 100644 index 801093d..0000000 --- a/WiiUseJ/src/wiiusej/wiiuseapirequest/IntValueRequest.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * This file is part of WiiuseJ. - * - * WiiuseJ 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 3 of the License, or - * (at your option) any later version. - * - * WiiuseJ is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WiiuseJ. If not, see . - */ -package wiiusej.wiiuseapirequest; - -/** - * Represents a request with an int value to pass to wiiuse API. - * - * @author guiguito - */ -public class IntValueRequest extends WiiUseApiRequest { - - private int intValue; - - /** - * Constructor setting the id of the wiimote - * concerned and the type of the request. - * - * @param id - * the id of the wiimote concerned. - */ - public IntValueRequest(int id, int type) { - super(id, type); - } - - /** - * Constructor setting the id of the wiimote - * concerned, the type of the request - * and the int value. - * - * @param id - * the id of the wiimote concerned. - * @param type - * type of the request - * @param th - * the int value. - */ - public IntValueRequest(int id, int type, int th) { - super(id, type); - intValue = th; - } - - /** - * Get the int value. - * @return the int value - */ - public int getIntValue() { - return intValue; - } - - /** - * Set the int value. - * @param val the value to set - */ - public void setIntValue(int val) { - this.intValue = val; - } - - - -} diff --git a/WiiUseJ/src/wiiusej/wiiuseapirequest/LedsRequest.java b/WiiUseJ/src/wiiusej/wiiuseapirequest/LedsRequest.java deleted file mode 100644 index 1a21024..0000000 --- a/WiiUseJ/src/wiiusej/wiiuseapirequest/LedsRequest.java +++ /dev/null @@ -1,125 +0,0 @@ -/** - * This file is part of WiiuseJ. - * - * WiiuseJ 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 3 of the License, or - * (at your option) any later version. - * - * WiiuseJ is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WiiuseJ. If not, see . - */ -package wiiusej.wiiuseapirequest; - -/** - * Represents a request to set leds of the wiimote with WiiUse API. - * - * @author guiguito - */ -public class LedsRequest extends wiiusej.wiiuseapirequest.WiiUseApiRequest { - - private boolean led1, led2, led3, led4; - - /** - * Constructor setting the id of the wiimote concerned. - * - * @param id - * id of the wiimote concerned - * @param type - * type of the request - */ - public LedsRequest(int id, int type) { - super(id, type); - } - - /** - * Constructor setting the id of the wiimote concerned. - * - * @param id - * id of the wiimote concerned - * @param type - * type of the request - * @param l1 - * led1 status. True=ON, False=OFF - * @param l2 - * led2 status. True=ON, False=OFF - * @param l3 - * led3 status. True=ON, False=OFF - * @param l4 - * led4 status. True=ON, False=OFF - */ - public LedsRequest(int id, int type, boolean l1, boolean l2, boolean l3, - boolean l4) { - super(id, type); - led1 = l1; - led2 = l2; - led3 = l3; - led4 = l4; - } - - /** - * @return the led1 - */ - public boolean isLed1() { - return led1; - } - - /** - * @param led1 - * the led1 to set - */ - public void setLed1(boolean led1) { - this.led1 = led1; - } - - /** - * @return the led2 - */ - public boolean isLed2() { - return led2; - } - - /** - * @param led2 - * the led2 to set - */ - public void setLed2(boolean led2) { - this.led2 = led2; - } - - /** - * @return the led3 - */ - public boolean isLed3() { - return led3; - } - - /** - * @param led3 - * the led3 to set - */ - public void setLed3(boolean led3) { - this.led3 = led3; - } - - /** - * @return the led4 - */ - public boolean isLed4() { - return led4; - } - - /** - * @param led4 - * the led4 to set - */ - public void setLed4(boolean led4) { - this.led4 = led4; - } - -} diff --git a/WiiUseJ/src/wiiusej/wiiuseapirequest/TwoIntValueRequest.java b/WiiUseJ/src/wiiusej/wiiuseapirequest/TwoIntValueRequest.java deleted file mode 100644 index 98e907e..0000000 --- a/WiiUseJ/src/wiiusej/wiiuseapirequest/TwoIntValueRequest.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * This file is part of WiiuseJ. - * - * WiiuseJ 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 3 of the License, or - * (at your option) any later version. - * - * WiiuseJ is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WiiuseJ. If not, see . - */ -package wiiusej.wiiuseapirequest; - - -/** - * Represents a request with two int values to pass to wiiuse API. - * - * @author guiguito - */ -public class TwoIntValueRequest extends IntValueRequest { - - private int secondIntValue; - - /** - * Constructor setting the id of the wiimote - * concerned and the type of the request. - * - * @param id the id of the wiimote concerned. - * @param type type of the request - */ - public TwoIntValueRequest(int id, int type) { - super(id, type); - } - - /** - * Constructor setting the id of the wiimote - * concerned, the type of the request - * and the two int values. - * - * @param id the id of the wiimote concerned. - * @param type type of the request - * @param x first int value. - * @param y second int value. - */ - public TwoIntValueRequest(int id, int type, int x, int y) { - super(id, type, x); - secondIntValue = y; - } - - /** - * Get the second int value. - * @return the secondIntValue - */ - public int getSecondIntValue() { - return secondIntValue; - } - - /** - * Set the second int value. - * @param secondIntValue the secondIntValue to set. - */ - public void setSecondIntValue(int secondIntValue) { - this.secondIntValue = secondIntValue; - } - - - -} diff --git a/WiiUseJ/src/wiiusej/wiiuseapirequest/WiiUseApiRequest.java b/WiiUseJ/src/wiiusej/wiiuseapirequest/WiiUseApiRequest.java deleted file mode 100644 index 1f4525b..0000000 --- a/WiiUseJ/src/wiiusej/wiiuseapirequest/WiiUseApiRequest.java +++ /dev/null @@ -1,112 +0,0 @@ -/** - * This file is part of WiiuseJ. - * - * WiiuseJ 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 3 of the License, or - * (at your option) any later version. - * - * WiiuseJ is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WiiuseJ. If not, see . - */ -package wiiusej.wiiuseapirequest; - -/** - * Represents a request we could do to the WiiUse API. - * - * @author guiguito - */ -public class WiiUseApiRequest { - - public static int WIIUSE_STATUS_REQUEST = 1; - public static int WIIUSE_ACTIVATE_SMOOTHING_REQUEST = 2; - public static int WIIUSE_DEACTIVATE_SMOOTHING_REQUEST = -2; - public static int WIIUSE_ACTIVATE_IR_TRACKING_REQUEST = 3; - public static int WIIUSE_DEACTIVATE_IR_TRACKING_REQUEST = -3; - public static int WIIUSE_ACTIVATE_MOTION_SENSING_REQUEST = 4; - public static int WIIUSE_DEACTIVATE_MOTION_SENSING_REQUEST = -4; - public static int WIIUSE_CLOSE_CONNECTION_REQUEST = 5; - public static int WIIUSE_ACTIVATE_CONTINUOUS_REQUEST = 6; - public static int WIIUSE_DEACTIVATE_CONTINUOUS_REQUEST = -6; - public static int WIIUSE_ACTIVATE_RUMBLE_REQUEST = 7; - public static int WIIUSE_DEACTIVATE_RUMBLE_REQUEST = -7; - public static int WIIUSE_LEDS_REQUEST = 8; - public static int WIIUSE_ORIENT_THRESHOLHD_REQUEST = 9; - public static int WIIUSE_ACCEL_THRESHOLHD_REQUEST = 10; - public static int WIIUSE_ALPHA_SMOOTHING_REQUEST = 11; - public static int WIIUSE_RESYNC = 12; - public static int WIIUSE_ASPECT_RATIO_4_3 = 13; - public static int WIIUSE_ASPECT_RATIO_16_9 = 14; - public static int WIIUSE_SENSOR_BAR_ABOVE = 15; - public static int WIIUSE_SENSOR_BAR_BELOW = 16; - public static int WIIUSE_SET_VIRTUAL_RESOLUTION = 17; - - private int wiimoteId = 0; - private int requestType = 0; - - /** - * Constructor setting the id of the wiimote concerned. - * - * @param id - * the id of the wiimote concerned. - */ - public WiiUseApiRequest(int id) { - wiimoteId = id; - } - - /** - * Constructor setting the id of the wiimote concerned. - * - * @param id - * the id of the wiimote concerned. - * - */ - public WiiUseApiRequest(int id, int type) { - wiimoteId = id; - requestType = type; - } - - /** - * Get id of the wiimote concerned by this request. - * - * @return id of the wiimote concerned - */ - public int getId() { - return wiimoteId; - } - - /** - * Set id of the wiimote concerned by this request. - * - * @param id - * id fh the wiimote concernet - */ - public void setId(int id) { - wiimoteId = id; - } - - /** - * Get the request type. - * - * @return the requestType - */ - public int getRequestType() { - return requestType; - } - - /** - * Set the request type. - * - * @param requestType - * the requestType to set - */ - public void setRequestType(int requestType) { - this.requestType = requestType; - } - -}