async void SensorValueChanged(object sender, X2CodingLab.SensorTag.SensorValueChangedEventArgs e) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { switch (e.Origin) { case SensorName.Accelerometer: double[] accValues = Accelerometer.CalculateCoordinates(e.RawData, 1 / 64.0); tbAccelerometer.Text = "X: " + accValues[0].ToString("0.00") + " Y: " + accValues[1].ToString("0.00") + " Z: " + accValues[2].ToString("0.00"); break; case SensorName.Gyroscope: float[] axisValues = Gyroscope.CalculateAxisValue(e.RawData, GyroscopeAxis.XYZ); tbGyroscope.Text = "X: " + axisValues[0].ToString("0.00") + " Y: " + axisValues[1].ToString("0.00") + " Z: " + axisValues[2].ToString("0.00"); break; case SensorName.HumiditySensor: tbHumidity.Text = HumiditySensor.CalculateHumidityInPercent(e.RawData).ToString("0.00") + "%"; break; case SensorName.Magnetometer: float[] magnetValues = Magnetometer.CalculateCoordinates(e.RawData); tbMagnetometer.Text = "X: " + magnetValues[0].ToString("0.00") + " Y: " + magnetValues[1].ToString("0.00") + " Z: " + magnetValues[2].ToString("0.00"); break; case SensorName.PressureSensor: try { tbPressure.Text = (PressureSensor.CalculatePressure(e.RawData, ps.CalibrationData) / 100).ToString("0.00"); } catch (NullReferenceException) { // in case another(!) setup is executed, so ps is null } break; case SensorName.SimpleKeyService: if (SimpleKeyService.LeftKeyHit(e.RawData)) { tbLeftKey.Text = "hit!"; await Task.Delay(200); tbLeftKey.Text = ""; } else if (SimpleKeyService.RightKeyHit(e.RawData)) { tbRightKey.Text = "hit!"; await Task.Delay(200); tbRightKey.Text = ""; } break; case SensorName.TemperatureSensor: double ambient = IRTemperatureSensor.CalculateAmbientTemperature(e.RawData, TemperatureScale.Celsius); double target = IRTemperatureSensor.CalculateTargetTemperature(e.RawData, ambient, TemperatureScale.Celsius); tbTemperature.Text = ambient.ToString("0.00"); tbTargetTemperature.Text = target.ToString("0.00"); break; } }); }
async void SensorValueChanged(object sender, X2CodingLab.SensorTag.SensorValueChangedEventArgs e) { switch (e.Origin) { case SensorName.Accelerometer: double[] accValues = Accelerometer.CalculateCoordinates(e.RawData, 1 / 64.0); //tbAccelerometer.Text = "X: " + accValues[0].ToString("0.00") + " Y: " + accValues[1].ToString("0.00") + " Z: " + accValues[2].ToString("0.00"); break; case SensorName.Gyroscope: float[] axisValues = Gyroscope.CalculateAxisValue(e.RawData, GyroscopeAxis.XYZ); //tbGyroscope.Text = "X: " + axisValues[0].ToString("0.00") + " Y: " + axisValues[1].ToString("0.00") + " Z: " + axisValues[2].ToString("0.00"); break; case SensorName.HumiditySensor: humidity = HumiditySensor.CalculateHumidityInPercent(e.RawData).ToString("0.00"); SensorValues.Humidity = humidity; //tbHumidity.Text = humidity + "%"; break; case SensorName.TemperatureSensor: double ambient = IRTemperatureSensor.CalculateAmbientTemperature(e.RawData, TemperatureScale.Farenheit); double target = IRTemperatureSensor.CalculateTargetTemperature(e.RawData, ambient, TemperatureScale.Farenheit); SensorValues.AmbientTemperature = ambient; SensorValues.TargetTemperature = target; //temp = ambient; break; } try { //SendDataToEventhub.serviceNamespace = "tisensordemosh"; //SendDataToEventhub.hubName = "tisensordemoeh"; //SendDataToEventhub.sharedAccessPolicyName = "all"; //SendDataToEventhub.sharedAccessKey = "mcxBEocF6f0KHQGhP2MtT7A44tUC+zhqyDcetP/Jt0o="; //SendDataToEventhub.deviceName = "sudhesh"; string body = ""; body = "{ \"from\":\"" + SendDataToEventhub.deviceName + "\""; body += ", \"dspl\":\"" + SendDataToEventhub.deviceName + "\""; body += ", \"time\":\"" + DateTime.UtcNow.ToString("O") + "\""; body += ", \"Subject\":\"wthr\""; if (!String.IsNullOrEmpty(SensorValues.Humidity)) { body += ", \"hmdt\":" + SensorValues.Humidity; } body += ", \"temp\":" + Math.Round(SensorValues.AmbientTemperature, 3); body += "}"; bool code = await SendDataToEventhub.SendMessage(body); SendDataToEventhub.status = body; //txtStatus.Text = code.ToString(); //this.Cursor = Cursors.Default; } catch (Exception ex) { //Debug.WriteLine(ex.ToString()); SendDataToEventhub.status = "error in sending data to eventhub"; } }