Exemplo n.º 1
0
        private void OnBLEDisconnected()
        {
            try
            {
                foreach (var chan in ButtonChannels.Values)
                {
                    _flicClient.RemoveConnectionChannel(chan);
                }

                _flicClient.Disconnect();
                _flicClient = null;

                DebugEx.TraceLog("FLIC: InitFlicClient from OnBLEDisconnected");
                _InitFlicClient();
            }
            catch (Exception ex)
            {
                DebugEx.Assert(ex);
            }
        }
Exemplo n.º 2
0
        private void GotButton(Bdaddr bdAddr)
        {
            var control = new FlicButtonControl();

            control.lblBdAddr.Text   = bdAddr.ToString();
            control.btnListen.Click += (o, args) =>
            {
                if (!control.Listens)
                {
                    control.Listens        = true;
                    control.btnListen.Text = "Stop";

                    control.Channel = new ButtonConnectionChannel(bdAddr);
                    control.Channel.CreateConnectionChannelResponse += (sender1, eventArgs) => Invoke((MethodInvoker) delegate
                    {
                        if (eventArgs.Error != CreateConnectionChannelError.NoError)
                        {
                            control.Listens        = false;
                            control.btnListen.Text = "Listen";
                        }
                        else
                        {
                            control.lblStatus.Text = eventArgs.ConnectionStatus.ToString();
                        }
                    });
                    control.Channel.Removed += (sender1, eventArgs) => Invoke((MethodInvoker) delegate
                    {
                        control.lblStatus.Text = "Disconnected";
                        control.Listens        = false;
                        control.btnListen.Text = "Listen";
                    });
                    control.Channel.ConnectionStatusChanged += (sender1, eventArgs) => Invoke((MethodInvoker) delegate
                    {
                        control.lblStatus.Text = eventArgs.ConnectionStatus.ToString();
                    });
                    control.Channel.ButtonUpOrDown += (sender1, eventArgs) => Invoke((MethodInvoker) delegate
                    {
                        control.pictureBox.BackColor = eventArgs.ClickType == ClickType.ButtonDown ? Color.LimeGreen : Color.Red;
                    });
                    _flicClient.AddConnectionChannel(control.Channel);
                }
                else
                {
                    _flicClient.RemoveConnectionChannel(control.Channel);
                }
            };
            buttonsList.Controls.Add(control);
        }