Remarks

AnalogJoystick
Status
Source code GitHub
NuGet package

Code Example

The following example prints horizontal and vertical values ranging from -1 to 1, 0 being the center position:

public class MeadowApp : App<F7Micro, MeadowApp>
{
    public MeadowApp()
    {
        AnalogJoystick joystick;

        public MeadowApp()
        {
            joystick = new AnalogJoystick(
                Device.CreateAnalogInputPort(Device.Pins.A01), 
                Device.CreateAnalogInputPort(Device.Pins.A00),
                null, false);

            joystick.SetCenterPosition(); //fire and forget 
            joystick.Updated += JoystickUpdated;
            joystick.StartUpdating();
        }

        void JoystickUpdated(object sender, Meadow.Peripherals.Sensors.Hid.JoystickPositionChangeResult e)
        {
            Console.WriteLine($"({e.New.HorizontalValue}, {e.New.VerticalValue})");
        }
    }
}

Sample projects available on GitHub

Wiring Example

Characteristic Locus
Inheritance System.Object FilterableChangeObservableBase<JoystickPositionChangeResult, JoystickPosition> > AnalogJoystick
Implements System.IObservable<JoystickPositionChangeResult>
Inherited Members FilterableChangeObservableBase<JoystickPositionChangeResult, JoystickPosition>._observers FilterableChangeObservableBase<JoystickPositionChangeResult, JoystickPosition>.NotifyObservers(JoystickPositionChangeResult) FilterableChangeObservableBase<JoystickPositionChangeResult, JoystickPosition>.Subscribe(IObserver<JoystickPositionChangeResult>) System.Object.ToString() System.Object.Equals(System.Object) System.Object.Equals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) System.Object.GetHashCode() System.Object.GetType() System.Object.MemberwiseClone()
Namespace Meadow.Foundation.Sensors.Hid
Assembly Meadow.Foundation.dll

Syntax

public class AnalogJoystick : FilterableChangeObservableBase<JoystickPositionChangeResult, JoystickPosition>, IObservable<JoystickPositionChangeResult>

Constructors

AnalogJoystick(IAnalogInputPort, IAnalogInputPort, AnalogJoystick.JoystickCalibration, Boolean)

Declaration
public AnalogJoystick(IAnalogInputPort horizontalInputPort, IAnalogInputPort verticalInputPort, AnalogJoystick.JoystickCalibration calibration = null, bool isInverted = false)

Parameters

Type Name Description
IAnalogInputPort horizontalInputPort
IAnalogInputPort verticalInputPort
AnalogJoystick.JoystickCalibration calibration
System.Boolean isInverted

AnalogJoystick(IIODevice, IPin, IPin, AnalogJoystick.JoystickCalibration, Boolean)

Declaration
public AnalogJoystick(IIODevice device, IPin horizontalPin, IPin verticalPin, AnalogJoystick.JoystickCalibration calibration = null, bool isInverted = false)

Parameters

Type Name Description
IIODevice device
IPin horizontalPin
IPin verticalPin
AnalogJoystick.JoystickCalibration calibration
System.Boolean isInverted

Properties

Calibration

Declaration
public AnalogJoystick.JoystickCalibration Calibration { get; protected set; }

Property Value

Type Description
AnalogJoystick.JoystickCalibration

HorizontalInputPort

Declaration
public IAnalogInputPort HorizontalInputPort { get; protected set; }

Property Value

Type Description
IAnalogInputPort

HorizontalValue

Declaration
public float HorizontalValue { get; protected set; }

Property Value

Type Description
System.Single

IsInverted

Declaration
public bool IsInverted { get; protected set; }

Property Value

Type Description
System.Boolean

Position

Declaration
public AnalogJoystick.DigitalJoystickPosition Position { get; }

Property Value

Type Description
AnalogJoystick.DigitalJoystickPosition

VerticalInputPort

Declaration
public IAnalogInputPort VerticalInputPort { get; protected set; }

Property Value

Type Description
IAnalogInputPort

VerticalValue

Declaration
public float VerticalValue { get; protected set; }

Property Value

Type Description
System.Single

Methods

GetHorizontalValue()

Declaration
public Task<float> GetHorizontalValue()

Returns

Type Description
System.Threading.Tasks.Task<System.Single>

GetPosition()

Declaration
public Task<AnalogJoystick.DigitalJoystickPosition> GetPosition()

Returns

Type Description
System.Threading.Tasks.Task<AnalogJoystick.DigitalJoystickPosition>

GetVerticalValue()

Declaration
public Task<float> GetVerticalValue()

Returns

Type Description
System.Threading.Tasks.Task<System.Single>

IsJoystickInPosition(AnalogJoystick.DigitalJoystickPosition)

Declaration
public bool IsJoystickInPosition(AnalogJoystick.DigitalJoystickPosition position)

Parameters

Type Name Description
AnalogJoystick.DigitalJoystickPosition position

Returns

Type Description
System.Boolean

RaiseEventsAndNotify(JoystickPositionChangeResult)

Declaration
protected void RaiseEventsAndNotify(JoystickPositionChangeResult changeResult)

Parameters

Type Name Description
JoystickPositionChangeResult changeResult

SetCenterPosition()

Declaration
public Task SetCenterPosition()

Returns

Type Description
System.Threading.Tasks.Task

SetRange(Int32)

Declaration
public Task SetRange(int duration)

Parameters

Type Name Description
System.Int32 duration

Returns

Type Description
System.Threading.Tasks.Task

StartUpdating(Int32, Int32, Int32)

Declaration
public void StartUpdating(int sampleCount = 3, int sampleIntervalDuration = 40, int standbyDuration = 100)

Parameters

Type Name Description
System.Int32 sampleCount
System.Int32 sampleIntervalDuration
System.Int32 standbyDuration

StopUpdating()

Declaration
public void StopUpdating()

Events

Updated

Raised when the value of the reading changes.

Declaration
public event EventHandler<JoystickPositionChangeResult> Updated

Event Type

Type Description
System.EventHandler<JoystickPositionChangeResult>