/// <summary>
        /// Queries the user friendly name of the sensor type.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static string GetSensorTypeName(this ESensorType type)
        {
            var ion = (BaseAndroidION)AppState.context;

            switch (type)
            {
            case ESensorType.Humidity:
                return(ion.context.GetString(Resource.String.humidity));

            case ESensorType.Pressure:
                return(ion.context.GetString(Resource.String.pressure));

            case ESensorType.Temperature:
                return(ion.context.GetString(Resource.String.temperature));

            case ESensorType.Vacuum:
                return(ion.context.GetString(Resource.String.vacuum));

            case ESensorType.Weight:
                return(ion.context.GetString(Resource.String.weight));

            default:
                return(ion.context.GetString(Resource.String.unknown));
            }
        }
        /// <summary>
        /// Queries the localized user friendly string representing a sensor type.
        /// </summary>
        /// <param name="sensorType"></param>
        /// <returns></returns>
        public static string GetTypeString(this ESensorType sensorType)
        {
            switch (sensorType)
            {
            case ESensorType.Length: {
                return(Strings.Sensor.Type.LENGTH.FromResources());
            }

            case ESensorType.Humidity: {
                return(Strings.Sensor.Type.HUMIDITY.FromResources());
            }

            case ESensorType.Weight: {
                return(Strings.Sensor.Type.WEIGHT.FromResources());
            }

            case ESensorType.Pressure: {
                return(Strings.Sensor.Type.PRESSURE.FromResources());
            }

            case ESensorType.Temperature: {
                return(Strings.Sensor.Type.TEMPERATURE.FromResources());
            }

            case ESensorType.Vacuum: {
                return(Strings.Sensor.Type.VACUUM.FromResources());
            }

            default: {
                return(Strings.Sensor.Type.UNKNOWN.FromResources());
            }
            }
        }
        /// <summary>
        /// Queries the default unit for the given sensor type.
        /// </summary>
        /// <returns>The default unit.</returns>
        /// <param name="sensorType">Sensor type.</param>
        public static Unit GetDefaultUnit(this ESensorType sensorType)
        {
            switch (sensorType)
            {
            /*
             *              case ESensorType.Humidity: {
             *                return DEFAULT_HUMIDITY_UNITS[0];
             *              }
             *              case ESensorType.Length: {
             *                return DEFAULT_LENGTH_UNITS[0];
             *              }
             *              case ESensorType.Mass: {
             *                return DEFAULT_MASS_UNITS[0];
             *              }
             */
            case ESensorType.Pressure:
                return(SensorUtils.DEFAULT_PRESSURE_UNITS[0]);

            case ESensorType.Temperature:
                return(SensorUtils.DEFAULT_TEMPERATURE_UNITS[0]);

            case ESensorType.Vacuum:
                return(SensorUtils.DEFAULT_VACUUM_UNITS[0]);

            case ESensorType.Weight:
                return(SensorUtils.DEFAULT_WEIGHT_UNITS[0]);

            default:
                throw new ArgumentException("Cannot get default unit for " + sensorType);
            }
        }
예제 #4
0
        /// <summary>
        /// Queries the localized user friendly abreviation string representation of a sensor type.
        /// </summary>
        /// <returns>The type abreviation string.</returns>
        /// <param name="sensorType">Sensor type.</param>
        public static string GetTypeAbreviationString(this ESensorType sensorType)
        {
            var ion = (BaseAndroidION)AppState.context;

            switch (sensorType)
            {
            case ESensorType.Humidity:
                return(ion.context.GetString(Resource.String.humidity_short));

            case ESensorType.Length:
                return(ion.context.GetString(Resource.String.length_short));

            case ESensorType.Weight:
                return(ion.context.GetString(Resource.String.weight_short));

            case ESensorType.Pressure:
                return(ion.context.GetString(Resource.String.pressure_short));

            case ESensorType.Temperature:
                return(ion.context.GetString(Resource.String.temperature_short));

            case ESensorType.Vacuum:
                return(ion.context.GetString(Resource.String.vacuum_short));

            default:
                return(ion.context.GetString(Resource.String.unknown));
            }
        }
 public GaugeDeviceSensor(IION ion, GaugeDevice device, int index, ESensorType sensorType, bool relative = true)
     : base(sensorType, ion.preferences.units.DefaultUnitFor(sensorType).OfScalar(0.0), relative)
 {
     this.device = device;
     this.index  = index;
     this.name   = device.name;
 }
예제 #6
0
        /// <summary>
        /// RETURNS THE BUFFER VALUE FOR THE GRAPH BASED ON THE UNIT A USER HAS CHOSEN
        /// </summary>
        /// <returns>THE GRAPH TOP AND BOTTOM BUFFER</returns>
        /// <param name="type">TYPE OF SENSOR</param>
        /// <param name="gaugeUnit">SPECIFIC UNIT CHOSEN BY USER FOR THE SENSOR TYPE</param>
        public double getUnitBuffer(ESensorType type, Unit gaugeUnit)
        {
            switch (type)
            {
            case ESensorType.Pressure:
                double psig            = 10;
                var    pressureBuffer  = new ScalarSpan(Units.Pressure.PSIG, psig);
                var    pressureConvert = pressureBuffer.ConvertTo(gaugeUnit);
                return(pressureConvert.magnitude);

            case ESensorType.Temperature:
                double fahrenheit         = 10;
                var    temperatureBuffer  = new ScalarSpan(Units.Temperature.FAHRENHEIT, fahrenheit);
                var    temperatureConvert = temperatureBuffer.ConvertTo(gaugeUnit);
                return(temperatureConvert.magnitude);

            case ESensorType.Vacuum:
                double micron        = 2000;
                var    vacuumBuffer  = new ScalarSpan(Units.Vacuum.MICRON, micron);
                var    vacuumConvert = vacuumBuffer.ConvertTo(gaugeUnit);
                return(vacuumConvert.magnitude);

            default:
                var defaultBuffer  = new ScalarSpan(Units.Pressure.PSIG, 10);
                var defaultConvert = defaultBuffer.ConvertTo(gaugeUnit);
                return(defaultConvert.magnitude);
            }
        }
        public TestParameters(EDeviceModel deviceModel, ESensorType sensorType, List <TargetPoint> targetPoints, HashSet <Grade> grades)
        {
            this.deviceModel  = deviceModel;
            this.sensorType   = sensorType;
            this.targetPoints = new List <TargetPoint>();
            this.grades       = grades;

            this.targetPoints.AddRange(targetPoints);

            targetPoints.Sort();
            targetPoints.Reverse();

            if (grades == null || grades.Count <= 0)
            {
                this.grades = new HashSet <Grade>();
                this.grades.Add(new Grade(1.00, "F", false));
            }

            errorBand = 1;
            foreach (var grade in grades)
            {
                if (grade.errorBand < errorBand)
                {
                    errorBand = grade.errorBand;
                }
            }
        }
예제 #8
0
 /// <summary>
 /// Creates a new manual sensor within this device. The sensor will last until explicitly destroyed.
 /// </summary>
 /// <param name="ion"></param>
 /// <param name="sensorType"></param>
 /// <returns></returns>
 public ManualSensor CreateNewSensor(IION ion, ESensorType sensorType, bool isRelative = true)
 {
     //var u = ion.preferences.units.DefaultUnitFor(sensorType);
     //var ret = new ManualSensor(this, sensorType, u.OfScalar(0), isRelative);
     //return ret;
     return(null);
 }
예제 #9
0
        public static Unit GetUnit(ESensorType sensorType, string code)
        {
            switch (sensorType)
            {
            case ESensorType.Humidity:
                return(GetHumidityUnit(code));

            case ESensorType.Length:
                return(GetLengthUnit(code));

            case ESensorType.Weight:
                return(GetWeightUnit(code));

            case ESensorType.Pressure:
                return(GetPressureUnit(code));

            case ESensorType.Temperature:
                return(GetTemperatureUnit(code));

            case ESensorType.Vacuum:
                return(GetVacuumUnit(code));

            default:
                throw new ArgumentException("Cannot find unit of type: " + sensorType + " for code " + code);
            }
        }
        public ManualSensorEditDialog(Context context, ESensorType sensorType, bool isRelative, EventHandler <Sensor> action)
        {
            this.context = context;
            this.sensor  = new ManualSensor(sensorType);
            this.action  = action;

            sensor.name = context.GetString(Resource.String.manual);
        }
예제 #11
0
        /// <summary>
        /// Creates a new sensor.
        /// </summary>
        /// <param name="sensorType">Sensor type.</param>
        /// <param name="initialMeasurement">Initial measurement.</param>
        /// <param name="isRelative">If set to <c>true</c> is relative.</param>
        protected Sensor(ESensorType sensorType, Scalar initialMeasurement, bool isRelative = true)
        {
            type            = sensorType;
            _measurement    = initialMeasurement;
            this.isRelative = isRelative;

            supportedUnits = new List <Unit>(SensorUtils.GetSensorTypeUnitMapping()[type]).ToArray();
        }
예제 #12
0
        public ManualSensorCreateDialog(Context context, Dictionary <ESensorType, IEnumerable <Unit> > options)
        {
            this.context = context;
            this.options = options;

            try {
                if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
                {
                    content = LayoutInflater.From(context).Inflate(Resource.Layout.dialog_manual_sensor_create_4_4, null, false);
                }
                else
                {
                    content = LayoutInflater.From(context).Inflate(Resource.Layout.dialog_manual_sensor_create, null, false);
                }
            } catch (Exception e) {
                Log.E(this, "Failed to set layout. Defaulting to old version", e);
                content = LayoutInflater.From(context).Inflate(Resource.Layout.dialog_manual_sensor_create_4_4, null, false);
            }

            name        = content.FindViewById <EditText>(Resource.Id.name);
            measurement = content.FindViewById <EditText>(Resource.Id.measurement);

            type = content.FindViewById <Button>(Resource.Id.type);
            unit = content.FindViewById <Button>(Resource.Id.unit);

            sensorType = options.Keys.First();
            sensorUnit = options[sensorType].First();
            type.Text  = sensorType.GetTypeString();
            unit.Text  = sensorUnit.ToString();

            type.Click += (sensor, obj) => {
                var dialog = new ListDialogBuilder(context);
                dialog.SetTitle(Resource.String.sensor_select_type);

                foreach (var t in options.Keys)
                {
                    dialog.AddItem(t.GetTypeString(), () => {
                        sensorType = t;
                        type.Text  = t.GetTypeString();

                        sensorUnit = options[sensorType].First();
                        unit.Text  = sensorUnit.ToString();
                    });
                }

                dialog.Show();
            };

            unit.Click += (sender, e) => {
                UnitDialog.Create(context, options[sensorType], (s1, e1) => {
                    sensorUnit = e1;
                    unit.Text  = sensorUnit.ToString();
                }).Show();
            };
        }
예제 #13
0
 public static Stimulus CreateStimulus(int stimType, ESensorType sensorType, Vector3 pos, object obj, float intensity = 0.5f)
 {
     return(new Stimulus()
     {
         StimulusType = stimType,
         EmitterPos = pos,
         TargetSensorType = sensorType,
         TargetObject = obj,
         Intensity = Mathf.Clamp01(intensity)
     });
 }
예제 #14
0
        /// <summary>
        /// Queries whether or not the device has a sensor of the given type.
        /// </summary>
        /// <returns><c>true</c> if this instance hash sensor of type the specified sensorType; otherwise, <c>false</c>.</returns>
        /// <param name="sensorType">Sensor type.</param>
        public bool HasSensorOfType(ESensorType sensorType)
        {
            foreach (var sensor in sensors)
            {
                if (sensorType == sensor.type)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #15
0
 public AirSensor(
     string title,
     EMeasurementUnit measurementUnit,
     ESensorType sensorType,
     double thresholdMin,
     double thresholdMax,
     double value,
     EActiveState activeState)
 {
     Title           = title;
     MeasurementUnit = measurementUnit;
     SensorType      = sensorType;
     ThresholdMin    = thresholdMin;
     ThresholdMax    = thresholdMax;
     Value           = value;
     ActiveState     = activeState;
 }
예제 #16
0
        // Overridden from IUnits
        public Unit DefaultUnitFor(ESensorType sensorType)
        {
            switch (sensorType)
            {
            case ESensorType.Length:
                return(length);

            case ESensorType.Pressure:
                return(pressure);

            case ESensorType.Temperature:
                return(temperature);

            case ESensorType.Vacuum:
                return(vacuum);

            default:
                return(sensorType.GetDefaultUnit());
            }
        }
        /// <summary>
        /// Resolves the default unit for the given sensor type.
        /// </summary>
        /// <returns>The unit for.</returns>
        /// <param name="prefs">Prefs.</param>
        /// <param name="sensorType">Sensor type.</param>
        public static Unit DefaultUnitFor(this IUnitPreferences prefs, ESensorType sensorType)
        {
            switch (sensorType)
            {
            case ESensorType.Length:
                return(prefs.length);

            case ESensorType.Pressure:
                return(prefs.pressure);

            case ESensorType.Temperature:
                return(prefs.temperature);

            case ESensorType.Vacuum:
                return(prefs.vacuum);

            default:
                return(sensorType.GetDefaultUnit());
            }
        }
        /// <summary>
        /// Gets the type of the all gauge device sensors of.
        /// </summary>
        /// <returns>The all gauge devices of type.</returns>
        /// <param name="sensorType">Sensor type.</param>
        public List <GaugeDeviceSensor> GetAllGaugeDeviceSensorsOfType(ESensorType sensorType)
        {
            var ret = new List <GaugeDeviceSensor>();

            foreach (var device in devices)
            {
                var gd = device as GaugeDevice;
                if (gd != null)
                {
                    foreach (var sensor in gd.sensors)
                    {
                        if (sensor.type == sensorType)
                        {
                            ret.Add(sensor);
                        }
                    }
                }
            }

            return(ret);
        }
예제 #19
0
        /// <summary>
        /// Determines whether or not the given unit is valid with the provided sensor type.
        /// </summary>
        /// <param name="sensorType"></param>
        /// <param name="unit"></param>
        /// <returns>True if the unit is valid for the sensor type, false otherwise.</returns>
        public static bool IsCompatibleWith(ESensorType sensorType, Unit unit)
        {
            switch (sensorType)
            {
            case ESensorType.Length:
            {
                return(unit.IsCompatible(Units.Length.METER));
            }

            case ESensorType.Humidity:
            {
                return(unit.IsCompatible(Units.Humidity.RELATIVE_HUMIDITY));
            }

            case ESensorType.Weight:
            {
                return(unit.IsCompatible(Units.Weight.KILOGRAM));
            }

            case ESensorType.Pressure:
            {
                return(unit.IsCompatible(Units.Pressure.PASCAL));
            }

            case ESensorType.Temperature:
            {
                return(unit.IsCompatible(Units.Temperature.KELVIN));
            }

            case ESensorType.Vacuum:
            {
                return(unit.IsCompatible(Units.Vacuum.MICRON));
            }

            default:
            {
                return(false);
            }
            }
        }
예제 #20
0
        private void HandleInput(string sensorData)
        {
            try
            {
                if (!string.IsNullOrEmpty(sensorData))
                {
                    var arduinoSensorType = sensorData.Substring(0, sensorData.IndexOf(":", StringComparison.Ordinal));

                    var sensorValue =
                        int.Parse(sensorData.Substring(sensorData.IndexOf(":", StringComparison.Ordinal) + 1));

                    ESensorType sensorType = GetEnumValue(arduinoSensorType);

                    if (!sensorType.Equals(ESensorType.Invalid))
                    {
                        _employeeManager.NewSensorDataReceived(sensorType, sensorValue);
                    }
                }
            }
            catch (Exception e)
            {
            }
        }
예제 #21
0
        public GaugeDeviceSensorSelectDialog(Context context, IION ion, ESensorType sensorType, OnSensorSelected onSensorSelected)
        {
            _context          = context;
            _onSensorSelected = onSensorSelected;

            _sensors = new List <GaugeDeviceSensor>();

            foreach (var device in ion.deviceManager.knownDevices)
            {
                var gd = device as GaugeDevice;
                if (gd != null)
                {
                    foreach (var sensor in gd.sensors)
                    {
                        if (sensor.type == sensorType)
                        {
                            _sensors.Add(sensor);
                        }
                    }
                }
            }

            _sensors.Sort(new GeneralSensorSorter());
        }
예제 #22
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");
                }
            }
        }
예제 #23
0
 /// <summary>
 /// Creates a new sensor.
 /// </summary>
 /// <param name="sensorType">Sensor type.</param>
 /// <param name="isRelative">If set to <c>true</c> is relative.</param>
 protected Sensor(ESensorType sensorType, bool isRelative = true) :
     this(sensorType, AppState.context.preferences.units.DefaultUnitFor(sensorType).OfScalar(0.0), isRelative)
 {
 }
예제 #24
0
 public HasSensorOfTypeFilter(ESensorType sensorType)
 {
     this.sensorType = sensorType;
 }
예제 #25
0
 /// <summary>
 /// Creates a new ManualSensor bound to the given ion instance.
 /// </summary>
 /// <returns>The create.</returns>
 /// <param name="ion">Ion.</param>
 /// <param name="sensorType">Sensor type.</param>
 /// <param name="isRelative">If set to <c>true</c> is relative.</param>
 public static ManualSensor Create(IION ion, ESensorType sensorType, bool isRelative = true)
 {
     return(ion.manualSensorContainer.CreateNewSensor(ion, sensorType, isRelative));
 }
예제 #26
0
 public static string ToFormattedString(ESensorType sensorType, Scalar measurement, bool includeUnit = false)
 {
     return(ToFormattedString(measurement, includeUnit));
 }
예제 #27
0
        public void NewSensorDataReceived(ESensorType sensorType, int sensorValue)
        {
            switch (sensorType)
            {
            case ESensorType.DistanceMeter1:
                if (ETransitionType.RisingEdge == ManagerSensors[ESensorType.DistanceMeter1].GetSensorTransition(sensorValue))
                {
                    if (!inRoom)
                    {
                        if ((DateTime.Now - _lastExitTime).Milliseconds < 500)
                        {
                            break;      // filter noise
                        }
                        inRoom = true;
                        if (null == _activeManInTheRoom)
                        {
                            _activeManInTheRoom = new ManInTheRoom();
                        }
                        lastEntryTime = ManagerSensors[ESensorType.DistanceMeter1].ChangeTime;
                        _ledControl.ChangeColor(255, 255, 0);       // yellow
                    }
                    else
                    {
                        inRoom = false;
                        if (null != _activeManInTheRoom)
                        {
                            _activeManInTheRoom.ExitTime = DateTime.Now;
                            // write to DB
                            _activeManInTheRoom = null;         //
                            _lastExitTime       = DateTime.Now; // to filter noise
                        }
                    }
                }
                break;

            case ESensorType.EmployeeCardReader:
                isEmployee = true;
                if (null == _activeManInTheRoom)
                {
                    _activeManInTheRoom = new ManInTheRoom();
                }
                _activeManInTheRoom.Id         = sensorValue;
                _activeManInTheRoom.IsEmployee = true;
                //EmployeeNumber = sensorValue;
                if (Math.Abs((lastWashTime - lastEntryTime).Milliseconds) < 15000)
                {
                    hansWaskedOK = true;
                    _ledControl.ChangeColor(0, 0, 255);     // green
                }
                else
                {
                    _ledControl.ChangeColor(0, 0, 255);     // blue
                }
                break;

            case ESensorType.PressureSensor:
                if (ETransitionType.RisingEdge == ManagerSensors[ESensorType.PressureSensor].GetSensorTransition(sensorValue))
                {
                    lastWashTime = ManagerSensors[ESensorType.PressureSensor].ChangeTime;
                    //if ((lastWashTime - lastEntryTime).Milliseconds < 15000) // less than 15 sec from entry to wash - OK!!!
                    if (inRoom)
                    {
                        if (null != _activeManInTheRoom)
                        {
                            _activeManInTheRoom.Sanitized    = true;
                            _activeManInTheRoom.SanitizeTime = lastWashTime;
                        }

                        hansWaskedOK = true;
                        _ledControl.ChangeColor(0, 0, 255);     // green
                    }
                }
                break;

            case ESensorType.DistanceMeter2:
                if (ETransitionType.RisingEdge == ManagerSensors[ESensorType.DistanceMeter2].GetSensorTransition(sensorValue))
                {
                    if (inRoom)
                    {
                        if ((DateTime.Now - lastEntryTime).Milliseconds < 1000)
                        {
                            break;                            // filter noise
                        }
                        _ledControl.ChangeColor(255, 255, 0); // yellow
                    }
                }
                break;

            default:
                break;
            }
            // periodic checks
            if (inRoom)
            {
                if ((!warningOn) && (!hansWaskedOK))
                {
                    if ((DateTime.Now - lastEntryTime).Milliseconds > 15000)
                    {
                        warningOn = true;
                        // turn on yellow light
                    }
                }
            }
            if ((DateTime.Now - lastEntryTime).Milliseconds > 60000)
            {
                hansWaskedOK = false;
                warningOn    = false;
                // turn off light after 2 minutes
            }
        }
