Ejemplo n.º 1
0
        public Component()
        {
            client = new HttpClient();
            // Create connection object
            _ipConnection = new IPConnection();

            // Create device objects
            _dualButtonBricklet  = new BrickletDualButton(DualButtonUID, _ipConnection);
            _lcdBricklet         = new BrickletLCD20x4(DisplayUID, _ipConnection);
            _temperatureBricklet = new BrickletTemperature(TemperatureUID, _ipConnection);
            _humidityBricklet    = new BrickletHumidity(HumidityUID, _ipConnection);
            _linearPoti          = new BrickletLinearPoti(LinearPotiUID, _ipConnection);
            _rgbButton           = new BrickletRGBLEDButton(RGBButtonUID, _ipConnection);
            _rotaryPoti          = new BrickletRotaryPoti(RotaryPotiUID, _ipConnection);
            _segmentDisplay      = new BrickletSegmentDisplay4x7(SegmentUID, _ipConnection);
            _motionDetector      = new BrickletMotionDetectorV2(motionDetectorUID, _ipConnection);
            _multiTouch          = new BrickletMultiTouch(multiTouchUID, _ipConnection);

            //register listeners
            _dualButtonBricklet.StateChangedCallback += DualButtonStateChanged;

            //register callback
            _linearPoti.PositionCallback                += PositionCb;
            _rotaryPoti.PositionCallback                += PositionRCB;
            _motionDetector.MotionDetectedCallback      += MotionDetectedCB;
            _motionDetector.DetectionCycleEndedCallback += DetectionCycleEndedCB;
            _multiTouch.TouchStateCallback              += TouchStateCB;
        }
    static private void ConfigureCustomChars(BrickletLCD20x4 lcd)
    {
        byte[][] c = new byte[8][];
        c[0] = new byte[8] {
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff
        };
        c[1] = new byte[8] {
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff
        };
        c[2] = new byte[8] {
            0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff
        };
        c[3] = new byte[8] {
            0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
        };
        c[4] = new byte[8] {
            0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff
        };
        c[5] = new byte[8] {
            0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
        };
        c[6] = new byte[8] {
            0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
        };
        c[7] = new byte[8] {
            0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
        };

        for (byte i = 0; i < c.Length; i++)
        {
            lcd.SetCustomCharacter(i, c[i]);
        }
    }
Ejemplo n.º 3
0
    // Callback handles device connections and configures possibly lost
    // configuration of lcd and temperature callbacks, backlight etc.
    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)
        {
            // Enumeration is for LCD Bricklet
            if (deviceIdentifier == BrickletLCD20x4.DEVICE_IDENTIFIER)
            {
                // Create lcd device object
                lcd = new BrickletLCD20x4(UID, ipcon);
                lcd.ButtonPressed += ButtonPressedCB;

                lcd.ClearDisplay();
                lcd.BacklightOn();
            }
            // Enumeration is for Temperature Bricklet
            if (deviceIdentifier == BrickletTemperature.DEVICE_IDENTIFIER)
            {
                // Create temperature device object
                temp              = new BrickletTemperature(UID, ipcon);
                temp.Temperature += TemperatureCB;

                temp.SetTemperatureCallbackPeriod(50);
            }
        }
    }
Ejemplo n.º 4
0
    // Callback handles device connections and configures possibly lost
    // configuration of lcd and temperature callbacks, backlight etc.
    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)
        {
            // Enumeration is for LCD Bricklet
            if(deviceIdentifier == BrickletLCD20x4.DEVICE_IDENTIFIER)
            {
                // Create lcd device object
                lcd = new BrickletLCD20x4(UID, ipcon);
                lcd.ButtonPressed += ButtonPressedCB;

                lcd.ClearDisplay();
                lcd.BacklightOn();
            }
            // Enumeration is for Temperature Bricklet
            if(deviceIdentifier == BrickletTemperature.DEVICE_IDENTIFIER)
            {
                // Create temperature device object
                temp = new BrickletTemperature(UID, ipcon);
                temp.Temperature += TemperatureCB;

                temp.SetTemperatureCallbackPeriod(50);
            }
        }
    }
