private void NewSensorData(object Sender, SensorDataEventArgs e) { FieldNumeric Num; FieldBoolean Bool; double? LightPercent = null; bool? Motion = null; if (e.HasRecentFields) { foreach (Field Field in e.RecentFields) { switch (Field.FieldName) { case "Temperature": if ((Num = Field as FieldNumeric) != null) { Num = Num.Convert("C"); if (Num.Unit == "C") { Controller.SetTemperature(Num.Value); } } break; case "Light": if ((Num = Field as FieldNumeric) != null) { Num = Num.Convert("%"); if (Num.Unit == "%" && Num.Value >= 0 && Num.Value <= 100) { Controller.SetLight(Num.Value); LightPercent = Num.Value; } } break; case "Motion": if ((Bool = Field as FieldBoolean) != null) { Controller.SetMotion(Bool.Value); Motion = Bool.Value; } break; } } if (LightPercent.HasValue && Motion.HasValue) { Controller.CheckControlRules(LightPercent.Value, Motion.Value); } } }
public SensorDataEventArgs ProcessData(SignalCalibration calibration, float[] rawData, bool amplify) { // data setup double threshold = 0.0; // preprocess the data float[] envelopedData = PreprocessSignal(calibration, rawData, amplify); if (envelopedData == null) { // this is a faulty signal, return 'null' return(null); } SensorDataEventArgs eventArgs = new SensorDataEventArgs(Sensor, rawData, envelopedData) { CutOffs = new Tuple <int, int>(Sensor.StartCutOff, Sensor.EndCutOff) }; // get the first/highest peak (if any exists) Tuple <int, float> firstPeak = GetFirstPeak(envelopedData); // check whether we found a peak if (firstPeak.Item1 != -1) { // we in fact did! // now, let's get the areas (all of them) threshold = 1.0 * firstPeak.Item2 / 1.5; threshold = Sensor.UpperTouchThreshold; Sensor.LowerTouchThreshold = (float)threshold; // Debug.WriteLine(Sensor.LowerTouchThreshold); // threshold = Sensor.UpperTouchThreshold; // Sensor.LowerTouchThreshold = (float)threshold; List <Tuple <int, int> > areas = GetRawAreas(envelopedData, threshold); // filter them (by merging) List <Tuple <int, int> > filteredAreas = FilterAreas(areas, envelopedData); // get the raw peaks from those areas List <Tuple <int, int, int, float> > peaks = GetPeaks(filteredAreas, envelopedData); // add the values to the result eventArgs.RawPeaks = peaks.ToArray(); eventArgs.Threshold = threshold; } return(eventArgs); }
private void NewCameraData(object Sender, SensorDataEventArgs e) { FieldNumeric Num; FieldString Str; if (e.HasRecentFields) { foreach (Field Field in e.RecentFields) { if (Field.FieldName == "Width" && (Num = Field as FieldNumeric) != null && string.IsNullOrEmpty(Num.Unit) && Num.Value > 0) { this.cameraWidth = (int)Num.Value; } else if (Field.FieldName == "Height" && (Num = Field as FieldNumeric) != null && string.IsNullOrEmpty(Num.Unit) && Num.Value > 0) { this.cameraHeight = (int)Num.Value; } else if (Field.FieldName == "URL" && (Str = Field as FieldString) != null) { this.cameraUrl = Str.Value; } } } }
private void SensorRawDataReceived(object sender, SensorDataEventArgs e) { // let's see whether we want that }
private void MainService_OnSensorDataUpdated(object sender, SensorDataEventArgs e) { var view = GetSensorDataView(e.UserSensors); Device.BeginInvokeOnMainThread(() => Content = view); }