Inheritance: ILightSensor
        public MainPage()
        {
            InitializeComponent();

            // this.NavigationCacheMode = NavigationCacheMode.Required;
            //DataEntry.saveAll();
            //DataEntry.loadAll();

            this.accelSensor = Accelerometer.GetDefault();
            if (this.accelSensor != null) this.accelSensor.ReadingChanged += new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(myAccelHandler);

            this.compSensor = Compass.GetDefault();
            if (this.compSensor != null) this.compSensor.ReadingChanged += new TypedEventHandler<Compass, CompassReadingChangedEventArgs>(myCompassHandler);

            this.gyroSensor = Gyrometer.GetDefault();
            if (this.gyroSensor != null) this.gyroSensor.ReadingChanged += new TypedEventHandler<Gyrometer, GyrometerReadingChangedEventArgs>(myGyroHandler);

            this.incliSensor = Inclinometer.GetDefault();
            if (this.incliSensor != null) this.incliSensor.ReadingChanged += new TypedEventHandler<Inclinometer, InclinometerReadingChangedEventArgs>(myIncliHandler);

            this.lightSensor = LightSensor.GetDefault();
            if (this.lightSensor != null) this.lightSensor.ReadingChanged += new TypedEventHandler<LightSensor, LightSensorReadingChangedEventArgs>(myLightHandler);

            accelX = accelY = accelZ = comp = gyroX = gyroY = gyroZ = incliYaw = incliPitch = incliRoll = light = 0;

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }
 private void sensor_ReadingChanged(LightSensor sender, LightSensorReadingChangedEventArgs args)
 {
     Debug.WriteLine("Sensor working");
     Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
     () => 
     LuxReading.Text = "Lux: " + args.Reading.IlluminanceInLux.ToString()
     );
 }
 async void sensor_ReadingChanged(LightSensor sender, LightSensorReadingChangedEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         Lux.Text = args.Reading.IlluminanceInLux.ToString();
         TimeStamp.Text = args.Reading.Timestamp.ToString();
     });
 }
Exemple #4
0
        private void SetupSensor()
        {
            _lightSensor = Sensor.LightSensor.GetDefault();

            if (_lightSensor == null)
            {
                // tell user no device
            }
        }
Exemple #5
0
 private async void LightSensorOnReadingChanged(Sensor.LightSensor sender, Sensor.LightSensorReadingChangedEventArgs args)
 {
     await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         var lightReading = args.Reading;
         LuxLums          = string.Format("{0,5:0.00}", lightReading.IlluminanceInLux);
         Brightness       = lightReading.IlluminanceInLux / 100;
     });
 }
        private void SetupSensor()
        {
            _lightSensor = Sensor.LightSensor.GetDefault();

            if (_lightSensor == null)
            {
                
                // tell user no device
            }
    }
Exemple #7
0
 private static Sensor GetSensor()
 {
     try
     {
         return(Sensor.GetDefault());
     }
     catch
     {
         return(null);
     }
 }
Exemple #8
0
        void OnReadingChanged(Sensor sender, LightSensorReadingChangedEventArgs args)
        {
            var handler = changed;

            if (handler != null)
            {
                var value = args.Reading.IlluminanceInLux;
                var e     = new AmbientLightEventArgs(value);
                handler.Invoke(this, e);
            }
        }
Exemple #9
0
 public Glance()
 {
     _updateSensor = new DispatcherTimer();
     _updateSensor.Interval = TimeSpan.FromSeconds(0.25);
     _updateSensor.Tick += UpdateSensor_Tick;
     sensor = LightSensor.GetDefault();
     if (sensor != null)
     {
         //sensor.ReportInterval = sensor.MinimumReportInterval;
         lastEffectiveReadingTime = DateTime.Now;
         lastState = sensor.GetCurrentReading().IlluminanceInLux <= Dark ? GlanceEventArgs.Dark : GlanceEventArgs.Light;
     }
 }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     sensor = LightSensor.GetDefault();
     if (sensor != null)
     {
         sensor.ReadingChanged += sensor_ReadingChanged;
         Data.Visibility = Visibility.Visible;
     }
     else
     {
         NoSensorMessage.Visibility = Visibility.Visible;
     }
 }
        public Scenario1_DataEvents()
        {
            this.InitializeComponent();

            _sensor = LightSensor.GetDefault();
            if (_sensor != null)
            {
                // Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
                // This value will be used later to activate the sensor.
                uint minReportInterval = _sensor.MinimumReportInterval;
                _desiredReportInterval = minReportInterval > 100 ? minReportInterval : 100;
            }
            else
            {
                rootPage.NotifyUser("No light sensor found", NotifyType.ErrorMessage);
            }
        }
Exemple #12
0
 public Log(MainWindow window, bool isBehavior = false)
 {
     this.window = window;
     this.isBehavior = isBehavior;
     this.statusAnalyzer = new StatusAnalyze(window);
     logDir = Directory.GetCurrentDirectory() + "\\logs\\" + Config.userName+ Config.startTime.ToString("_MM_dd_HH_mm_ss");
     if (!Directory.Exists(logDir))
     {
         Directory.CreateDirectory(logDir);
     }
     logList = new List<LogRecord>();
     this.accelerometer = Accelerometer.GetDefault();
     this.inclinometer = Inclinometer.GetDefault();
     //this.inclinometer.ReadingChanged += onInclinometerReadingChanged;
     this.gyrometer = Gyrometer.GetDefault();
     this.orientationSensor = OrientationSensor.GetDefault();
     this.compass = Compass.GetDefault();
     this.lightsensor = LightSensor.GetDefault();
 }
