private Sensor ReadManualSensor(BinaryReader reader) { // Read the actual sensor type var sensorType = (ESensorType)reader.ReadInt32(); // Read whether or not the sensor is relative var relative = reader.ReadBoolean(); // Read and determine the unit code var rawUnit = reader.ReadByte(); // Read the amount of the sensor var amount = reader.ReadDouble(); // Read the minimum measurement of the sensor var rawMinUnit = reader.ReadByte(); var rawMinAmount = 0.0; if (rawMinUnit != 0) { rawMinAmount = reader.ReadDouble(); } // Read the maximum measurement of the sensor var rawMaxUnit = reader.ReadByte(); var rawMaxAmount = 0.0; if (rawMaxUnit != 0) { rawMaxAmount = reader.ReadDouble(); } var name = reader.ReadString(); //var ret = new ManualSensor(sensorType, AppState.context.preferences.units.DefaultUnitFor(sensorType).OfScalar(0.0), relative); var ret = new ManualSensor(AppState.context.manualSensorContainer, sensorType, AppState.context.preferences.units.DefaultUnitFor(sensorType).OfScalar(0.0), relative); ret.SetMeasurement(UnitLookup.GetUnit(rawUnit).OfScalar(amount)); if (rawMinUnit != 0) { ret.minMeasurement = UnitLookup.GetUnit(rawMinUnit).OfScalar(rawMinAmount); } if (rawMaxUnit != 0) { ret.maxMeasurement = UnitLookup.GetUnit(rawMaxUnit).OfScalar(rawMaxAmount); } ret.name = name; return(ret); }
// Overridden from ISensorModel public Sensor ToSensor(IION ion) { var sensorType = (ESensorType)Enum.Parse(typeof(ESensorType), type); //var ret = new ManualSensor(sensorType, AppState.context.preferences.units.DefaultUnitFor(sensorType).OfScalar(0.0), isRelative); var ret = new ManualSensor(ion.manualSensorContainer, sensorType, AppState.context.preferences.units.DefaultUnitFor(sensorType).OfScalar(0.0), isRelative); ret.name = name; ret.SetMeasurement(UnitLookup.GetUnit(unit).OfScalar(measurement)); if (hasMinMeasurement) { ret.minMeasurement = UnitLookup.GetUnit(minUnit).OfScalar(minMeasurement); } if (hasMaxMeasurement) { ret.maxMeasurement = UnitLookup.GetUnit(maxUnit).OfScalar(maxMeasurement); } return(ret); }