예제 #1
0
 private void InitializeSensorReading_Click(object sender, RoutedEventArgs e)
 {
     if (SpheroConnected)
     {
         const string accelFile = "AccelerometerData";
         const string gyroFile  = "GyrometerData";
         AccelerometerFiltered = new FilteredSensor(FILTER_COUNTS, accelFile);
         GyrometerFiltered     = new FilteredSensor(FILTER_COUNTS, gyroFile);
         m_robot.SensorControl.AccelerometerUpdatedEvent += OnAccelerometerUpdated;
         m_robot.SensorControl.GyrometerUpdatedEvent     += OnGyrometerUpdated;
     }
 }
예제 #2
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            if (!isOn)
            {
                isOn = true;
                string file = "CSVData";
                filter = new FilteredSensor(FILTER_COUNTS, file);

                //            // Create an inferred delegate that invokes methods for the timer.
                AutoResetEvent autoEvent = new AutoResetEvent(false);
                TimerCallback  tcb       = getFilter;
                aTimer         = new Timer(tcb, autoEvent, 1000, 250);
                button.Content = "Click to Stop";
                //if (EnsureUnsnapped())
                //{
                //    FileSavePicker savePicker = new FileSavePicker();
                //    savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                //    // Dropdown of file types the user can save the file as
                //    savePicker.FileTypeChoices.Add("Comma-Separated-Values", new List<string>() { ".csv" });

                //    // Default file name if the user does not type one in or select a file to replace
                //    savePicker.SuggestedFileName = "CSVData";
                //    StorageFile file = await savePicker.PickSaveFileAsync();
                //    if (file != null)
                //    {
                //        // Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync.
                //        CachedFileManager.DeferUpdates(file);
                //        // write to file
                //        // Application now has read/write access to all contents in the picked folder (including other sub-folder contents)
                //        StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFileToken", file);
                //        Debug.WriteLine("file: " + file.Name);

                //        // Let Windows know that we're finished changing the file so the other app can update the remote version of the file.
                //        // Completing updates may require Windows to ask for user input.
                //        FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
                //        if (status == FileUpdateStatus.Complete)
                //        {
                //            Debug.WriteLine("File " + file.Name + " was saved.");
                //            filter = new FilteredSensor(FILTER_COUNTS, file);

                //            // Create an inferred delegate that invokes methods for the timer.
                //            AutoResetEvent autoEvent = new AutoResetEvent(false);
                //            TimerCallback tcb = getFilter;
                //            aTimer = new Timer(tcb, autoEvent, 1000, 250);
                //            button.Content = "Click to Stop";
                //        }
                //        else
                //        {
                //            Debug.WriteLine("File " + file.Name + " couldn't be saved.");
                //        }
                //    }
                //    else
                //    {
                //        Debug.WriteLine("Operation cancelled.");
                //    }
                //}
            }
            else
            {
                try
                {
                    aTimer.Dispose();
                }
                catch (Exception)
                {
                    throw;
                }
                if (filter.close())
                {
                    Debug.WriteLine("Stream successfully closed.");
                    button.Content = "Click to Start";
                    isOn           = false;
                }
                else
                {
                    Debug.WriteLine("Unable to close stream,/n" +
                                    "please close application and manually delete file://" + filter.filePath);
                }
            }
        }