Ejemplo n.º 1
0
        // 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);
            }
        }
Ejemplo n.º 2
0
 private void button1_Click(object sender, EventArgs e)
 {
     I2CAccelerometerControl.SetFrequency(Convert.ToInt32(textBox1.Text));
     I2CAccelerometerControl.SetThreshold1(Convert.ToDouble(textBox2.Text));
     I2CAccelerometerControl.SetDuration1(Convert.ToDouble(textBox3.Text));
     I2CAccelerometerControl.SetThreshold2(Convert.ToDouble(textBox4.Text));
     I2CAccelerometerControl.SetDuration2(Convert.ToDouble(textBox5.Text));
     I2CAccelerometerControl.EnableInterrupts();
     button2_Click(sender, e); // if settings are being changed, then flags should probably be reset too.
 }