/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (Microsoft.Xna.Framework.Input.Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Escape)) { this.Exit(); } AmbientLightSensorDataReport lightReport = (AmbientLightSensorDataReport)_lightSensor.GetDataReport(); _illuminanceLux = lightReport.IlluminanceLux; // If the accelerometer is providing a value, we treat it as if it is measuring // the direction of gravity and pass it into the marble so it can move around the screen. // If the accelerometer is providing no value, the marble will not move. _marble.UpdatePosition(gameTime, _orientationSourceProvider.Vector); base.Update(gameTime); }
/// <summary> /// Fired when sensor data is updated. /// </summary> void OnDataUpdated(Sensor sensor, SensorDataReport newData) { AmbientLightSensorDataReport alsReport = (AmbientLightSensorDataReport)newData; System.Diagnostics.Debug.WriteLine("Data event timestamp: " + alsReport.Timestamp.ToString()); // get the illuminance property value double lightLux = alsReport.IlluminanceLux; // Get the sensor id so we can associate the sensor lux value // with a specific sensor id in our collection Guid sensorId = sensor.SensorID; if (sensorId != Guid.Empty) { // Set the sensor light value SetSensorLightLuxValue(sensorId, lightLux); } }
/// <summary> /// Query the sensor for any sensor data it has, then update the sensor /// data by using the OnDataUpdated callback. /// </summary> private void RequestSensorDataReport(AmbientLightSensor sensor) { if (sensor != null) { // If the sensor is ready, we can query for the current sensor value AmbientLightSensorDataReport data = null; try { data = (AmbientLightSensorDataReport)sensor.GetDataReport(); } catch (COMException ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } if (data != null) { // Initialize the sensor data value using the callback OnDataUpdated(sensor, data); } } }