Esempio n. 1
0
        private bool TestUpdate()
        {
            bool started       = false;
            bool result        = false;
            bool requestResult = false;

            TypedEventHandler <IPenClient, object> firmwareInstallationStarted;
            TypedEventHandler <IPenClient, ProgressChangeEventArgs> firmwareInstallationStatusUpdated;
            TypedEventHandler <IPenClient, SimpleResultEventArgs>   firmwareInstallationFinished;

            firmwareInstallationStarted = new TypedEventHandler <IPenClient, object>((IPenClient sender, object args) =>
            {
                requestResult = true;
            });

            _controller.FirmwareInstallationStarted += firmwareInstallationStarted;

            firmwareInstallationStatusUpdated = new TypedEventHandler <IPenClient, ProgressChangeEventArgs>((IPenClient sender, ProgressChangeEventArgs args) =>
            {
                started = true;
                Debug.WriteLine(args.AmountDone + " / " + args.Total);
            });

            _controller.FirmwareInstallationStatusUpdated += firmwareInstallationStatusUpdated;

            firmwareInstallationFinished = new TypedEventHandler <IPenClient, SimpleResultEventArgs>((IPenClient sender, SimpleResultEventArgs args) =>
            {
                result = args.Result;
                _autoResetEvent.Set();
            });

            _controller.FirmwareInstallationFinished += firmwareInstallationFinished;

            Task.Factory.StartNew(async() =>
            {
                StorageFile file = await KnownFolders.PicturesLibrary.GetFileAsync(FIRMWARE_FILENAME);
                _controller.RequestFirmwareInstallation(file, FIRMWARE_VERSION);
            });

            _autoResetEvent.WaitOne();

            _controller.FirmwareInstallationStarted       -= firmwareInstallationStarted;
            _controller.FirmwareInstallationStatusUpdated -= firmwareInstallationStatusUpdated;
            _controller.FirmwareInstallationFinished      -= firmwareInstallationFinished;

            return(requestResult && started && result);
        }
Esempio n. 2
0
        private async void btnFirmwareUpdate_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            if (txtFirmwareFile.Text.Equals(""))
            {
                await ShowMessage("Select firmware binary file");

                txtFirmwareFile.Focus(Windows.UI.Xaml.FocusState.Pointer);
                return;
            }

            if (txtFirmwareVersion.Text.Equals(""))
            {
                await ShowMessage("Input version of firmware");

                txtFirmwareVersion.Focus(Windows.UI.Xaml.FocusState.Keyboard);
                return;
            }

            _controller?.RequestFirmwareInstallation(mFile, txtFirmwareVersion.Text);
        }