Collecting relevant sensor data

The field event handler is called when sensor data is received from the subscription. It will contain an enumeration of fields. All we need to do is loop through them and see if we can find the fields we are looking for. If we do, we update our internal state, and make sure we update the controller output. We also make sure to update our main window, so that we get visual feedback:

private void Subscription_OnFieldsReceived(object Sender, 
   IEnumerable<Field> NewFields) 
{ 
   bool RecalcOutput = false; 
 
   this.lastEventFields = DateTime.Now; 
 
   foreach (Field Field in NewFields) 
   { 
         switch (Field.Name) 
         { 
               case "Light": 
                     if (Field is QuantityField Q) 
                     { 
                           MainPage.Instance.LightUpdated( 
                                 Q.Value, Q.NrDecimals, Q.Unit); 
                           if (Q.Unit == "%") 
                           { 
                                 this.light = Q.Value; 
                                 RecalcOutput = true; 
                           } 
                     } 
                     break; 
 
               case "Motion": 
                     if (Field is BooleanField B) 
                     { 
                           MainPage.Instance.MotionUpdated( 
                                 B.Value); 
                           this.motion = B.Value; 
                           RecalcOutput = true; 
                     } 
                     break; 
         } 
   } 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset