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

Release 1.5.0 #169

Merged
merged 1 commit into from
Nov 29, 2023
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
10 changes: 5 additions & 5 deletions Source/Meadow.Contracts/CircularBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CircularBuffer<T> : IEnumerable<T>
/// <summary>
/// Event raised when an item is added to the buffer
/// </summary>
public event EventHandler ItemAdded = delegate { };
public event EventHandler ItemAdded = default!;

// TODO: this should probably be Span<T>
private readonly T[] _list;
Expand All @@ -27,19 +27,19 @@ public class CircularBuffer<T> : IEnumerable<T>
/// <summary>
/// Fires when an element is added to the buffer when it is already full
/// </summary>
public event EventHandler Overrun = delegate { };
public event EventHandler Overrun = default!;
/// <summary>
/// Fires when an attempt is made to remove an item from an empty buffer
/// </summary>
public event EventHandler Underrun = delegate { };
public event EventHandler Underrun = default!;
/// <summary>
/// Fires when the number of elements reaches a non-zero HighWaterLevel value on an Enqueue call. This event fires only once when passing upward across the boundary.
/// </summary>
public event EventHandler HighWater = delegate { };
public event EventHandler HighWater = default!;
/// <summary>
/// Fires when the number of elements reaches a non-zero LowWaterLevel value on a Remove call. This event fires only once when passing downward across the boundary.
/// </summary>
public event EventHandler LowWater = delegate { };
public event EventHandler LowWater = default!;
/// <summary>
/// Gets the maximum number of elements the buffer can hold.
/// </summary>
Expand Down
25 changes: 25 additions & 0 deletions Source/Meadow.Contracts/Enums/ServerCertificateValidationMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

namespace Meadow;

/// <summary>
/// Enum representing different server certificate validation modes for TLS protocols.
/// </summary>
[Flags]
public enum ServerCertificateValidationMode
{
/// <summary>
/// No certificate validation is performed (Insecure)
/// </summary>
None = 0,

/// <summary>
/// Certificate validation is optional. Handshake continues even if verification fails
/// </summary>
Optional = 1,

/// <summary>
/// Peer must present a valid certificate; handshake is aborted if verification fails
/// </summary>
Required = 2
}
2 changes: 1 addition & 1 deletion Source/Meadow.Contracts/FilterableChangeObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class FilterableChangeObserver<UNIT> : IObserver<IChangeResult<UNIT>>
/// <summary>
/// Than handler that is called in `OnNext` if the filter is satisfied.
/// </summary>
protected Action<IChangeResult<UNIT>> Handler { get; } = delegate { };
protected Action<IChangeResult<UNIT>> Handler { get; } = default!;
/// <summary>
/// A filter that specifies whether or not the observer should get notified.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class AnalogInputPortBase : AnalogPortBase, IAnalogInputPort
/// <summary>
/// Raised when the value of the reading changes.
/// </summary>
public event EventHandler<IChangeResult<Voltage>> Updated = delegate { };
public event EventHandler<IChangeResult<Voltage>> Updated = default!;

/// <summary>
/// Gets the sample buffer. Make sure to call StartUpdating() before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class BiDirectionalInterruptPortBase : BiDirectionalPortBase, IB
/// <summary>
/// Event raised when the port value changes
/// </summary>
public event EventHandler<DigitalPortResult> Changed = delegate { };
public event EventHandler<DigitalPortResult> Changed = default!;

/// <summary>
/// Gets a list of port State observers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class DigitalInterruptPortBase : DigitalInputPortBase, IDigitalI
/// <summary>
/// Occurs when the state is changed. To enable this, set the InterruptMode at construction
/// </summary>
public event EventHandler<DigitalPortResult> Changed = delegate { };
public event EventHandler<DigitalPortResult> Changed = default!;

/// <summary>
/// Gets or sets a value indicating the type of interrupt monitoring this input.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,52 @@ public ISerialPort CreateSerialPort(int baudRate = 9600, int dataBits = 8, Parit
return _serialPortName.CreateSerialPort(baudRate, dataBits, parity, stopBits, readBufferSize);
}

