// Reads accelerometer status on a separate thread private void BackgroundWorker_doWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; double[] data = { 0, 0, 0 }; while (continuePolling) //*** Currently nothing changes the continuePolling variable, so this will run until the program shuts down. { System.Threading.Thread.Sleep(pollInterval); connected = I2CAccelerometerControl.VerifyAccelerometer(); if (!connected) { MCUSBI2C.Close(); MCUSBI2C.Open(); pollCounter = 0; configString = ""; } else { data = I2CAccelerometerControl.GetData(); configString = I2CAccelerometerControl.GetConfiguration(); I2CAccelerometerControl.GetInterruptStatus1().CopyTo(interrupt1Status, 0); I2CAccelerometerControl.GetInterruptStatus2().CopyTo(interrupt2Status, 0); pollCounter++; } backgroundWorker.ReportProgress(0, data); } }
public Form1() { MCUSBI2C.Open(); connected = false; continuePolling = true; pollInterval = 0; // Set to zero for continuous polling pollCounter = 0; configString = ""; interrupt1Status = new bool[4] { false, false, false, false }; interrupt2Status = new bool[4] { false, false, false, false }; InitializeComponent(); backgroundWorker = new BackgroundWorker(); backgroundWorker.DoWork += new DoWorkEventHandler(BackgroundWorker_doWork); backgroundWorker.RunWorkerAsync(); backgroundWorker.WorkerReportsProgress = true; backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(BackgroundWorker_NewData); }