Added SportPreviewActivity and SportPreviewCanvas

This commit is contained in:
Luca Warmenhoven
2024-05-14 13:40:59 +02:00
parent 714a8a1c51
commit b7459f531b
3 changed files with 40 additions and 8 deletions

View File

@@ -12,9 +12,6 @@ public class SportPreviewActivity extends RobotActivity implements RobotLifecycl
}
@Override
@Override
public void onRobotFocusLost() {

View File

@@ -4,19 +4,41 @@ import android.content.Context;
import android.graphics.Canvas;
import android.view.View;
import com.example.fitbot.util.processing.GesturePath;
import com.example.fitbot.util.processing.MotionProcessor;
public class SportPreviewCanvas extends View {
private GesturePath path;
private double pathTime = 0.0D; // The timestamp at which the path is currently at.
private MotionProcessor motionProcessor;
private void calculatePath
/**
* Method that recalculates the path that will be drawn on the
* screen.
*/
private void calculateDrawingPath() {
}
public SportPreviewCanvas(Context context, GesturePath path) {
super(context);
this.path = path;
this.motionProcessor = new MotionProcessor();
this.motionProcessor.startListening();
// Add the event handler
this.motionProcessor.setMotionDataEventHandler((processed, preprocessed, sampleIndex, sampleRate) -> {
calculateDrawingPath();
});
}
@Override
public void onDraw(Canvas canvas) {
// Draw the sport preview canvas
}
}

View File

@@ -9,7 +9,6 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;
public class MotionProcessor {
@@ -20,7 +19,7 @@ public class MotionProcessor {
private final List<Vector3> relativePath = new ArrayList<>(); // Relative path of the motion data
private Vector3 ZERO = new Vector3(0, 0, 0);
private double sampleRate = 1.0D; // samples/second
private Consumer<Vector3> motionDataConsumer = (data) -> {};
private DataConsumer motionDataConsumer = (p1, p2, p3, p4) -> {};
private GesturePath path;
private WebSocket socket;
@@ -108,7 +107,7 @@ public class MotionProcessor {
Vector3 previous = this.relativePath.isEmpty() ? ZERO : this.relativePath.get(this.relativePath.size() - 1);
Vector3 relativeVector = getRelativeVector(data).add(previous);
this.relativePath.add(relativeVector);
motionDataConsumer.accept(relativeVector);
motionDataConsumer.accept(relativeVector, data, this.relativePath.size(), this.sampleRate);
}
/**
@@ -125,7 +124,7 @@ public class MotionProcessor {
* Function for setting the motion data receiver.
* @param consumer The consumer to set.
*/
public void setMotionDataEventHandler(Consumer<Vector3> consumer) {
public void setMotionDataEventHandler(DataConsumer consumer) {
if ( consumer != null)
this.motionDataConsumer = consumer;
}
@@ -241,6 +240,20 @@ public class MotionProcessor {
Log.i("MotionProcessor", "Path length: " + relativePath.size());
Log.i("MotionProcessor", "Sample rate: " + sampleRate);
Log.i("MotionProcessor", "Calibration point: " + ZERO.toString());
}
/**
* Interface that accepts motion data and the transformed vector.
*/
public interface DataConsumer {
/**
* Function for accepting motion data and the transformed vector.
* @param transformedVector The transformed vector.
* @param motionData The input motion data.
* @param sampleIndex The index of the current sample
* @param sampleRate The sample rate.
*/
void accept(Vector3 transformedVector, MotionData motionData, int sampleIndex, double sampleRate);
}
}