Ejemplo n.º 1
0
        public static void Listen(
			EventRouter events, SPWrapper sp,
			Settings settings, DeviceWatcher watcher)
        {
            DeployListener.sp = sp;
            DeployListener.settings = settings;
            DeployListener.watcher = watcher;

            events.SubDataEvent (SPPluginEvents.StartDeploy, de => startDeploy());
            events.SubDataEvent (SPPluginEvents.StartBuild, de => startBuild());
        }
        public SpaceportMenuController(
			SpaceportMenu menu, Control mainForm,
			Version version, EventRouter events,
			Settings settings, DeviceWatcher watcher)
        {
            this.mainForm = mainForm;
            this.settings = settings;
            this.watcher = watcher;

            menu.SelectTargets.Click += SelectTargets_Clicked;
            menu.About.Click += About_Clicked;
            menu.SpaceportWebsite.Click += SpaceportWebsite_Clicked;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Open the device that the user wanted to open if it hasn't been opened yet and auto reconnect is enabled.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="deviceInfo"></param>
 private void OnDeviceAdded(DeviceWatcher sender, DeviceInformation deviceInfo)
 {
     if ((deviceInformation != null) && (deviceInfo.Id == deviceInformation.Id) && !IsDeviceConnected && isEnabledAutoReconnect)
     {
     }
 }
 /// <summary>Event fired when the enumeration is complete</summary>
 private void DevWatcher_EnumerationCompleted(DeviceWatcher sender, object args)
 {
     this.log.Info("DevWatcher_EnumerationCompleted", "*****");
     this.DeviceDiscoveryCompleted?.Invoke(this, true);
 }
 /// <summary>Fired when a device disappears</summary>
 /// <param name="sender"></param>
 /// <param name="updateInfo">The removed device. Use the ID</param>
 private void DevWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate updateInfo)
 {
     this.log.Info("DevWatcher_Removed", () => string.Format("REMOVED ----- {0}", updateInfo.Id));
     this.DeviceRemoved?.Invoke(sender, updateInfo.Id);
 }
Ejemplo n.º 6
0
 private void AdaptersAdded(DeviceWatcher sender, DeviceInformation args)
 {
     _wiFiAdapters.Add(args.Id, null);
 }
 /// <summary>Event fired when the watcher is stopped</summary>
 private void DevWatcher_Stopped(DeviceWatcher sender, object args)
 {
     this.log.Info("DevWatcher_Stopped", "*****");
     this.stopped.Set();
 }
Ejemplo n.º 8
0
 void DeviceWatcherAdded(DeviceWatcher sender, DeviceInformation args)
 {
     _bleDevices.Add(args.Id, args);
 }
Ejemplo n.º 9
0
 private void AdaptersRemoved(DeviceWatcher sender, DeviceInformationUpdate args)
 {
     _wiFiAdapters.Remove(args.Id);
 }
