Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrawehr committed Feb 22, 2021
1 parent d5234e8 commit 176694e
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/devices/Arduino/ArduinoAnalogController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Linq;
using System.Text;
using System.Threading;
using UnitsNet;

namespace Iot.Device.Arduino
{
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Arduino/ArduinoAnalogInputPin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/devices/Arduino/FirmataCommandSequence.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
5 changes: 1 addition & 4 deletions src/devices/Arduino/samples/Arduino.Monitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@

namespace Arduino.Samples
{
/// <summary>
/// Sample application for Ft4222
/// </summary>
internal class Program
{
/// <summary>
/// Main entry point
/// </summary>
/// <param name="args">Unused</param>
/// <param name="args">The first argument gives the Port name. Default "COM4"</param>
public static void Main(string[] args)
{
string portName = "COM4";
Expand Down
9 changes: 6 additions & 3 deletions src/devices/Arduino/tests/ApiBehaviorTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<TimeoutException>(() => board.Initialize());
Assert.Throws<TimeoutException>(() => board.FirmataVersion);
}

[Fact]
Expand All @@ -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<NotSupportedException>(() => board.Initialize());
Assert.Throws<NotSupportedException>(() => board.FirmataVersion);
}
}
}
7 changes: 6 additions & 1 deletion src/devices/Arduino/tests/FirmataTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/devices/Common/System/Device/Analog/AnalogController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Device.Gpio;
using System.Linq;
using UnitsNet;

namespace System.Device.Analog
{
Expand Down Expand Up @@ -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 <see cref="AnalogInputPin.ReadVoltage"/> method to return correct values.
/// </summary>
public double VoltageReference
public ElectricPotential VoltageReference
{
get;
set;
Expand Down
4 changes: 2 additions & 2 deletions src/devices/Common/System/Device/Analog/AnalogInputPin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class AnalogInputPin : IDisposable
/// Construct an instance of an analog pin.
/// This is not usually called directly. Use <see cref="AnalogController.OpenPin(int)"/> instead.
/// </summary>
public AnalogInputPin(AnalogController controller, int pinNumber, double voltageReference)
public AnalogInputPin(AnalogController controller, int pinNumber, ElectricPotential voltageReference)
{
Controller = controller;
VoltageReference = voltageReference;
Expand All @@ -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.
/// </summary>
public double VoltageReference
public ElectricPotential VoltageReference
{
get;
}
Expand Down

0 comments on commit 176694e

Please sign in to comment.