Exemplo n.º 1
0
 static void HumidityV2CB(BrickletHumidityV2 sender, int humidity)
 {
     if (brickletLCD != null)
     {
         string text = string.Format("Humidity   {0,6:###.00} %", humidity / 100.0);
         brickletLCD.WriteLine(1, 0, text);
         System.Console.WriteLine("Write to line 1: " + text);
     }
 }
Exemplo n.º 2
0
 static void EnumerateCB(IPConnection sender, string UID, string connectedUID, char position,
                         short[] hardwareVersion, short[] firmwareVersion,
                         int deviceIdentifier, short enumerationType)
 {
     if (enumerationType == IPConnection.ENUMERATION_TYPE_CONNECTED ||
         enumerationType == IPConnection.ENUMERATION_TYPE_AVAILABLE)
     {
         if (deviceIdentifier == BrickletLCD20x4.DEVICE_IDENTIFIER)
         {
             try
             {
                 brickletLCD = new BrickletLCD20x4(UID, ipcon);
                 brickletLCD.ClearDisplay();
                 brickletLCD.BacklightOn();
                 System.Console.WriteLine("LCD 20x4 initialized");
             }
             catch (TinkerforgeException e)
             {
                 System.Console.WriteLine("LCD 20x4 init failed: " + e.Message);
                 brickletLCD = null;
             }
         }
         else if (deviceIdentifier == BrickletAmbientLight.DEVICE_IDENTIFIER)
         {
             try
             {
                 brickletAmbientLight = new BrickletAmbientLight(UID, ipcon);
                 brickletAmbientLight.SetIlluminanceCallbackPeriod(1000);
                 brickletAmbientLight.Illuminance += IlluminanceCB;
                 System.Console.WriteLine("Ambient Light initialized");
             }
             catch (TinkerforgeException e)
             {
                 System.Console.WriteLine("Ambient Light init failed: " + e.Message);
                 brickletAmbientLight = null;
             }
         }
         else if (deviceIdentifier == BrickletAmbientLightV2.DEVICE_IDENTIFIER)
         {
             try
             {
                 brickletAmbientLightV2 = new BrickletAmbientLightV2(UID, ipcon);
                 brickletAmbientLightV2.SetConfiguration(BrickletAmbientLightV2.ILLUMINANCE_RANGE_64000LUX,
                                                         BrickletAmbientLightV2.INTEGRATION_TIME_200MS);
                 brickletAmbientLightV2.SetIlluminanceCallbackPeriod(1000);
                 brickletAmbientLightV2.Illuminance += IlluminanceV2CB;
                 System.Console.WriteLine("Ambient Light 2.0 initialized");
             }
             catch (TinkerforgeException e)
             {
                 System.Console.WriteLine("Ambient Light 2.0 init failed: " + e.Message);
                 brickletAmbientLightV2 = null;
             }
         }
         else if (deviceIdentifier == BrickletHumidity.DEVICE_IDENTIFIER)
         {
             try
             {
                 brickletHumidity = new BrickletHumidity(UID, ipcon);
                 brickletHumidity.SetHumidityCallbackPeriod(1000);
                 brickletHumidity.Humidity += HumidityCB;
                 System.Console.WriteLine("Humidity initialized");
             }
             catch (TinkerforgeException e)
             {
                 System.Console.WriteLine("Humidity init failed: " + e.Message);
                 brickletHumidity = null;
             }
         }
         else if (deviceIdentifier == BrickletHumidityV2.DEVICE_IDENTIFIER)
         {
             try
             {
                 brickletHumidityV2 = new BrickletHumidityV2(UID, ipcon);
                 brickletHumidityV2.SetHumidityCallbackConfiguration(1000, true, 'x', 0, 0);
                 brickletHumidityV2.HumidityCallback += HumidityV2CB;
                 System.Console.WriteLine("Humidity 2.0 initialized");
             }
             catch (TinkerforgeException e)
             {
                 System.Console.WriteLine("Humidity 2.0 init failed: " + e.Message);
                 brickletHumidityV2 = null;
             }
         }
         else if (deviceIdentifier == BrickletBarometer.DEVICE_IDENTIFIER)
         {
             try
             {
                 brickletBarometer = new BrickletBarometer(UID, ipcon);
                 brickletBarometer.SetAirPressureCallbackPeriod(1000);
                 brickletBarometer.AirPressure += AirPressureCB;
                 System.Console.WriteLine("Barometer initialized");
             }
             catch (TinkerforgeException e)
             {
                 System.Console.WriteLine("Barometer init failed: " + e.Message);
                 brickletBarometer = null;
             }
         }
     }
 }
Exemplo n.º 3
0
 static void HumidityV2CB(BrickletHumidityV2 sender, int humidity)
 {
     latestHumidity = humidity / 100.0;
 }