示例#1
0
            public DefaultSensorModel(Sensor sensor)
            {
                type        = sensor.type.ToString();
                isRelative  = sensor.isRelative;
                isEditable  = sensor.isEditable;
                name        = sensor.name;
                unit        = UnitLookup.GetCode(sensor.unit);
                measurement = sensor.measurement.amount;

                if (sensor.minMeasurement != null)
                {
                    var min = sensor.minMeasurement;
                    hasMinMeasurement = true;
                    minUnit           = UnitLookup.GetCode(min.unit);
                    minMeasurement    = min.amount;
                }

                if (sensor.maxMeasurement != null)
                {
                    var max = sensor.maxMeasurement;
                    hasMaxMeasurement = true;
                    maxUnit           = UnitLookup.GetCode(max.unit);
                    maxMeasurement    = max.amount;
                }
            }
示例#2
0
        /// <summary>
        /// Parses the target points from the given xml element.
        /// </summary>
        /// <param name="el">El.</param>
        /// <param name="b">The blue component.</param>
        private static void ParseTargetPoints(XElement el, TargetPointTest.Builder b, ESensorType st)
        {
            foreach (var child in el.Elements())
            {
                if (TAG_TARGET_POINT.Equals(child.Name))
                {
                    var usamount = child.Attribute(ATT_AMOUNT).ToString();
                    var usunit   = child.Attribute(ATT_UNIT).ToString();

                    double amount;
                    Unit   unit = UnitLookup.GetUnit(st, usunit);

                    if (!double.TryParse(usamount, out amount))
                    {
                        throw new Exception("Cannot parse TargetPointTest: malformed amount: " + usamount);
                    }

                    b.AddTargetPoint(unit.OfScalar(amount));
                }
                else
                {
                    Log.E(TAG, "Unexpected tag {" + child.Name + "} in test");
                }
            }
        }
            public BoundedHandler(SensorAlarmActivity activity, IION ion, BoundedSensorAlarm alarm, View view)
            {
                this.activity = activity;
                this.alarm    = alarm;

                toggle      = view.FindViewById <Switch>(Resource.Id.toggle);
                measurement = view.FindViewById <EditText>(Resource.Id.measurement);
                unit        = view.FindViewById <Button>(Resource.Id.unit);

                toggle.SetOnCheckedChangeListener(new ViewCheckChangedAction((but, check) => {
                    alarm.Reset();
                }));
                unit.SetOnClickListener(new ViewClickAction((v) => {
                    UnitDialog.Create(activity, alarm.sensor.supportedUnits, (obj, u) => {
                        var dialog = obj as Android.App.Dialog;

                        if (dialog != null)
                        {
                            dialog.Dismiss();
                        }

                        unit.Text = u.ToString();
                        unitCode  = UnitLookup.GetCode(u);
                    }).Show();
                }));

                toggle.Checked   = alarm.enabled;
                measurement.Text = alarm.bounds.amount + "";
                unit.Text        = alarm.bounds.unit.ToString();
                unitCode         = UnitLookup.GetCode(alarm.bounds.unit);
            }
        /// <summary>
        /// Parses the provided packet. If the packet cannot be parsed, this method will
        /// throw an argument exception.
        /// </summary>
        /// <param name="packet">The packet to parse.</param>
        /// <returns></returns>
        public override GaugePacket ParsePacket(byte[] packet)
        {
            if (packet.Length < 18 || packet.Length > 20)
            {
                throw new Exception("Packet too short");
            }
            using (BinaryReader r = new BinaryReader(new MemoryStream(packet))) {
                var version = (EProtocolVersion)r.ReadByte();
                var battery = (int)r.ReadByte();

                var readings = new List <GaugeReading>();

                // According to the rigado protocol specification, the packet length should be no more than 19 bytes.
                var           count = 17;                                      // 19 - version and battery
                SensorPayload sp;
                while (count >= (sp = new SensorPayload(r.ReadByte())).length) // While the count still has another potential packet, pull the next packet.
                {
                    count -= sp.length;
                    if (sp.unitCode == 0)
                    {
                        continue;
                    }
                    sp.Parse(r);
                    readings.Add(new GaugeReading()
                    {
                        removed    = !sp.connected,
                        sensorType = UnitLookup.GetSensorTypeFromCode(sp.unitCode),
                        reading    = sp.unit.OfScalar(sp.measurement),
                    });
                }

                return(new GaugePacket(version, battery, readings.ToArray()));
            }
        }
        public TestParameters Parse(Stream stream)
        {
            var     serializer = new XmlSerializer(typeof(XmlTest));
            XmlTest test       = null;

            using (var reader = new StreamReader(stream)) {
                test = (XmlTest)serializer.Deserialize(reader);
            }

            var deviceModel = (EDeviceModel)Enum.Parse(typeof(EDeviceModel), test.deviceModel);
            var sensorType  = (ESensorType)Enum.Parse(typeof(ESensorType), test.sensorType);

            var targetPoints = new List <TestParameters.TargetPoint>();

            foreach (var xtp in test.targetPoints.targetPoints)
            {
                var unit = UnitLookup.GetUnit(sensorType, xtp.unit);
                targetPoints.Add(new TestParameters.TargetPoint(unit.OfScalar(xtp.amount)));
            }

            var grades = new HashSet <TestParameters.Grade>();

            foreach (var xg in test.gradeScale.grades)
            {
                grades.Add(new TestParameters.Grade(xg.errorBand, xg.grade, xg.passable));
            }

            return(new TestParameters(deviceModel, sensorType, targetPoints, grades));
        }
        /// <summary>
        /// Creates a packet that, when received by a remote terminus, will set the
        /// altitude that is retained within the terminus' memory.
        /// </summary>
        /// <param name="altitude">A scalar whose base unit is METER.</param>
        /// <returns></returns>
        public override byte[] CreateSetAltitudeCommand(Scalar altitude)
        {
            var v   = (int)altitude.amount;
            var msb = (byte)((v >> 8) & 0xff);
            var lsb = (byte)(v & 0xff);

            return(new byte[] { 0x04, msb, lsb, (byte)UnitLookup.GetCode(altitude.unit) });
        }