Exemple #13
0
        public MainPage()
        {
            InitializeComponent();
            _locator = new Geolocator();
            Loaded += OnControlLoaded;

            _lightSensor = LightSensor.GetDefault();
            if (_lightSensor != null)
            {
                //For now we get a base reading to use to compare later
                _baseReading = _lightSensor.GetCurrentReading();
                //Register for the reading change
                _lightSensor.ReadingChanged += OnLightReadingChanged;
            }

            _accelerometerSensor = Accelerometer.GetDefault();
            if (_accelerometerSensor != null)
            {
                _accelerometerSensor.Shaken += OnShaken;
            }
            _compassSensor = Compass.GetDefault();
            if (_compassSensor != null)
            {
                _compassSensor.ReadingChanged += OnCompassReadingChanged;
            }
            _gyroSensor = Gyrometer.GetDefault();
            if (_gyroSensor != null)
            {
                _gyroSensor.ReadingChanged += OnGyroReadingChanged;
            }
            _inclineSensor = Inclinometer.GetDefault();
            if (_inclineSensor != null)
            {
                _inclineSensor.ReadingChanged += OnInclineReadingChanged;
            }
            _orientationSensor = OrientationSensor.GetDefault();
            if (_orientationSensor != null)
            {
                _orientationSensor.ReadingChanged += OnOrientationReadingChanged;
            }
        }
        public Scenario2()
        {
            this.InitializeComponent();

            _sensor = LightSensor.GetDefault();
            if (_sensor != null)
            {
                // Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
                // This value will be used later to activate the sensor.
                uint minReportInterval = _sensor.MinimumReportInterval;
                _desiredReportInterval = minReportInterval > 100 ? minReportInterval : 100;

                // Set up a DispatchTimer
                _dispatcherTimer = new DispatcherTimer();
                _dispatcherTimer.Tick += DisplayCurrentReading;
                _dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, (int)_desiredReportInterval);
            }
            else
            {
                rootPage.NotifyUser("No light sensor found", NotifyType.ErrorMessage);
            }
        }
 private void first_Click(object sender, RoutedEventArgs e)
 {
     sensor = LightSensor.GetDefault();
     sensor.ReportInterval = 500;
     sensor.ReadingChanged+=sensor_ReadingChanged;
 }
Exemple #16
0
        private void OnLightReadingChanged(LightSensor sender, LightSensorReadingChangedEventArgs args)
        {
            //Read the local settings and see if AutoQuietTime has been setup
            if ((bool?) ApplicationData.Current.LocalSettings.Values["AutoQuietTime"] == true)
            {
                //If so check if the light in the last reading has dropped below our darkness threshold, could be configured for sensativity
                //This will also turn the application noise back up, when the lights are back on
                //We could also look at the time of the last reading and determine if the lights have been off for a period of time

                //_lastReadingTime = args.Reading.Timestamp;
                bool shouldBeQuietTime = args.Reading.IlluminanceInLux < (_baseReading.IlluminanceInLux - 100);
                ApplicationData.Current.LocalSettings.Values["ShouldBeQuietTime"] = shouldBeQuietTime;
            }
        }
 public LightSensorEvents(LightSensor This)
 {
     this.This = This;
 }
 public void myLightHandler(LightSensor l, LightSensorReadingChangedEventArgs e)
 {
     Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
         () =>
         {
             this.value_light_lux.Text = e.Reading.IlluminanceInLux.ToString("0.00");
             this.light = e.Reading.IlluminanceInLux;
             checkTimeToLog();
         }
     );
 }
 /// <summary>
 /// Light sensor reading changed. Send data to Azure Event Hub if checkbox checked in the UI
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 async private void light_ReadingChanged(LightSensor sender, LightSensorReadingChangedEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         txtLightSensor.Text = args.Reading.IlluminanceInLux.ToString();
         if (Convert.ToBoolean(chkLightSensor.IsChecked))
         {
             ConnectTheDotsSensor sensor = ctdHelper.sensors.Find(item => item.measurename == "Light");
             if (sensor != null)
             {
                 sensor.value = args.Reading.IlluminanceInLux;
                 sensor.timecreated = DateTime.UtcNow.ToString("o");
                 ctdHelper.sendMessage(sensor.ToJson());
             }
         }
     });
 }
        /// <summary>
        /// Initialize hardware sensors on the device
        /// </summary>
        private void InitSensors()
        {
            // Get default light sensor 
            light = LightSensor.GetDefault();
            if (light != null)
            {
                light.ReportInterval = RealSensorDataTick;
                light.ReadingChanged += light_ReadingChanged; 
            }

            // Get default acelerometer sensor 
            accelerometer = Accelerometer.GetDefault();
            if (accelerometer != null)
            {
                accelerometer.ReportInterval = RealSensorDataTick;
                accelerometer.ReadingChanged += accelerometer_ReadingChanged;
            }
        }
Exemple #21
0
        void OnReadingChanged(Sensor sender, LightSensorReadingChangedEventArgs args)
        {
            var handler = changed;

            if (handler != null)
            {
                var value = args.Reading.IlluminanceInLux;
                var e = new AmbientLightEventArgs(value);
                handler.Invoke(this, e);
            }
        }
 async void MainPage_ReadingChanged( LightSensor sender, LightSensorReadingChangedEventArgs args )
 {
     await Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () =>
     {
         TextLight.Text = string.Format( @"Light Sensor : {0}", args.Reading.IlluminanceInLux.ToString() );
     } );
 }