From 176694ea0142a4b0cdfebb6bee303b2c92871b7e Mon Sep 17 00:00:00 2001 From: Patrick Grawehr Date: Mon, 22 Feb 2021 16:48:23 +0100 Subject: [PATCH] Address review comments --- src/devices/Arduino/ArduinoAnalogController.cs | 3 ++- src/devices/Arduino/ArduinoAnalogInputPin.cs | 2 +- src/devices/Arduino/FirmataCommandSequence.cs | 5 ++++- src/devices/Arduino/samples/Arduino.Monitor.cs | 5 +---- src/devices/Arduino/tests/ApiBehaviorTests.cs | 9 ++++++--- src/devices/Arduino/tests/FirmataTestFixture.cs | 7 ++++++- .../Common/System/Device/Analog/AnalogController.cs | 3 ++- .../Common/System/Device/Analog/AnalogInputPin.cs | 4 ++-- 8 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/devices/Arduino/ArduinoAnalogController.cs b/src/devices/Arduino/ArduinoAnalogController.cs index 1f25d02a7f..8a3ecb4fab 100644 --- a/src/devices/Arduino/ArduinoAnalogController.cs +++ b/src/devices/Arduino/ArduinoAnalogController.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Text; using System.Threading; +using UnitsNet; namespace Iot.Device.Arduino { @@ -26,7 +27,7 @@ public ArduinoAnalogController(ArduinoBoard board, PinCount = _supportedPinConfigurations.Count; // Note: While the Arduino does have an external analog input reference pin, Firmata doesn't allow configuring it. - VoltageReference = 5.0; + VoltageReference = ElectricPotential.FromVolts(5.0); } public override int PinCount diff --git a/src/devices/Arduino/ArduinoAnalogInputPin.cs b/src/devices/Arduino/ArduinoAnalogInputPin.cs index 1c191297c8..5b8414adba 100644 --- a/src/devices/Arduino/ArduinoAnalogInputPin.cs +++ b/src/devices/Arduino/ArduinoAnalogInputPin.cs @@ -17,7 +17,7 @@ internal class ArduinoAnalogInputPin : AnalogInputPin private ArduinoBoard _board; public ArduinoAnalogInputPin(ArduinoBoard board, AnalogController controller, SupportedPinConfiguration configuration, - int pinNumber, double voltageReference) + int pinNumber, ElectricPotential voltageReference) : base(controller, pinNumber, voltageReference) { _board = board; diff --git a/src/devices/Arduino/FirmataCommandSequence.cs b/src/devices/Arduino/FirmataCommandSequence.cs index f60429a669..84aaaefbc2 100644 --- a/src/devices/Arduino/FirmataCommandSequence.cs +++ b/src/devices/Arduino/FirmataCommandSequence.cs @@ -1,4 +1,7 @@ -using System; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; using System.Collections.Generic; using System.Text; diff --git a/src/devices/Arduino/samples/Arduino.Monitor.cs b/src/devices/Arduino/samples/Arduino.Monitor.cs index d6fbd5f3d0..cc941583d6 100644 --- a/src/devices/Arduino/samples/Arduino.Monitor.cs +++ b/src/devices/Arduino/samples/Arduino.Monitor.cs @@ -24,15 +24,12 @@ namespace Arduino.Samples { - /// - /// Sample application for Ft4222 - /// internal class Program { /// /// Main entry point /// - /// Unused + /// The first argument gives the Port name. Default "COM4" public static void Main(string[] args) { string portName = "COM4"; diff --git a/src/devices/Arduino/tests/ApiBehaviorTests.cs b/src/devices/Arduino/tests/ApiBehaviorTests.cs index a6500fac9b..45f8651cf7 100644 --- a/src/devices/Arduino/tests/ApiBehaviorTests.cs +++ b/src/devices/Arduino/tests/ApiBehaviorTests.cs @@ -1,4 +1,7 @@ -using System; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; using System.IO; using Moq; using Xunit; @@ -37,7 +40,7 @@ public void InitializeWithStreamNoConnection() streamMock.Setup(x => x.CanWrite).Returns(true); streamMock.Setup(x => x.Close()); var board = new ArduinoBoard(streamMock.Object); - Assert.Throws(() => board.Initialize()); + Assert.Throws(() => board.FirmataVersion); } [Fact] @@ -47,7 +50,7 @@ public void TestStreamIsReadWrite() _streamMock.Setup(x => x.CanRead).Returns(true); _streamMock.Setup(x => x.CanWrite).Returns(false); var board = new ArduinoBoard(_streamMock.Object); - Assert.Throws(() => board.Initialize()); + Assert.Throws(() => board.FirmataVersion); } } } diff --git a/src/devices/Arduino/tests/FirmataTestFixture.cs b/src/devices/Arduino/tests/FirmataTestFixture.cs index b1af3d2661..f3ed85a7ad 100644 --- a/src/devices/Arduino/tests/FirmataTestFixture.cs +++ b/src/devices/Arduino/tests/FirmataTestFixture.cs @@ -26,7 +26,12 @@ public FirmataTestFixture() _socket.NoDelay = true; _networkStream = new NetworkStream(_socket, true); Board = new ArduinoBoard(_networkStream); - Board.Initialize(); + if (!(Board.FirmataVersion > new Version(1, 0))) + { + // Actually not expecting to get here (but the above will throw a SocketException if the remote end is not there) + throw new NotSupportedException("Very old firmware found"); + } + Board.LogMessages += (x, y) => Console.WriteLine(x); return; diff --git a/src/devices/Common/System/Device/Analog/AnalogController.cs b/src/devices/Common/System/Device/Analog/AnalogController.cs index 9e06dfaddf..0bd3879273 100644 --- a/src/devices/Common/System/Device/Analog/AnalogController.cs +++ b/src/devices/Common/System/Device/Analog/AnalogController.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Device.Gpio; using System.Linq; +using UnitsNet; namespace System.Device.Analog { @@ -42,7 +43,7 @@ public abstract int PinCount /// Reference voltage (the maximum voltage measurable). /// For some hardware, it might be necessary to manually set this value for the method to return correct values. /// - public double VoltageReference + public ElectricPotential VoltageReference { get; set; diff --git a/src/devices/Common/System/Device/Analog/AnalogInputPin.cs b/src/devices/Common/System/Device/Analog/AnalogInputPin.cs index e6c8fe30dc..18f5232905 100644 --- a/src/devices/Common/System/Device/Analog/AnalogInputPin.cs +++ b/src/devices/Common/System/Device/Analog/AnalogInputPin.cs @@ -23,7 +23,7 @@ public abstract class AnalogInputPin : IDisposable /// Construct an instance of an analog pin. /// This is not usually called directly. Use instead. /// - public AnalogInputPin(AnalogController controller, int pinNumber, double voltageReference) + public AnalogInputPin(AnalogController controller, int pinNumber, ElectricPotential voltageReference) { Controller = controller; VoltageReference = voltageReference; @@ -42,7 +42,7 @@ protected AnalogController Controller /// The reference voltage level to convert raw values into voltages. /// Some boards (i.e. the ADS111x series) always return an absolute voltage. Then this value is meaningless. /// - public double VoltageReference + public ElectricPotential VoltageReference { get; }