/// <summary> /// Read the sensor output and convert the sensor readings into acceleration values. /// </summary> public async Task Update() { X = (await _x.Read() * SupplyVoltage - _zeroGVoltage) / XVoltsPerG; Y = (await _y.Read() * SupplyVoltage - _zeroGVoltage) / YVoltsPerG; Z = (await _z.Read() * SupplyVoltage - _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(this, new SensorVectorEventArgs(lastNotifiedReading, currentReading)); } }
/// <summary> /// Convenience method to get the current temperature. 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<AtmosphericConditions> Read(int sampleCount = 10, int sampleIntervalDuration = 40) { // read the voltage float voltage = await AnalogInputPort.Read(sampleCount, sampleIntervalDuration); // convert and save to our temp property for later retreival Temperature = VoltageToTemperature(voltage); // return return new AtmosphericConditions(Temperature, 0, 0); //return Temperature; }
/// <summary> /// Convenience method to get the current soil moisture. For frequent reads, use /// StartUpdating() and StopUpdating(). /// </summary> /// <param name="sampleCount">The number of sample readings to take. /// Must be greater than 0.</param> /// <param name="sampleInterval">The interval, in milliseconds, between /// sample readings.</param> /// <returns></returns> public async Task <float> Read(int sampleCount = 10, int sampleInterval = 40) { // read the voltage float voltage = await AnalogInputPort.Read(sampleCount, sampleInterval); // convert and save to our temp property for later retrieval Moisture = VoltageToMoisture(voltage); // return return(Moisture); }
/// <summary> /// Convenience method to get the current soil moisture. For frequent reads, use /// StartUpdating() and StopUpdating(). /// </summary> /// <param name="sampleCount">The number of sample readings to take. /// Must be greater than 0.</param> /// <param name="sampleInterval">The interval, in milliseconds, between /// sample readings.</param> /// <returns></returns> public async Task <float> Read(int sampleCount = 10, int sampleInterval = 40) { DigitalPort.State = true; float voltage = await AnalogInputPort.Read(sampleCount, sampleInterval); DigitalPort.State = false; // convert and save to our temp property for later retrieval Moisture = VoltageToMoisture(voltage); return(Moisture); }
/// <summary> /// Convenience method to get the current temperature. 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 <float> Read(int sampleCount = 10, int sampleIntervalDuration = 40) { // read the voltage float voltage = await AnalogInputPort.Read(sampleCount, sampleIntervalDuration); // convert and save to our temp property for later retreival WaterLevel = VoltageToWaterLevel(voltage); // return return(WaterLevel); }
/// <summary> /// Convenience method to get the current soil moisture. For frequent reads, use /// StartUpdating() and StopUpdating(). /// </summary> /// <param name="sampleCount">The number of sample readings to take. /// Must be greater than 0.</param> /// <param name="sampleInterval">The interval, in milliseconds, between /// sample readings.</param> /// <returns></returns> public async Task <FloatChangeResult> Read(int sampleCount = 10, int sampleInterval = 40) { // save previous moisture value float previousMoisture = Moisture; // read the voltage float voltage = await AnalogInputPort.Read(sampleCount, sampleInterval); // convert and save to our temp property for later retrieval Moisture = VoltageToMoisture(voltage); // return new and old Moisture values return(new FloatChangeResult(Moisture, previousMoisture)); }
/// <summary> /// Voltage being output by the sensor. /// </summary> public async Task <double> GetVoltage() { return(await _referenceVoltagePort.Read() * 3.3); }