示例#1
0
  private void queueCommands() {
    final ObdCommandJob airTemp = new ObdCommandJob(new AmbientAirTemperatureObdCommand());
    final ObdCommandJob speed = new ObdCommandJob(new SpeedObdCommand());
    final ObdCommandJob fuelEcon = new ObdCommandJob(new FuelEconomyObdCommand());
    final ObdCommandJob rpm = new ObdCommandJob(new EngineRPMObdCommand());
    final ObdCommandJob maf = new ObdCommandJob(new MassAirFlowObdCommand());
    final ObdCommandJob fuelLevel = new ObdCommandJob(new FuelLevelObdCommand());
    final ObdCommandJob ltft1 =
        new ObdCommandJob(new FuelTrimObdCommand(FuelTrim.LONG_TERM_BANK_1));
    final ObdCommandJob ltft2 =
        new ObdCommandJob(new FuelTrimObdCommand(FuelTrim.LONG_TERM_BANK_2));
    final ObdCommandJob stft1 =
        new ObdCommandJob(new FuelTrimObdCommand(FuelTrim.SHORT_TERM_BANK_1));
    final ObdCommandJob stft2 =
        new ObdCommandJob(new FuelTrimObdCommand(FuelTrim.SHORT_TERM_BANK_2));
    final ObdCommandJob equiv = new ObdCommandJob(new CommandEquivRatioObdCommand());

    // mServiceConnection.addJobToQueue(airTemp);
    mServiceConnection.addJobToQueue(speed);
    // mServiceConnection.addJobToQueue(fuelEcon);
    mServiceConnection.addJobToQueue(rpm);
    mServiceConnection.addJobToQueue(maf);
    mServiceConnection.addJobToQueue(fuelLevel);
    //		mServiceConnection.addJobToQueue(equiv);
    mServiceConnection.addJobToQueue(ltft1);
    // mServiceConnection.addJobToQueue(ltft2);
    // mServiceConnection.addJobToQueue(stft1);
    // mServiceConnection.addJobToQueue(stft2);
  }
示例#2
0
  public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem startItem = menu.findItem(START_LIVE_DATA);
    MenuItem stopItem = menu.findItem(STOP_LIVE_DATA);
    MenuItem settingsItem = menu.findItem(SETTINGS);
    MenuItem commandItem = menu.findItem(COMMAND_ACTIVITY);

    // validate if preRequisites are satisfied.
    if (preRequisites) {
      if (mServiceConnection.isRunning()) {
        startItem.setEnabled(false);
        stopItem.setEnabled(true);
        settingsItem.setEnabled(false);
        commandItem.setEnabled(false);
      } else {
        stopItem.setEnabled(false);
        startItem.setEnabled(true);
        settingsItem.setEnabled(true);
        commandItem.setEnabled(false);
      }
    } else {
      startItem.setEnabled(false);
      stopItem.setEnabled(false);
      settingsItem.setEnabled(false);
      commandItem.setEnabled(false);
    }

    return true;
  }
示例#3
0
  private void stopLiveData() {
    Log.d(TAG, "Stopping live data..");

    if (mServiceConnection.isRunning()) stopService(mServiceIntent);

    // remove runnable
    mHandler.removeCallbacks(mQueueCommands);

    releaseWakeLockIfHeld();
  }
示例#4
0
  private void startLiveData() {
    Log.d(TAG, "Starting live data..");

    if (!mServiceConnection.isRunning()) {
      Log.d(TAG, "Service is not running. Going to start it..");
      startService(mServiceIntent);
    }

    // start command execution
    mHandler.post(mQueueCommands);

    // screen won't turn off until wakeLock.release()
    wakeLock.acquire();
  }
示例#5
0
        public void run() {
          /*
           * If values are not default, then we have values to calculate MPG
           */
          Log.d(TAG, "SPD:" + speed + ", MAF:" + maf + ", LTFT:" + ltft);
          if (speed > 1 && maf > 1 && ltft != 0) {
            FuelEconomyWithMAFObdCommand fuelEconCmd =
                new FuelEconomyWithMAFObdCommand(
                    FuelType.DIESEL, speed, maf, ltft, false /* TODO */);
            TextView tvMpg = (TextView) findViewById(R.id.fuel_econ_text);
            String liters100km = String.format("%.2f", fuelEconCmd.getLitersPer100Km());
            tvMpg.setText("" + liters100km);
            Log.d(TAG, "FUELECON:" + liters100km);
          }

          if (mServiceConnection.isRunning()) queueCommands();

          // run again in 2s
          mHandler.postDelayed(mQueueCommands, 2000);
        }