示例#7
0
 public ManualSensorParcelable(ManualSensor sensor)
 {
     sensorType = sensor.type;
     isRelative = sensor.isRelative;
     unitCode   = UnitLookup.GetCode(sensor.unit);
     amount     = sensor.measurement.amount;
     name       = sensor.name;
 }
示例#8
0
        // Overridden from SensorParcelable
        public override Sensor Get(IION ion)
        {
            var ret = new ManualSensor(sensorType, isRelative);

            ret.name        = name;
            ret.measurement = UnitLookup.GetUnit(unitCode).OfScalar(amount);

            return(ret);
        }
示例#9
0
        /// <summary>
        /// Parses an array of gauge device sensor definitions from the xml elements.
        /// </summary>
        /// <returns>The gauge device sensors.</returns>
        /// <param name="elements">Elements.</param>
        private static List <SensorDefinition> ParseGaugeDeviceSensors(XElement[] elements)
        {
            var ret = new List <SensorDefinition>();

            foreach (var element in elements)
            {
                var st        = (ESensorType)Enum.Parse(typeof(ESensorType), element.Attribute(TYPE).Value, true);
                var minUnit   = UnitLookup.GetUnit(st, element.Attribute(MIN_UNIT).Value);
                var maxUnit   = UnitLookup.GetUnit(st, element.Attribute(MAX_UNIT).Value);
                var relative  = true;
                var removable = false;

                var relatt = element.Attribute(RELATIVE);
                if (relatt != null)
                {
                    if (!bool.TryParse(relatt.Value, out relative))
                    {
                        relative = true;
                    }
                }

                var rematt = element.Attribute(REMOVABLE);
                if (rematt != null)
                {
                    if (!bool.TryParse(rematt.Value, out removable))
                    {
                        removable = false;
                    }
                }

                var minatt = element.Attribute(MIN).Value;
                var maxatt = element.Attribute(MAX).Value;
                var min    = minUnit.OfScalar(double.Parse(minatt));
                var max    = maxUnit.OfScalar(double.Parse(maxatt));

                var units = new List <Unit>();
                foreach (var e in element.Elements())
                {
                    if (SUPPORTED_UNIT.Equals(e.Name.LocalName))
                    {
                        units.Add(UnitLookup.GetUnit(st, e.Value));
                    }
                }

                ret.Add(new SensorDefinition()
                {
                    sensorType         = st,
                    minimumMeasurement = min,
                    maximumMeasurement = max,
                    isRelative         = relative,
                    isRemovable        = removable,
                    supportedUnits     = units,
                });
            }

            return(ret);
        }