Ejemplo n.º 5
0
        private static void Main()
        {
            double setPoint = 400;

            IPConnection ipcon = new IPConnection(); // Create IP connection

            ipcon.Connect(HOST, PORT);               // Connect to brickd
            var display    = new BrickletLCD20x4(UidLcdDisplay, ipcon);
            var displayPID = new BrickletLCD20x4(UidLcdDisplayPID, ipcon);
            var light      = new BrickletAmbientLight(UidAmbientLight, ipcon);

            ledStrip = new BrickletLEDStrip(UidLedStrip, ipcon);
            var pid = new PidCompute(0.3, 0.0001, 0.0000003);

            ledStrip.SetChannelMapping(6);
            var rotaryPotiP = new BrickletRotaryPoti(UiWheelP, ipcon);
            var rotaryPotiI = new BrickletRotaryPoti(UiWheelI, ipcon);
            var rotaryPotiD = new BrickletRotaryPoti(UiWheelD, ipcon);
            var linerPoti   = new BrickletLinearPoti("bxu", ipcon);

            display.BacklightOn();
            displayPID.BacklightOn();

            var    ledHandler = new LedHanlder(ledStrip);
            double P          = 0.15;
            double I          = 0.15;
            double D          = 0.15;

            while (true)
            {
                P        = rotaryPotiP.GetAnalogValue() / 100000.0;
                I        = rotaryPotiI.GetAnalogValue() / 1000000.0;
                D        = rotaryPotiD.GetAnalogValue() / 1000000.0;
                setPoint = linerPoti.GetAnalogValue() / 10;

                pid = new PidCompute(P, I, D);
                Console.WriteLine("Goal: " + setPoint);
                var lux = light.GetIlluminance();
                Console.Out.WriteLine($"Lux: {lux}");
                var res = 0.1 * pid.Compute(setPoint, lux);
                Console.Out.WriteLine($"PID Result: {res}");
                ledHandler.SetLedStrip(res);
                display.ClearDisplay();
                displayPID.ClearDisplay();
                display.WriteLine(0, 0, $"Setpoint: {setPoint}");
                display.WriteLine(1, 0, $"Lux: {lux}");
                display.WriteLine(2, 0, $"PID Result: {res}");
                displayPID.WriteLine(0, 0, $"P: {P}");
                displayPID.WriteLine(1, 0, $"I: {I}");
                displayPID.WriteLine(2, 0, $"D: {D}");
                Thread.Sleep(10);
            }

            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
            ipcon.Disconnect();
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Callback for enumeration => List of sensors connected to master brick
 /// </summary>
 /// <param name="sender">IPConnection</param>
 /// <param name="UID">UID of brick/bricklet</param>
 /// <param name="connectedUID">UID of masterbrick</param>
 /// <param name="position">Position of brick/bricklet in stack</param>
 /// <param name="hardwareVersion">Info about hardware version</param>
 /// <param name="firmwareVersion">Info about firmware version</param>
 /// <param name="deviceIdentifier">Brick/Bricklet type identifier</param>
 /// <param name="enumerationType">Kind of enumeration</param>
 private void InstantiateLCDBricklet(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) &&
         (deviceIdentifier == BrickletLCD20x4.DEVICE_IDENTIFIER))
     {
         _Bricklet = new BrickletLCD20x4(UID, _TFConnection);
         _Bricklet.ClearDisplay();
         _Bricklet.BacklightOn();
     }
 }
    static void PressedCB(BrickletLCD20x4 sender, byte button)
    {
        if (button == buttonPressed)
        {
            buttonPressedCounter[button]++;
        }
        else
        {
            buttonPressed = button;
        }

        brickletLCD.ClearDisplay();
        UpdateSwitch();
    }
	static void PressedCB(BrickletLCD20x4 sender, byte button)
	{
		if(button == buttonPressed)
		{
			buttonPressedCounter[button]++;
		}
		else
		{
			buttonPressed = button;
		}

		brickletLCD.ClearDisplay();
		UpdateSwitch();
	}
Ejemplo n.º 9
0
 /// <summary>
 /// Callback for enumeration => List of sensors connected to master brick
 /// </summary>
 /// <param name="sender">IPConnection</param>
 /// <param name="UID">UID of brick/bricklet</param>
 /// <param name="connectedUID">UID of masterbrick</param>
 /// <param name="position">Position of brick/bricklet in stack</param>
 /// <param name="hardwareVersion">Info about hardware version</param>
 /// <param name="firmwareVersion">Info about firmware version</param>
 /// <param name="deviceIdentifier">Brick/Bricklet type identifier</param>
 /// <param name="enumerationType">Kind of enumeration</param>
 private void InstantiateLCDBricklet(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) &&
         (deviceIdentifier == BrickletLCD20x4.DEVICE_IDENTIFIER))
     {
         Bricklet = new BrickletLCD20x4(UID, TFConnection);
         Bricklet.ClearDisplay();
         Bricklet.BacklightOn();
         Bricklet.WriteLine(0, 0, DateTime.Now.ToString(LcdConfig.Instance.TimestampFormat));
     }
 }
