static bool EndScan()
        {
            scanHandler = null;

            if (onScanEnd != null)
            {
                onScanEnd();
            }

            onScanEnd = null;
            return(true);
        }
        public static void Start(ScanFlags scanFlags, ScanHandler scanHandler, System.Action onScanEnd)
        {
            if (isScanning)
            {
                Stop();
            }

            m_scanStartTime         = Time.unscaledTime;
            isScanning              = true;
            ScanService.scanFlags   = scanFlags;
            ScanService.onScanEnd   = onScanEnd;
            ScanService.scanHandler = scanHandler;
        }
Exemple #3
0
        public void Start(float startTime, ScanFlags scanFlags, ScanHandler scanHandler, System.Action onScanEnd)
        {
            if (IsScanning)
            {
                Stop();
            }

            m_scanStartTime = startTime;
            this.scanFlags  = scanFlags;
            this.onScanEnd  = onScanEnd;
            m_scanHandler   = scanHandler;

            IsScanning = true;
        }
        /// <summary>
        /// Asynchronously requests wireless interfaces to scan (rescan) wireless LANs.
        /// </summary>
        /// <param name="timeout">Timeout duration</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns>Interface IDs that successfully scanned</returns>
        public static async Task <IEnumerable <Guid> > ScanNetworksAsync(TimeSpan timeout, CancellationToken cancellationToken)
        {
            using (var client = new Base.WlanClient())
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(client.Handle);
                var interfaceIds      = interfaceInfoList.Select(x => x.InterfaceGuid).ToArray();

                var tcs     = new TaskCompletionSource <bool>();
                var handler = new ScanHandler(tcs, interfaceIds);

                Action <IntPtr, IntPtr> callback = (data, context) =>
                {
                    var notificationData = Marshal.PtrToStructure <WLAN_NOTIFICATION_DATA>(data);
                    if (notificationData.NotificationSource != WLAN_NOTIFICATION_SOURCE_ACM)
                    {
                        return;
                    }

                    Debug.WriteLine("Callback: {0}", (WLAN_NOTIFICATION_ACM)notificationData.NotificationCode);

                    switch (notificationData.NotificationCode)
                    {
                    case (uint)WLAN_NOTIFICATION_ACM.wlan_notification_acm_scan_complete:
                        handler.SetSuccess(notificationData.InterfaceGuid);
                        break;

                    case (uint)WLAN_NOTIFICATION_ACM.wlan_notification_acm_scan_fail:
                        handler.SetFailure(notificationData.InterfaceGuid);
                        break;
                    }
                };

                Base.RegisterNotification(client.Handle, WLAN_NOTIFICATION_SOURCE_ACM, callback);

                foreach (var interfaceId in interfaceIds)
                {
                    var result = Base.Scan(client.Handle, interfaceId);
                    if (!result)
                    {
                        handler.SetFailure(interfaceId);
                    }
                }

                var scanTask = tcs.Task;
                await Task.WhenAny(scanTask, Task.Delay(timeout, cancellationToken));

                return(handler.Results);
            }
        }
        private void StopInputScan()
        {
            _scanResult.scanFlags    = ScanFlags.None;
            _scanResult.key          = KeyCode.None;
            _scanResult.joystick     = -1;
            _scanResult.joystickAxis = -1;
            _scanResult.mouseAxis    = -1;
            _scanResult.userData     = _scanUserData;

            _scanHandler(_scanResult);

            _scanHandler         = null;
            _scanResult.userData = null;
            _scanFlags           = ScanFlags.None;
        }
