public frmSensorOptions(sensorTypeEnum tpy, sensor selectedSensor) { InitializeComponent(); _tpy = new sensorType(tpy); List<Node> allNodes = FrmMain.getAllConnectedNodes(); foreach (Node node in allNodes) { if (node.hasSensorOf(_tpy)) { cboNodes.Items.Add(node); } } if (cboNodes.Items.Count == 0) { lblError.Text = "No nodes of this type are connected"; btnOK.Enabled = false; cboNodes.Enabled = false; } else { lblError.Text = ""; cboNodes.SelectedIndex = 0; } if (selectedSensor != null) cboNodes.SelectedItem = selectedSensor; }
Moving_Average_Filter[] filter = new Moving_Average_Filter[2]; // Array of filters public Form1() { InitializeComponent(); // construct the sensors mySensor = new sensor[sId]; // creates a dimensional array for ( i = 0; i < sId; i++) { mySensor[i] = new sensor(i); } // create the filters filter[0] = new Moving_Average_Filter(); filter[1] = new MovingAverageFilter(); }
private void CMB_sensor_SelectedIndexChanged(object sender, EventArgs e) { sensor sensorselected = ((sensor)((ComboBox)sender).SelectedValue); if (sensorselected.Name != "None") { MainV2.comPort.setParam("AMP_PER_VOLT", sensorselected.ampspervolt); MainV2.comPort.setParam("VOLT_DIVIDER", sensorselected.voltspervolt); // enable volt and current MainV2.comPort.setParam("BATT_MONITOR", 4); } else { // disable volt and current MainV2.comPort.setParam("BATT_MONITOR", 0); } }
/* * Precondition:string and double * Postcondition:filename is str and 2d array copies the file,double sets the drainRate for the battery for the sensor */ public robot(string str) { Random random = new Random(); double drainRate = random.Next(minDrain, maxDrain); if (str == null) { throw new ArgumentNullException("invalid file"); } orientationState = orientation.Up; filename = str; grid = new int[SIZE, SIZE]; count = 0; upSensor = new sensor(drainRate, 0); downSensor = new sensor(drainRate, 1); rightSensor = new sensor(drainRate, 2); leftSensor = new sensor(drainRate, 3); nAct = new actuator(0); sAct = new actuator(1); eAct = new actuator(2); wAct = new actuator(3); rCoord = 5; cCoord = 5; state = true; string text = System.IO.File.ReadAllText(filename); string ss = text.Replace("\n", " "); ss = string.Join(" ", ss.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); string[] arr = ss.Split(' '); for (int r = 0; r <= 10; r++) { for (int c = 0; c <= 10; c++) { grid[r, c] = Int32.Parse(arr[count]);; count++; } } }
private void CMB_sensor_SelectedIndexChanged(object sender, EventArgs e) { sensor sensorselected = ((sensor)((ComboBox)sender).SelectedValue); try { if (sensorselected.Name != "None") { MainV2.comPort.setParam("BATT_AMP_PERVOLT", sensorselected.ampspervolt); MainV2.comPort.setParam("BATT_VOLT_MULT", sensorselected.voltspervolt); // enable volt and current MainV2.comPort.setParam("BATT_MONITOR", 4); } else { // disable volt and current MainV2.comPort.setParam("BATT_MONITOR", 0); } } catch { CustomMessageBox.Show("Set BATT_MONITOR Failed"); } }
public byte[] getSensorValue(int packetId) { sensor toReturn = this.getSensor(packetId); return(toReturn.getValue()); }
public void Add(sensor sensorToAdd) { sList.Add(sensorToAdd); }
public void KeyDown() { sensor s = Line[StageManager.LCountS[lineID - 1]]; float Correcttime = s.Correcttime; float stagetime = StageManager.StageTime; float Endtime = s.Endtime; GameObject Note = s.gameObject; if (!s.Hold) { if (Correcttime - stagetime <= -StageManager.MissTs) { Debug.Log("MISS"); StageManager.Combo = 0; StageManager.Miss++; Destroy(Note); StageManager.LCountS[lineID - 1]++; } if (Input.GetKeyDown(code)) { //Debug.Log(Correcttime + "," + stagetime ); if (Mathf.Abs(Correcttime - stagetime) <= StageManager.MissTs) { if (Mathf.Abs(Correcttime - stagetime) <= StageManager.PerfectTs) { StageManager.Combo++; StageManager.Perfect++; Destroy(Note); StageManager.LCountS[lineID - 1]++; GameObject Par = Instantiate(PerfectPar, transform.position, Quaternion.identity); Par.transform.position = transform.localPosition; } else if (Mathf.Abs(Correcttime - stagetime) <= StageManager.GoodTs) { StageManager.Combo++; StageManager.Good++; Destroy(Note); StageManager.LCountS[lineID - 1]++; GameObject Par = Instantiate(GoodPar, transform.position, Quaternion.identity); Par.transform.position = transform.localPosition; } } else if (Correcttime - stagetime < -StageManager.MissTs) { StageManager.Combo = 0; StageManager.Miss++; Destroy(Note); StageManager.LCountS[lineID - 1]++; } } } else if (s.Hold) { Debug.Log(HoldStarted); if (Endtime - stagetime <= -StageManager.MissTs) { StageManager.Combo = 0; StageManager.Miss++; Destroy(Note); StageManager.LCountS[lineID - 1]++; } if (!HoldStarted) { if (Correcttime - stagetime <= -StageManager.MissTs) { StageManager.Combo = 0; StageManager.Miss++; StageManager.LCountS[lineID - 1]++; s.gameObject.GetComponent <Animator>().SetBool("Miss", true); } if (Input.GetKeyDown(code)) { if (Correcttime - stagetime <= StageManager.MissTs) { if (Mathf.Abs(Correcttime - stagetime) <= StageManager.PerfectTs) { HoldStarted = true; StageManager.Combo++; StageManager.Perfect++; GameObject Par = Instantiate(PerfectPar, transform.position, Quaternion.identity); Par.transform.position = transform.localPosition; } else if (Mathf.Abs(Correcttime - stagetime) <= StageManager.GoodTs) { HoldStarted = true; StageManager.Combo++; StageManager.Good++; GameObject Par = Instantiate(GoodPar, transform.position, Quaternion.identity); Par.transform.position = transform.localPosition; } } } } else { if (HoldStarted) { if (Endtime - stagetime > StageManager.MissTs) { if (Input.GetKeyUp(code)) { //StageManager.Miss++; StageManager.Combo = 0; StageManager.LCountS[lineID - 1]++; s.gameObject.GetComponent <Animator>().SetBool("Miss", true); HoldStarted = false; } else { StageManager.HoldBouns++; GameObject Par = Instantiate(HoldPar, transform.position, Quaternion.identity); Par.transform.position = transform.localPosition; } } else if (Endtime - stagetime <= 0) { Destroy(Note); StageManager.LCountS[lineID - 1]++; HoldStarted = false; } } } } }
public void addSensor(sensor sensor_) { sensors.Add(sensor_); }
/// <summary> /// decodeSensorEvent is the callback function for sensor messages, humidity or temperature, from the Tellstick. /// The function is registered with the Telldus service and will then be called from Telldus everytime a device /// is changed. The object properties will be updated with the new values. /// </summary> /// <param name="protocol">Name of protocol used by Tellstick</param> /// <param name="model">Sensor model</param> /// <param name="deviceId">Tellstick Id of device who changed</param> /// <param name="dataType">Type of value from this sensor</param> /// <param name="value">New sensor value.</param> /// <param name="timestamp">Tellstick timestamp in number of seconds since 1/1 1970.</param> /// <param name="callbackId">Id given by Telldus when function was registered</param> /// <param name="obj">Optional object given to Telldus when callback function was registered. (Not used)</param> /// <returns>Success or error code (Will always be 0)</returns> public int decodeSensorEvent(string protocol, string model, int deviceId, int dataType, string value, int timestamp, int callbackId, Object obj) { logD("decodeSensorEvent", dataTypeToString(dataType), model + " CallbackSensorEvent." + protocol + "Id: " + deviceId + " Value: " + value + " Timestamp: " + timestamp + " CallbackId: " + callbackId); int result = 0; NumberStyles styles = NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign; NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat; float v = float.Parse(value, styles, nfi); // Tellstick values are using '.' as decimal separator. try { OSAEObject o = getSensorObject(deviceId, dataType, protocol, model); if (o != null) { // If no object, then this is a new sensor, but objects should not be created, so just ignore it if (o.State.Value != objStatDisable) { if (!sensorList.ContainsKey(deviceId)) { sensor s = new sensor(); sensorList.Add(int.Parse(o.Property(propDevId).Value), s); } if ((dataType != TelldusNETWrapper.TELLSTICK_HUMIDITY) || (value != "255")) // What is this????? { logD("decodeSensorEvent", o.Name, dataTypeToString(dataType) + " Sensor event: " + value, o); // Store the value in the parameter. Will only trigger an event if value is changed setPropertyValue(o, dataTypeToString(dataType), v.ToString()); // Write value in local format, i.e. correct decimal separator switch (dataType) { case TelldusNETWrapper.TELLSTICK_HUMIDITY: sensorList[deviceId].addValue(deviceId , v, TelldusNETWrapper.TELLSTICK_HUMIDITY); if (v < float.Parse(getPropertyValue(o, propMinHum))) setPropertyValue(o, propMinHum, v.ToString()); if (v > float.Parse(getPropertyValue(o, propMaxHum))) setPropertyValue(o, propMaxHum, v.ToString()); break; case TelldusNETWrapper.TELLSTICK_TEMPERATURE: sensorList[deviceId].addValue(deviceId , v, TelldusNETWrapper.TELLSTICK_TEMPERATURE); if (v < float.Parse(getPropertyValue(o, propMinTemp))) setPropertyValue(o, propMinTemp, v.ToString()); if (v > float.Parse(getPropertyValue(o, propMaxTemp))) setPropertyValue(o, propMaxTemp, v.ToString()); break; default: break; } //Will always trigger an event o.SetState(objStatOn); // Always set to on, to reset the OFF TIMER } } else { logD("decodeSensorEvent", o.Name, "Sensor events should not be handled: " + o.State.Value, o); } //if result = 0; } else result = -1; return result; } catch (Exception ex) { logE("decodeSensorEvent", "", "Exception in callback function: ", ex); return -1; } }
/// <summary> /// getSensorObject will try to find an exsisting object from the deviceId, if not found a new one will be created /// but only if the property AddSensors is TRUE. /// </summary> /// <param name="deviceId">Id of object to try to find.</param> /// <param name="dataType">dataRype used if a new object is created.</param> /// <param name="protocol">protocol used if a new object is created.</param> /// <param name="model"> model used if a new object is created.</param> /// <returns>Returns the object found or created.</returns> private OSAEObject getSensorObject(int deviceId, int dataType, string protocol, string model) { try { OSAEObject o = OSAEObjectManager.GetObjectByAddress(addrPrefixSensor + deviceId); if (o == null) { //No object existed, create the new one if (getPropertyValue(OSAEObjectManager.GetObjectByName(Name), propAddSensors).ToUpper() == "TRUE") { o = createSensorObject(deviceId, dataType, protocol, model); sensor s = new sensor(); sensorList.Add(deviceId, s); } else { logD("getSensorObject", model, deviceId.ToString() + " New sensor objects will not be created."); return null; } } else logD("getSensorObject", o.Name, o.Address + " Object found.", o); return o; } catch (Exception ex) { logE("getSensorObject", "", "Exception in getSensorObject: ", ex); OSAEObject o = null; return o; } }
public sensor getSensor(int packetId) { sensor toReturn = new sensor("", 0, 0); for (int i = 0; i < sList.Count - 1; i++) { if (sList[i].getPacketId() == packetId) { toReturn = sList[i]; break; } } return toReturn; }
private void dataUpdaterFunction() { try { while (true) { this.container.Dispatcher.Invoke((Action)(() => { using (var db = new pb_TunnelVisualizarDatabaseEntities()) { this._sensor = db.sensors.Find(this._sensor.iddata); if (this._sensor.data_waterFlow.Count() > 0) { this._dataWaterFlow = this._sensor.data_waterFlow.Last(); this.flow_rate_label.Content = this._dataWaterFlow.data == null ? "null" : this._dataWaterFlow.data.ToString(); try { if (Convert.ToDouble(this._dataWaterFlow.data) <= Convert.ToDouble(this.flow_rate_label_meter.Text)) { this.Card.Background = Brushes.Red; this.flag_1 = false; } else { flag_1 = true; if (flag_1 && flag_2) { this.Card.Background = Brushes.WhiteSmoke; } } } catch (Exception e) { } } if (this._sensor.data_waterLavel.Count() > 0) { this._dataWaterLavel = this._sensor.data_waterLavel.Last(); this.water_height_label.Content = this._dataWaterLavel.data == null ? "null" : this._dataWaterLavel.data.ToString(); try { if (Convert.ToDouble(this._dataWaterLavel.data) <= Convert.ToDouble(this.water_height_label_meter.Text)) { this.Card.Background = Brushes.Red; this.flag_2 = false; } else { flag_2 = true; if (flag_1 && flag_2) { this.Card.Background = Brushes.WhiteSmoke; } } } catch (Exception e) { } } } })); Thread.Sleep(1000); } } catch (Exception e) { SystemConsole.setConsoleTxtThreadSafe(e.Message); } }
public SensorUnit(sensor _sensor, data_waterFlow _dataWaterFlow, data_waterLavel _dataWaterLavel) { this._sensor = _sensor; this._dataWaterFlow = _dataWaterFlow; this._dataWaterLavel = _dataWaterLavel; }
public static void GetSensors(m_garden garden) { List <sensor> sensors = new List <sensor>(); HTTPRequest request_getSensor1 = new HTTPRequest(new Uri(data.IP + "/getTemperatureSensorByGardenId?gardenId=" + garden.getId()), HTTPMethods.Get, (req_sensor1, res_sensor1) => { Debug.Log(res_sensor1.DataAsText); JArray array = JArray.Parse(res_sensor1.DataAsText); foreach (var e in array) { sensor temp = new sensor(); temp.setId((long)e["id"]); temp.setName((string)e["name"]); temp.setX((int)e["x"] * data.width / garden.getLength()); temp.setY((int)e["y"] * data.length / garden.getWidth()); temp.setType(true); sensors.Add(temp); } garden.addSensor(sensors); }).Send(); HTTPRequest request_getSensor2 = new HTTPRequest(new Uri(data.IP + "/getWetnessSensorByGardenId?gardenId=" + garden.getId()), HTTPMethods.Get, (req_sensor2, res_sensor2) => { Debug.Log(res_sensor2.DataAsText); JArray array = JArray.Parse(res_sensor2.DataAsText); foreach (var e in array) { sensor temp = new sensor(); temp.setId((long)e["id"]); temp.setName((string)e["name"]); temp.setX((int)e["x"] * data.width / garden.getLength()); temp.setY((int)e["y"] * data.length / garden.getWidth()); temp.setType(false); sensors.Add(temp); } garden.addSensor(sensors); }).Send(); HTTPRequest request_getSensorData1 = new HTTPRequest(new Uri(data.IP + "/getLatestTemperatureByGardenId?gardenId=" + garden.getId()), HTTPMethods.Get, (req_data1, res_data1) => { Debug.Log(res_data1.DataAsText); JArray array = JArray.Parse(res_data1.DataAsText); foreach (var e in array) { foreach (sensor n in garden.getSensors()) { if (n.getId() == (long)e["id"] && n.getType()) { n.setData((float)e["temperature"]); } } } foreach (sensor e in garden.getSensors()) { if (e.getType() && e.getData() != 0) { MapBG.drawOne(e.getId(), e.getName(), e.getX(), e.getY(), MapBG.SensorControllerType.Temperature, true, e.getData(), garden.getIdealTemperature() * (float)1.2, garden.getIdealTemperature() * (float)0.8); } else if (e.getType() && e.getData() == 0) { MapBG.drawOne(e.getId(), e.getName(), e.getX(), e.getY(), MapBG.SensorControllerType.Temperature, false, garden.getIdealTemperature(), garden.getIdealTemperature() * (float)1.2, garden.getIdealTemperature() * (float)0.8); } } }).Send(); HTTPRequest request_getSensorData2 = new HTTPRequest(new Uri(data.IP + "/getLatestWetnessByGardenId?gardenId=" + garden.getId()), HTTPMethods.Get, (req_data2, res_data2) => { Debug.Log(res_data2.DataAsText); JArray array = JArray.Parse(res_data2.DataAsText); foreach (var e in array) { foreach (sensor n in garden.getSensors()) { if (n.getId() == (long)e["id"] && !n.getType()) { n.setData((float)e["wetness"]); } } } foreach (sensor e in garden.getSensors()) { if (!e.getType() && e.getData() != 0) { MapBG.drawOne(e.getId(), e.getName(), e.getX(), e.getY(), MapBG.SensorControllerType.Humidity, true, e.getData(), garden.getIdealHumidity() * (float)1.2, garden.getIdealHumidity() * (float)0.8); } else if (!e.getType() && e.getData() == 0) { MapBG.drawOne(e.getId(), e.getName(), e.getX(), e.getY(), MapBG.SensorControllerType.Humidity, false, garden.getIdealHumidity(), garden.getIdealHumidity() * (float)1.2, garden.getIdealHumidity() * (float)0.8); } } }).Send(); return; }