Skip to content

Commit

Permalink
Merge pull request #23 from WildernessLabs/pin_controller
Browse files Browse the repository at this point in the history
Updates for pin controller pattern
  • Loading branch information
patridge authored Feb 17, 2023
2 parents bb3822d + 5bb2848 commit c6eebf3
Show file tree
Hide file tree
Showing 47 changed files with 80 additions and 165 deletions.
4 changes: 1 addition & 3 deletions Source/Button/Driver/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ public Button(IDigitalInputPort interruptPort)
/// <summary>
/// Creates a new Button driver
/// </summary>
/// <param name="device"></param>
/// <param name="inputPin"></param>
/// <param name="resistorMode"></param>
public Button(
IDigitalInputController device,
IPin inputPin,
ResistorMode resistorMode = ResistorMode.InternalPullUp)
: base(device, inputPin, resistorMode)
: base(inputPin, resistorMode)
{ }
}
}
2 changes: 1 addition & 1 deletion Source/Button/Sample/Button_Sample/MeadowApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override Task Initialize()
{
Console.WriteLine("Initialize...");

button = new Button(Device, Device.Pins.D13)
button = new Button(Device.Pins.D13)
{
LongClickedThreshold = TimeSpan.FromMilliseconds(1500)
};
Expand Down
4 changes: 1 addition & 3 deletions Source/Buzzer/Driver/Buzzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ public Buzzer(IPwmPort port)
/// <summary>
/// Creates a new Buzzer driver
/// </summary>
/// <param name="device">The Pwm controller connected to the buzzer (typically Meadow)</param>
/// <param name="pin">The pin connected to the buzzer/param>
public Buzzer(
IPwmOutputController device,
IPin pin)
: base(device, pin, new Frequency(440))
: base(pin, new Frequency(440))
{ }
}
}
2 changes: 1 addition & 1 deletion Source/Buzzer/Sample/Buzzer_Sample/MeadowApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override Task Initialize()
{
Console.WriteLine("Initialize...");

buzzer = new Buzzer(Device, Device.Pins.D13);
buzzer = new Buzzer(Device.Pins.D13);

return Task.CompletedTask;
}
Expand Down
9 changes: 2 additions & 7 deletions Source/FlameSensor/Driver/FlameSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@ public FlameSensor(IDigitalInputPort signalPort)
/// <summary>
/// Creates a Flame Sensor driver
/// </summary>
/// <param name="device"></param>
/// <param name="inputPin"></param>
public FlameSensor(
IDigitalInputController device,
IPin inputPin)
: this(
device.CreateDigitalInputPort(
inputPin,
public FlameSensor(IPin inputPin)
: this(inputPin.CreateDigitalInputPort(
InterruptMode.EdgeBoth,
ResistorMode.InternalPullUp,
TimeSpan.Zero,
Expand Down
2 changes: 1 addition & 1 deletion Source/FlameSensor/Sample/FlameSensor_Sample/MeadowApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override Task Initialize()
{
Console.WriteLine("Initialize...");

flameSensor = new FlameSensor(Device, Device.Pins.D13);
flameSensor = new FlameSensor(Device.Pins.D13);

flameSensor.FlameDetected += (s, e) =>
{
Expand Down
9 changes: 3 additions & 6 deletions Source/LEDButton/Driver/LEDButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,15 @@ public LEDButton(IDigitalInputPort buttonPort, IDigitalOutputPort ledPort)
/// <summary>
/// Creates an LEDButton driver
/// </summary>
/// <param name="device"></param>
/// <param name="buttonPin"></param>
/// <param name="ledPin"></param>
/// <param name="resistorMode"></param>
public LEDButton(
IMeadowDevice device,
IPin buttonPin,
public LEDButton(IPin buttonPin,
IPin ledPin,
ResistorMode resistorMode = ResistorMode.InternalPullUp)
: base(device, buttonPin, resistorMode)
: base(buttonPin, resistorMode)
{
led = new Led(device, ledPin);
led = new Led(ledPin);
}
}
}
5 changes: 1 addition & 4 deletions Source/LEDButton/Sample/LEDButton_Sample/MeadowApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ public override Task Initialize()
{
Console.WriteLine("Initialize...");

ledButton = new LEDButton(
device: Device,
buttonPin: Device.Pins.D12,
ledPin: Device.Pins.D13);
ledButton = new LEDButton(buttonPin: Device.Pins.D12, ledPin: Device.Pins.D13);

ledButton.LongClickedThreshold = TimeSpan.FromMilliseconds(1500);

Expand Down
5 changes: 2 additions & 3 deletions Source/LEDSocket/Driver/LEDSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ public LEDSocket(IDigitalOutputPort port)
/// <summary>
/// Creates an LEDSocker driver
/// </summary>
/// <param name="device"></param>
/// <param name="pin"></param>
public LEDSocket(IDigitalOutputController device, IPin pin)
: base(device, pin)
public LEDSocket(IPin pin)
: base(pin)
{ }
}
}
2 changes: 1 addition & 1 deletion Source/LEDSocket/Sample/LEDSocket_Sample/MeadowApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override Task Initialize()
{
Console.WriteLine("Initialize...");

led = new LEDSocket(Device, Device.Pins.D13);
led = new LEDSocket(Device.Pins.D13);

return Task.CompletedTask;
}
Expand Down
11 changes: 4 additions & 7 deletions Source/LightSensor/Driver/LightSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ public LightSensor(IAnalogInputPort port) : base(port)
/// Creates a new LightSensor driver
/// </summary>
public LightSensor(
IAnalogInputController device,
IPin pin,
int sampleCount = 5,
TimeSpan? sampleInterval = null,
Voltage? voltage = null)
: this (
device.CreateAnalogInputPort(
pin,
sampleCount,
sampleInterval ?? TimeSpan.FromMilliseconds(40),
voltage ?? new Voltage(3.3)))
: this (pin.CreateAnalogInputPort(
sampleCount,
sampleInterval ?? TimeSpan.FromMilliseconds(40),
voltage ?? new Voltage(3.3)))
{ }
}
}
2 changes: 1 addition & 1 deletion Source/LightSensor/Sample/LightSensor_Sample/MeadowApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override Task Initialize()
{
Console.WriteLine("Initialize...");

sensor = new LightSensor(Device, Device.Pins.A01);
sensor = new LightSensor(Device.Pins.A01);

var consumer = LightSensor.CreateObserver(
handler: result => Console.WriteLine($"Observer filter satisfied: {result.New.Millivolts:N2}mV, old: {result.Old?.Millivolts:N2}mV"),
Expand Down
15 changes: 6 additions & 9 deletions Source/LineFinder/Driver/LineFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,13 @@ public LineFinder(IDigitalInputPort signalPort)
/// <summary>
/// Creates a new LineFinder driver
/// </summary>
/// <param name="device"></param>
/// <param name="inputPin"></param>
public LineFinder(IDigitalInputController device, IPin inputPin)
: this(
device.CreateDigitalInputPort(
inputPin,
InterruptMode.EdgeBoth,
ResistorMode.InternalPullUp,
TimeSpan.Zero,
TimeSpan.FromMilliseconds(25)))
public LineFinder(IPin inputPin)
: this(inputPin.CreateDigitalInputPort(
InterruptMode.EdgeBoth,
ResistorMode.InternalPullUp,
TimeSpan.Zero,
TimeSpan.FromMilliseconds(25)))
{ }

void SignalPortChanged(object sender, DigitalPortResult e)
Expand Down
2 changes: 1 addition & 1 deletion Source/LineFinder/Sample/LineFinder_Sample/MeadowApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override Task Initialize()
{
Console.WriteLine("Initialize...");

var lineFinder = new LineFinder(Device, Device.Pins.D13);
var lineFinder = new LineFinder(Device.Pins.D13);

lineFinder.ColorChanged += (s, e) =>
{
Expand Down
5 changes: 1 addition & 4 deletions Source/LoudnessSensor/Driver/LoudnessSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ public LoudnessSensor(IAnalogInputPort port) : base(port)
/// </summary>
/// <param name="pin">AnalogChannel connected to the sensor.</param>
public LoudnessSensor(
IAnalogInputController device,
IPin pin,
int sampleCount = 5,
TimeSpan? sampleInterval = null,
Voltage? voltage = null)
: this(
device.CreateAnalogInputPort(
pin,
: this(pin.CreateAnalogInputPort(
sampleCount,
sampleInterval ?? TimeSpan.FromMilliseconds(40),
voltage ?? new Voltage(3.3)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override Task Initialize()
{
Console.WriteLine("Initialize...");

sensor = new LoudnessSensor(Device, Device.Pins.A01);
sensor = new LoudnessSensor(Device.Pins.A01);

var consumer = LoudnessSensor.CreateObserver(
handler: result => Console.WriteLine($"Observer filter satisfied: {result.New.Millivolts:N2}mV, old: {result.Old?.Millivolts:N2}mV"),
Expand Down
9 changes: 2 additions & 7 deletions Source/MagneticSwitch/Driver/MagneticSwitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,9 @@ public MagneticSwitch(IDigitalInputPort signalPort)
/// <summary>
/// Creates a MagneticSwitch driver
/// </summary>
/// <param name="device"></param>
/// <param name="inputPin"></param>
public MagneticSwitch(
IDigitalInputController device,
IPin inputPin)
: this(
device.CreateDigitalInputPort(
inputPin,
public MagneticSwitch(IPin inputPin)
: this(inputPin.CreateDigitalInputPort(
InterruptMode.EdgeBoth,
ResistorMode.InternalPullUp,
TimeSpan.Zero,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override Task Initialize()
{
Console.WriteLine("Initialize...");

var magneticSwitch = new MagneticSwitch(Device, Device.Pins.D13);
var magneticSwitch = new MagneticSwitch(Device.Pins.D13);

magneticSwitch.Changed += (s, e) =>
{
Expand Down
9 changes: 2 additions & 7 deletions Source/MiniPIRMotionSensor/Driver/MiniPIRMotionSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,18 @@ public MiniPIRMotionSensor(IDigitalInputPort digitalInputPort)
/// <summary>
/// Creates a MiniPIRMotionSensor driver
/// </summary>
/// <param name="device">The Meadow device</param>
/// <param name="pin">The pin connected to the PIR sensor</param>
/// <param name="interruptMode">The interrupt mode of the pin</param>
/// <param name="resistorMode">The resistor mode of the pin</param>
/// <param name="debounceDuration">The debounce duration</param>
/// <param name="glitchDuration">The glitch duration (can typically be set to zero)</param>
public MiniPIRMotionSensor(
IDigitalInputController device,
IPin pin,
InterruptMode
interruptMode,
InterruptMode interruptMode,
ResistorMode resistorMode,
TimeSpan debounceDuration,
TimeSpan glitchDuration)
: base(
device,
pin,
: base(pin,
interruptMode,
resistorMode,
debounceDuration,
Expand Down
5 changes: 1 addition & 4 deletions Source/MoistureSensor/Driver/MoistureSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ public MoistureSensor(IAnalogInputPort port)
/// </summary>
/// <param name="pin">AnalogChannel connected to the sensor.</param>
public MoistureSensor(
IAnalogInputController device,
IPin pin,
int sampleCount = 5,
TimeSpan? sampleInterval = null,
Voltage? voltage = null)
: this(
device.CreateAnalogInputPort(
pin,
: this(pin.CreateAnalogInputPort(
sampleCount,
sampleInterval ?? TimeSpan.FromMilliseconds(40),
voltage ?? new Voltage(3.3)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override Task Initialize()
{
Console.WriteLine("Initialize...");

sensor = new MoistureSensor(Device, Device.Pins.A01);
sensor = new MoistureSensor(Device.Pins.A01);

var consumer = MoistureSensor.CreateObserver(
handler: result => Console.WriteLine($"Observer filter satisfied: {result.New.Millivolts:N2}mV, old: {result.Old?.Millivolts:N2}mV"),
Expand Down
6 changes: 1 addition & 5 deletions Source/PIRMotionSensor/Driver/PIRMotionSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,18 @@ public PIRMotionSensor(IDigitalInputPort digitalInputPort)
/// <summary>
/// Creates a PIRMotionSensor driver
/// </summary>
/// <param name="device">The Meadow device</param>
/// <param name="pin">The pin connected to the PIR sensor</param>
/// <param name="interruptMode">The interrupt mode of the pin</param>
/// <param name="resistorMode">The resistor mode of the pin</param>
/// <param name="debounceDuration">The debounce duration</param>
/// <param name="glitchDuration">The glitch duration (can typically be set to zero)</param>
public PIRMotionSensor(
IDigitalInputController device,
IPin pin,
InterruptMode interruptMode,
ResistorMode resistorMode,
TimeSpan debounceDuration,
TimeSpan glitchDuration)
: base(
device,
pin,
: base(pin,
interruptMode,
resistorMode,
debounceDuration,
Expand Down
5 changes: 2 additions & 3 deletions Source/Relay/Driver/Relay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ public Relay(IDigitalOutputPort port)
/// <summary>
/// Creates a new Relay driver
/// </summary>
/// <param name="device"></param>
/// <param name="pin"></param>
public Relay(IDigitalOutputController device, IPin pin)
: base(device, pin)
public Relay(IPin pin)
: base(pin)
{ }
}
}
2 changes: 1 addition & 1 deletion Source/Relay/Sample/Relay_Sample/MeadowApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override Task Initialize()
{
Console.WriteLine("Initialize...");

relay = new Relay(Device, Device.Pins.D13);
relay = new Relay(Device.Pins.D13);

return Task.CompletedTask;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/RotaryAngleSensor/Driver/RotaryAngleSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public RotaryAngleSensor(IAnalogInputPort port) : base(port)
/// Creates a new RotaryAngleSensor driver
/// </summary>
/// <param name="pin">AnalogChannel connected to the sensor.</param>
public RotaryAngleSensor(IAnalogInputController device, IPin pin, int sampleCount = 5, TimeSpan? sampleInterval = null, Voltage? voltage = null)
: this(device.CreateAnalogInputPort(pin, sampleCount, sampleInterval ?? TimeSpan.FromMilliseconds(40), voltage ?? new Voltage(3.3)))
public RotaryAngleSensor(IPin pin, int sampleCount = 5, TimeSpan? sampleInterval = null, Voltage? voltage = null)
: this(pin.CreateAnalogInputPort(sampleCount, sampleInterval ?? TimeSpan.FromMilliseconds(40), voltage ?? new Voltage(3.3)))
{ }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override Task Initialize()
{
Console.WriteLine("Initialize...");

sensor = new RotaryAngleSensor(Device, Device.Pins.A01);
sensor = new RotaryAngleSensor(Device.Pins.A01);

var consumer = RotaryAngleSensor.CreateObserver(
handler: result => Console.WriteLine($"Observer filter satisfied: {result.New.Millivolts:N2}mV, old: {result.Old?.Millivolts:N2}mV"),
Expand Down
7 changes: 3 additions & 4 deletions Source/Servo/Driver/Servo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ public Servo(IPwmPort pwm)
/// <summary>
/// Creates a Servo driver
/// </summary>
/// <param name="device"></param>
/// <param name="pwm"></param>
public Servo(IPwmOutputController device, IPin pwm)
: base(device, pwm, NamedServoConfigs.SG90)
/// <param name="pwmPin"></param>
public Servo(IPin pwmPin)
: base(pwmPin, NamedServoConfigs.SG90)
{ }
}
}
2 changes: 1 addition & 1 deletion Source/Servo/Sample/Servo_Sample/MeadowApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override Task Initialize()
{
Console.WriteLine("Initialize...");

servo = new Servo(Device, Device.Pins.D13);
servo = new Servo(Device.Pins.D13);

return Task.CompletedTask;
}
Expand Down
Loading

0 comments on commit c6eebf3

Please sign in to comment.