public MainWindow()
        {
            InitializeComponent();

            autoReadTimer          = new DispatcherTimer();
            autoReadTimer.Tick    += new EventHandler(autoReadObjects);
            autoReadTimer.Interval = new TimeSpan(0, 0, 1);   // Hours, Minutes, Seconds



            // try to connect to device. Show status in status bar
            try
            {
                traqpaq = new TraqpaqDevice();
                // update status bar
                //traqpaq.myOTPreader.reqSerialNumber();
                statusBarItemTraqpaq.Content = "Device connected";
                oneTimeRead();
                autoReadTimer.Start();
            }
            catch (TraqPaqNotConnectedException)
            {
                // Device not found
                traqpaq = null;
                // update status bar
                statusBarItemTraqpaq.Content = "Device not found";
                // Set up event handler to wait for a usb device to connect to
                deviceNotifier = DeviceNotifier.OpenDeviceNotifier();
                deviceNotifier.OnDeviceNotify += new EventHandler <DeviceNotifyEventArgs>(deviceNotifier_OnDeviceNotify);
            }
        }
 /// <summary>
 /// Called whenever a usb device is plugged in or unplugged
 /// </summary>
 void deviceNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
 {
     // Detected a device, try to see if it is the traqpaq
     if (e.EventType == EventType.DeviceArrival)  // check for device arrival
     {
         //MessageBox.Show(e.Device.IdProduct.ToString() + "\n" + e.Device.IdVendor.ToString());
         if (traqpaq == null)
         {//TODO could also check for specifics with the e.Device..... properties
             // try to connect again
             try
             {
                 traqpaq = new TraqpaqDevice();
                 statusBarItemTraqpaq.Content = "Device connected";
                 oneTimeRead();
                 autoReadTimer.Start();
             }
             catch (TraqPaqNotConnectedException) { }    // Silently fail
         }
     }
     else if (e.EventType == EventType.DeviceRemoveComplete)
     {
         //TODO use this to disconnect the device. The event handler would need to be created regardless
         //of wether or not the device is connected at first though.
         if (traqpaq.MyUSBDevice.IsOpen)
         {
             traqpaq.MyUSBDevice.Close();
             statusBarItemTraqpaq.Content = "Device not found";
             autoReadTimer.Stop();
         }
     }
 }
        public MainWindow()
        {
            InitializeComponent();

            autoReadTimer = new DispatcherTimer();
            autoReadTimer.Tick += new EventHandler(autoReadObjects);
            autoReadTimer.Interval = new TimeSpan(0, 0, 1);   // Hours, Minutes, Seconds

            // try to connect to device. Show status in status bar
            try
            {
                traqpaq = new TraqpaqDevice();
                // update status bar
                //traqpaq.myOTPreader.reqSerialNumber();
                statusBarItemTraqpaq.Content = "Device connected";
                oneTimeRead();
                autoReadTimer.Start();

            }
            catch (TraqPaqNotConnectedException)
            {
                // Device not found
                traqpaq = null;
                // update status bar
                statusBarItemTraqpaq.Content = "Device not found";
                // Set up event handler to wait for a usb device to connect to
                deviceNotifier = DeviceNotifier.OpenDeviceNotifier();
                deviceNotifier.OnDeviceNotify += new EventHandler<DeviceNotifyEventArgs>(deviceNotifier_OnDeviceNotify);
            }
        }
Beispiel #4
0
 public RecordDataReader(TraqpaqDevice parent, RecordTableReader.RecordTable recordTable)
 {
     this.traqpaq     = parent;
     this.recordTable = recordTable;
     // allocate the recordData array, 256 bytes per page
     this.numPages        = (recordTable.EndAddress - recordTable.StartAddress) / Constants.MEMORY_PAGE_SIZE;
     this.recordDataPages = new RecordDataPage[numPages];
 }
Beispiel #5
0
 public RecordTableReader(TraqpaqDevice parent)
 {
     this.traqpaq = parent;
 }
Beispiel #6
0
 public SavedTrackReader(TraqpaqDevice parent)
 {
     this.traqpaq = parent;
     // get all the saved tracks and add them to the list
     getAllTracks();
 }