Exemple #6
0
        private void btnScan_Click(object sender, EventArgs e)
        {
            try
            {
                btnScan.Enabled = false;

                if (btnScan.Text == CLanguage.Lan("开始扫描"))
                {
                    if (comMon == null)
                    {
                        labStatus.Text      = CLanguage.Lan("请确定串口是否打开?");
                        labStatus.ForeColor = Color.Red;
                        return;
                    }

                    _startAddr = System.Convert.ToInt16(txtStartAddr.Text);

                    _endAddr = System.Convert.ToInt16(txtEndAddr.Text);

                    DevView.Rows.Clear();

                    _rowNum = 0;

                    ScanHandler scanEvent = new ScanHandler(OnScan);

                    scanEvent.BeginInvoke(null, null);

                    _scanStopFlag = false;

                    btnScan.Text = CLanguage.Lan("停止扫描");
                }
                else
                {
                    _scanStopFlag = true;
                }
            }
            catch (Exception ex)
            {
                labStatus.Text      = ex.ToString();
                labStatus.ForeColor = Color.Red;
            }
            finally
            {
                btnScan.Enabled = true;
            }
        }
        private bool ScanJoystickButton()
        {
            int scanStart = (int)KeyCode.Joystick1Button0;
            int scanEnd   = (int)KeyCode.Joystick8Button19;

            if (m_scanJoystick.HasValue)
            {
                scanStart = (int)KeyCode.Joystick1Button0 + m_scanJoystick.Value * 20;
                scanEnd   = scanStart + 20;
            }

            for (int key = scanStart; key < scanEnd; key++)
            {
                if (Input.GetKeyDown((KeyCode)key))
                {
                    if (m_scanJoystick.HasValue)
                    {
                        m_scanResult.Key      = (KeyCode)key;
                        m_scanResult.Joystick = m_scanJoystick.Value;
                    }
                    else
                    {
                        m_scanResult.Key      = (KeyCode)((int)KeyCode.JoystickButton0 + (key - (int)KeyCode.Joystick1Button0) % 20);
                        m_scanResult.Joystick = ((key - (int)KeyCode.Joystick1Button0) / 20);
                    }

                    m_scanResult.JoystickAxis      = -1;
                    m_scanResult.JoystickAxisValue = 0.0f;
                    m_scanResult.MouseAxis         = -1;
                    m_scanResult.UserData          = m_scanUserData;
                    m_scanResult.ScanFlags         = ScanFlags.JoystickButton;

                    if (m_scanHandler(m_scanResult))
                    {
                        m_scanHandler         = null;
                        m_scanResult.UserData = null;
                        m_scanFlags           = ScanFlags.None;
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #8
0
        public static void StartScan(ScanSettings settings, ScanHandler scanHandler)
        {
            if (settings.joystick < 0 || settings.joystick >= AxisConfiguration.MaxJoystickAxes)
            {
                throw new ArgumentException("The joystick id you want to scan for is out of range");
            }

            if (_instance._scanFlags != ScanFlags.None)
            {
                _instance.StopInputScan();
            }

            _instance._scanTimeout      = settings.timeout;
            _instance._scanFlags        = settings.scanFlags;
            _instance._scanStartTime    = _instance.ignoreTimescale ? Time.realtimeSinceStartup : Time.time;
            _instance._cancelScanButton = settings.cancelScanButton;
            _instance._scanJoystick     = settings.joystick;
            _instance._scanUserData     = settings.userData;
            _instance._scanHandler      = scanHandler;
        }
        public static void StartScan(ScanSettings settings, ScanHandler scanHandler)
        {
            if (settings.joystick < 0 || settings.joystick >= AxisConfiguration.MaxJoystickAxes)
            {
                Debug.LogError("Joystick is out of range. Cannot start scan.");
                return;
            }

            if (_instance._scanFlags != ScanFlags.None)
            {
                _instance.StopInputScan();
            }

            _instance._scanTimeout      = settings.timeout;
            _instance._scanFlags        = settings.scanFlags;
            _instance._scanStartTime    = _instance.ignoreTimescale ? Time.realtimeSinceStartup : Time.time;
            _instance._cancelScanButton = settings.cancelScanButton;
            _instance._scanJoystick     = settings.joystick;
            _instance._scanUserData     = settings.userData;
            _instance._scanHandler      = scanHandler;
        }
        public void Stop()
        {
            if (IsScanning)
            {
                m_scanResult.ScanFlags         = ScanFlags.None;
                m_scanResult.Key               = KeyCode.None;
                m_scanResult.Joystick          = -1;
                m_scanResult.JoystickAxis      = -1;
                m_scanResult.JoystickAxisValue = 0.0f;
                m_scanResult.MouseAxis         = -1;
                m_scanResult.UserData          = m_scanUserData;

                m_scanHandler(m_scanResult);

                m_scanJoystick        = null;
                m_scanHandler         = null;
                m_scanResult.UserData = null;
                m_scanFlags           = ScanFlags.None;
                IsScanning            = false;
            }
        }
        public void Start(ScanSettings settings, ScanHandler scanHandler)
        {
            if (settings.Joystick.HasValue && (settings.Joystick < 0 || settings.Joystick >= InputBinding.MAX_JOYSTICK_AXES))
            {
                Debug.LogError("Joystick is out of range. Cannot start scan.");
                return;
            }

            if (IsScanning)
            {
                Stop();
            }

            m_scanTimeout   = settings.Timeout;
            m_scanFlags     = settings.ScanFlags;
            m_scanStartTime = GameTime;
            m_cancelScanKey = settings.CancelScanKey;
            m_scanJoystick  = settings.Joystick;
            m_scanUserData  = settings.UserData;
            m_scanHandler   = scanHandler;
            IsScanning      = true;
        }
Exemple #12
0
        private bool ScanMouseAxis()
        {
            for (int i = 0; i < _rawMouseAxes.Length; i++)
            {
                if (Mathf.Abs(Input.GetAxis(_rawMouseAxes[i])) > 0.0f)
                {
                    _scanResult.scanFlags    = ScanFlags.MouseAxis;
                    _scanResult.key          = KeyCode.None;
                    _scanResult.joystick     = -1;
                    _scanResult.joystickAxis = -1;
                    _scanResult.mouseAxis    = i;
                    _scanResult.userData     = _scanUserData;
                    if (_scanHandler(_scanResult))
                    {
                        _scanHandler         = null;
                        _scanResult.userData = null;
                        _scanFlags           = ScanFlags.None;
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #13
0
        private bool ScanJoystickButton()
        {
            for (int key = (int)KeyCode.JoystickButton0; key < (int)KeyCode.Joystick4Button19; key++)
            {
                if (Input.GetKeyDown((KeyCode)key))
                {
                    _scanResult.scanFlags    = ScanFlags.JoystickButton;
                    _scanResult.key          = (KeyCode)key;
                    _scanResult.joystick     = -1;
                    _scanResult.joystickAxis = -1;
                    _scanResult.mouseAxis    = -1;
                    _scanResult.userData     = _scanUserData;
                    if (_scanHandler(_scanResult))
                    {
                        _scanHandler         = null;
                        _scanResult.userData = null;
                        _scanFlags           = ScanFlags.None;
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #14
0
 public static void StartInputScan(ScanFlags scanFlags, ScanHandler scanHandler, System.Action onScanEnd)
 {
     m_instance.m_scanService.Start(Time.unscaledTime, scanFlags, scanHandler, onScanEnd);
 }
        public static void StartScan(ScanSettings settings, ScanHandler scanHandler)
        {
            if (settings.joystick < 0 || settings.joystick >= AxisConfiguration.MaxJoystickAxes)
                throw new ArgumentException ("The joystick id you want to scan for is out of range");

            if (_instance._scanFlags != ScanFlags.None)
                _instance.StopInputScan ();

            _instance._scanTimeout = settings.timeout;
            _instance._scanFlags = settings.scanFlags;
            _instance._scanStartTime = _instance.ignoreTimescale ? Time.realtimeSinceStartup : Time.time;
            _instance._cancelScanButton = settings.cancelScanButton;
            _instance._scanJoystick = settings.joystick;
            _instance._scanUserData = settings.userData;
            _instance._scanHandler = scanHandler;
        }
        private void StopInputScan()
        {
            _scanResult.scanFlags = ScanFlags.None;
            _scanResult.key = KeyCode.None;
            _scanResult.joystick = -1;
            _scanResult.joystickAxis = -1;
            _scanResult.mouseAxis = -1;
            _scanResult.userData = _scanUserData;

            _scanHandler (_scanResult);

            _scanHandler = null;
            _scanResult.userData = null;
            _scanFlags = ScanFlags.None;
        }
        private bool ScanMouseAxis()
        {
            for (int i = 0; i < _rawMouseAxes.Length; i++) {
                if (Mathf.Abs (Input.GetAxis (_rawMouseAxes [i])) > 0.0f) {
                    _scanResult.scanFlags = ScanFlags.MouseAxis;
                    _scanResult.key = KeyCode.None;
                    _scanResult.joystick = -1;
                    _scanResult.joystickAxis = -1;
                    _scanResult.mouseAxis = i;
                    _scanResult.userData = _scanUserData;
                    if (_scanHandler (_scanResult)) {
                        _scanHandler = null;
                        _scanResult.userData = null;
                        _scanFlags = ScanFlags.None;
                        return true;
                    }
                }
            }

            return false;
        }
        private bool ScanKey()
        {
            int length = _keys.Length;
            for (int i = 0; i < length; i++) {
                if ((int)_keys [i] >= (int)KeyCode.JoystickButton0)
                    break;

                if (Input.GetKeyDown (_keys [i])) {
                    _scanResult.scanFlags = ScanFlags.Key;
                    _scanResult.key = _keys [i];
                    _scanResult.joystick = -1;
                    _scanResult.joystickAxis = -1;
                    _scanResult.mouseAxis = -1;
                    _scanResult.userData = _scanUserData;
                    if (_scanHandler (_scanResult)) {
                        _scanHandler = null;
                        _scanResult.userData = null;
                        _scanFlags = ScanFlags.None;
                        return true;
                    }
                }
            }

            return false;
        }
        private bool ScanJoystickButton()
        {
            for (int key = (int)KeyCode.JoystickButton0; key < (int)KeyCode.Joystick4Button19; key++) {
                if (Input.GetKeyDown ((KeyCode)key)) {
                    _scanResult.scanFlags = ScanFlags.JoystickButton;
                    _scanResult.key = (KeyCode)key;
                    _scanResult.joystick = -1;
                    _scanResult.joystickAxis = -1;
                    _scanResult.mouseAxis = -1;
                    _scanResult.userData = _scanUserData;
                    if (_scanHandler (_scanResult)) {
                        _scanHandler = null;
                        _scanResult.userData = null;
                        _scanFlags = ScanFlags.None;
                        return true;
                    }
                }
            }

            return false;
        }
        private bool ScanJoystickAxis()
        {
            int scanStart = _scanJoystick * AxisConfiguration.MaxJoystickAxes;
            for (int i = 0; i < AxisConfiguration.MaxJoystickAxes; i++) {
                if (Mathf.Abs (Input.GetAxisRaw (_rawJoystickAxes [scanStart + i])) >= 1.0f) {
                    _scanResult.scanFlags = ScanFlags.JoystickAxis;
                    _scanResult.key = KeyCode.None;
                    _scanResult.joystick = _scanJoystick;
                    _scanResult.joystickAxis = i;
                    _scanResult.mouseAxis = -1;
                    _scanResult.userData = _scanUserData;
                    if (_scanHandler (_scanResult)) {
                        _scanHandler = null;
                        _scanResult.userData = null;
                        _scanFlags = ScanFlags.None;
                        return true;
                    }
                }
            }

            return false;
        }
Exemple #21
0
 public static void StartInputScan(ScanSettings settings, ScanHandler scanHandler)
 {
     m_instance.m_scanService.Start(settings, scanHandler);
 }
		public static void StartScan(ScanSettings settings, ScanHandler scanHandler)
		{
			if(settings.joystick < 0 || settings.joystick >= AxisConfiguration.MaxJoystickAxes)
			{
				Debug.LogError("Joystick is out of range. Cannot start scan.");
				return;
			}
			
			if(_instance._scanFlags != ScanFlags.None)
				_instance.StopInputScan();
			
			_instance._scanTimeout = settings.timeout;
			_instance._scanFlags = settings.scanFlags;
			_instance._scanStartTime = _instance.ignoreTimescale ? Time.realtimeSinceStartup : Time.time;
			_instance._cancelScanButton = settings.cancelScanButton;
			_instance._scanJoystick = settings.joystick;
			_instance._scanUserData = settings.userData;
			_instance._scanHandler = scanHandler;
		}