More cleanup

This commit is contained in:
2015-01-16 18:44:29 -05:00
parent 7413a23886
commit f4f1c3c784
17 changed files with 277 additions and 464 deletions

View File

@@ -1,6 +1,6 @@
using OneWireAPI;
using System.Diagnostics;
using System.Runtime.Serialization;
using OneWireAPI;
using WeatherService.Values;
namespace WeatherService.Devices
@@ -8,28 +8,19 @@ namespace WeatherService.Devices
[DataContract]
public class WindSpeedDevice : DeviceBase
{
#region Member variables
private readonly Value _speedValue; // Cached speed value
private long _lastTicks; // Last time we checked the counter
private uint _lastCount; // The count at the last check
#endregion
#region Constructor
public WindSpeedDevice(Session session, owDevice device) : base(session, device, DeviceType.WindSpeed)
public WindSpeedDevice(Session session, Device device)
: base(session, device, DeviceType.WindSpeed)
{
_speedValue = new Value(WeatherValueType.WindSpeed, this);
_valueList.Add(WeatherValueType.WindSpeed, _speedValue);
Values.Add(WeatherValueType.WindSpeed, _speedValue);
}
#endregion
#region Internal methods
internal override void RefreshCache()
{
_speedValue.SetValue(ReadSpeed());
@@ -40,7 +31,7 @@ namespace WeatherService.Devices
internal double ReadSpeed()
{
// Get a reference to the device
owDeviceFamily1D counterDevice = (owDeviceFamily1D) _device;
var counterDevice = (DeviceFamily1D) OneWireDevice;
// Special case if we have never read before
if (_lastTicks == 0)
@@ -54,14 +45,14 @@ namespace WeatherService.Devices
}
// Get the current counter and time
uint currentCount = counterDevice.GetCounter(15);
long currentTicks = Stopwatch.GetTimestamp();
var currentCount = counterDevice.GetCounter(15);
var currentTicks = Stopwatch.GetTimestamp();
// Get the time difference in seconds
double timeDifference = (double) (currentTicks - _lastTicks) / Stopwatch.Frequency;
var timeDifference = (double) (currentTicks - _lastTicks) / Stopwatch.Frequency;
// Figure out how many revolutions per second in the last interval
double revolutionsPerSecond = ((currentCount - _lastCount) / timeDifference) / 2D;
var revolutionsPerSecond = ((currentCount - _lastCount) / timeDifference) / 2D;
// Store the current time and counter
_lastTicks = currentTicks;
@@ -70,7 +61,5 @@ namespace WeatherService.Devices
// Convert the revolutions per second to wind speed
return (revolutionsPerSecond * 2.453F);
}
#endregion
}
}