示例#1
0
  private void doSearch(final CoronataFullObserver observer) {
    observer.coronataStarted();

    final WiiUseApiManager wiiUseApiManager;

    try {
      wiiUseApiManager = new WiiUseApiManager();
      observer.libraryLoaded();

      observer.searchStarted();
      Wiimote[] wiimotesFound = wiiUseApiManager.getWiimotes(config.getWiiRemotesExpected());
      if (wiimotesFound.length > 0) observer.wiiRemoteIdentified();
      for (Wiimote w : wiimotesFound) {
        observer.wiiRemoteConnected(new WiiuseJWiiRemoteAdapter(w, config.getWiiRemoteListener()));
      }
      observer.searchFinished();

    } catch (WiiusejNativeLibraryLoadingException e) {
      observer.errorOccurred(exceptionFactory.errorLoadingNativeLibraries(e));
    }
  }
示例#2
0
  /** @param args */
  public static void main(String[] args) {
    Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(4, true);
    if (wiimotes.length > 0) {
      System.out.println(wiimotes[0]);
      Tests tests = new Tests(wiimotes[0]);
    } else {
      System.out.println("No wiimotes found !!!");
    }

    // java.util.Timer timer = new java.util.Timer();
    // timer.scheduleAtFixedRate(new LedsTask(), 0, 100);

  }
示例#3
0
  public WiiMoteTracker() {
    // adds button colors to array
    colors.add(Color.RED);
    colors.add(Color.BLUE);
    colors.add(Color.YELLOW);
    colors.add(Color.GREEN);

    // Searching for WiiRemotes
    wiimotes = WiiUseApiManager.getWiimotes(4, true);
    // checking if there are wii remotes connected. If so set led 2,3,4 on
    // else exit program
    int wiimoteNumber = 0;
    for (Wiimote wiimote : wiimotes) {
      switch (wiimoteNumber) {
        case 0:
          wiimote.setLeds(true, false, false, false);
          break;
        case 1:
          wiimote.setLeds(false, true, false, false);
          break;
        case 2:
          wiimote.setLeds(false, false, true, false);
          break;
        case 3:
          wiimote.setLeds(false, false, false, true);
          break;
      }
      wiimoteNumber++;
      wiimote.addWiiMoteEventListeners(this);
    }

    if (wiimotes == null) {
      System.out.println("No Wii Remotes found");
      System.exit(0);
    }

    // Timer which on tick changes the color of the rectangle back to the original one.
    ActionListener update =
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent arg0) {
            timer.stop();
            changeColorBack();
          }
        };
    // time the color stays changed
    timer = new Timer(500, update);
  }
示例#4
0
  public void init() {
    Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true);
    remote = wiimotes[0];
    remote.activateIRTRacking();
    remote.activateMotionSensing();
    remote.addWiiMoteEventListeners(
        new WiimoteListener() {
          // REDUNDANT
          public void onStatusEvent(StatusEvent arg0) {}

          public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {}

          public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {}

          public void onMotionSensingEvent(MotionSensingEvent arg0) {}

          public void onIrEvent(IREvent arg0) {}

          public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {}

          public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {}

          public void onExpansionEvent(ExpansionEvent arg0) {}

          public void onDisconnectionEvent(DisconnectionEvent arg0) {}

          public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent arg0) {}

          public void onClassicControllerInsertedEvent(ClassicControllerInsertedEvent arg0) {}

          // NOT REDUNDANT
          public void onButtonsEvent(WiimoteButtonsEvent arg0) {
            if (arg0.isButtonUpJustReleased() && !GameLogic.getInstance().isDisplaying()) {
              ViewLogic.getInstance().selectUpwards();
            }
            if (arg0.isButtonDownJustReleased() && !GameLogic.getInstance().isDisplaying()) {
              ViewLogic.getInstance().selectDownwards();
            }
            if (arg0.isButtonLeftJustReleased() && !GameLogic.getInstance().isDisplaying()) {
              ViewLogic.getInstance().selectLeft();
            }
            if (arg0.isButtonRightJustReleased() && !GameLogic.getInstance().isDisplaying()) {
              ViewLogic.getInstance().selectRight();
            }
            if (arg0.isButtonOneJustReleased() && !GameLogic.getInstance().isPlaying()) {
              GameLogic.getInstance().generateNext();
              GameLogic.getInstance().highlightSequence();
              GameLogic.getInstance().togglePlaying();
            }
            if (arg0.isButtonAJustReleased()) {
              if (GameLogic.getInstance().isPlaying()) {
                boolean isCorrect = GameLogic.getInstance().checkInput();
                if (isCorrect) {
                  if (GameLogic.getInstance().getcurrentPoint() == 0) {
                    GameLogic.getInstance().generateNext();
                    GameLogic.getInstance().highlightSequence();
                  }
                } else {
                  remote.activateRumble();

                  try {
                    Thread.sleep(1500);
                  } catch (InterruptedException e) {
                  }
                  remote.deactivateRumble();
                  GameLogic.getInstance().reset();
                  GameLogic.getInstance().togglePlaying();
                }
              }
            }
            if (arg0.isButtonAHeld() && arg0.isButtonBHeld()) {
              System.exit(0);
            }
            if (arg0.isButtonAHeld()) aHeld = true;
            else aHeld = false;
          }
        });
  }