Example #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;
        }
Example #2
0
        private void DualButtonStateChanged(BrickletDualButton sender, byte buttonL, byte buttonR, byte ledl, byte ledr)
        {
            _lcdBricklet.BacklightOn();
            if (buttonL == BrickletDualButton.BUTTON_STATE_PRESSED)
            {
                ButtonActive = false;
                GetData();
            }
            else if (buttonL == BrickletDualButton.BUTTON_STATE_RELEASED)
            {
                //Console.WriteLine("Left Button: Released");
            }

            if (buttonR == BrickletDualButton.BUTTON_STATE_PRESSED)
            {
                ButtonActive = true;
                Clickcount   = 0;
                MoveCount    = 0;
                Console.WriteLine("Right Button: Pressed");

                _lcdBricklet.ClearDisplay();
                _lcdBricklet.WriteLine(0, 0,
                                       "Temperature: " + Convert.ToString(ReadTemperature() / 100.0) + UTF16ToKS0066U("°C"));
                _lcdBricklet.WriteLine(1, 0,
                                       "Humidity: " + Convert.ToString(ReadHumidity() / 100.0) + UTF16ToKS0066U("%"));

                _lcdBricklet.WriteLine(3, 0, "Move count: " + MoveCount);
            }
            else if (buttonR == BrickletDualButton.BUTTON_STATE_RELEASED)
            {
                //Console.WriteLine("Right Button: Released");
            }

            Console.WriteLine("");
        }
Example #3
0
    public DualButtonInput(IPConnection ipcon, BlockingQueue<char> keyQueue)
    {
        this.keyQueue = keyQueue;

        byte buttonL;
        byte buttonR;

        if (Config.UID_DUAL_BUTTON_BRICKLET[0] == null)
        {
            System.Console.WriteLine("Not Configured: Dual Button 1");
        }
        else
        {
            dualButton1 = new BrickletDualButton(Config.UID_DUAL_BUTTON_BRICKLET[0], ipcon);

            try
            {
                dualButton1.GetButtonState(out buttonL, out buttonR);
                System.Console.WriteLine("Found: Dual Button 1 ({0})",
                                         Config.UID_DUAL_BUTTON_BRICKLET[0]);
            }
            catch (TinkerforgeException)
            {
                System.Console.WriteLine("Not Found: Dual Button 1 ({0})",
                                         Config.UID_DUAL_BUTTON_BRICKLET[0]);
            }

            dualButton1.StateChanged += StateChanged1CB;
        }

        if (Config.UID_DUAL_BUTTON_BRICKLET[1] == null)
        {
            System.Console.WriteLine("Not Configured: Dual Button 2");
        }
        else
        {
            dualButton2 = new BrickletDualButton(Config.UID_DUAL_BUTTON_BRICKLET[1], ipcon);

            try
            {
                dualButton2.GetButtonState(out buttonL, out buttonR);
                System.Console.WriteLine("Found: Dual Button 2 ({0})",
                                         Config.UID_DUAL_BUTTON_BRICKLET[0]);
            }
            catch (TinkerforgeException)
            {
                System.Console.WriteLine("Not Found: Dual Button 2 ({0})",
                                         Config.UID_DUAL_BUTTON_BRICKLET[0]);
            }

            dualButton2.StateChanged += StateChanged2CB;
        }

        pressTimer = new Timer(delegate(object state) { PressTick(); }, null, 100, 100);
    }
Example #4
0
    public DualButtonInput(IPConnection ipcon, BlockingQueue <char> keyQueue)
    {
        this.keyQueue = keyQueue;

        byte buttonL;
        byte buttonR;

        if (Config.UID_DUAL_BUTTON_BRICKLET[0] == null)
        {
            System.Console.WriteLine("Not Configured: Dual Button 1");
        }
        else
        {
            dualButton1 = new BrickletDualButton(Config.UID_DUAL_BUTTON_BRICKLET[0], ipcon);

            try
            {
                dualButton1.GetButtonState(out buttonL, out buttonR);
                System.Console.WriteLine("Found: Dual Button 1 ({0})",
                                         Config.UID_DUAL_BUTTON_BRICKLET[0]);
            }
            catch (TinkerforgeException)
            {
                System.Console.WriteLine("Not Found: Dual Button 1 ({0})",
                                         Config.UID_DUAL_BUTTON_BRICKLET[0]);
            }

            dualButton1.StateChanged += StateChanged1CB;
        }

        if (Config.UID_DUAL_BUTTON_BRICKLET[1] == null)
        {
            System.Console.WriteLine("Not Configured: Dual Button 2");
        }
        else
        {
            dualButton2 = new BrickletDualButton(Config.UID_DUAL_BUTTON_BRICKLET[1], ipcon);

            try
            {
                dualButton2.GetButtonState(out buttonL, out buttonR);
                System.Console.WriteLine("Found: Dual Button 2 ({0})",
                                         Config.UID_DUAL_BUTTON_BRICKLET[0]);
            }
            catch (TinkerforgeException)
            {
                System.Console.WriteLine("Not Found: Dual Button 2 ({0})",
                                         Config.UID_DUAL_BUTTON_BRICKLET[0]);
            }

            dualButton2.StateChanged += StateChanged2CB;
        }

        pressTimer = new Timer(delegate(object state) { PressTick(); }, null, 100, 100);
    }
Example #5
0
    private void StateChanged2CB(BrickletDualButton sender, byte buttonL, byte buttonR, byte ledL, byte ledR)
    {
        int l            = buttonL == BrickletDualButton.BUTTON_STATE_PRESSED ? 1 : 0;
        int r            = buttonR == BrickletDualButton.BUTTON_STATE_PRESSED ? 1 : 0;
        int state        = (l << 2) | (r << 3);
        int changedState = (currentState ^ state) & 12 /* 0b1100 */;

        currentState = state;

        StateToQueue(changedState & currentState);
    }
    private static string UID = "XYZ"; // Change XYZ to the UID of your Dual Button Bricklet

    #endregion Fields

    #region Methods

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

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

        // Register state changed callback to function StateChangedCB
        db.StateChanged += StateChangedCB;

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
    // Callback function for state changed callback
    static void StateChangedCB(BrickletDualButton sender, byte buttonL, byte buttonR,
	                           byte ledL, byte ledR)
    {
        if(buttonL == BrickletDualButton.BUTTON_STATE_PRESSED)
        {
            Console.WriteLine("Left button pressed");
        }
        else
        {
            Console.WriteLine("Left button released");
        }

        if(buttonR == BrickletDualButton.BUTTON_STATE_PRESSED)
        {
            Console.WriteLine("Right button pressed");
        }
        else
        {
            Console.WriteLine("Right button released");
        }

        Console.WriteLine("");
    }
Example #8
0
    private void StateChanged2CB(BrickletDualButton sender, byte buttonL, byte buttonR, byte ledL, byte ledR)
    {
        int l = buttonL == BrickletDualButton.BUTTON_STATE_PRESSED ? 1 : 0;
        int r = buttonR == BrickletDualButton.BUTTON_STATE_PRESSED ? 1 : 0;
        int state = (l << 2) | (r << 3);
        int changedState = (currentState ^ state) & 12 /* 0b1100 */;

        currentState = state;

        StateToQueue(changedState & currentState);
    }