示例#6
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /*
     * TODO clean-up this upload thing
     *
     * ExceptionHandler.register(this,
     * "http://www.whidbeycleaning.com/droid/server.php");
     */
    setContentView(R.layout.main);

    commandText = (EditText) this.findViewById(R.id.commandText);
    resultText = (TextView) this.findViewById(R.id.resultText);
    sendButton = (Button) this.findViewById(R.id.sendButton);

    sendButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            final MyCommand command = new MyCommand(commandText.getText().toString());
            mServiceConnection.addJobToQueue(new ObdCommandJob(command));

            mHandler.postDelayed(
                new Runnable() {
                  @Override
                  public void run() {
                    resultText.setText(command.getName() + ">>" + command.getResult());
                  }
                },
                2000);
          }
        });

    mListener =
        new IPostListener() {
          public void stateUpdate(ObdCommandJob job) {
            String cmdName = job.getCommand().getName();
            String cmdResult = job.getCommand().getFormattedResult();

            Log.d(TAG, FuelTrim.LONG_TERM_BANK_1.getBank() + " equals " + cmdName + "?");

            if (AvailableCommandNames.ENGINE_RPM.getValue().equals(cmdName)) {
              TextView tvRpm = (TextView) findViewById(R.id.rpm_text);
              tvRpm.setText(cmdResult);
            } else if (AvailableCommandNames.SPEED.getValue().equals(cmdName)) {
              TextView tvSpeed = (TextView) findViewById(R.id.spd_text);
              tvSpeed.setText(cmdResult);
              speed = ((SpeedObdCommand) job.getCommand()).getMetricSpeed();
            } else if (AvailableCommandNames.MAF.getValue().equals(cmdName)) {
              maf = ((MassAirFlowObdCommand) job.getCommand()).getMAF();
              addTableRow(cmdName, cmdResult);
            } else if (FuelTrim.LONG_TERM_BANK_1.getBank().equals(cmdName)) {
              ltft = ((FuelTrimObdCommand) job.getCommand()).getValue();
            } else if (AvailableCommandNames.EQUIV_RATIO.getValue().equals(cmdName)) {
              equivRatio = ((CommandEquivRatioObdCommand) job.getCommand()).getRatio();
              addTableRow(cmdName, cmdResult);
            } else {
              addTableRow(cmdName, cmdResult);
            }
          }
        };

    /*
     * Validate GPS service.
     */
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (locationManager.getProvider(LocationManager.GPS_PROVIDER) == null) {
      /*
       * TODO for testing purposes we'll not make GPS a pre-requisite.
       */
      // preRequisites = false;
      showDialog(NO_GPS_ID);
    }

    /*
     * Validate Bluetooth service.
     */
    // Bluetooth device exists?
    final BluetoothAdapter mBtAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBtAdapter == null) {
      preRequisites = false;
      showDialog(NO_BLUETOOTH_ID);
    } else {
      // Bluetooth device is enabled?
      if (!mBtAdapter.isEnabled()) {
        preRequisites = false;
        showDialog(BLUETOOTH_DISABLED);
      }
    }

    /*
     * Get Orientation sensor.
     */
    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    List<Sensor> sens = sensorManager.getSensorList(Sensor.TYPE_ORIENTATION);
    if (sens.size() <= 0) {
      showDialog(NO_ORIENTATION_SENSOR);
    } else {
      orientSensor = sens.get(0);
    }

    // validate app pre-requisites
    if (preRequisites) {
      /*
       * Prepare service and its connection
       */
      mServiceIntent = new Intent(this, ObdGatewayService.class);
      mServiceConnection = new ObdGatewayServiceConnection();
      mServiceConnection.setServiceListener(mListener);

      // bind service
      Log.d(TAG, "Binding service..");
      bindService(mServiceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
    }
  }