Beispiel #7
0
 public Battery(TraqpaqDevice parent)
 {
     this.traqpaq = parent;
 }
Beispiel #8
0
 public OTPreader(TraqpaqDevice parent)
 {
     this.parent = parent;
 }
 public OTPreader(TraqpaqDevice parent)
 {
     this.parent = parent;
 }
Beispiel #10
0
 public RecordDataReader(TraqpaqDevice parent, RecordTableReader.RecordTable recordTable)
 {
     this.traqpaq = parent;
     this.recordTable = recordTable;
     // allocate the recordData array, 256 bytes per page
     this.numPages = (recordTable.EndAddress - recordTable.StartAddress) / Constants.MEMORY_PAGE_SIZE;
     this.recordDataPages = new RecordDataPage[numPages];
 }
        public Record(TraqpaqDevice traqpaq, TraqpaqDevice.RecordTableReader.RecordTable recordTable)
        {
            // get the track name
            trackName = traqpaq.trackList[recordTable.TrackID].trackName;
            //TODO need to convert to readable date format
            DateStamp = recordTable.DateStamp.ToLongDateString();
            // get the data at the record
            //TODO separate laps for now assume 1 lap
            TraqpaqDevice.RecordDataReader dataReader = new TraqpaqDevice.RecordDataReader(traqpaq, recordTable);
            dataReader.readRecordData();

            List<double> longitudes = new List<double>();
            List<double> latitutes = new List<double>();
            List<double> altitudes = new List<double>();
            List<double> velocities = new List<double>();

            foreach (var page in dataReader.recordDataPages)
            {
                foreach (var data in page.RecordData)
                {
                    longitudes.Add(data.Longitude);
                    latitutes.Add(data.Latitude);
                    altitudes.Add(data.Altitude);
                    velocities.Add(data.Speed);
                }
            }
            LapInfo lap = new LapInfo();
            lap.Latitudes = latitutes;
            lap.Longitudes = longitudes;
            lap.LapColor = Colors.Red;
            lap.LapNo = "1";
            lap.LapTime = "1:20";
            lap.Track = trackName;
            Laps.Add(lap);
        }
 public UploadPage(MainWindow main)
 {
     this.main = main;
     this.traqpaq = main.traqpaq;
     InitializeComponent();
 }
        //public delegate void Populate();

        public MainWindow()
        {
            InitializeComponent();

            // Set up event handler to wait for a usb device to connect to
            deviceNotifier = DeviceNotifier.OpenDeviceNotifier();
            deviceNotifier.OnDeviceNotify += new EventHandler<DeviceNotifyEventArgs>(deviceNotifier_OnDeviceNotify);

            // try to connect to device (if device was connected previously). Show status in status bar
            try
            {
                traqpaq = new TraqpaqDevice();
                // update status bar
                statusBarItemTraqpaq.Content = "Device connected: " + traqpaq.reqSerialNumber();
            }
            catch (TraqPaqNotConnectedException)
            {
                // Device not found
                traqpaq = null;
                // update status bar
                statusBarItemTraqpaq.Content = "Device not found";
            }

            // Create the pages
            homePage = new HomePage(this);
            settingsPage = new SettingsPage(this);
            uploadPage = new UploadPage(this);

            // assign the pages to the respective tabs
            frameUpload.Navigate(uploadPage);
            frameSettings.Navigate(settingsPage);

            // Go to the welcome page
            frameHome.Navigate(homePage);

            // create the log book page
            logBookPage = new LogBookPage(this);
            frameLogBook.Navigate(logBookPage);
            if (traqpaq != null)
            {
                logBookPage.populateTracks();
            }

            // configure the background worker
            //bw.DoWork += bw_DoWork;
            //bw.WorkerReportsProgress = false;
            // attempt with backgroundworker if connected
            //if (traqpaq != null)
            //{
            //    logBookPage.populateTracks();
            //    //bw.RunWorkerAsync();
            //}


            //// create the log book page as a background task
            //Thread threadCreateRecordPage = new System.Threading.Thread(
            //    new ThreadStart(
            //        delegate()
            //        {
            //            System.Windows.Threading.DispatcherOperation dispatcherOp = frameLogBook.Dispatcher.BeginInvoke(
            //                System.Windows.Threading.DispatcherPriority.Normal,
            //                new Action(delegate()
            //                {
            //                    logBookPage.populateTracks();                                
            //                }));
            //        }));
            //threadCreateRecordPage.SetApartmentState(ApartmentState.STA);
            //threadCreateRecordPage.Start();

            //Action createRecordPage = delegate()
            //{
            //    logBookPage.populateTracks();
            //};
            //Task taskLogPage = Task.Factory.StartNew(createRecordPage);

        }
        //void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        //{
        //    MessageBox.Show("Complete");
        //}

        //void bw_DoWork(object sender, DoWorkEventArgs e)
        //{
        //    Populate handler = logBookPage.populateTracks;
        //    logBookPage.Dispatcher.BeginInvoke(handler);
        //}

        /// <summary>
        /// Called whenever a usb device is plugged in or unplugged
        /// </summary>
        void deviceNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
        {
            // Detected a device, try to see if it is the traqpaq
            if (e.Device.IdProduct == Constants.PID && e.Device.IdVendor == Constants.VID)
            {
                if (e.EventType == EventType.DeviceArrival)  // check for device arrival
                {
                    if (traqpaq == null)
                    {
                        // try to connect again
                        try
                        {
                            traqpaq = new TraqpaqDevice();
                            statusBarItemTraqpaq.Content = "Device connected: " + traqpaq.reqSerialNumber();
                            // populate tracks
                            //TODO fix populate tracks
                            logBookPage.populateTracks();                            
                        }
                        catch (TraqPaqNotConnectedException) { return; }    // Silently fail and exit method

                        //BackgroundWorker bw = new BackgroundWorker();
                        //bw.DoWork += bw_DoWork;
                        //bw.RunWorkerAsync(); 
                    }
                }
                else    // device removal
                {
                    traqpaq.disconnectDevice();
                    traqpaq = null;
                    // update status bar
                    statusBarItemTraqpaq.Content = "Traqpaq disconnected";
                }
            }
        }
