Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for more interfaces / multiple interfaces at once #4

Merged
merged 2 commits into from
Oct 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Analog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using OSVR.ClientKit;


namespace OSVRFreePIE
{
public class Analog
{
private AnalogInterface analogInterface;
private double analogValue;

public Analog(ClientContext context, String path)
{
analogValue = 0.0f;
analogInterface = context.GetAnalogInterface(path);
analogInterface.StateChanged += AnalogInterface_StateChanged;
}

private void AnalogInterface_StateChanged(object sender, TimeValue timestamp, Int32 sensor, Double report)
{
analogValue = report;
}

public double value
{
get
{
return analogValue;
}
}

static public implicit operator float(Analog a)
{
return (float)a.analogValue;
}



static public implicit operator double(Analog a)
{
return a.analogValue;
}

}
}
48 changes: 48 additions & 0 deletions Button.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using OSVR.ClientKit;

namespace OSVRFreePIE
{
public class Button
{
private ButtonInterface buttonInterface;
private bool buttonValue;

public Button(ClientContext context, String path)
{
buttonValue = false;
buttonInterface = context.GetButtonInterface(path);
buttonInterface.StateChanged += ButtonInterface_StateChanged;
}

public bool value
{
get
{
return buttonValue;
}
}

private void ButtonInterface_StateChanged(object sender, TimeValue timestamp, int sensor, byte report)
{
buttonValue = (report == ButtonInterface.Pressed);
}


static public implicit operator bool(Button b)
{
return b.buttonValue;
}

public bool __bool__()
{
return buttonValue;
}

public bool __nonzero__()
{
return buttonValue;
}

}
}
99 changes: 99 additions & 0 deletions Controller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System;
using OSVR.ClientKit;

namespace OSVRFreePIE
{
public class Controller
{
private Tracker tracker;
public Button one;
public Button two;
public Button three;
public Button four;
public Button bumper;
public Button joystick;
public Button middle;
public Analog joystickX;
public Analog joystickY;
public Analog trigger;

public Controller(ClientContext context, String side)
{
tracker = new Tracker(context, "/me/hands/" + side);
one = new Button(context, "/controller/" + side + "/1");
two = new Button(context, "/controller/" + side + "/2");
three = new Button(context, "/controller/" + side + "/3");
four = new Button(context, "/controller/" + side + "/4");
bumper = new Button(context, "/controller/" + side + "/bumper");
joystick = new Button(context, "/controller/" + side + "/joystick/button");
middle = new Button(context, "/controller/" + side + "/middle");
joystickX = new Analog(context, "/controller/" + side + "/joystick/x");
joystickY = new Analog(context, "/controller/" + side + "/joystick/y");
trigger = new Analog(context, "/controller/" + side + "/trigger");
}

public Vec3 position
{
get
{
return tracker.position;
}
}

public Quaternion orientation
{
get
{
return tracker.orientation;
}
}

public double x
{
get
{
return tracker.x;
}
}

public double y
{
get
{
return tracker.y;
}
}

public double z
{
get
{
return tracker.z;
}
}

public double roll
{
get
{
return tracker.roll;
}
}

public double pitch
{
get
{
return tracker.pitch;
}
}

public double yaw
{
get
{
return tracker.yaw;
}
}
}
}
44 changes: 44 additions & 0 deletions Direction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using OSVR.ClientKit;

namespace OSVRFreePIE
{
public class Direction
{
private DirectionInterface directionInterface;
private Vec3 value;

public Direction(ClientContext context, String path)
{
directionInterface = context.GetDirectionInterface(path);
directionInterface.StateChanged += DirectionInterface_StateChanged;
}

private void DirectionInterface_StateChanged(object sender, TimeValue timestamp, int sensor, Vec3 report)
{
value = report;
}

public double x
{
get
{
return value.x;
}
}
public double y
{
get
{
return value.y;
}
}
public double z
{
get
{
return value.z;
}
}
}
}
93 changes: 93 additions & 0 deletions EyeTracker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using OSVR.ClientKit;

namespace OSVRFreePIE
{
public class EyeTracker
{
private EyeTracker2DInterface eyeTracker2DInterface;
private EyeTracker3DInterface eyeTracker3DInterface;
private EyeTrackerBlinkInterface eyeTrackerBlinkInterface;

private Vec2 value2D;
private EyeTracker3DState value3D;
private bool valueBlink;

public EyeTracker(ClientContext context, String path)
{
valueBlink = false;
eyeTracker2DInterface = context.GetEyeTracker2DInterface(path);
eyeTracker3DInterface = context.GetEyeTracker3DInterface(path);
eyeTrackerBlinkInterface = context.GetEyeTrackerBlinkInterface(path);

eyeTracker2DInterface.StateChanged += EyeTracker2DInterface_StateChanged;
eyeTracker3DInterface.StateChanged += EyeTracker3DInterface_StateChanged;
eyeTrackerBlinkInterface.StateChanged += EyeTrackerBlinkInterface_StateChanged;
}

private void EyeTracker2DInterface_StateChanged(object sender, TimeValue timestamp, int sensor, Vec2 report)
{
value2D = report;
}

private void EyeTracker3DInterface_StateChanged(object sender, TimeValue timestamp, int sensor, EyeTracker3DState report)
{
value3D = report;
}


private void EyeTrackerBlinkInterface_StateChanged(object sender, TimeValue timestamp, int sensor, bool report)
{
valueBlink = report;
}

public bool blink
{
get
{
return valueBlink;
}
}

public Vec2 direction2D
{
get
{
return value2D;
}
}


public Vec3 basePoint3D
{
get
{
return value3D.basePoint;
}
}

public Vec3 direction3D
{
get
{
return value3D.direction;
}
}

public bool basePoint3DValid
{
get
{
return value3D.basePointValid;
}
}

public bool direction3DValid
{
get
{
return value3D.directionValid;
}
}
}
}
Binary file removed FreePIE.Core.Contracts.dll
Binary file not shown.
38 changes: 38 additions & 0 deletions Location2D.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using OSVR.ClientKit;

namespace OSVRFreePIE
{
public class Location2D
{
private Location2DInterface location2DInterface;
private Vec2 value;

public Location2D(ClientContext context, String path)
{
location2DInterface = context.GetLocation2DInterface(path);
location2DInterface.StateChanged += Location2DInterface_StateChanged;
}

private void Location2DInterface_StateChanged(object sender, TimeValue timestamp, int sensor, Vec2 report)
{
value = report;
}

public double x
{
get
{
return value.x;
}
}

public double y
{
get
{
return value.y;
}
}
}
}
Loading