Beispiel #1
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);
        }
        /// EVENT THAT UPDATES THE LOW/HIGH AREA SUBVIEWS IF THEY HAVE BEEN ADDED
        /// MAX MIN HOLD ALT RoC SH/SC P/T VALUES DETERMINED FROM SENSOR VALUES
        public void gaugeUpdating(SensorEvent Event)
        {
            //Console.WriteLine("lowHighSensor gaugeUpdating called. Sensor name " + manifold.primarySensor.name + " working with fluid " + manifold.ptChart.fluid.name);

            if (currentSensor.device.isConnected)
            {
                connectionColor.BackgroundColor = UIColor.Green;
                Connection.Image = UIImage.FromBundle("ic_bluetooth_connected");
            }
            else
            {
                connectionColor.BackgroundColor = UIColor.Red;
                Connection.Image = UIImage.FromBundle("ic_bluetooth_disconnected");
            }

            if (currentSensor.device.connection.connectionState == EConnectionState.Connecting)
            {
                activityConnectStatus.StartAnimating();
            }
            else
            {
                activityConnectStatus.StopAnimating();
            }

            if (currentSensor.unit != Units.Vacuum.MICRON)
            {
                LabelMiddle.Text = " " + Event.sensor.measurement.amount.ToString("N");
            }
            else
            {
                LabelMiddle.Text = " " + Event.sensor.measurement.amount;
            }

            LabelBottom.Text = Event.sensor.measurement.unit.ToString() + "  ";

            foreach (var property in currentSensor.sensorProperties)
            {
                if (property is MaxSensorProperty)
                {
                    if (Convert.ToDouble(LabelMiddle.Text) > max)
                    {
                        max     = Convert.ToDouble(LabelMiddle.Text);
                        maxType = currentSensor.unit.ToString();
                    }
                    if (currentSensor.unit != Units.Vacuum.MICRON)
                    {
                        maxReading.Text = max.ToString("N") + " " + maxType;
                    }
                    else
                    {
                        maxReading.Text = max.ToString() + " " + maxType;
                    }
                }
                else if (property is MinSensorProperty)
                {
                    if (Convert.ToDouble(LabelMiddle.Text) < min)
                    {
                        min     = Convert.ToDouble(LabelMiddle.Text);
                        minType = currentSensor.unit.ToString();
                    }
                    if (currentSensor.unit != Units.Vacuum.MICRON)
                    {
                        minReading.Text = min.ToString("N") + " " + minType + " ";
                    }
                    else
                    {
                        minReading.Text = min.ToString() + " " + minType + " ";
                    }
                }
                else if (property is HoldSensorProperty)
                {
                    holdReading.Text = LabelMiddle.Text + " " + LabelBottom.Text + " ";
                }
                else if (property is AlternateUnitSensorProperty)
                {
                    var tempUnit = alt.unit;

                    alt.Dispose();

                    alt = property as AlternateUnitSensorProperty;

                    alt.unit = tempUnit;

                    altReading.Text = SensorUtils.ToFormattedString(alt.modifiedMeasurement, true);
                }
                else if (property is RateOfChangeSensorProperty)
                {
                    roc.onSensorPropertyChanged -= DoUpdateRocCell;
                    roc.onSensorPropertyChanged += DoUpdateRocCell;
                }
            }

            if (Event.type == SensorEvent.EType.LinkedSensorAdded)
            {
                Console.WriteLine("Adding secondary sensor");

                var compareSensor = currentSensor.linkedSensor;
                /////CHECK IF SENSOR IS ON THE ANALYZER ALREADY TO MAKE ASSOCIATION
                foreach (var slot in sensorList)
                {
                    if (slot.currentSensor != null)
                    {
                        ////SECONDARY SENSOR MATCHES THE SENSOR OF A SENSOR MOUNT
                        if (slot.currentSensor == compareSensor)
                        {
                            var window = UIApplication.SharedApplication.KeyWindow;
                            var vc     = window.RootViewController;
                            while (vc.PresentedViewController != null)
                            {
                                vc = vc.PresentedViewController;
                            }
                            var locationIndex = ion.currentAnalyzer.IndexOfSensor(currentSensor.linkedSensor);

                            Console.WriteLine("Added sensor from location " + locationIndex);
                            if (LabelSubview.BackgroundColor == UIColor.Blue && locationIndex > 3)
                            {
                                Console.WriteLine("blue. Adding sensor from location " + locationIndex);
                                UIAlertController noneAvailable;
                                noneAvailable = UIAlertController.Create(Util.Strings.Analyzer.CANTADD, Util.Strings.Analyzer.SAMESIDE, UIAlertControllerStyle.Alert);
                                noneAvailable.AddAction(UIAlertAction.Create(Util.Strings.OK, UIAlertActionStyle.Default, (action) => { }));
                                vc.PresentViewController(noneAvailable, true, null);

                                ion.currentAnalyzer.lowSideSensor.SetLinkedSensor(null);
                                updateSHSCCell();
                                return;
                            }
                            else if (LabelSubview.BackgroundColor == UIColor.Red && locationIndex < 4)
                            {
                                Console.WriteLine("red. Adding sensor from location " + locationIndex);
                                UIAlertController noneAvailable;
                                noneAvailable = UIAlertController.Create(Util.Strings.Analyzer.CANTADD, Util.Strings.Analyzer.SAMESIDE, UIAlertControllerStyle.Alert);
                                noneAvailable.AddAction(UIAlertAction.Create(Util.Strings.OK, UIAlertActionStyle.Default, (action) => { }));
                                vc.PresentViewController(noneAvailable, true, null);

                                ion.currentAnalyzer.highSideSensor.SetLinkedSensor(null);
                                updateSHSCCell();
                                return;
                            }

                            attachedSensor = slot;
                            slot.topLabel.BackgroundColor = LabelSubview.BackgroundColor;
                            slot.topLabel.TextColor       = UIColor.White;
                            break;
                        }
                    }
                }
            }
            else if (Event.type == SensorEvent.EType.LinkedSensorRemoved)
            {
                //Console.WriteLine("current sensor secondary sensor removed");
                if (attachedSensor != null)
                {
                    attachedSensor.topLabel.BackgroundColor = UIColor.Clear;
                    attachedSensor.topLabel.TextColor       = UIColor.Gray;
                    attachedSensor = null;
                }
            }

            updateSHSCCell();

            updatePTCell();

            if (currentSensor != null && currentSensor.linkedSensor != null)
            {
                secondaryReading.Text = currentSensor.linkedSensor.measurement.amount.ToString("N") + " " + currentSensor.linkedSensor.unit;
            }
            else if (manualSensor != null && manualSensor.linkedSensor != null)
            {
                secondaryReading.Text = manualSensor.linkedSensor.measurement.amount.ToString("N") + " " + manualSensor.linkedSensor.unit;
            }
            else
            {
                secondaryReading.Text = "Not Linked";
            }
        }
Beispiel #3
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");
            }
        }