Ejemplo n.º 10
0
		public LCDisplayHelper(BrickletLCD20x4 lcd) {
			this.lcd = lcd;
			Initial_Scroll_Delay = 4000;
			Scroll_Delay_After_Each_Character = 1000;
			Thread scroll_thread = new Thread(new ThreadStart(scroller));
			
			for (int i = 0; i < display.Length; i++) {
				display[i] = string.Empty;
				delay[i] = DateTime.Now;
				current_character_offset[i] = 0;
				scroll_direction[i] = false;
			}
			
			scroll_thread.Start();
		}
    private static void ConfigureCustomChars(BrickletLCD20x4 lcd)
    {
        byte[][] c = new byte[8][];
        c[0] = new byte[8] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
        c[1] = new byte[8] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff};
        c[2] = new byte[8] {0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff};
        c[3] = new byte[8] {0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff};
        c[4] = new byte[8] {0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff};
        c[5] = new byte[8] {0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
        c[6] = new byte[8] {0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
        c[7] = new byte[8] {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};

        for(byte i = 0; i < c.Length; i++)
        {
            lcd.SetCustomCharacter(i, c[i]);
        }
    }
Ejemplo n.º 12
0
 // Callback switches lcd backlight on/off based on lcd button 0
 static void ButtonPressedCB(BrickletLCD20x4 sender, byte button)
 {
     if(lcd != null)
     {
         if(button == 0)
         {
             if(lcd.IsBacklightOn())
             {
                 lcd.BacklightOff();
             }
             else
             {
                 lcd.BacklightOn();
             }
         }
     }
 }
Ejemplo n.º 13
0
 // Callback switches lcd backlight on/off based on lcd button 0
 static void ButtonPressedCB(BrickletLCD20x4 sender, byte button)
 {
     if (lcd != null)
     {
         if (button == 0)
         {
             if (lcd.IsBacklightOn())
             {
                 lcd.BacklightOff();
             }
             else
             {
                 lcd.BacklightOn();
             }
         }
     }
 }
    static void Main()
    {
        IPConnection ipcon = new IPConnection(); // Create IP connection
        BrickletLCD20x4 lcd = new BrickletLCD20x4(UID, ipcon); // Create device object

        ipcon.Connect(HOST, PORT); // Connect to brickd
        // Don't use device before ipcon is connected

        // Register button pressed callback to function ButtonPressedCB
        lcd.ButtonPressed += ButtonPressedCB;

        // Register button released callback to function ButtonReleasedCB
        lcd.ButtonReleased += ButtonReleasedCB;

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
    private static string UID = "XYZ"; // Change XYZ to the UID of your LCD 20x4 Bricklet

    #endregion Fields

    #region Methods

    static void Main()
    {
        IPConnection ipcon = new IPConnection(); // Create IP connection
        BrickletLCD20x4 lcd = new BrickletLCD20x4(UID, ipcon); // Create device object

        ipcon.Connect(HOST, PORT); // Connect to brickd
        // Don't use device before ipcon is connected

        // Turn backlight on
        lcd.BacklightOn();

        // Write "Hello World"
        lcd.WriteLine(0, 0, "Hello World");

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
Ejemplo n.º 16
0
		public static bool init(ref IPConnection brick_connection) {
			
			// get UIDs of bricks and bricklets
			AppSettingsReader config = new AppSettingsReader();
			
			host = (string)config.GetValue("host", typeof(string));
			port = (int)config.GetValue("port", typeof(int));
			server_port = (int)config.GetValue("server_port", typeof(int));
			string master_brick_uid = (string)config.GetValue("master_brick_uid", typeof(string));
			string ambient_bricklet_uid = (string)config.GetValue("ambient_light_bricklet_uid", typeof(string));
			string temperature_bricklet_uid = (string)config.GetValue("temperature_bricklet_uid", typeof(string));
			string lcd_20x4_bricklet_uid = (string)config.GetValue("lcd_20x4_bricklet_uid", typeof(string));
			
#if DEBUG
			Console.WriteLine("Master Brick Host:Port ...: {0}:{1}", host, port);
			Console.WriteLine("Serverport (udp msgs).....: :{0}", server_port);
			Console.WriteLine("Master Brick UID .........: {0}", master_brick_uid);
			Console.WriteLine("Ambient Bricklet UID .....: {0}", ambient_bricklet_uid);
			Console.WriteLine("Temperature Bricklet UID .: {0}", temperature_bricklet_uid);
			Console.WriteLine("LCD 20x4 Bricklet UID ....: {0}", lcd_20x4_bricklet_uid);
#endif
			
			// setup connection to master und bricklets
			try {
				brick_connection = new IPConnection(host, port);
				
				ambient_light = new BrickletAmbientLight(ambient_bricklet_uid);
				temperature = new BrickletTemperature(temperature_bricklet_uid);
				lcd = new BrickletLCD20x4(lcd_20x4_bricklet_uid);
				displayHelper = new LCDisplayHelper(lcd);
			
				brick_connection.AddDevice(ambient_light);
				brick_connection.AddDevice(temperature);
				brick_connection.AddDevice(lcd);
			} catch (Tinkerforge.TimeoutException te) {
				Console.WriteLine(te.Message);
				return false;
			}
			
			return true;
		}
Ejemplo n.º 17
0
    private static string UID = "XYZ"; // Change XYZ to the UID of your LCD 20x4 Bricklet

    #endregion Fields

    #region Methods

    static void Main()
    {
        IPConnection ipcon = new IPConnection(); // Create IP connection
        BrickletLCD20x4 lcd = new BrickletLCD20x4(UID, ipcon); // Create device object

        ipcon.Connect(HOST, PORT); // Connect to brickd
        // Don't use device before ipcon is connected

        // Turn backlight on
        lcd.BacklightOn();

        // Write some strings using the UTF16ToKS0066U function to map to the LCD charset
        lcd.WriteLine(0, 0, UTF16ToKS0066U("Stromstärke: 17µA"));
        lcd.WriteLine(1, 0, UTF16ToKS0066U("Temperatur:  23°C"));

        // Write a string directly including characters from the LCD charset
        lcd.WriteLine(2, 0, "Drehzahl:   750min\xe9");

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
 // Callback function for button released callback
 static void ButtonReleasedCB(BrickletLCD20x4 sender, byte button)
 {
     Console.WriteLine("Button Released: " + button);
 }
Ejemplo n.º 19
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 == 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;
                }
            }
        }
    }
