From 49442ea16327ed9d13392f93a281238cbb302a1a Mon Sep 17 00:00:00 2001 From: "guilhem.duche" Date: Thu, 8 May 2008 00:08:47 +0000 Subject: [PATCH] 0.12 work in progress git-svn-id: http://wiiusej.googlecode.com/svn/trunk@137 ae48ae66-6a45-0410-b38e-211266189506 --- WiiUseJ/WiiUseJ.dll | Bin 27956 -> 28468 bytes WiiUseJ/src/wiiusej/WiiUseApiManager.java | 4 +- WiiUseJ/src/wiiusej/Wiimote.java | 62 +++- WiiUseJ/src/wiiusej/test/Tests.java | 15 +- WiiUseJ/src/wiiusej/test/WiiuseJGuiTest.java | 16 +- .../src/wiiusej/utils/AccelerationPanel.java | 16 +- .../src/wiiusej/utils/ButtonsEventPanel.java | 16 +- WiiUseJ/src/wiiusej/utils/GForcePanel.java | 16 +- WiiUseJ/src/wiiusej/utils/IRPanel.java | 16 +- .../src/wiiusej/utils/OrientationPanel.java | 16 +- .../physicalevents/NunchukButtonsEvent.java | 2 +- .../wiiusejevents/utils/EventsGatherer.java | 12 +- .../utils/WiiUseApiListener.java | 2 +- .../wiiusejevents/utils/WiimoteListener.java | 19 +- .../wiiuseapievents/DisconnectionEvent.java | 44 +++ .../wiiuseapievents/NunchukInsertedEvent.java | 46 +++ .../wiiuseapievents/NunchukRemovedEvent.java | 45 +++ .../wiiuseapievents/StatusEvent.java | 256 ++++++++++++++++ .../wiiuseapievents/WiiUseApiEvent.java | 66 +++++ .../wiiuseapievents/WiimoteEvent.java | 275 ++++++++++++++++++ 20 files changed, 903 insertions(+), 41 deletions(-) create mode 100644 WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/DisconnectionEvent.java create mode 100644 WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukInsertedEvent.java create mode 100644 WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukRemovedEvent.java create mode 100644 WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/StatusEvent.java create mode 100644 WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/WiiUseApiEvent.java create mode 100644 WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/WiimoteEvent.java diff --git a/WiiUseJ/WiiUseJ.dll b/WiiUseJ/WiiUseJ.dll index 3824937d9d9eb06c3dda5e1af4b94b6d1bbf2de4..944cd8c7bafb5d1190f6e4864a1ecad6515ac3f0 100644 GIT binary patch delta 3403 zcmZ8k4Nz0r6}~S72`ui5o1lnMSQ0GQ=;lvK03rMYf}%zQhaEw1B}zpkVzjiQOLmjA z#wRs+Y=`OCS+KjE?RKXl#3Da-8kHR!yE^zYF8(g#c1KWJ)78bl)%4u=Kuh1u%XhwW z?z`vQbI!f*<@j~x_-)3wFYd4=(Lz!Qc~eBl2$`XLgAt{X*@O^X>(SJ(U^i*KQ6!2L zL93_)OxY6VFnqwQW`b~$`6wzDpCL}X#r|K2&M`4yNR5{G&q)Tl%-Cg7?RoVfFvNpq`0C7*g!9`6k2a?Kva=v2Z zv@K~lXu>DEvX$>jY`{O@qWV4;ay!-Q(;IMvZ$Q?4?}t!m(0mi~LAaUCG|k#T%khPj zx19VD4`L@L?`%`R4mqao9v|asum?Qp3vezVjGC z&j<}8elpBg-2<=p8y4AyQDBjq=?>1U5~)jyy>_=RFs&k=mqym7iTgEn}>EF z=d7i*$;Z7zgQ=ketHM=Eadb2`Gcs{VC=6!gF(#w`xlowNoieqbu<5b>!Vz?ub(cNI zl;GBjz|6hMnvWKE>>V^s42b*bG0S@5v1ca+B>iDLo5eF}KOP)t3qzJf66kTr%)RmW zvg@1hu?LuI%;>i`fSZGXE4;&D;!gJO&O5}$uOxO#F@i(r%6QH>X_Fw8dWVHmff?qU z!&HX{0#`Xg*E)GbOdgN?**12Y?kRK76_B)f&B3uBp24lRp65DMYP;)6$dQ5v?iq*7 zJ2Ba9A^GpAX~nJyd{YGC)%MYQ!BFVk^_6F|0oO7&n#lbq+=?DI#L3g*gLu4qzr8PS z>Bc|^w?@n{u2T{Q-wJB`2Ty~rL;mxWQX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tx9fAtOaaMU~rjRuNV`t$EpAT4%?`v;&uZNM=(%jbej`sBoxZD;ELY z%m8?k3x%N!z1D-?^k$-8LUjK4=BI|1HKDDnT#=2e1%8=%NW;$kX$A-UJF{HoA&|&L z;Ctg1u3Xlx0gKfPk2$OCge30Evch>T79JsHWyL~WwiN~tClJ%KW5I52sl=`z@fq+~qB<93IQ?B*!irMhl%BA4Hs)ezkTRF&9 zOVTcwTHT7eLu+(0n-+@WBEZ3=DYx6JU*Ang2`sU>Bir$C(`xbL;KwqH5UbeHY0Vnc zsNsQ4r>W4=s;Rzc$Lpn~DD}b8wf|s-;Qrcr#sa_2)6wZVl4oXW;9{PRalm(Zy2$t$ z;l7?tNYo6?Bx)8w+&UfhZPU7XjdF(dP5>c=FuHC;^K79-m8F%tOYOL{}z;MEHm^Ys1Jv2>+9)Z@T`wuSn%6Wt}UM7 zbQu{QnFAXlu%&. + */ +package wiiusej.wiiusejevents.wiiuseapievents; + + +/** + * Class representing a disconnection event. + * @author guiguito + */ +public class DisconnectionEvent extends WiiUseApiEvent { + + /** + * Construct the DisconnectionEvent setting up the id. + * + * @param id + * the Wiimote id + */ + public DisconnectionEvent(int id) { + super(id,WiiUseApiEvent.DISCONNECTION_EVENT); + } + + @Override + public String toString() { + String out = ""; + /* Status */ + out += "/*********** DISCONNECTION EVENT : WIIMOTE ID :" + super.getWiimoteId() + " ********/\n"; + return out; + } + +} diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukInsertedEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukInsertedEvent.java new file mode 100644 index 0000000..ce53fe7 --- /dev/null +++ b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukInsertedEvent.java @@ -0,0 +1,46 @@ +/** + * 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.wiiusejevents.wiiuseapievents; + + +/** + * Event that represents the connection of a nunchuk to a wiimote. + * @author guiguito + * + */ +public class NunchukInsertedEvent extends WiiUseApiEvent { + + /** + * Construct the NunchukInsertedEvent setting up the id. + * @param id id of the wiimote. + */ + public NunchukInsertedEvent(int id) { + super(id, WIIUSE_NUNCHUK_INSERTED); + } + + /* (non-Javadoc) + * @see wiiusej.wiiusejevents.WiiUseApiEvent#toString() + */ + @Override + public String toString() { + String out = ""; + /* Status */ + out += "/*********** NUNCHUK INSERTED EVENT : WIIMOTE ID :" + super.getWiimoteId() + " ********/\n"; + return out; + } + +} diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukRemovedEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukRemovedEvent.java new file mode 100644 index 0000000..50306bf --- /dev/null +++ b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukRemovedEvent.java @@ -0,0 +1,45 @@ +/** + * 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.wiiusejevents.wiiuseapievents; + + +/** + * Event that represents the connection of a nunchuk to a wiimote. + * @author guiguito + */ +public class NunchukRemovedEvent extends WiiUseApiEvent { + + /** + * Construct the NunchukInsertedEvent setting up the id. + * @param id id of the wiimote. + */ + public NunchukRemovedEvent(int id) { + super(id, WIIUSE_NUNCHUK_REMOVED); + } + + /* (non-Javadoc) + * @see wiiusej.wiiusejevents.WiiUseApiEvent#toString() + */ + @Override + public String toString() { + String out = ""; + /* Status */ + out += "/*********** NUNCHUK REMOVED EVENT : WIIMOTE ID :" + super.getWiimoteId() + " ********/\n"; + return out; + } + +} diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/StatusEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/StatusEvent.java new file mode 100644 index 0000000..9c2a6d4 --- /dev/null +++ b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/StatusEvent.java @@ -0,0 +1,256 @@ +/** + * 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.wiiusejevents.wiiuseapievents; + + +/** + * Class used to represent a status event. This class is used to know what are + * the settings of the wiimote. + * + * @author guiguito + */ +public class StatusEvent extends WiiUseApiEvent { + + protected static short WIIMOTE_LED_1 = 1; + protected static short WIIMOTE_LED_2 = 2; + protected static short WIIMOTE_LED_3 = 4; + protected static short WIIMOTE_LED_4 = 8; + + /* ATTACHMENT CONSTANTS */ + + private static short EXP_NONE = 0; + private static short EXP_NUNCHUK = 1; + private static short EXP_CLASSIC = 2; + private static short EXP_GUITAR_HERO_3 = 3; + + /* Status variables */ + private boolean connected = false; + + private float batteryLevel = -1; + + private short leds = 0; + + private boolean isSpeakerEnabled = false; + + private int attachment = 0; + + private boolean isRumbleActive = false; + + private boolean isContinuousActive = false; + + private boolean isIrActive = false; + + private boolean isMotionSensingActive = false; + + /** + * Construct the StatusEvent setting up the id. + * + * @param id + * the Wiimote id + */ + public StatusEvent(int id) { + super(id, WiiUseApiEvent.STATUS_EVENT); + } + + /** + * Build a StatusEvent with all fields set. + * + * @param id + * id of the wiimote + * @param connect + * true if the wiimote is connected + * @param batt + * battery level + * @param led + * status of leds + * @param speak + * speakers status + * @param attach + * attachment status + * @param rumbleState + * true if rumble is active + * @param continuousState + * true if continuous flag is activated + * @param irState + * true if ir is active + * @param motionSensingState + * true if accelerometer is active + */ + public StatusEvent(int id, boolean connect, float batt, short led, + boolean speak, int attach, boolean rumbleState, + boolean continuousState, boolean irState, boolean motionSensingState) { + super(id, WiiUseApiEvent.STATUS_EVENT); + connected = connect; + this.batteryLevel = batt; + this.leds = led; + this.isSpeakerEnabled = speak; + this.attachment = attach; + isRumbleActive = rumbleState; + isContinuousActive = continuousState; + isIrActive = irState; + isMotionSensingActive = motionSensingState; + } + + /** + * True if the wiimote is connected false otherwise. + * + * @return return the connected status. + */ + public boolean isConnected() { + return connected; + } + + /** + * Get battery level. + * + * @return battery level. 1 = 100% + */ + public float getBatteryLevel() { + return batteryLevel; + } + + /** + * Get status of the leds . + * + * @return a short representing LEDS turned on. + */ + public short getLeds() { + return leds; + } + + /** + * Tells if the given led is turned on according to the leds status int. + * @param led the int encoding a led. + * @return true if the led is turned on false otherwise. + */ + private boolean ledStatusCheck(short led) { + if ((leds & led) > 0) { + return true; + } else { + return false; + } + } + + /** + * Get led1 status. + * + * @return true if the led is set. + */ + public boolean isLed1Set() { + return ledStatusCheck(WIIMOTE_LED_1); + } + + /** + * Get led2 status. + * + * @return true if the led is set. + */ + public boolean isLed2Set() { + return ledStatusCheck(WIIMOTE_LED_2); + } + + /** + * Get led3 status. + * + * @return true if the led is set. + */ + public boolean isLed3Set() { + return ledStatusCheck(WIIMOTE_LED_3); + } + + /** + * Get led4 status. + * + * @return true if the led is set. + */ + public boolean isLed4Set() { + return ledStatusCheck(WIIMOTE_LED_4); + } + + /** + * Tell if the speaker is enable for this wiimote + * + * @return TRUE if it enabled false otherwise + */ + public boolean isSpeakerEnabled() { + return isSpeakerEnabled; + } + + /** + * Get the int representing the attachment type. + * + * @return value of the Attachment Type + */ + public int getAttachment() { + return attachment; + } + + /** + * Get the status of rumble. + * + * @return true if the rumble is active false otherwise + */ + public boolean isRumbleActive() { + return isRumbleActive; + } + + /** + * Tell if the CONTINUOUS option is activated. + * + * @return the isContinuousActive + */ + public boolean isContinuousActive() { + return isContinuousActive; + } + + /** + * Tell if the IR Tracking is active. + * + * @return TRUE if it is active or false otherwise. + */ + public boolean isIrActive() { + return isIrActive; + } + + /** + * Get the flag indicating if the motion sensing is active. + * + * @return true if the motion sensing is active false otherwise + */ + public boolean isMotionSensingActive() { + return isMotionSensingActive; + } + + @Override + public String toString() { + String out = ""; + /* Status */ + out += "/*********** STATUS EVENT : WIIMOTE ID :" + + super.getWiimoteId() + " ********/\n"; + out += "--- connected : " + connected + "\n"; + out += "--- Battery level : " + batteryLevel + "\n"; + out += "--- Leds : " + leds + "\n"; + out += "--- Speaker enabled : " + isSpeakerEnabled + "\n"; + out += "--- Attachment ? : " + attachment + "\n"; + out += "--- Rumble ? : " + isRumbleActive + "\n"; + out += "--- Continuous ? : " + isContinuousActive + "\n"; + out += "--- IR active ? : " + isIrActive + "\n"; + out += "--- Motion sensing active ? : " + isMotionSensingActive + "\n"; + return out; + } + +} diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/WiiUseApiEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/WiiUseApiEvent.java new file mode 100644 index 0000000..0527b13 --- /dev/null +++ b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/WiiUseApiEvent.java @@ -0,0 +1,66 @@ +/** + * 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.wiiusejevents.wiiuseapievents; + +import wiiusej.wiiusejevents.GenericEvent; + +/** + * This class describes the structure of an event from the WiiUse API event. + * + * @author guiguito + */ +public abstract class WiiUseApiEvent extends GenericEvent{ + + public static int NONE_EVENT = 0; + public static int GENERIC_EVENT = 1; + public static int STATUS_EVENT = 2; + public static int DISCONNECTION_EVENT = 3; + public static int WIIUSE_READ_DATA = 4; + public static int WIIUSE_NUNCHUK_INSERTED = 5; + public static int WIIUSE_NUNCHUK_REMOVED = 6; + public static int WIIUSE_CLASSIC_CTRL_INSERTED = 7; + public static int WIIUSE_CLASSIC_CTRL_REMOVED = 8; + public static int WIIUSE_GUITAR_HERO_3_CTRL_INSERTED = 9; + public static int WIIUSE_GUITAR_HERO_3_CTRL_REMOVED = 10; + + /* Event Type */ + private int eventType; + + /** + * Construct the WiiUseApiEvent setting up the id. + * + * @param id + * the Wiimote id + * @param type + * type of the event + */ + public WiiUseApiEvent(int id, int type) { + super(id); + eventType = type; + } + + /** + * Get the event type. + * @return the eventType + */ + public int getEventType() { + return eventType; + } + + public abstract String toString(); + +} diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/WiimoteEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/WiimoteEvent.java new file mode 100644 index 0000000..1975eb8 --- /dev/null +++ b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/WiimoteEvent.java @@ -0,0 +1,275 @@ +/** + * 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.wiiusejevents.wiiuseapievents; + +import wiiusej.wiiusejevents.physicalevents.ExpansionEvent; +import wiiusej.wiiusejevents.physicalevents.IREvent; +import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; +import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent; + +/** + * Class that is a bean to be filled by the wiiuse API on an event that occurs + * on a wiimote. + * + * @author guiguito + */ +public class WiimoteEvent extends WiiUseApiEvent { + + WiimoteButtonsEvent buttonsEvent = null; + IREvent infraredEvent = null; + MotionSensingEvent motionSensingEvent = null; + ExpansionEvent expansionEvent = null; + + /** + * Construct the Wiimote setting up the id. + * + * @param id + * the Wiimote id + */ + public WiimoteEvent(int id) { + super(id, WiiUseApiEvent.GENERIC_EVENT); + } + + /** + * Construct the Wiimote setting up the id and the buttons. + * + * @param id + * the Wiimote id + * @param buttonsJustPressed + * buttons just pressed + * @param buttonsJustReleased + * buttons just released + * @param buttonsHeld + * buttons held + */ + public WiimoteEvent(int id, short buttonsJustPressed, + short buttonsJustReleased, short buttonsHeld) { + super(id, WiiUseApiEvent.GENERIC_EVENT); + buttonsEvent = new WiimoteButtonsEvent(id, buttonsJustPressed, + buttonsJustReleased, buttonsHeld); + } + + /** + * Tell if there is an IR Event. + * + * @return TRUE if there is an IR event. + */ + public boolean isThereIrEvent() { + return infraredEvent != null; + } + + /** + * Tell if there is a motion sensing Event. + * + * @return TRUE if there is a motion sensing event. + */ + public boolean isThereMotionSensingEvent() { + return motionSensingEvent != null; + } + + /** + * Tell if there is an expansion Event. + * + * @return TRUE if there is an expansion event. + */ + public boolean isThereExpansionEvent() { + return expansionEvent != null; + } + + /** + * Get buttons event. + * + * @return the buttons event. + */ + public WiimoteButtonsEvent getButtonsEvent() { + return buttonsEvent; + } + + /** + * Get the IR event. + * + * @return the IR event if there is one or null. + */ + public IREvent getIREvent() { + return infraredEvent; + } + + /** + * Get the motion sensing event. + * + * @return the motion sensing event if there is one or null. + */ + public MotionSensingEvent getMotionSensingEvent() { + return motionSensingEvent; + } + + /** + * Get the expansion event. + * + * @return the expansion event if there is one or null. + */ + public ExpansionEvent getExpansionEvent() { + return expansionEvent; + } + + /** + * Prepare an IR event to populate. + * + * @param x + * calculated X coordinate. + * @param y + * calculated Y coordinate. + * @param z + * calculated distance. + * @param ax + * absolute X coordinate. + * @param ay + * absolute Y coordinate + * @param xVRes + * IR virtual screen x resolution. + * @param yVRes + * IR virtual screen y resolution. + * @param xOffset + * IR X correction offset. + * @param yOffset + * IR Y correction offset. + * @param sensorBarPostion + * aspect ratio of the screen. + * @param screenAsPectRatio + * IR sensor bar position. + * @param irSensitivity + * Sensitivity of the infrared camera. + * @param distance + * Pixel Distance between first two dots + */ + public void prepareIRevent(int x, int y, int z, int ax, int ay, int xVRes, + int yVRes, int xOffset, int yOffset, short sensorBarPostion, + short screenAsPectRatio, short irSensitivity, float distance) { + if (infraredEvent == null) { + infraredEvent = new IREvent(getWiimoteId(), x, y, z, ax, ay, xVRes, + yVRes, xOffset, yOffset, sensorBarPostion, + screenAsPectRatio, irSensitivity, distance); + } + } + + /** + * Add an IR point to the generic event. Create an IR Event if it's not + * created yet. + * + * @param x + * x coordinates. + * @param y + * y coordinates + * @param rx + * raw X coordinate (0-1023). + * @param ry + * raw Y coordinate (0-1023). + * @param size + * size of the IR dot (0-15). + */ + public void addIRpoint(int x, int y, short rx, short ry, short size) { + if (infraredEvent != null) + infraredEvent.addIRpoint(x, y, rx, ry, size); + } + + /** + * Set the Motion Sensing Event. + * + * @param orientationThreshold + * value of the minimum angle between two events with the + * accelerometer + * @param accelerationThreshold + * value of the value variation between two events with the + * accelerometer + * @param smoothingState + * true if smoothing flag is activated + * @param alphaSmooth + * value of the alpha smoothing parameter + * @param r + * roll + * @param p + * pitch + * @param ya + * yaw + * @param ar + * absolute roll + * @param ap + * absolute pitch + * @param x + * gravity force on x axis + * @param y + * gravity force on y axis + * @param z + * gravity force on z axis + * @param xx + * raw acceleration on x axis + * @param yy + * raw acceleration on y axis + * @param zz + * raw acceleration on z axis + */ + public void setMotionSensingEvent(float orientationThreshold, + int accelerationThreshold, boolean smoothingState, + float alphaSmooth, float r, float p, float ya, float ar, float ap, + float x, float y, float z, short xx, short yy, short zz) { + motionSensingEvent = new MotionSensingEvent(getWiimoteId(), + orientationThreshold, accelerationThreshold, smoothingState, + alphaSmooth, r, p, ya, ar, ap, x, y, z, xx, yy, zz); + } + + public void setNunchukEvent(){ + + } + + public void setClassicControllerEvent(){ + //@TODO + } + + @Override + public String toString() { + String out = ""; + /* Status */ + out += "/*********** GENERIC EVENT : WIIMOTE ID :" + getWiimoteId() + + " ********/\n"; + + out += buttonsEvent; + + if (infraredEvent != null) { + out += infraredEvent; + } else { + out += "/******** IR Tracking ********/\n"; + out += "--- Active : false\n"; + } + + if (motionSensingEvent != null) { + out += motionSensingEvent; + } else { + out += "/******** Motion sensing ********/\n"; + out += "--- Motion sensing : false \n"; + } + + if (expansionEvent != null) { + out += expansionEvent; + } else { + out += "/******** Expansion ********/\n"; + out += "--- No expansion connected \n"; + } + + return out; + } + +}