All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lejos.remote.ev3.RemoteRequestSampleProvider Maven / Gradle / Ivy

Go to download

leJOS (pronounced like the Spanish word "lejos" for "far") is a tiny Java Virtual Machine. In 2013 it was ported to the LEGO EV3 brick.

The newest version!
package lejos.remote.ev3;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import lejos.robotics.SampleProvider;

public class RemoteRequestSampleProvider implements SampleProvider {
	private ObjectInputStream is;
	private ObjectOutputStream os;
	private int portNum;

	public RemoteRequestSampleProvider(ObjectInputStream is,
			ObjectOutputStream os, String portName, String sensorName, String modeName) {
		this.is = is;
		this.os = os;
		portNum = portName.charAt(1) - '1';
		EV3Request req = new EV3Request();
		req.request = EV3Request.Request.CREATE_SAMPLE_PROVIDER;
		req.str = sensorName;
		req.str2 = portName;
		req.str3 = modeName;
		sendRequest(req, true);
	}
	
	public RemoteRequestSampleProvider(ObjectInputStream is,
			ObjectOutputStream os, String portName, String sensorName, String modeName, String topic, float frequency) {
		this.is = is;
		this.os = os;
		portNum = portName.charAt(1) - '1';
		EV3Request req = new EV3Request();
		req.request = EV3Request.Request.CREATE_SAMPLE_PROVIDER_PUBLISH;
		req.str = sensorName;
		req.str2 = portName;
		req.str3 = modeName;
		req.str4 = topic;
		req.floatValue = frequency;
		sendRequest(req, true);
	}
	
	@Override
	public int sampleSize() {
		EV3Request req = new EV3Request();
		req.request = EV3Request.Request.SAMPLE_SIZE;
		return sendRequest(req, true).reply;
	}

	@Override
	public void fetchSample(float[] sample, int offset) {
		EV3Request req = new EV3Request();
		req.request = EV3Request.Request.FETCH_SAMPLE;
		req.replyRequired = true;
		EV3Reply reply = sendRequest(req, true);
		for(int i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy