void SavePressed(object sender, EventArgs e)
        {
            //Session newSession = new Session(_session.Mapping);
            Preferences prefs = new Preferences();

            bool   hasErrors    = false;
            string errorMessage = "";

            // Verify user has selected save path
            if (_chosenFilePath == null)
            {
                hasErrors     = true;
                errorMessage += "- File path to save log not chosen\n";
            }
            else
            {
                prefs.System.LogFilePath = _chosenFilePath;
            }

            // Verify user has selected serial port
            if (_portDropdown.Active == -1)
            {
                hasErrors     = true;
                errorMessage += "- No serial port selected\n";
            }
            else
            {
                prefs.System.Serial.PortName = _portDropdown.ActiveText;
            }

            // Save chosen baud rate
            if (int.TryParse(_baudRateDropdown.ActiveText, out int baud))
            {
                prefs.System.Serial.BaudRate = baud;
            }
            else
            {
                hasErrors     = true;
                errorMessage += "- Conversion error in baud rate\n";
            }

            // Show settings on startup
            prefs.Visual.ShowSettingsOnStartup = _chkSettingsOnStartup.Checked;

            // Update sensor component settings
            foreach (ComponentSettingWidget widget in _componentWidgets)
            {
                SensorSettings sensorSettings = new SensorSettings();
                sensorSettings.Enabled = widget.Enabled;
                //newSession.Mapping.ComponentsByID()[widget.Component.BoardID].Enabled = widget.Enabled;

                if (ValidateSensorLimits(widget, out float min, out float max, out string err))
                {
                    hasErrors     = true;
                    errorMessage += err;
                }
Example #2
0
 public Bme680(II2cBus bus, byte address = 0x77, SensorSettings sensorSettings = null) : base(bus, address)
 {
     if (sensorSettings == null)
     {
         sensorSettings = new SensorSettings();
     }
     _settings    = sensorSettings;
     _lock        = new object();
     _initialized = false;
 }
        public ISensor Build()
        {
            var temp     = _sockets.Select(x => new SocketWithSensorParameters(x.Key.ID, x.Key.Name, x.Value)).ToList();
            var settings = new SensorSettings("TimeSwitch", _parameters, temp);

            var timeSwitch = new TimeSwitch();

            timeSwitch.Initialize(settings);
            return(timeSwitch);
        }
Example #4
0
 public IActionResult Update([FromBody] SensorSettings newObject)
 {
     try {
         var c = repositorio.Update(newObject);
         return(this.Ok(c));
     }
     catch (Exception ex) {
         Console.WriteLine(ex.Message);
         return(BadRequest());
     }
 }
Example #5
0
 public void OnGet()
 {
     if (Order == null)
     {
         Order      = new SensorSettings();
         Order.HWID = "thiago";
         Order.CalibrationParameters = new List <double>();
         Order.CalibrationParameters.Add(0.1);
         Order.CalibrationParameters.Add(12.0);
     }
 }
Example #6
0
 public IActionResult Read()
 {
     try {
         SensorSettings temp       = (SensorSettings)repositorio.Read();
         string         jsonstring = JsonConvert.SerializeObject(temp);
         return(this.Ok(jsonstring));
     }
     catch (Exception ex) {
         Console.WriteLine(ex.Message);
         return(null);
     }
 }
Example #7
0
        public int InputSettings(SensorSettings settings)
        {
            int result = -1;

            if (m_isConnectionExist == true)
            {
                // Forward these settings to the sensor.
                result = 0;
            }

            return(result);
        }
Example #8
0
        public SensorSettings OutputSettings()
        {
            SensorSettings settings = null;

            if (m_isConnectionExist == true)
            {
                // Get these settings from sensor and then create the object.
                settings = new SensorSettings(5, "fast");
            }

            return(settings);
        }
Example #9
0
        public void SaveToLocalSettings()
        {
            var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            var ss            = new SensorSettings
            {
                RangeMin = RangeMin,
                RangeMax = RangeMax,
                DangerLo = DangerLo,
                DangerHi = DangerHi,
                Unit     = Unit,
                Triggers = Triggers
            };

            localSettings.Values[settingsKey] = ss.ToJson();
        }
Example #10
0
        private void SensorSettingClicked(object sender, RoutedEventArgs routedEventArgs)
        {
            var control = sender as SensorDataControl;

            if (control != null)
            {
                SensorSettings.SaveSettings += SensorSettings_SaveSettings;

                _selectedSensorControl = control;

                SensorSettings.Show(
                    control.BrickInputPort,
                    _brick.Ports[control.BrickInputPort].Type,
                    _brick.Ports[control.BrickInputPort].Mode);
            }
        }
Example #11
0
        public void LoadFromLocalSettings()
        {
            var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            var json          = localSettings.Values[settingsKey] as string;
            var ss            = SensorSettings.CreateFromJson(json);

            if (ss != null)
            {
                RangeMin = ss.RangeMin;
                RangeMax = ss.RangeMax;
                DangerLo = ss.DangerLo;
                DangerHi = ss.DangerHi;
                Unit     = ss.Unit;
                Triggers = ss.Triggers;
            }
        }
Example #12
0
 public object Update(object newObject)   //Update de Operation State
 {
     try
     {
         OpState = (OperationState)newObject;
         SensorSettings temp = (SensorSettings)Program.sensorSettings;
         temp.State = OpState.State;
         Program.sensorSettingsRepo.Update(temp);
         return(OpState);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(null);
     }
 }
Example #13
0
            public static SensorReading CreateFromDevice(I2cPeripheral device, SensorSettings sensorSettings)
            {
                // Read the current control register
                var status = device.ReadRegister(RegisterAddresses.ControlTemperatureAndPressure.Address);

                // Force a sample
                status = BitHelpers.SetBit(status, 0x00, true);
                device.WriteRegister(RegisterAddresses.ControlTemperatureAndPressure.Address, status);
                // Wait for the sample to be taken.
                do
                {
                    status = device.ReadRegister(RegisterAddresses.ControlTemperatureAndPressure.Address);
                } while (BitHelpers.GetBitValue(status, 0x00));

                var sensorData = device.ReadRegisters(
                    RegisterAddresses.AllSensors.Address,
                    RegisterAddresses.AllSensors.Length)
                                 .AsSpan();

                var rawPressure    = GetRawValue(sensorData.Slice(0, 3));
                var rawTemperature = GetRawValue(sensorData.Slice(3, 3));
                var rawHumidity    = GetRawValue(sensorData.Slice(6, 2));
                //var rawVoc = GetRawValue(sensorData.Slice(8, 2));
                var compensationData1 = device.ReadRegisters(RegisterAddresses.CompensationData1.Address,
                                                             RegisterAddresses.CompensationData1.Length);
                var compensationData2 = device.ReadRegisters(RegisterAddresses.CompensationData2.Address,
                                                             RegisterAddresses.CompensationData2.Length);
                var compensationData = ArrayPool <byte> .Shared.Rent(64);

                try {
                    Array.Copy(compensationData1, 0, compensationData, 0, compensationData1.Length);
                    Array.Copy(compensationData2, 0, compensationData, 25, compensationData2.Length);

                    var temp = RawToTemp(rawTemperature,
                                         new TemperatureCompensation(compensationData));

                    var pressure = RawToPressure(temp, rawPressure,
                                                 new PressureCompensation(compensationData));
                    var humidity = RawToHumidity(temp, rawHumidity,
                                                 new HumidityCompensation(compensationData));

                    return(new SensorReading(pressure, temp, humidity, 0, sensorSettings));
                } finally {
                    ArrayPool <byte> .Shared.Return(compensationData, true);
                }
            }
Example #14
0
        private IEnumerable <SensorSettings> readSensorSettings()
        {
            var sensorNames = readSensorNames();

            var listOfSensorSettings = new List <SensorSettings>();

            foreach (string sensorName in sensorNames)
            {
                var parameters = readGlobalSensorParameters(sensorName);

                var sensorSettings = new SensorSettings(sensorName, parameters, readSocketsWithSensorParameters(sensorName));

                listOfSensorSettings.Add(sensorSettings);
            }

            return(listOfSensorSettings);
        }
Example #15
0
        public string Execute(ref SensorAPI sensorAPI)
        {
            SensorSettings settings = sensorAPI.OutputSettings();

            if (settings != null)
            {
                Console.WriteLine("Get sensor settings");
                Console.WriteLine("frames : {0}, scan mode : {1}", settings.numFrames, settings.scanMode);
                Logger.Log("Sensor output settings", settings.numFrames.ToString(), settings.scanMode);
            }
            else
            {
                Console.WriteLine("No Connection to the sensor");
                Logger.Log("No Connection to the sensor");
            }

            return(Command.OUTPUT_SETTINGS);
        }
Example #16
0
        public ActionResult OnGet(int idx)
        {
            if (idx < 0)
            {
                return(NotFound());
            }

            try
            {
                medidor = MedidoresModel.Medidores.ElementAt(idx);

                /*client.Headers["Content-type"] = "application/json";
                 * Stream data = client.OpenRead (HWIP+"/medidor/sensorsettings");
                 * StreamReader reader = new StreamReader (data);
                 * string s = reader.ReadToEnd();
                 * medidor = (SensorSettings)JsonConvert.DeserializeObject(s,typeof(SensorSettings));*/
                string[] lista = { "Off", "On", "Calibrate" };
                for (int id = 0; id < lista.Count(); id++)
                {
                    if (id == medidor.State)
                    {
                        listaOpStates.ElementAt(id).Selected = true;
                    }
                }
                foreach (var item in GrandezasModel.grandezas)
                {
                    if (item.IdGrandeza == medidor.OperationType)
                    {
                        listaGrandezas.ElementAt(item.IdGrandeza - 1).Selected = true;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
                medidor = new SensorSettings();
                return(NotFound());
            }

            Page_Title = "Editar Medidor";
            return(Page());
        }
Example #17
0
        public string Execute(ref SensorAPI sensorAPI)
        {
            SensorSettings settings = new SensorSettings(2, "slow");

            int result = sensorAPI.InputSettings(settings);

            if (result == 0)
            {
                Console.WriteLine("Set sensor settings:");
                Console.WriteLine("frames : {0}, scan mode : {1}", settings.numFrames, settings.scanMode);
                Logger.Log("Sensor output settings", settings.numFrames.ToString(), settings.scanMode);
            }
            else
            {
                Console.WriteLine("No Connection to the sensor");
                Logger.Log("No Connection to the sensor");
            }

            return(Command.INPUT_SETTINGS);
        }
Example #18
0
        public ISensor CreateSensor(SensorSettings sensorSettings)
        {
            switch (sensorSettings.Type)
            {
            case SensorType.RandomThermometer:
                return(new RandomSensor(21m, 3m, sensorSettings.Name, ReadingType.Temperature));

            case SensorType.RandomHygrometer:
                return(new RandomSensor(45m, 10m, sensorSettings.Name, ReadingType.Humidity));

            case SensorType.ChipsetThermometer:
                return(new ChipsetThermometer(_shellHelper, sensorSettings.Name));

            case SensorType.DS18B20:
                return(new DS18B20Thermometer(_shellHelper, sensorSettings));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #19
0
        public static void Main(string[] args)
        {
            try
            {
                settingsConf = File.Open("settings.conf", FileMode.OpenOrCreate);
                StreamReader reader     = new StreamReader(settingsConf);
                string       jsonstring = reader.ReadToEnd();
                sensorSettings       = new SensorSettings();
                sensorSettings       = (SensorSettings)JsonConvert.DeserializeObject(jsonstring, typeof(SensorSettings));
                sensorSettings.State = 0;
                operationStateRepo.Update(new OperationState( )
                {
                    State = 0
                });
                List <string> url      = new List <string>();
                string        hostName = Dns.GetHostName(); // Retrive the Name of HOST
                Console.WriteLine(hostName);
                // nao efetivo se a rede nao possuir um roteador caseiro que atualiza o dns dinamicamente
                // ou seja, so funciona se o raspberry estiver inserido no dns da rede

                /* foreach(var ip in Dns.GetHostEntry(hostName).AddressList){
                 *  if(ip.ToString().Contains('.'))
                 *  {
                 *     // Console.WriteLine("My IP Address is :"+ip);
                 *      var temp = (ip.ToString().Contains(":")?"["+ip+"]":ip.ToString());
                 *      url.Add("http://"+temp+":1000");
                 *  }
                 * }   */

                //Get IP.  Funciona sempre
                foreach (NetworkInterface netif in NetworkInterface.GetAllNetworkInterfaces())
                {
                    if (netif.Name != "lo" && netif.Name != "wlan0")
                    {
                        IPInterfaceProperties prop = netif.GetIPProperties();
                        var listaIps = (from p in prop.UnicastAddresses where !p.Address.ToString().Contains(":") select "http://" + p.Address.ToString() + ":1000").Distinct().ToList();
                        url = listaIps;
                        Console.WriteLine("quase no for");
                        foreach (var p in url)
                        {
                            Console.WriteLine(p);
                        }
                        Console.WriteLine("sai do for");
                    }
                }
                //fim do Get Ip

                endereco            = url;
                sensorSettings.HWIP = endereco[0];
            }
            catch (System.Exception ex)
            {
                List <string> url      = new List <string>();
                string        hostName = Dns.GetHostName(); // Retrive the Name of HOST
                Console.WriteLine(hostName);
                // Get the IP
                foreach (NetworkInterface netif in NetworkInterface.GetAllNetworkInterfaces())
                {
                    if (netif.Name != "lo")
                    {
                        IPInterfaceProperties prop = netif.GetIPProperties();
                        var listaIps = (from p in prop.UnicastAddresses where !p.Address.ToString().Contains(":") select "http://" + p.Address.ToString() + ":1000").Distinct().ToList();
                        url = listaIps;
                        Console.WriteLine("quase no for");
                        foreach (var p in url)
                        {
                            Console.WriteLine(p);
                        }
                        Console.WriteLine("sai do for");
                    }
                }
                sensorSettings               = new SensorSettings();
                endereco                     = url;
                sensorSettings.HWIP          = endereco[0];
                sensorSettings.OperationType = 1;
                sensorSettings.State         = 0;
                sensorSettings.ServersIP     = "http://localhost:2005";
                sensorSettings.HWIP          = endereco.First();
                System.Console.Write(ex.Message);
            }

            sensorSettingsRepo.Update(sensorSettings);

            longThread.Start();
            CreateWebHostBuilder(args).Build().Run();
        }
Example #20
0
 public Sensor(SensorSettings settings)
 {
     this.Settings = settings;
 }
Example #21
0
            private SensorReading(double pressure, double temperature, double humidity, double voc, SensorSettings settings)
            {
                switch (settings.PressureUnit)
                {
                case PressureUnit.Pa:
                    Pressure = pressure;
                    break;

                case PressureUnit.Psia:
                    Pressure = pressure / 6894.75728;
                    break;

                case PressureUnit.Atm:
                    Pressure = pressure / 101325;
                    break;
                }

                switch (settings.TemperatureUnit)
                {
                case TemperatureUnit.C:
                    Temperature = temperature;
                    break;

                case TemperatureUnit.F:
                    Temperature = (temperature * (9D / 5D)) + 32;
                    break;
                }

                Humidity = humidity;
                VOC      = voc;
            }
 public DS18B20Thermometer(IShellHelper shellHelper, SensorSettings settings)
 {
     _shellHelper = shellHelper;
     _deviceId    = settings.DeviceId;
     Name         = settings.Name;
 }
Example #23
0
 public void UpdateSensorSettings(SensorSettings sensorSettings)
 {
     _settings = sensorSettings;
     Initialize();
 }
Example #24
0
 public ProcessBasedSensorBase(SensorSettings settings) : base(settings)
 {
 }
Example #25
0
 internal void Initialize(SensorSettings settings)
 {
     _timer          = new Timer(1000);
     _timer.Elapsed += _timer_Elapsed;
     _cache          = settings.Sockets.Select(x => new Cache(x, parseParameters(x.Parameters))).ToList();
 }