Beispiel #15
0
 public SavedTrack(TraqpaqDevice traqpaq, ushort index)
 {
     this.traqpaq = traqpaq;
     this.index = index;
 }
Beispiel #16
0
 public Battery(TraqpaqDevice parent)
 {
     this.traqpaq = parent;
 }
 /// <summary>
 /// Called whenever a usb device is plugged in or unplugged
 /// </summary>
 void deviceNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
 {
     // Detected a device, try to see if it is the traqpaq
     if (e.EventType == EventType.DeviceArrival)  // check for device arrival
     {
         //MessageBox.Show(e.Device.IdProduct.ToString() + "\n" + e.Device.IdVendor.ToString());
         if (traqpaq == null)
         {//TODO could also check for specifics with the e.Device..... properties
             // try to connect again
             try
             {
                 traqpaq = new TraqpaqDevice();
                 statusBarItemTraqpaq.Content = "Device connected";
                 oneTimeRead();
                 autoReadTimer.Start();
             }
             catch (TraqPaqNotConnectedException) { }    // Silently fail
         }
     }
     else if(e.EventType == EventType.DeviceRemoveComplete)
     {
         //TODO use this to disconnect the device. The event handler would need to be created regardless
         //of wether or not the device is connected at first though.
         if (traqpaq.MyUSBDevice.IsOpen)
         {
             traqpaq.MyUSBDevice.Close();
             statusBarItemTraqpaq.Content = "Device not found";
             autoReadTimer.Stop();
         }
     }
 }
Beispiel #18
0
 public RecordTableReader(TraqpaqDevice parent)
 {
     this.traqpaq = parent;
 }
 public SavedTrackReader(TraqpaqDevice parent)
 {
     this.traqpaq = parent;
     // get all the saved tracks and add them to the list
     getAllTracks();
 }