Ejemplo n.º 20
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;
             }
         }
     }
 }
Ejemplo n.º 21
0
        public void doSmth()
        {
            //Create IP Connection
            IPConnection ipcon = new IPConnection();

            // Connect to brickd
            ipcon.Connect(HOST, PORT);

            var BrickletLCD          = new BrickletLCD20x4(SECRET_LCD, ipcon);
            var BrickletAmbientLight = new BrickletAmbientLight(SECRET_AMBIENTLIGHT, ipcon);
            var BrickletCO2          = new BrickletCO2(SECRET_CO2, ipcon);
            var BrickletBarometer    = new BrickletBarometer(SECRET_BAROMETER, ipcon);
            var BrickletTemperature  = new BrickletTemperature(SECRET_TEMPERATURE, ipcon);

            int i = 100;

            var data = new Bricklet_Model();
            var tb   = new Thingsboard();


            while (true)
            {
                var co2value       = BrickletCO2.GetCO2Concentration();                          // unit ppm - parts per million
                var lightvalue     = BrickletAmbientLight.GetAnalogValue();                      // lcd
                var barometervalue = String.Format("{0:n}", BrickletBarometer.GetAirPressure()); // in mbar
                // var barometervalue = bV / 1000;

                double tempvalue = (Math.Round((double)BrickletTemperature.GetTemperature() * 100) / 10000) - 5; // in °c


                tb.LightValue  = lightvalue;
                tb.Barometer   = Convert.ToDouble(barometervalue) / 1000;
                tb.Temperature = tempvalue;
                tb.CO2         = co2value;
                //tb.LightValue = 100;
                //tb.Barometer = 99;
                //tb.Temperature = 98;
                //tb.CO2 = 97;
                c.PublishMessage(tb);

                /*
                 * var temperatur = new Temperatur();
                 * _context.Temperatur.Add(temperatur);
                 * _context.Entry(temperatur).CurrentValues.SetValues(new Temperatur { Datum = new DateTime(), Einheit = "Grad", Wert = CO2Value, idTemperatur = i++ });
                 * _context.SaveChanges();
                 */
                BrickletLCD.SetConfig(true, true);
                BrickletLCD.BacklightOn();
                Console.WriteLine(
                    " LightValue: " + lightvalue + " BarometerValue " +
                    barometervalue + "mbar " + " TempValue " + tempvalue.ToString() + "°C " + " CO2-Value: " + co2value);
                BrickletLCD.WriteLine(0, 0, "CO2 Value: " + co2value.ToString());
                BrickletLCD.WriteLine(1, 0, "LightValue: " + lightvalue.ToString());
                BrickletLCD.WriteLine(2, 0, "BarometerValue:" + barometervalue.ToString());
                BrickletLCD.WriteLine(3, 0, "Temperature " + tempvalue.ToString());

                Thread.Sleep(500);
            }

            ipcon.Disconnect();
        }