예제 #1
1
파일: GamePad.cs 프로젝트: dworki93/dron
 public GamePad(OnConnectionChange function)
 {
     onConnectionChange += function;
     controller = new Controller(UserIndex.One);
     status = Connected;
     onConnectionChange.Invoke(status);
 }
예제 #2
0
파일: GamePad.cs 프로젝트: hnjm/dron
 public GamePad(OnConnectionChange function)
 {
     onConnectionChange += function;
     controller          = new Controller(UserIndex.One);
     status              = Connected;
     onConnectionChange.Invoke(status);
 }
예제 #3
0
        public void Shutdown()
        {
            try
            {
                if (port != null)
                {
                    var prt = port;
                    port = null;
                    if (prt.IsOpen)
                    {
                        prt.Close();
                    }
                    prt.Dispose();
                }
            }
            catch (Exception) { }
            try
            {
                if (!CommsTimeout && _TmrPeriodic != null)
                {
                    var tmr = _TmrPeriodic;
                    _TmrPeriodic = null;
                    tmr.Dispose();
                }
            }
            catch (Exception) { }

            GetSetSuctionPressure(0);
            ComponentPickedupMinPressure = 0;
            PressureAtPickup             = 0;
            ConnectionState = "Disconnected";
            OnConnectionChange?.Invoke(ConnectionState);
        }
예제 #4
0
 private void WebSocket_OnClose(object sender, bool e)
 {
     isConnectedEvent.Reset();
     isDisconnectedEvent.Set();
     logger.LogInformation($"WebSocket_OnClose uri:{Uri} Connect Closed!");
     OnConnectionChange?.Invoke(this, IsConnected);
 }
예제 #5
0
        private async Task DoConnect(CancellationToken cancellationToken)
        {
            Type prevException = null;

            isConnectedEvent.Reset();
            isDisconnectedEvent.Set();

            while (!cancellationToken.IsCancellationRequested && IsRunning)
            {
                try
                {
                    logger.LogDebug($"MqttClientHelper Connecting with ClientId:{Config.ClientId}");
                    if (string.IsNullOrEmpty(Config.Username))
                    {
                        Client.Connect(Config.ClientId);
                    }
                    else
                    {
                        Client.Connect(Config.ClientId, Config.Username, Config.Password);
                    }

                    logger.LogInformation($"MqttClientHelper Connected ClientId:{Config.ClientId}");

                    prevException = null;
                    isConnectedEvent.Set();
                    isDisconnectedEvent.Reset();

                    OnConnectionChange?.Invoke(this, IsConnected);

                    // block while is connected
                    isDisconnectedEvent.WaitOne();
                }
                catch (Exception e)
                {
                    if (cancellationToken.IsCancellationRequested || !IsRunning)
                    {
                        break;
                    }

                    if (e.GetType() != prevException)
                    {
                        prevException = e.GetType();
                        logger.LogError(e, "MqttClientHelper Connect Error");
                        logger.LogWarning($"MqttClientHelper ClientId:{Config.ClientId} Connect Failed, retry on {Config.ReconnectDealy / 1000} seconds");
                    }

                    await Task.Delay(Config.ReconnectDealy, cancellationToken);
                }
                finally
                {
                    isConnectedEvent.Reset();
                    isDisconnectedEvent.Set();
                }
            }

            logger.LogInformation($"MqttClientHelper ClientId:{Config.ClientId} Connection Closed!");
            OnConnectionChange?.Invoke(this, IsConnected);
        }
예제 #6
0
        private async Task DoConnect(CancellationToken cancellationToken)
        {
            Type prevException = null;

            IsRunning = true;
            isConnectedEvent.Reset();
            isDisconnectedEvent.Set();

            while (!cancellationToken.IsCancellationRequested && IsRunning)
            {
                try
                {
                    logger.LogDebug($"WebSocketClient Connecting with uri:{Uri}");

                    await client.ConnectAsync(Uri, cancellationToken);

                    logger.LogInformation($"WebSocketClient Connected uri:{Uri}");

                    prevException = null;
                    isConnectedEvent.Set();
                    isDisconnectedEvent.Reset();

                    OnConnectionChange?.Invoke(this, IsConnected);

                    // block while is connected
                    isDisconnectedEvent.WaitOne();
                }
                catch (Exception e)
                {
                    if (cancellationToken.IsCancellationRequested || !IsRunning)
                    {
                        break;
                    }

                    if (e.GetType() != prevException)
                    {
                        prevException = e.GetType();
                        logger.LogError(e, "WebSocketClient Connect Error");
                        logger.LogInformation($"WebSocketClient uri:{Uri} Connect Failed, retry on {ReconnectDelay}.");
                    }

                    await Task.Delay(ReconnectDelay, cancellationToken);
                }
                finally
                {
                    isConnectedEvent.Reset();
                    isDisconnectedEvent.Set();
                }
            }

            logger.LogInformation($"WebSocketClient uri:{Uri} Connection Closed!");
            OnConnectionChange?.Invoke(this, IsConnected);
        }
예제 #7
0
        public void Update(GameTime gameTime, GamePadDeadZone deadZoneMode)
        {
            _lastGamePadState    = _currentGamePadState;
            _currentGamePadState = GamePad.GetState(PlayerNumber, deadZoneMode);
            UpdateVibrating(gameTime);
            CheckGamePadTouched();

            if (Connected)
            {
                OnConnectionChange?.Invoke(true);
            }

            if (Disconnected)
            {
                OnConnectionChange?.Invoke(false);
            }
        }
예제 #8
0
        public ESuctionSensorState Init()
        {
            //Get our settings.
            if (!PressureSettings.SuctionSensorEnable)
            {
                _Main.DisplayText(SuctionSensorNotEnabled);
                Shutdown();
                return(ESuctionSensorState.InitialisedOk);
            }
            //Get our serial port.

            if (string.IsNullOrEmpty(PressureSettings.SuctionSensorPort))
            {
                MessageForUser = SuctionSensorNoPort;
                _Main.DisplayText(MessageForUser, System.Drawing.KnownColor.Red);
                return(ESuctionSensorState.RequireOkStopUserConfirmation);
            }
            try
            {
                //init the port.
                port               = new SerialPort(PressureSettings.SuctionSensorPort);
                port.BaudRate      = 38400;
                port.StopBits      = StopBits.One;
                port.Parity        = Parity.None;
                port.DataReceived += Port_DataReceived;
                port.Open();
                CommsTimeout    = false;
                ConnectionState = "Connected!";
                OnConnectionChange?.Invoke(ConnectionState);
            }
            catch (Exception ex)
            {
                Shutdown();
                MessageForUser = SuctionSensorNoPort + $"Err: {ex.Message}";
                _Main.DisplayText(MessageForUser, System.Drawing.KnownColor.Red);
                return(ESuctionSensorState.RequireOkStopUserConfirmation);
            }
            //We might be trying to reconnect after a disconnection.
            if (_TmrPeriodic == null)
            {
                _TmrPeriodic = new Timer(TmrTick, this, TimerTickRate, Timeout.Infinite);
            }
            return(ESuctionSensorState.InitialisedOk);
        }
예제 #9
0
 private void MqttOnConnectionClosed(object sender, EventArgs e)
 {
     OnConnectionChange?.Invoke(this, IsConnected());
 }
예제 #10
0
 private void OnConnectionClosed(object sender, EventArgs e)
 {
     isDisconnectedEvent.Set();
     logger.LogInformation($"MqttClientHelper ClientId:{Config.ClientId} Connect Closed!");
     OnConnectionChange?.Invoke(this, IsConnected);
 }