/// <summary>
/// Creates an <see cref="ISerialMessagePort"/> directly from a <see cref="SerialPortName"/> using the current <see cref="IMeadowDevice"/>
/// </summary>
/// <param name="suffixDelimiter"></param>
/// <param name="preserveDelimiter"></param>
/// <param name="baudRate">The speed, in bits per second, of the serial port.</param>
/// <param name="parity">The `Parity` enum describing what type of cyclic-redundancy-check (CRC) bit, if any, should be expected in the serial message frame. Default is `Parity.None`.</param>
/// <param name="dataBits">The number of data bits expected in the serial message frame. Default is 8.</param>
/// <param name="stopBits">The `StopBits` describing how many bits should be expected at the end of every character in the serial message frame. Default is `StopBits.One`.</param>
/// <param name="readBufferSize">The size, in bytes, of the read buffer. Default is 1024.</param>
public ISerialMessagePort CreateSerialMessagePort(
byte[] suffixDelimiter,
bool preserveDelimiter,
int baudRate = 9600,
int dataBits = 8,
Parity parity = Parity.None,
StopBits stopBits = StopBits.One,
int readBufferSize = 512)
{
return _serialPortName.CreateSerialMessagePort(suffixDelimiter, preserveDelimiter, baudRate, dataBits, parity, stopBits, readBufferSize)!;
}

/// <summary>
/// Creates an <see cref="ISerialMessagePort"/> directly from a <see cref="SerialPortName"/> using the current <see cref="IMeadowDevice"/>
/// </summary>
/// <param name="prefixDelimiter"></param>
/// <param name="preserveDelimiter"></param>
/// <param name="messageLength"></param>
/// <param name="baudRate">The speed, in bits per second, of the serial port.</param>
/// <param name="parity">The `Parity` enum describing what type of cyclic-redundancy-check (CRC) bit, if any, should be expected in the serial message frame. Default is `Parity.None`.</param>
/// <param name="dataBits">The number of data bits expected in the serial message frame. Default is 8.</param>
/// <param name="stopBits">The `StopBits` describing how many bits should be expected at the end of every character in the serial message frame. Default is `StopBits.One`.</param>
/// <param name="readBufferSize">The size, in bytes, of the read buffer. Default is 1024.</param>
public ISerialMessagePort CreateSerialMessagePort(
byte[] prefixDelimiter,
bool preserveDelimiter,
int messageLength,
int baudRate = 9600,
int dataBits = 8,
Parity parity = Parity.None,
StopBits stopBits = StopBits.One,
int readBufferSize = 512)
{
return _serialPortName.CreateSerialMessagePort(prefixDelimiter, preserveDelimiter, messageLength, baudRate, dataBits, parity, stopBits, readBufferSize)!;
}