Ejemplo n.º 10
0
        public void Initialize()
        {
            AppDomain.CurrentDomain.UnhandledException += (s, e) => {
                var ex = e.ExceptionObject as Exception;
                logger.Fatal (ex.Message, ex);
            };

            EventManager.AddEventHandler (this, EventType.Command);
            Log4NetHelper.ConfigureFromXML (Resources.log4net);
            SubDataEvent (SPPluginEvents.Enabled, OnPluginEnabled);
            SubDataEvent (SPPluginEvents.Disabled, OnPluginDisabled);
            SubDataEvent (ProjectManagerEvents.Project, OnProjectChanged);
            LoadSettings();

            logger = LogManager.GetLogger (typeof (Launchpad));
            version = Assembly.GetExecutingAssembly ().GetName ().Version;
            A = new Analytics (version);
            sp = new SPWrapper (LaunchpadPaths.SpaceportPath);
            watcher = new DeviceWatcher (sp);

            var mainForm = PluginBase.MainForm.MenuStrip.Parent.Parent;
            var menu = new SpaceportMenu (PluginBase.MainForm.MenuStrip);

            pc = new ProjectMenuController (this, sp, settings);
            uc = new UpdaterController (menu, mainForm, version, settings);
            spc = new SpaceportMenuController (menu, mainForm, version,
                this, settings, watcher);

            DeployListener.Listen (this, sp, settings, watcher);
            InstallListener.Listen (this, sp, settings);

            A.OnStarted();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// This method opens the device using the WinRT Serial API. After the device is opened, save the device
        /// so that it can be used across scenarios.
        ///
        /// It is important that the FromIdAsync call is made on the UI thread because the consent prompt can only be displayed
        /// on the UI thread.
        ///
        /// This method is used to reopen the device after the device reconnects to the computer and when the app resumes.
        /// </summary>
        /// <returns>
        /// True if the device was successfully opened, false if the device could not be opened for well known reasons.
        /// An exception may be thrown if the device could not be opened for extraordinary reasons.
        /// </returns>
        public async Task <bool> OpenDeviceAsync(DeviceInformation deviceInfo, string deviceSelector)
        {
            bool       successfullyOpenedDevice = false;
            NotifyType notificationStatus;
            string     notificationMessage = null;

            Device = await SerialDevice.FromIdAsync(deviceInfo.Id);

            // Device could have been blocked by user or the device has already been opened by another app.
            if (Device != null)
            {
                successfullyOpenedDevice = true;
                DeviceInformation        = deviceInfo;
                DeviceSelector           = deviceSelector;

                // necessary for the MALT read/write to work
                try
                {
                    Device.BaudRate  = 9600;
                    Device.DataBits  = 8;
                    Device.Handshake = SerialHandshake.None;
                }
                catch { }

                // should be set by default
                try
                {
                    Device.StopBits = SerialStopBitCount.One;
                    Device.Parity   = SerialParity.None;
                }
                catch { }

                notificationStatus  = NotifyType.StatusMessage;
                notificationMessage = "Device " + DeviceInformation.Id + " opened";

                // Notify registered callback handle that the device has been opened
                OnDeviceConnected?.Invoke(this, DeviceInformation);

                if (appSuspendEventHandler == null || appResumeEventHandler == null)
                {
                    RegisterForAppEvents();
                }

                // Register for DeviceAccessInformation.AccessChanged event and react to any changes to the
                // user access after the device handle was opened.
                if (deviceAccessEventHandler == null)
                {
                    RegisterForDeviceAccessStatusChange();
                }

                // Create and register device watcher events for the device to be opened unless we're reopening the device
                if (deviceWatcher == null)
                {
                    deviceWatcher = DeviceInformation.CreateWatcher(deviceSelector);
                    RegisterForDeviceWatcherEvents();
                }

                if (!watcherStarted)
                {
                    // Start the device watcher after we made sure that the device is opened.
                    StartDeviceWatcher();
                }
            }
            else
            {
                successfullyOpenedDevice = false;
                notificationStatus       = NotifyType.ErrorMessage;

                var deviceAccessStatus = DeviceAccessInformation.CreateFromId(deviceInfo.Id).CurrentStatus;
                if (deviceAccessStatus == DeviceAccessStatus.DeniedByUser)
                {
                    notificationMessage = "Access to the device was blocked by the user : "******"Access to the device was blocked by the system : " + deviceInfo.Id;
                }
                else
                {
                    // Most likely the device is opened by another app, but cannot be sure
                    notificationMessage = "Unknown error, possibly opened by another app : " + deviceInfo.Id;
                }
            }

            MainPage.Current.NotifyUser(notificationMessage, notificationStatus);
            return(successfullyOpenedDevice);
        }
Ejemplo n.º 12
0
 private void DeviceWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate args)
 {
     Debug.WriteLine("xArm removed.");
 }
