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

Fixing warnings and nullables #827

Merged
merged 2 commits into from
Nov 1, 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class ByteCommsSensorBase<UNIT> :
/// <summary>
/// Bus communications object, i.e. an I2cCommunications or SpiCommunications
/// </summary>
protected IByteCommunications? BusComms { get; set; }
protected IByteCommunications BusComms { get; set; }

/// <summary>
/// The read buffer
Expand Down Expand Up @@ -69,8 +69,7 @@ protected ByteCommsSensorBase(
/// </summary>
/// <param name="readBufferSize">Read buffer size</param>
/// <param name="writeBufferSize">Write buffer size</param>
protected ByteCommsSensorBase(
int readBufferSize = 8, int writeBufferSize = 8)
protected ByteCommsSensorBase(int readBufferSize = 8, int writeBufferSize = 8)
{
Init(readBufferSize, writeBufferSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class SerialTextFile
/// <summary>
/// A complete line of text has been read, send this to the event subscriber.
/// </summary>
public event LineReceived OnLineReceived = delegate { };
public event LineReceived OnLineReceived = default!;

#endregion Events and delegates

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class SpiCommunications : ISpiCommunications
/// <summary>
/// The SPI chip select port
/// </summary>
public IDigitalOutputPort ChipSelect { get; }
public IDigitalOutputPort? ChipSelect { get; }

/// <summary>
/// The chip select mode (active high or active low)
Expand Down
2 changes: 1 addition & 1 deletion Source/Meadow.Foundation.Core/Relays/Relay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Meadow.Foundation.Relays
public class Relay : IRelay
{
/// <inheritdoc/>
public event EventHandler<bool> OnRelayChanged = delegate { };
public event EventHandler<bool> OnRelayChanged = default!;

/// <summary>
/// Returns digital output port
Expand Down
2 changes: 1 addition & 1 deletion Source/Meadow.Foundation.Core/SamplingSensorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract class SamplingSensorBase<UNIT> : ObservableBase<UNIT>, ISampling
/// <summary>
/// Event handler for updated values
/// </summary>
public event EventHandler<IChangeResult<UNIT>> Updated = delegate { };
public event EventHandler<IChangeResult<UNIT>> Updated = default!;

/// <summary>
/// Sampling cancellation token source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ public abstract class PushButtonBase : IButton, IDisposable
/// <summary>
/// Raised when a press starts
/// </summary>
public event EventHandler PressStarted = delegate { };
public event EventHandler PressStarted = default!;

/// <summary>
/// Raised when a press ends
/// </summary>
public event EventHandler PressEnded = delegate { };
public event EventHandler PressEnded = default!;

/// <summary>
/// Raised when the button is released after a press
/// </summary>
public event EventHandler Clicked = delegate { };
public event EventHandler Clicked = default!;

/// <summary>
/// Raised when the button is pressed for LongClickedThreshold or longer and then releases
/// </summary>
public event EventHandler LongClicked = delegate { };
public event EventHandler LongClicked = default!;

/// <summary>
/// Track if we created the input port in the PushButton instance (true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class LinearHallEffectTachometer
/// Event raised when the RPM change is greater than the
/// RPMChangeNotificationThreshold value.
/// </summary>
public event EventHandler<ChangeResult<float>> RPMsChanged = delegate { };
public event EventHandler<ChangeResult<float>> RPMsChanged = default!;

/// <summary>
/// Any changes to the RPMs that are greater than the RPM change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DigitalJoystick : IDigitalJoystick
/// <summary>
/// Raised when the digital joystick position changes
/// </summary>
public event EventHandler<ChangeResult<DigitalJoystickPosition>> Updated = delegate { };
public event EventHandler<ChangeResult<DigitalJoystickPosition>> Updated = default!;

/// <summary>
/// The PushButton class for the up digital joystick switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public partial class AnalogLightSensor
/// <summary>
/// Raised when the value of the reading changes.
/// </summary>
public event EventHandler<IChangeResult<Illuminance>> IlluminanceUpdated = delegate { };
public event EventHandler<IChangeResult<Illuminance>> IlluminanceUpdated = default!;

/// <summary>
/// Illuminance sensor calibration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class RotaryEncoder : IRotaryEncoder
/// <summary>
/// Raised when the rotary encoder is rotated and returns a RotaryTurnedEventArgs object which describes the direction of rotation.
/// </summary>
public event EventHandler<RotaryChangeResult> Rotated = delegate { };
public event EventHandler<RotaryChangeResult> Rotated = default!;

/// <summary>
/// Returns the pin connected to the A-phase output on the rotary encoder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ public class RotaryEncoderWithButton : RotaryEncoder, IRotaryEncoderWithButton
/// <summary>
/// Raised when the button circuit is re-opened after it has been closed
/// </summary>
public event EventHandler Clicked = delegate { };
public event EventHandler Clicked = default!;

/// <summary>
/// Raised when a press ends
/// </summary>
public event EventHandler PressEnded = delegate { };
public event EventHandler PressEnded = default!;

/// <summary>
/// Raised when a press starts
/// </summary>
public event EventHandler PressStarted = delegate { };
public event EventHandler PressStarted = default!;

/// <summary>
/// Raised when the button circuit is pressed for LongPressDuration
/// </summary>
public event EventHandler LongClicked = delegate { };
public event EventHandler LongClicked = default!;

/// <summary>
/// The minimum duration for a long press
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class DipSwitch
/// <summary>
/// Raised when one of the switches is switched on or off.
/// </summary>
public event ArrayEventHandler Changed = delegate { };
public event ArrayEventHandler Changed = default!;

/// <summary>
/// Creates a new DipSwitch connected to the specified switchPins, with the InterruptMode and ResisterMode specified by the type parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public bool IsOn
/// <summary>
/// Raised when the switch circuit is opened or closed.
/// </summary>
public event EventHandler Changed = delegate { };
public event EventHandler Changed = default!;

/// <summary>
/// Instantiates a new SpdtSwitch object with the center pin connected to the specified digital pin, one pin connected to common/ground and one pin connected to high/3.3V.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public bool IsOn
/// <summary>
/// Raised when the switch circuit is opened or closed.
/// </summary>
public event EventHandler Changed = delegate { };
public event EventHandler Changed = default!;

/// <summary>
/// Returns the DigitalInputPort.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public partial class AnalogTemperature : SamplingSensorBase<Units.Temperature>,
/// <summary>
/// Raised when the value of the reading changes.
/// </summary>
public event EventHandler<IChangeResult<Units.Temperature>> TemperatureUpdated = delegate { };
public event EventHandler<IChangeResult<Units.Temperature>> TemperatureUpdated = default!;

///<Summary>
/// AnalogInputPort connected to temperature sensor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class NumericBase : InputBase
/// <summary>
/// Raised when the numeric value changes
/// </summary>
public override event ValueChangedHandler ValueChanged = delegate { };
public override event ValueChangedHandler ValueChanged = default!;

/// <summary>
/// Create a new NumericBase object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ namespace Meadow.Foundation.Displays.UI.InputTypes
/// </summary>
public abstract class TimeBase : InputBase
{
/// <summary>
/// Value for each time part
/// </summary>
protected int[] timeParts;

/// <summary>
/// The current position
/// </summary>
protected byte position = 0;

/// <summary>
Expand All @@ -19,7 +26,7 @@ public abstract class TimeBase : InputBase
/// Raised if the input value changes
/// </summary>

public override event ValueChangedHandler ValueChanged = delegate { };
public override event ValueChangedHandler ValueChanged = default!;

/// <summary>
/// Create a new TimeBase object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Date : InputBase
/// <summary>
/// Raised when the date value changes
/// </summary>
public override event ValueChangedHandler ValueChanged;
public override event ValueChangedHandler ValueChanged = default!;

/// <summary>
/// Create a new Date input object
Expand All @@ -39,6 +39,11 @@ byte CursorPosition
{
get
{
if (display == null)
{
return 0;
}

return position switch
{
0 => (byte)(display.DisplayConfig.Width - 7),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class ListBase : InputBase
/// <summary>
/// The value changed event handler
/// </summary>
public override event ValueChangedHandler ValueChanged = delegate { };
public override event ValueChangedHandler ValueChanged = default!;

/// <summary>
/// The output display text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public class TextDisplayMenu
/// <summary>
/// Raised when the menu receives a selected input
/// </summary>
public event MenuSelectedHandler Selected = delegate { };
public event MenuSelectedHandler Selected = default!;

/// <summary>
/// Raised when a value changes
/// </summary>
public event ValueChangedHandler ValueChanged = delegate { };
public event ValueChangedHandler ValueChanged = default!;

/// <summary>
/// Raised when the user exits the menu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,13 @@ public void DrawBuffer(int x, int y, IPixelBuffer buffer)
public void DrawImage(int x, int y, Image image,
HorizontalAlignment alignmentH = HorizontalAlignment.Left,
VerticalAlignment alignmentV = VerticalAlignment.Top)
=> DrawBuffer(x, y, image.DisplayBuffer, alignmentH, alignmentV);
{
if (image.DisplayBuffer is not null)
{
DrawBuffer(x, y, image.DisplayBuffer, alignmentH, alignmentV);
}
throw new Exception("Image does not have a display buffer");
}

/// <summary>
/// Draw an Image onto the display buffer at the specified location
Expand All @@ -1371,7 +1377,13 @@ public void DrawImage(int x, int y, Image image,
/// <param name="y">x location of target to draw buffer</param>
/// <param name="image">the source image to write to the display buffer</param>
public void DrawImage(int x, int y, Image image)
=> DrawBuffer(x, y, image.DisplayBuffer);
{
if (image.DisplayBuffer is not null)
{
DrawBuffer(x, y, image.DisplayBuffer);
}
throw new Exception("Image does not have a display buffer");
}

/// <summary>
/// Draw an Image onto the display buffer at (0, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public abstract class ClickableControl : ThemedControl, IClickableControl
/// <summary>
/// Occurs when the clickable control is clicked.
/// </summary>
public event EventHandler Clicked = delegate { };
public event EventHandler Clicked = default!;

private bool _pressed = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Meadow.Foundation.Displays.UI;

public class MeadowApp : App<Windows>
{
private DisplayScreen _screen;
private DisplayScreen? _screen;

public static async Task Main(string[] args)
{
Expand Down Expand Up @@ -144,4 +144,4 @@ private LineChartSeries GetCosineSeries(double xScale = 4, double yScale = 1.5,

return series;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class MeadowApp : App<Windows>
{
private Ft232h expander = new Ft232h();
private DisplayScreen screen;
private DisplayScreen? screen;

public override Task Initialize()
{
Expand Down Expand Up @@ -41,7 +41,7 @@ public override Task Run()

public void Text()
{
var label = new Label(0, 0, screen.Width, screen.Height);
var label = new Label(0, 0, screen!.Width, screen.Height);
label.Font = new Font12x20();
label.HorizontalAlignment = HorizontalAlignment.Center;
label.VerticalAlignment = VerticalAlignment.Center;
Expand All @@ -54,7 +54,7 @@ public void Text()

public void TextOnBox()
{
var box = new Box(0, 0, screen.Width / 4, screen.Height);
var box = new Box(0, 0, screen!.Width / 4, screen.Height);
box.ForeColor = Color.Red;
var label = new Label(0, 0, screen.Width / 4, screen.Height);
label.HorizontalAlignment = HorizontalAlignment.Center;
Expand All @@ -75,7 +75,7 @@ public void TextOnBox()

public void Sweep()
{
var box = new Box(0, 0, screen.Width / 4, screen.Height);
var box = new Box(0, 0, screen!.Width / 4, screen.Height);
box.ForeColor = Color.Red;

screen.Controls.Add(box);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class MeadowApp : App<Windows>
{
private readonly Ft232h expander = new Ft232h();
private DisplayScreen screen;
private DisplayScreen? screen;

public override Task Initialize()
{
Expand All @@ -33,7 +33,7 @@ public override Task Run()

public void Text()
{
var label = new Label(0, 0, screen.Width, screen.Height);
var label = new Label(0, 0, screen!.Width, screen.Height);
label.HorizontalAlignment = Meadow.Foundation.Graphics.HorizontalAlignment.Center;
label.VerticalAlignment = Meadow.Foundation.Graphics.VerticalAlignment.Center;
label.TextColor = Color.White;
Expand All @@ -45,7 +45,7 @@ public void Text()

public void TextOnBox()
{
var box = new Box(0, 0, screen.Width / 4, screen.Height);
var box = new Box(0, 0, screen!.Width / 4, screen.Height);
box.ForeColor = Color.Red;
var label = new Label(0, 0, screen.Width / 4, screen.Height);
label.HorizontalAlignment = Meadow.Foundation.Graphics.HorizontalAlignment.Center;
Expand All @@ -66,7 +66,7 @@ public void TextOnBox()

public void Sweep()
{
var box = new Box(0, 0, screen.Width / 4, screen.Height);
var box = new Box(0, 0, screen!.Width / 4, screen.Height);
box.ForeColor = Color.Red;

screen.Controls.Add(box);
Expand Down
Loading