forked from nanoframework/nanoFramework.IoT.Device
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConversionResult.cs
55 lines (49 loc) · 1.72 KB
/
ConversionResult.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Iot.Device.Mcp3428
{
/// <summary>
/// Conversion result
/// </summary>
public readonly struct ConversionResult
{
/// <summary>
/// Constructs ConversionResult instance
/// </summary>
/// <param name="channel">ADC channel</param>
/// <param name="rawData">Raw ADC value</param>
/// <param name="resolution">ADC resolution</param>
public ConversionResult(byte channel, short rawData, AdcResolution resolution)
{
Channel = channel;
RawValue = rawData;
VoltageDivisor = Helpers.LsbDivisor(resolution);
}
/// <summary>
/// ID of the measuring channel.
/// </summary>
/// <value>The channel.</value>
public byte Channel { get; }
/// <summary>
/// Raw measurement data. Has to be scaled based on the measurement resolution to get voltage.
/// </summary>
/// <value>The raw data.</value>
public short RawValue { get; }
/// <summary>
/// Divisor to scale raw data.
/// </summary>
/// <value>The divisor.</value>
public ushort VoltageDivisor { get; }
/// <summary>
/// Accuracy of the voltage measurement
/// </summary>
/// <value>The LSB value.</value>
public double Accuracy => 1.0 / VoltageDivisor;
/// <summary>
/// Gets the voltage.
/// </summary>
/// <value>The voltage.</value>
/// <autogeneratedoc />
public double Voltage => (double)RawValue / VoltageDivisor;
}
}