示例#10
0
        // Overridden from IGaugeProtocol
        public override GaugePacket ParsePacket(byte[] packetIn)
        {
            byte[] packet = Trim(packetIn);
            using (BinaryReader r = new BinaryReader(new MemoryStream(packet))) {
                int len = packet.Length;

                if (len < 8 || len % 6 != 2)
                {
                    /////should not throw exeptions
                    //throw new ArgumentException("Cannot parse: bad packet size {" + len + "}");
                }

                var v = r.ReadByte();

                if (v != 1 && v != 2)
                {
                    /////should not throw exeptions
                    //throw new ArgumentException("Cannot parse: invalid version code");
                }

                int battery = r.ReadByte();

                int maxGaugeCount = (len - 2) / 6;
                var readings      = new List <GaugeReading>();

                for (int i = 0; i < maxGaugeCount; i++)
                {
                    int exponent       = r.ReadByte();
                    int encodedReading = r.ReadInt32BE();
                    int unitCode       = r.ReadByte();

                    if (unitCode == 0)
                    {
                        break;
                    }

                    Unit unit = UnitLookup.GetUnit(unitCode);

                    var gr = new GaugeReading()
                    {
                        removed    = removedGaugeValue == encodedReading,
                        sensorType = UnitLookup.GetSensorTypeFromCode(unitCode),
                        reading    = unit.OfScalar(encodedReading / System.Math.Pow(10, exponent)),
                    };

                    if (gr.removed)
                    {
                        gr.reading = unit.OfScalar(0);
                    }

                    readings.Add(gr);
                }

                return(new GaugePacket(version, battery, readings.ToArray()));
            }
        }
示例#11
0
        // Implemented for ISubviewParser
        //public ISensorProperty Read(IION ion, Manifold manifold, BinaryReader reader)	{
        public ISensorProperty Read(IION ion, Sensor sensor, BinaryReader reader)
        {
            //var ret = new AlternateUnitSensorProperty(manifold);
            var ret = new AlternateUnitSensorProperty(sensor);

            var usunit = reader.ReadInt32();

            ret.unit = UnitLookup.GetUnit(usunit);

            return(ret);
        }
示例#12
0
 /// <summary>
 /// Safely gets the unit for the given key. If the desired unit could not be
 /// fetched, we will return the backup.
 /// </summary>
 /// <returns>The unit get.</returns>
 /// <param name="preferenceKey">Preference key.</param>
 /// <param name="backup">Backup.</param>
 private Unit AssertUnitGet(string preferenceKey, Unit backup)
 {
     try {
         var ret = UnitLookup.GetUnit(GetInt(preferenceKey));
         return(ret);
     } catch (Exception e) {
         Log.E(this, "Failed to retrieve unit for key: " + preferenceKey, e);
         AssertUnitSet(preferenceKey, backup.quantity, backup);
         return(backup);
     }
 }
示例#13
0
 // Implemented for ISubviewParser
 public bool Write(ISensorProperty sp, BinaryWriter writer)
 {
     try {
         var alt = (AlternateUnitSensorProperty)sp;
         writer.Write(UnitLookup.GetCode(alt.unit));
         return(true);
     } catch (Exception e) {
         Log.E(this, "Failed to write.", e);
         return(false);
     }
 }
示例#14
0
        /// <summary>
        /// Safely gets the unit for the given key. If the desired unit could not be
        /// fetched, we will return the backup.
        /// </summary>
        /// <returns>The unit get.</returns>
        /// <param name="preferenceKey">Preference key.</param>
        /// <param name="backup">Backup.</param>
        private Unit AssertUnitGet(int preferenceKey, Unit backup)
        {
            var key = context.GetString(preferenceKey);

            try {
                var ret = UnitLookup.GetUnit(int.Parse(prefs.GetString(key, null)));
                return(ret);
            } catch (Exception) {
                AssertUnitSet(preferenceKey, backup.quantity, backup);
                return(backup);
            }
        }
示例#15
0
        private void WriteSensorProperty(ISensorProperty property, BinaryWriter writer)
        {
            var name = property.GetType();

            writer.Write(name.Name);

            if (property is AlternateUnitSensorProperty)
            {
                var sp = property as AlternateUnitSensorProperty;
                writer.Write(UnitLookup.GetCode(sp.unit));
            }
        }