Ejemplo n.º 13
0
        /// <summary>
        /// This method opens the device using the WinRT Usb API. After the device is opened, save the device
        /// so that it can be used across scenarios.
        ///
        /// It is important that the FromIdAsync call is made on the UI thread because the consent prompt can only be displayed
        /// on the UI thread.
        ///
        /// This method is used to reopen the device after the device reconnects to the computer and when the app resumes.
        /// </summary>
        /// <param name="deviceInfo">Device information of the device to be opened</param>
        /// <param name="deviceSelector">The AQS used to find this device</param>
        /// <returns>True if the device was successfully opened, false if the device could not be opened for well known reasons.
        /// An exception may be thrown if the device could not be opened for extraordinary reasons.</returns>
        public async Task <bool> OpenDeviceAsync(DeviceInformation deviceInfo, String deviceSelector)
        {
            device = await Windows.Devices.Usb.UsbDevice.FromIdAsync(deviceInfo.Id);

            bool successfullyOpenedDevice = false;

            try
            {
                // Device could have been blocked by user or the device has already been opened by another app.
                if (device != null)
                {
                    successfullyOpenedDevice = true;

                    deviceInformation   = deviceInfo;
                    this.deviceSelector = deviceSelector;

                    Debug.WriteLine($"Device {deviceInformation.Id} opened");

                    // Notify registered callback handle that the device has been opened
                    deviceConnectedCallback?.Invoke(this, deviceInformation);

                    // Background tasks are not part of the app, so app events will not have an affect on the device
                    if (!isBackgroundTask && (appSuspendEventHandler == null || appResumeEventHandler == null))
                    {
                        RegisterForAppEvents();
                    }

                    // User can block the device after it has been opened in the Settings charm. We can detect this by registering for the
                    // DeviceAccessInformation.AccessChanged event
                    if (deviceAccessEventHandler == null)
                    {
                        RegisterForDeviceAccessStatusChange();
                    }

                    // Create and register device watcher events for the device to be opened unless we're reopening the device
                    if (deviceWatcher == null)
                    {
                        deviceWatcher = DeviceInformation.CreateWatcher(deviceSelector);

                        RegisterForDeviceWatcherEvents();
                    }

                    if (!watcherStarted)
                    {
                        // Start the device watcher after we made sure that the device is opened.
                        StartDeviceWatcher();
                    }
                }
                else
                {
                    successfullyOpenedDevice = false;

                    //notificationStatus = NotifyType.ErrorMessage;

                    var deviceAccessStatus = DeviceAccessInformation.CreateFromId(deviceInfo.Id).CurrentStatus;

                    switch (deviceAccessStatus)
                    {
                    case DeviceAccessStatus.DeniedByUser:
                        Debug.WriteLine($"Access to the device was blocked by the user : {deviceInfo.Id}");
                        break;

                    case DeviceAccessStatus.DeniedBySystem:
                        // This status is most likely caused by app permissions (did not declare the device in the app's package.appxmanifest)
                        // This status does not cover the case where the device is already opened by another app.
                        Debug.WriteLine($"Access to the device was blocked by the system : {deviceInfo.Id}");
                        break;

                    default:
                        // Most likely the device is opened by another app, but cannot be sure
                        Debug.WriteLine($"Unknown error, possibly opened by another app : {deviceInfo.Id}");
                        break;
                    }
                }
            }
            // catch all because the device open might fail for a number of reasons
            catch { }

            return(successfullyOpenedDevice);
        }
Ejemplo n.º 14
0
 void StopDeviceWatcher()
 {
     deviceWatcher.Stop();
     deviceWatcher = null;
 }
Ejemplo n.º 15
0
 private void DeviceWatcher_Stopped(DeviceWatcher sender, object e)
 {
 }
Ejemplo n.º 16
0
 private void DeviceWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate)
 {
 }
 private void OnStopped(DeviceWatcher deviceWatcher, object o)
 {
     rootPage.NotifyUserFromBackground("DeviceWatcher stopped", NotifyType.StatusMessage);
 }
 private void OnEnumerationCompleted(DeviceWatcher deviceWatcher, object o)
 {
     rootPage.NotifyUserFromBackground("DeviceWatcher enumeration completed", NotifyType.StatusMessage);
 }
Ejemplo n.º 19
0
 static void DeviceWatcherUpdated(DeviceWatcher sender, DeviceInformationUpdate args)
 {
 }
Ejemplo n.º 20
0
 private static void DeviceWatcher_EnumerationCompleted(DeviceWatcher sender, object args)
 {
     waitHandle.Set();
 }