예제 #28
0
 public GetSensorValueQuery(PinPort pinPort, ESensorType type)
 {
     PinPort = pinPort;
     Type    = type;
 }
예제 #29
0
 // Implemented for DataLogReport.ILocalization
 public string GetSensorTypeString(ESensorType sensorType)
 {
     return(sensorType.GetSensorTypeName());
 }
예제 #30
0
        public static string ToFormattedString(ESensorType sensorType, ScalarSpan measurement, bool includeUnit = false)
        {
            var unit   = measurement.unit;
            var amount = measurement.magnitude;

            string ret = "";

            if (double.IsNaN(amount))
            {
                ret = "---";
            }
            else
            {
                // PRESSURE UNITS
                if (Units.Pressure.PASCAL.Equals(unit))
                {
                    ret = amount.ToString("0");
                }
                else if (Units.Pressure.KILOPASCAL.Equals(unit))
                {
                    if (ESensorType.Vacuum == sensorType)
                    {
                        ret = amount.ToString("0.0000");
                    }
                    else
                    {
                        ret = amount.ToString("0");
                    }
                }
                else if (Units.Pressure.MEGAPASCAL.Equals(unit))
                {
                    ret = amount.ToString("0.000");
                }
                else if (Units.Pressure.MILLIBAR.Equals(unit))
                {
                    ret = amount.ToString("0.000");
                }
                else if (Units.Pressure.PSIG.Equals(unit))
                {
                    ret = amount.ToString("0.0");
                }
                else if (Units.Pressure.PSIA.Equals(unit))
                {
                    ret = amount.ToString("0.0000");
                }
                else if (Units.Pressure.IN_HG.Equals(unit))
                {
                    if (ESensorType.Vacuum == sensorType)
                    {
                        ret = amount.ToString("0.000");
                    }
                    else
                    {
                        ret = amount.ToString("0.00");
                    }
                }
                // VACUUM PRESSURE
                else if (Units.Vacuum.MICRON.Equals(unit))
                {
                    ret = amount.ToString("###,##0");
                }
                else if (Units.Vacuum.MILLITORR.Equals(unit))
                {
                    ret = amount.ToString("###,##0");
                }
                // DEFAULT
                else
                {
                    ret = amount.ToString("0.00");
                }
            }

            if (includeUnit)
            {
                ret += " " + unit.ToString();
            }

            return(ret);
        }