Beispiel #1
0
 void UpdateSensor_Tick(object sender, EventArgs e)
 {
     if (sensor == null)
     {
         return;
     }
     try
     {
         lock (sensor)
         {
             float lux = sensor.GetCurrentReading().IlluminanceInLux;
             if (lastEffectiveReadingTime < DateTime.Now - GraceTime)
             {
                 if (lux <= Dark && lastState == GlanceEventArgs.Light)
                 {
                     lastEffectiveReadingTime = DateTime.Now;
                     lastState = GlanceEventArgs.Dark;
                     RaiseGlanceEvent(GlanceEventArgs.Dark);
                 }
                 else if (lux > Dark && lastState == GlanceEventArgs.Dark)
                 {
                     lastEffectiveReadingTime = DateTime.Now;
                     lastState = GlanceEventArgs.Light;
                     RaiseGlanceEvent(GlanceEventArgs.Light);
                 }
             }
         }
     }
     catch { }
 }
Beispiel #2
0
 private void RaiseGlanceEvent(GlanceEventArgs args)
 {
     if (this.GlanceEvent != null)
     {
         this.GlanceEvent(this, args);
     }
 }
Beispiel #3
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;
     }
 }
Beispiel #4
0
 void UpdateSensor_Tick(object sender, EventArgs e)
 {
     if(sensor == null) return;
     try
     {
         lock (sensor)
         {
             float lux = sensor.GetCurrentReading().IlluminanceInLux;
             if (lastEffectiveReadingTime < DateTime.Now - GraceTime)
             {
                 if (lux <= Dark && lastState == GlanceEventArgs.Light)
                 {
                     lastEffectiveReadingTime = DateTime.Now;
                     lastState = GlanceEventArgs.Dark;
                     RaiseGlanceEvent(GlanceEventArgs.Dark);
                 }
                 else if (lux > Dark && lastState == GlanceEventArgs.Dark)
                 {
                     lastEffectiveReadingTime = DateTime.Now;
                     lastState = GlanceEventArgs.Light;
                     RaiseGlanceEvent(GlanceEventArgs.Light);
                 }
             }
         }
     }
     catch { }
 }
Beispiel #5
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;
     }
 }
Beispiel #6
0
 private void RaiseGlanceEvent(GlanceEventArgs args)
 {
     if (this.GlanceEvent != null) this.GlanceEvent(this, args);
 }