/// <summary> /// Read the sensor output and convert the sensor readings into acceleration values. /// </summary> public async Task Update() { X = (await _xPort.Read() - _zeroGVoltage) / XVoltsPerG; Y = (await _yPort.Read() - _zeroGVoltage) / YVoltsPerG; Z = (await _zPort.Read() - _zeroGVoltage) / ZVoltsPerG; if (_updateInterval == 0 || ((Math.Abs(X - _lastX) > AccelerationChangeNotificationThreshold) || (Math.Abs(Y - _lastY) > AccelerationChangeNotificationThreshold) || (Math.Abs(Z - _lastZ) > AccelerationChangeNotificationThreshold))) { var lastNotifiedReading = new Vector(_lastX, _lastY, _lastZ); var currentReading = new Vector(_lastX = X, _lastY = Y, _lastZ = Z); AccelerationChanged?.Invoke(this, new SensorVectorEventArgs(lastNotifiedReading, currentReading)); } }
/// <summary> /// Convenience method to get the current wind azimuth. For frequent reads, use /// StartSampling() and StopSampling() in conjunction with the SampleBuffer. /// </summary> /// <param name="sampleCount">The number of sample readings to take. /// Must be greater than 0. These samples are automatically averaged.</param> /// <param name="sampleIntervalDuration">The time, in milliseconds, /// to wait in between samples during a reading.</param> /// <returns>A float value that's ann average value of all the samples taken.</returns> public async Task <Azimuth> Read(int sampleCount = 5, int sampleIntervalDuration = 20) { // read the voltage float voltage = await inputPort.Read(sampleCount, sampleIntervalDuration); // get the azimuth return(LookupWindDirection(voltage)); }
public async Task <float> ReadDistance() { var value = await analogInputPort.Read(); CurrentDistance = 26 / value; CurrentDistance = Math.Max(CurrentDistance, MinimumDistance); CurrentDistance = Math.Min(CurrentDistance, MaximumDistance); return(CurrentDistance); }
protected async void StartReading() { float v0, v1; while (true) { v0 = await _a00.Read(1); Thread.Sleep(1000); v1 = await _a01.Read(1); Console.WriteLine($"Voltages: {v0}\t{v1}"); Thread.Sleep(1000); } }
/// <summary> /// Read the sensor output and convert the sensor readings into acceleration values. /// </summary> public async Task Update() { Conditions.XAcceleration = (await _xPort.Read() - _zeroGVoltage) / XVoltsPerG; Conditions.YAcceleration = (await _yPort.Read() - _zeroGVoltage) / YVoltsPerG; Conditions.ZAcceleration = (await _zPort.Read() - _zeroGVoltage) / ZVoltsPerG; }
/// <summary> /// Voltage being output by the sensor. /// </summary> public Task <float> GetVoltage() { return(sensor.Read()); }
/// <summary> /// Voltage being output by the sensor. /// </summary> public double GetVoltage() { return(_referenceVoltagePort.Read().Result * 3.3); }
public async Task <float> ReadAsync() { float millivolts = await analogPort.Read(1) * 1000; return((millivolts - yIntercept) / millivoltsPerDegreeC); }