Beispiel #1
0
    public void initIR() throws ConnectionLostException, InterruptedException {
      float baseVal = 0f, baseVolt = 0f;

      for (int i = 0; i < iRSensors.iSamples; i++) {
        baseVal += iRSensors.input.read();
        baseVolt += iRSensors.input.getVoltage();
        // Thread.sleep(5);
      }
      iRSensors.initialize(baseVal / iRSensors.iSamples, baseVolt / iRSensors.iSamples);
      /*
      Log.d("INIT IR", "Base Val: " + baseVal/iRSensors.iSamples +
              ", base Volt: " + baseVolt/iRSensors.iSamples);*/
    }
Beispiel #2
0
    /**
     * Called every time a connection with IOIO has been established. Typically used to open pins.
     *
     * @throws ConnectionLostException When IOIO connection is lost.
     * @see ioio.lib.util.IOIOLooper
     */
    @Override
    protected void setup() throws ConnectionLostException, InterruptedException {
      showVersions(ioio_, "IOIO connected!");
      led_ = ioio_.openDigitalOutput(0, true);
      iRSensors.input = ioio_.openAnalogInput(iRSensors.pin);
      initIR();

      try {
        pwm =
            ioio_.openPwmOutput(
                35, 100); // new DigitalOutput.Spec(35, DigitalOutput.Spec.Mode.OPEN_DRAIN)
      } catch (ConnectionLostException e) {
        Log.d("Connection Lost", "IO Connection Lost");
      }
    }
Beispiel #3
0
    /**
     * Called repetitively while the IOIO is connected.
     *
     * @throws ConnectionLostException When IOIO connection is lost.
     * @throws InterruptedException When the IOIO thread has been interrupted.
     * @see ioio.lib.util.IOIOLooper#loop()
     */
    @Override
    public void loop() throws ConnectionLostException, InterruptedException {
      int re = r.nextInt(100 - 0); // random number between 0 and 100 for rotation enable
      int ra = r.nextInt(3 - 0); // random number between 0 and 100 for rotation angle

      if (actionEnable) {
        if (re <= 1) { // % chance that the head will rotate
          switch (ra) {
            case 0:
              newPos = 1000;
              break; // limit 600
            case 1:
              newPos = 1550;
              break;
            case 2:
              newPos = 2000;
              break; // limit 2450
            default:
              break;
          }

          if (newPos != currentPos) {
            led_.write(true);
            pwm.setPulseWidth(newPos);
            currentPos = newPos;
            Log.d("ROTATE", "Moving to position: " + newPos + "...");
            Thread.sleep(1000);
            Log.d("ROTATE", "At position: " + newPos);
            initIR();
          }
        } else {
          float measVal = iRSensors.input.read();
          float measVolt = iRSensors.input.getVoltage();
          if (!action.TTSE.t1.isSpeaking()) {
            if (iRSensors.motionDetect(measVal, measVolt)) {
              led_.write(false);
              Log.d(
                  "MOTION",
                  "Detected motion!"
                      + " BaseVal: "
                      + iRSensors.baseValue
                      + "/"
                      + measVal
                      + ", BaseVolt: "
                      + iRSensors.baseVolt
                      + "/"
                      + measVolt);

              action.executeGreeting(); // execute a random greeting

              action.executeRandActivity();
              /*
                                          if(action.getCurrentAction() == ActionEngine.ACTION_PAGE ||
                                                  action.getCurrentAction() == ActionEngine.ACTION_QUIZ){
                                              pageQueue.add(action.getWebPage());
                                              interactionTimer.run();
                                          }
              */
              switch (action.getCurrentAction()) {
                case ActionEngine.ACTION_PAGE:
                  pageQueue.add(action.getWebPage());
                  interactionTimer.run();
                  break;
                case ActionEngine.ACTION_QUIZ:
                  pageQueue.add(action.getQuiz());
                  interactionTimer.run();
                  break;
                default:
                  break;
              }

              /*
              int rn = r.nextInt(2-0);
              if(rn == 1) action.executeQuiz();
              else action.executePage();
              */
              // action.executeMakeTweet("IR sensor voltage: " + measVolt);
              // action.executeTweetSearch(true);
              // action.executeTimelineSearch(true);
              // action.executeRSS(true);

              Log.d("IR SENSORS", "reinitializing...");
              initIR();
            } else {
              led_.write(true);
            }
          } else {
            led_.write(true);
          }
        }
      }

      Thread.sleep(100);
    }