-1

I need your help. I'm making a controlling program that use Wiimote, and I need to make 2 different type of control. Each controller code is defined in the class controlType1 and controlType2 (which the #2 isn't included here, but mostly it is the same with #1).

The idea is, when I press certain button on the WiiMote, the controller switched from type1 to type2. I've instantiate 2 objects, and it should removes the listener of one of the object when the button is pressed and change it to the other object.

Currently, I've gone this far and get stuck here. Any idea how should I do this?

public class WiiDroneControl implements ControlSwitchListener {

private Wiimote wiimote;

private WiimoteListener control1 = (WiimoteListener) new controlType1(this);
private WiimoteListener control2 = (WiimoteListener) new controlType2(this);

public WiiDroneControl() {

    Wiimote wiimotes[] = WiiUseApiManager.getWiimotes(1, true);

    if(wiimotes!= null && wiimotes.length > 0)
    {
        wiimote = wiimotes[0];

        wiimote.addWiiMoteEventListeners(control1);
        wiimote.addWiiMoteEventListeners(control2);

        wiimote.activateMotionSensing();
        wiimote.activateContinuous();
        wiimote.getStatus();
    }
}

@Override
public void onSwitchEvent() {
    // TODO Auto-generated method stub

}
}

the other class

public class controlType1 implements WiimoteListener{

ControlSwitchListener listener = null;

public controlType1(ControlSwitchListener l) {
    listener = l;
}

@Override
public void onButtonsEvent(WiimoteButtonsEvent e) {
    // TODO Auto-generated method stub
    listener.onSwitchEvent();

    if (e.isButtonOnePressed())
    {
        //switch controller object when this button is pressed
    }
}
}
Duncan Jones
  • 67,400
  • 29
  • 193
  • 254

1 Answers1

0

If I correct understood your question...

    public class WiiDroneControl implements ControlSwitchListener {

    private Wiimote wiimote;
    private WiimoteListener control1 =  new controlType1(this);
    private WiimoteListener control2 =  new controlType2(this);
    private WiimoteListener current = control1;

    public WiiDroneControl() {

        Wiimote wiimotes[] = WiiUseApiManager.getWiimotes(1, true);

        if(wiimotes!= null && wiimotes.length > 0)
        {
            wiimote = wiimotes[0];
            wiimote.addWiiMoteEventListeners(current);

            wiimote.activateMotionSensing();
            wiimote.activateContinuous();
            wiimote.getStatus();
        }
    }

    @Override
    public void onSwitchEvent() {
        current = current.equals(control1) ? control2 : control1;
    }
}
Georgy Gobozov
  • 13,633
  • 8
  • 72
  • 78
  • how to pass the event from the class controlType1 so that the method onSwitchEvent() in the other class will recognize? thanks anyway for the help – evan harijanto Jun 27 '13 at 10:42
  • pls, can you describe your task with more clarity. You have two controllesr and want recognize which controller was fired? – Georgy Gobozov Jun 27 '13 at 11:13