示例#16
0
        /// <summary>
        /// Safely attempts to set the unit for the given key.
        /// </summary>
        /// <returns>The unit set.</returns>
        private void AssertUnitSet(string preferenceKey, Quantity quantity, Unit unit)
        {
            try {
                if (quantity != unit.quantity)
                {
                    throw new ArgumentException("Unit: " + unit + " is not compatible with quantity + " + quantity);
                }

                PutInt(preferenceKey, UnitLookup.GetCode(unit));
            } catch (Exception e) {
                Log.E(this, "Failed to set unit " + unit + " for key: " + preferenceKey, e);
            }
        }
            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);
            }
 public void Commit()
 {
     if (toggle.Checked)
     {
         try {
             var title   = string.Format(activity.GetString(Resource.String.alarm_low_for_1arg), alarm.sensor.name);
             var summary = string.Format(activity.GetString(Resource.String.alarm_low_for_summary_2arg), alarm.sensor.name, alarm.bounds);
             alarm.name        = title;
             alarm.description = summary;
             alarm.enabled     = toggle.Checked;
             alarm.bounds      = UnitLookup.GetUnit(unitCode).OfScalar(double.Parse(measurement.Text));
         } catch (Exception) {
             activity.Alert(Resource.String.error_invalid_number_entry);
         }
     }
 }
示例#19
0
        public RemoteSensorMount(Analyzer analyzer, Sensor sensor)
        {
            var gds = sensor as GaugeDeviceSensor;

            if (gds == null)
            {
                throw new Exception("Cannot create sensor mount for {" + sensor + "}: sensor must not be null");
            }
            else if (!analyzer.HasSensor(sensor))
            {
                throw new Exception("Cannot create sensor mount for {" + sensor + "}: sensor must be in analyzer");
            }

            serialNumber  = gds.device.serialNumber.ToString();
            sensorIndex   = gds.index + "";
            analyzerIndex = analyzer.IndexOfSensor(sensor) + "";
            value         = sensor.measurement.amount + "";
            unit          = UnitLookup.GetCode(sensor.unit) + "";
        }
示例#20
0
        /// <summary>
        /// Safely attempts to set the unit for the given key.
        /// </summary>
        /// <returns>The unit set.</returns>
        private void AssertUnitSet(int preferenceKey, Quantity quantity, Unit unit)
        {
            var key = context.GetString(preferenceKey);

            try {
                if (quantity != unit.quantity)
                {
                    throw new ArgumentException("Unit: " + unit + " is not compatible with quantity + " + quantity);
                }

                var e = prefs.Edit();

                e.PutString(key, UnitLookup.GetCode(unit) + "");

                e.Commit();
            } catch (Exception e) {
                Log.E(this, "Failed to set unit " + unit + " for key: " + key, e);
            }
        }
            private void WriteManualSensor(Sensor sensor, BinaryWriter writer)
            {
                // Write actual sensor type
                writer.Write((int)sensor.type);
                // Write whether or not the sensor is relative
                writer.Write(sensor.isRelative);
                // Write the unit code of the sensor
                writer.Write((byte)UnitLookup.GetCode(sensor.measurement.unit));
                // Write the double amount of the sensor
                writer.Write(sensor.measurement.amount);
                // Write the minimum measurement of the sensor
                if (sensor.minMeasurement.unit == null)
                {
                    writer.Write((byte)0);
                }
                else
                {
                    writer.Write((byte)UnitLookup.GetCode(sensor.minMeasurement.unit));
                    writer.Write(sensor.minMeasurement.amount);
                }
                // Write the maximum measurement of the sensor
                if (sensor.maxMeasurement.unit == null)
                {
                    writer.Write((byte)0);
                }
                else
                {
                    writer.Write((byte)UnitLookup.GetCode(sensor.maxMeasurement.unit));
                    writer.Write(sensor.maxMeasurement.amount);
                }

                if (string.IsNullOrEmpty(sensor.name))
                {
                    sensor.name = "Manual";
                    writer.Write(sensor.name);
                }
                else
                {
                    writer.Write(sensor.name);
                }
            }
示例#22
0
            // 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);
            }
示例#23
0
 public RemoteGaugeDeviceSensor(GaugeDeviceSensor sensor)
 {
     measurement = sensor.measurement.amount;
     unit        = UnitLookup.GetCode(sensor.unit);
     sensorIndex = sensor.index;
 }