/// <summary>
/// Gets the connector's I2C bus
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,50 @@ public ISerialPort CreateSerialPort(int baudRate = 9600, int dataBits = 8, Parit
{
return _serialPortName.CreateSerialPort(baudRate, dataBits, parity, stopBits, readBufferSize);
}

/// <summary>
/// Creates an <see cref="ISerialMessagePort"/> directly from a <see cref="SerialPortName"/> using the current <see cref="IMeadowDevice"/>
/// </summary>
/// <param name="suffixDelimiter"></param>
/// <param name="preserveDelimiter"></param>
/// <param name="baudRate">The speed, in bits per second, of the serial port.</param>
/// <param name="parity">The `Parity` enum describing what type of cyclic-redundancy-check (CRC) bit, if any, should be expected in the serial message frame. Default is `Parity.None`.</param>
/// <param name="dataBits">The number of data bits expected in the serial message frame. Default is 8.</param>
/// <param name="stopBits">The `StopBits` describing how many bits should be expected at the end of every character in the serial message frame. Default is `StopBits.One`.</param>
/// <param name="readBufferSize">The size, in bytes, of the read buffer. Default is 1024.</param>
public ISerialMessagePort CreateSerialMessagePort(
byte[] suffixDelimiter,
bool preserveDelimiter,
int baudRate = 9600,
int dataBits = 8,
Parity parity = Parity.None,
StopBits stopBits = StopBits.One,
int readBufferSize = 512)
{
return _serialPortName.CreateSerialMessagePort(suffixDelimiter, preserveDelimiter, baudRate, dataBits, parity, stopBits, readBufferSize)!;
}

/// <summary>
/// Creates an <see cref="ISerialMessagePort"/> directly from a <see cref="SerialPortName"/> using the current <see cref="IMeadowDevice"/>
/// </summary>
/// <param name="prefixDelimiter"></param>
/// <param name="preserveDelimiter"></param>
/// <param name="messageLength"></param>
/// <param name="baudRate">The speed, in bits per second, of the serial port.</param>
/// <param name="parity">The `Parity` enum describing what type of cyclic-redundancy-check (CRC) bit, if any, should be expected in the serial message frame. Default is `Parity.None`.</param>
/// <param name="dataBits">The number of data bits expected in the serial message frame. Default is 8.</param>
/// <param name="stopBits">The `StopBits` describing how many bits should be expected at the end of every character in the serial message frame. Default is `StopBits.One`.</param>
/// <param name="readBufferSize">The size, in bytes, of the read buffer. Default is 1024.</param>
public ISerialMessagePort CreateSerialMessagePort(
byte[] prefixDelimiter,
bool preserveDelimiter,
int messageLength,
int baudRate = 9600,
int dataBits = 8,
Parity parity = Parity.None,
StopBits stopBits = StopBits.One,
int readBufferSize = 512)
{
return _serialPortName.CreateSerialMessagePort(prefixDelimiter, preserveDelimiter, messageLength, baudRate, dataBits, parity, stopBits, readBufferSize)!;
}
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,51 @@
using Meadow.Units;
using System;

namespace Meadow.Hardware
namespace Meadow.Hardware;

/// <summary>
/// Contract for devices that expose `IAnalogInputPort(s)`.
/// </summary>
public interface IAnalogInputController : IPinController
{
// TODO: if Microsoft ever gets around to fixing the compile time const
// thing, we should make this a `Voltage`
/// <summary>
/// The default Analog to Digital converter reference voltage.
/// </summary>
public const float DefaultA2DReferenceVoltage = 3.3f;

/// <summary>
/// Contract for devices that expose `IAnalogInputPort(s)`.
/// Initializes the specified pin to be an AnalogInput and returns the
/// port used to sample the port value.
/// </summary>
public interface IAnalogInputController : IPinController
{
// TODO: if Microsoft ever gets around to fixing the compile time const
// thing, we should make this a `Voltage`
/// <summary>
/// The default Analog to Digital converter reference voltage.
/// </summary>
public const float DefaultA2DReferenceVoltage = 3.3f;
/// <param name="pin">The pin to create the port on.</param>
/// <param name="sampleCount">The number of samples to use for input averaging</param>
/// <returns></returns>
IAnalogInputPort CreateAnalogInputPort(
IPin pin,
int sampleCount
) => CreateAnalogInputPort(pin, sampleCount, TimeSpan.FromSeconds(1), new Voltage(DefaultA2DReferenceVoltage, Voltage.UnitType.Volts));

/// <summary>
/// Initializes the specified pin to be an AnalogInput and returns the
/// port used to sample the port value.
/// </summary>
/// <param name="pin">The pin to create the port on.</param>
/// <param name="sampleCount">The number of samples to use for input averaging</param>
/// <returns></returns>
IAnalogInputPort CreateAnalogInputPort(
IPin pin,
int sampleCount
) => CreateAnalogInputPort(pin, sampleCount, TimeSpan.FromSeconds(1), new Voltage(DefaultA2DReferenceVoltage, Voltage.UnitType.Volts));
/// <summary>
/// Initializes the specified pin to be an AnalogInput and returns the
/// port used to sample the port value.
/// </summary>
/// <param name="pin">The pin to create the port on.</param>
/// <param name="sampleCount"></param>
/// <param name="sampleInterval"></param>
/// <param name="voltageReference">Reference maximum analog input port
/// voltage in Volts. Default is 3.3V.</param>
IAnalogInputPort CreateAnalogInputPort(
IPin pin,
int sampleCount,
TimeSpan sampleInterval,
Voltage voltageReference
);

/// <summary>
/// Initializes the specified pin to be an AnalogInput and returns the
/// port used to sample the port value.
/// </summary>
/// <param name="pin">The pin to create the port on.</param>
/// <param name="sampleCount"></param>
/// <param name="sampleInterval"></param>
/// <param name="voltageReference">Reference maximum analog input port
/// voltage in Volts. Default is 3.3V.</param>
/// <returns></returns>
IAnalogInputPort CreateAnalogInputPort(
IPin pin,
int sampleCount,
TimeSpan sampleInterval,
Voltage voltageReference
);
}
/// <summary>
/// Creates an IAnalogInputArray instance from the specified set of pins
/// </summary>
/// <param name="pins">The pins to use for the IAnalogInputArray</param>
IAnalogInputArray CreateAnalogInputArray(params IPin[] pins);
}
Loading
Loading