Skip to main content

Class AnalogJoystick

2-axis analog joystick

Assembly: Meadow.Foundation.dll
View Source
public class AnalogJoystick : SamplingSensorBase<AnalogJoystickPosition>, IObservable<IChangeResult<AnalogJoystickPosition>>, ISamplingSensor<AnalogJoystickPosition>, ISensor<AnalogJoystickPosition>, ISensor, ISamplingSensor, IAnalogJoystick, IDisposable

Inheritance: System.Object -> Meadow.Foundation.ObservableBase<UNIT> -> Meadow.Foundation.SamplingSensorBase<UNIT>

Implements:
System.IObservable<Meadow.IChangeResult<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>>, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>, Meadow.Peripherals.Sensors.ISensor<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>, Meadow.Peripherals.Sensors.ISensor, Meadow.Peripherals.Sensors.ISamplingSensor, Meadow.Peripherals.Sensors.Hid.IAnalogJoystick, System.IDisposable

Properties

HorizontalInputPort

Analog port connected to horizontal joystick pin

View Source
protected IAnalogInputPort HorizontalInputPort { get; set; }

VerticalInputPort

Analog port connected to vertical joystick pin

View Source
protected IAnalogInputPort VerticalInputPort { get; set; }

IsHorizontalInverted

Is the horizontal / x-axis inverted

View Source
public bool IsHorizontalInverted { get; set; }

IsVerticalInverted

Is the vertical / y-axis inverted

View Source
public bool IsVerticalInverted { get; set; }

Position

Current position of analog joystick

View Source
public AnalogJoystickPosition? Position { get; protected set; }

DigitalPosition

Digital position of joystick

View Source
public DigitalJoystickPosition? DigitalPosition { get; }

Calibration

Calibration for 2-axis analog joystick

View Source
public AnalogJoystick.JoystickCalibration Calibration { get; protected set; }

IsDisposed

Is the object disposed

View Source
public bool IsDisposed { get; }

Fields

sampleCount

Number of samples used to calculate position

View Source
protected int sampleCount

sampleIntervalMs

Interval between samples

View Source
protected int sampleIntervalMs

Methods

SetCenterPosition()

sets the current position as the center position and saves to the calibration.

View Source
public Task SetCenterPosition()
Returns

System.Threading.Tasks.Task

GetDigitalJoystickPosition()

Translates an analog position into a digital position, taking into account the calibration information.

View Source
protected DigitalJoystickPosition GetDigitalJoystickPosition()
Returns

Meadow.Peripherals.Sensors.Hid.DigitalJoystickPosition: The digital joystick position as DigitalJoystickPosition### ReadSensor() Convenience method to get the current temperature. For frequent reads, use StartSampling() and StopSampling() in conjunction with the SampleBuffer.

View Source
protected override Task<AnalogJoystickPosition> ReadSensor()
Returns

System.Threading.Tasks.Task<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>

StartUpdating(TimeSpan?)

Starts continuously sampling the sensor.

This method also starts raising Changed events and IObservable subscribers getting notified. Use the readIntervalDuration parameter to specify how often events and notifications are raised/sent.

View Source
public override void StartUpdating(TimeSpan? updateInterval)
Parameters
TypeNameDescription
System.Nullable<System.TimeSpan>updateIntervalA TimeSpan that specifies how long to
 wait between readings. This value influences how often `*Updated`
 events are raised and `IObservable` consumers are notified.
 The default is 5 seconds. |

StopUpdating()

Stops sampling the joystick position

View Source
public override void StopUpdating()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

View Source
public void Dispose()

Dispose(bool)

Dispose of the object

View Source
protected virtual void Dispose(bool disposing)
Parameters
TypeNameDescription
System.BooleandisposingIs disposing

Implements

  • System.IObservable<Meadow.IChangeResult<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>>
  • Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>
  • Meadow.Peripherals.Sensors.ISensor<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>
  • Meadow.Peripherals.Sensors.ISensor
  • Meadow.Peripherals.Sensors.ISamplingSensor
  • Meadow.Peripherals.Sensors.Hid.IAnalogJoystick
  • System.IDisposable