示例#24
0
        //private void ReadSensorProperty(IION ion, Manifold manifold, BinaryReader reader)	{
        private void ReadSensorProperty(IION ion, Sensor sensor, BinaryReader reader)
        {
            var name = reader.ReadString();

            if (name != null)
            {
                if (name.Equals(typeof(MinSensorProperty).Name))
                {
                    //manifold.AddSensorProperty(new MinSensorProperty(manifold));
                    sensor.AddSensorProperty(new MinSensorProperty(sensor));
                }
                else if (name.Equals(typeof(MaxSensorProperty).Name))
                {
                    //manifold.AddSensorProperty(new MaxSensorProperty(manifold));
                    sensor.AddSensorProperty(new MaxSensorProperty(sensor));
                }
                else if (name.Equals(typeof(PTChartSensorProperty).Name))
                {
                    //manifold.AddSensorProperty(new PTChartSensorProperty(manifold));
                    sensor.AddSensorProperty(new PTChartSensorProperty(sensor));
                }
                else if (name.Equals(typeof(RateOfChangeSensorProperty).Name))
                {
                    //manifold.AddSensorProperty(new RateOfChangeSensorProperty(manifold, ion.preferences.device.trendInterval));
                    sensor.AddSensorProperty(new RateOfChangeSensorProperty(sensor, ion.preferences.device.trendInterval));
                }
                else if (name.Equals(typeof(SecondarySensorProperty).Name))
                {
                    //manifold.AddSensorProperty(new SecondarySensorProperty(manifold));
                    sensor.AddSensorProperty(new SecondarySensorProperty(sensor));
                }
                else if (name.Equals(typeof(SuperheatSubcoolSensorProperty).Name))
                {
                    //manifold.AddSensorProperty(new SuperheatSubcoolSensorProperty(manifold));
                    sensor.AddSensorProperty(new SuperheatSubcoolSensorProperty(sensor));
                }
                else if (name.Equals(typeof(TimerSensorProperty).Name))
                {
                    //manifold.AddSensorProperty(new TimerSensorProperty(manifold));
                    sensor.AddSensorProperty(new TimerSensorProperty(sensor));
                }
                else if (name.Equals(typeof(HoldSensorProperty).Name))
                {
                    //manifold.AddSensorProperty(new HoldSensorProperty(manifold));
                    sensor.AddSensorProperty(new HoldSensorProperty(sensor));
                }
                else if (name.Equals(typeof(AlternateUnitSensorProperty).Name))
                {
                    var sp = new AlternateUnitSensorProperty(sensor);
                    //manifold.AddSensorProperty(sp);
                    sensor.AddSensorProperty(sp);
                    var usunit = reader.ReadInt32();
                    sp.unit = UnitLookup.GetUnit(usunit);
                }
                else
                {
                    Log.E(this, "Name for sensor property doesn't match an ISensorProperty");
                }
            }
            else
            {
                Log.E(this, "Couldn't read the name from the binary file for the sensor property");
            }
        }
        /// <summary>
        /// Creates a packet that, when received by a remote terminus, will set the unit
        /// for a given sensor.
        /// </summary>
        /// <param name="sensorIndex">The 1-based index of the sensor to set the unit for.</param>
        /// <param name="sensorType">The sensor type. This is necessary to deduce the proper
        /// unit code for the packet.</param>
        /// <param name="unit">The unit that the terminus will be set to.</param>
        /// <returns></returns>
        // Overridden from IGaugeProtocol
        public override byte[] CreateSetUnitCommand(int sensorIndex, Sensors.ESensorType sensorType, Unit unit)
        {
            var ret = new byte[] { 0x02, (byte)UnitLookup.GetCode(unit), (byte)sensorIndex };

            return(ret);
        }
