Android Open Source - Sensors2OSC Osc Dispatcher






From Project

Back to project page Sensors2OSC.

License

The source code is released under:

Author: Thomas Mayer <thomas@residuum.org> Antonio Deusany de Carvalho Junior Copyright (c) 2014 Thomas Mayer, Antonio Deusany de Carvalho Junior Permission is hereby granted, free of charge, to any...

If you think the Android project Sensors2OSC listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.sensors2.osc.communication;
/*  w  w  w .  j  a  v  a  2 s. c o m*/
import org.sensors2.common.sensors.DataDispatcher;
import org.sensors2.common.sensors.Measurement;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by thomas on 07.11.14.
 */
public class OscDispatcher implements DataDispatcher {

  private List<SensorConfiguration> sensorConfigurations;

  public OscDispatcher() {
    this.sensorConfigurations = new ArrayList<SensorConfiguration>();
  }

  public void addSensorConfiguration(SensorConfiguration sensorConfiguration) {
    this.sensorConfigurations.add(sensorConfiguration);
  }

  @Override
  public void dispatch(Measurement sensorData) {
    int length = sensorData.getValues().length;
    for (int i = 0; i < length; i++) {
      for (SensorConfiguration sensorConfiguration : this.sensorConfigurations) {
        if (sensorConfiguration.getIndex() == i && sensorConfiguration.getSensorType() == sensorData.getSensorType()) {
          this.trySend(sensorConfiguration, sensorData.getValues()[i]);
        }
      }
    }
  }

  private void trySend(SensorConfiguration sensorConfiguration, float value) {
    if (!sensorConfiguration.sendingNeeded(value)) {
      return;
    }
    new OscCommunication(OscConfiguration.getInstance()).execute(sensorConfiguration.getOscParam(), Float.toString(value));
  }
}




Java Source Code List

org.sensors2.osc.ApplicationTest.java
org.sensors2.osc.activities.AboutActivity.java
org.sensors2.osc.activities.SettingsActivity.java
org.sensors2.osc.activities.StartUpActivity.java
org.sensors2.osc.communication.OscCommunication.java
org.sensors2.osc.communication.OscConfiguration.java
org.sensors2.osc.communication.OscDispatcher.java
org.sensors2.osc.communication.SensorConfiguration.java
org.sensors2.osc.fragments.SensorFragment.java
org.sensors2.osc.fragments.SensorGroupFragment.java
org.sensors2.osc.sensors.Parameters.java
org.sensors2.osc.sensors.Settings.java