示例#26
0
        public void makeEvents(lowHighSensor lhSensor, CGRect tableRect)
        {
            cellHeader = new UILabel(new CGRect(0, 0, 1.006 * tableRect.Width, .5 * lhSensor.cellHeight));
            cellButton = new UIButton(new CGRect(0, .5 * lhSensor.cellHeight, tableRect.Width, .5 * lhSensor.cellHeight));

            cellHeader.Text                      = "ALT";
            cellHeader.TextColor                 = UIColor.White;
            cellHeader.BackgroundColor           = UIColor.Black;
            cellHeader.Font                      = UIFont.FromName("Helvetica-Bold", 21f);
            cellHeader.TextAlignment             = UITextAlignment.Center;
            cellHeader.AdjustsFontSizeToFitWidth = true;

            cellReading = lhSensor.altReading;
            cellReading.AdjustsFontSizeToFitWidth = true;
            cellReading.TextAlignment             = UITextAlignment.Right;

            cellButton.BackgroundColor   = UIColor.Clear;
            cellButton.Layer.BorderColor = UIColor.Black.CGColor;

            if (lhSensor.isManual)
            {
                if (lhSensor.currentSensor.type == ESensorType.Pressure)
                {
                    manSensor = new ManualSensor(AppState.context.manualSensorContainer, ESensorType.Pressure, AppState.context.preferences.units.DefaultUnitFor(ESensorType.Pressure).OfScalar(0.0));
                    //manSensor = new ManualSensor(ESensorType.Pressure, AppState.context.preferences.units.DefaultUnitFor(ESensorType.Pressure).OfScalar(0.0));
                    manSensor.unit = AnalyserUtilities.getManualUnit(ESensorType.Pressure, lhSensor.LabelBottom.Text.ToLower());
                    ((ManualSensor)manSensor).SetMeasurement(manSensor.unit.OfScalar(Convert.ToDouble(lhSensor.LabelMiddle.Text)));
                    lhSensor.alt = new AlternateUnitSensorProperty(manSensor);
                }
                else if (lhSensor.currentSensor.type == ESensorType.Temperature)
                {
                    manSensor = new ManualSensor(AppState.context.manualSensorContainer, ESensorType.Temperature, AppState.context.preferences.units.DefaultUnitFor(ESensorType.Temperature).OfScalar(0.0));
                    //manSensor = new ManualSensor(ESensorType.Temperature, AppState.context.preferences.units.DefaultUnitFor(ESensorType.Temperature).OfScalar(0.0));
                    manSensor.unit = AnalyserUtilities.getManualUnit(ESensorType.Temperature, lhSensor.LabelBottom.Text.ToLower());
                    ((ManualSensor)manSensor).SetMeasurement(manSensor.unit.OfScalar(Convert.ToDouble(lhSensor.LabelMiddle.Text)));
                    lhSensor.alt = new AlternateUnitSensorProperty(manSensor);
                }
                else if (lhSensor.currentSensor.type == ESensorType.Vacuum)
                {
                    manSensor = new ManualSensor(AppState.context.manualSensorContainer, ESensorType.Vacuum, AppState.context.preferences.units.DefaultUnitFor(ESensorType.Vacuum).OfScalar(0.0));
                    //manSensor = new ManualSensor(ESensorType.Vacuum, AppState.context.preferences.units.DefaultUnitFor(ESensorType.Vacuum).OfScalar(0.0));
                    manSensor.unit = AnalyserUtilities.getManualUnit(ESensorType.Vacuum, lhSensor.LabelBottom.Text.ToLower());
                    ((ManualSensor)manSensor).SetMeasurement(manSensor.unit.OfScalar(Convert.ToDouble(lhSensor.LabelMiddle.Text)));
                    lhSensor.alt = new AlternateUnitSensorProperty(manSensor);
                }
                if (lhSensor.altUnit != null)
                {
                    lhSensor.alt.unit = lhSensor.altUnit;
                }
                else
                {
                    lhSensor.alt.unit = manSensor.unit;
                }
                cellReading.Text = SensorUtils.ToFormattedString(lhSensor.alt.modifiedMeasurement, true);
            }
            else
            {
                lhSensor.alt = new AlternateUnitSensorProperty(lhSensor.currentSensor as Sensor);
                if (lhSensor.altUnit != null)
                {
                    lhSensor.alt.unit = lhSensor.altUnit;
                }
                else
                {
                    if (lhSensor.currentSensor.type == ESensorType.Pressure)
                    {
                        lhSensor.alt.unit = AnalyserUtilities.getManualUnit(lhSensor.currentSensor.type, lhSensor.altUnits[0].Replace("/", "").ToLower());
                    }
                    else if (lhSensor.currentSensor.type == ESensorType.Temperature)
                    {
                        lhSensor.alt.unit = AnalyserUtilities.getManualUnit(lhSensor.currentSensor.type, lhSensor.tempUnits[0].Replace("/", "").ToLower());
                    }
                    else if (lhSensor.currentSensor.type == ESensorType.Vacuum)
                    {
                        lhSensor.alt.unit = AnalyserUtilities.getManualUnit(lhSensor.currentSensor.type, lhSensor.vacUnits[0].Replace("/", "").ToLower());
                    }
                }
            }
            cellButton.TouchUpInside += delegate {
                var window = UIApplication.SharedApplication.KeyWindow;
                var vc     = window.RootViewController;
                while (vc.PresentedViewController != null)
                {
                    vc = vc.PresentedViewController;
                }

                UIAlertController altUnit = UIAlertController.Create(Util.Strings.Analyzer.CHOOSEUNIT, "", UIAlertControllerStyle.Alert);

                if (lhSensor.alt.sensor.type == ESensorType.Pressure)
                {
                    foreach (String unit in lhSensor.altUnits)
                    {
                        altUnit.AddAction(UIAlertAction.Create(unit, UIAlertActionStyle.Default, (action) => {
                            if (lhSensor.isManual)
                            {
                                lhSensor.altUnit         = UnitLookup.GetUnit(lhSensor.alt.sensor.type, unit.Replace("/", "").ToLower());
                                lhSensor.alt.unit        = UnitLookup.GetUnit(lhSensor.alt.sensor.type, unit.Replace("/", "").ToLower());
                                lhSensor.altReading.Text = SensorUtils.ToFormattedString(lhSensor.alt.modifiedMeasurement, true);
                            }
                            else
                            {
                                lhSensor.altUnit         = UnitLookup.GetUnit(lhSensor.currentSensor.type, unit.Replace("/", "").ToLower());
                                lhSensor.alt.unit        = UnitLookup.GetUnit(lhSensor.currentSensor.type, unit.Replace("/", "").ToLower());
                                lhSensor.altReading.Text = SensorUtils.ToFormattedString(lhSensor.alt.modifiedMeasurement, true);
                            }
                        }));
                    }
                }
                else if (lhSensor.alt.sensor.type == ESensorType.Temperature)
                {
                    foreach (String unit in lhSensor.tempUnits)
                    {
                        altUnit.AddAction(UIAlertAction.Create(unit, UIAlertActionStyle.Default, (action) => {
                            if (lhSensor.isManual)
                            {
                                lhSensor.altUnit         = UnitLookup.GetUnit(lhSensor.alt.sensor.type, unit.Replace("/", "").ToLower());
                                lhSensor.alt.unit        = UnitLookup.GetUnit(lhSensor.alt.sensor.type, unit.Replace("/", "").ToLower());
                                lhSensor.altReading.Text = SensorUtils.ToFormattedString(lhSensor.alt.modifiedMeasurement, true);
                            }
                            else
                            {
                                lhSensor.altUnit         = UnitLookup.GetUnit(lhSensor.currentSensor.type, unit.Replace("/", "").ToLower());
                                lhSensor.alt.unit        = UnitLookup.GetUnit(lhSensor.currentSensor.type, unit.Replace("/", "").ToLower());
                                lhSensor.altReading.Text = SensorUtils.ToFormattedString(lhSensor.alt.modifiedMeasurement, true);
                            }
                        }));
                    }
                }
                else if (lhSensor.alt.sensor.type == ESensorType.Vacuum)
                {
                    foreach (String unit in lhSensor.vacUnits)
                    {
                        altUnit.AddAction(UIAlertAction.Create(unit, UIAlertActionStyle.Default, (action) => {
                            if (lhSensor.isManual)
                            {
                                lhSensor.altUnit         = UnitLookup.GetUnit(lhSensor.alt.sensor.type, unit.Replace("/", "").ToLower());
                                lhSensor.alt.unit        = UnitLookup.GetUnit(lhSensor.alt.sensor.type, unit.Replace("/", "").ToLower());
                                lhSensor.altReading.Text = SensorUtils.ToFormattedString(lhSensor.alt.modifiedMeasurement, true);
                            }
                            else
                            {
                                lhSensor.altUnit         = UnitLookup.GetUnit(lhSensor.currentSensor.type, unit.Replace("/", "").ToLower());
                                lhSensor.alt.unit        = UnitLookup.GetUnit(lhSensor.currentSensor.type, unit.Replace("/", "").ToLower());
                                lhSensor.altReading.Text = SensorUtils.ToFormattedString(lhSensor.alt.modifiedMeasurement, true);
                            }
                        }));
                    }
                }

                altUnit.AddAction(UIAlertAction.Create(Util.Strings.CANCEL, UIAlertActionStyle.Cancel, (action) => {}));

                vc.PresentViewController(altUnit, true, null);
            };

            this.AddSubview(cellHeader);
            this.AddSubview(cellButton);
            this.AddSubview(cellReading);
        }