void accel_AccelerationChange(object sender, AccelerationChangeEventArgs e)
 {
     Accelerometer attached = (Accelerometer)sender;
     if (State == StateEnum.ACCELERO)
     {
         for (int index = 0; index < StaticUtilities.numberOfAcceleroMeterAxis; index++)
         {
             accelerationText(index, Convert.ToInt32(e.Acceleration[index]));
         }
     }
 }
示例#2
0
 //Acceleration change event handler...Display which axis the device is
 //accelerating in as well as the measured acceleration value
 static void accel_AccelerationChange(object sender,
                                      AccelerationChangeEventArgs e)
 {
     Console.WriteLine("Axes {0} Acceleration {1}", e.Index, e.Acceleration);
 }
示例#3
0
        void accel_AccelerationChange(object sender, AccelerationChangeEventArgs e)
        {
            formGraphicsContext = new BufferedGraphicsContext();

            formGraphicsBuffer = formGraphicsContext.Allocate(Graphics.FromImage(formDrawingSurface), rectBounds);

            formGraphicsBuffer.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            formGraphicsBuffer.Graphics.Clear(SystemColors.Control);

            int i = 0;
            //low pass filtering
            switch (e.Index)
            {
                case 0:
                    xOut = 0;
                    xFilt[6] = e.Acceleration;
                    for (i = 0; i < 6; i++)
                    {
                        xFilt[i] = xFilt[i + 1];
                        xOut = xOut + xFilt[i];
                    }
                    xOut = xOut / 6;
                    label6.Text = e.Acceleration.ToString();
                    break;
                case 1:
                    yOut = 0;
                    yFilt[6] = e.Acceleration;
                    for (i = 0; i < 6; i++)
                    {
                        yFilt[i] = yFilt[i + 1];
                        yOut = yOut + yFilt[i];
                    }
                    yOut = yOut / 6;
                    label7.Text = e.Acceleration.ToString();
                    break;
                case 2:
                    zOut = 0;
                    zFilt[6] = e.Acceleration;
                    for (i = 0; i < 6; i++)
                    {
                        zFilt[i] = zFilt[i + 1];
                        zOut = zOut + zFilt[i];
                    }
                    zOut = zOut / 6;
                    label8.Text = e.Acceleration.ToString();
                    break;
            }

            x1Old = xCenter - (float)xOut * circleRadius;
            y1Old = yCenter + (float)yOut * circleRadius;

            formGraphicsBuffer.Graphics.DrawLine(xyAxisPen, xCenter, yCenter, x1Old, y1Old);
            formGraphicsBuffer.Graphics.DrawEllipse(circlePen, circleRectangle);

            if (accel.axes.Count == 3)
            {
                if (zOut > 0)
                {
                    formGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Red, 2),
                        new Rectangle((int)xCenter - (int)(circleRadius * zOut), (int)yCenter - (int)(circleRadius * zOut),
                        (int)(circleDiameter * zOut), (int)(circleDiameter * zOut)));
                }
                else
                {
                    formGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Green, 2),
                        new Rectangle((int)xCenter - (int)(circleRadius * -zOut), (int)yCenter - (int)(circleRadius * -zOut),
                        (int)(circleDiameter * -zOut), (int)(circleDiameter * -zOut)));
                }
            }

            formGraphicsBuffer.Render(panel1.CreateGraphics());

            formGraphicsBuffer.Dispose();

            formGraphicsContext.Dispose();
        }
示例#4
0
        void accel_AccelerationChange(object sender, AccelerationChangeEventArgs e)
        {
            formGraphicsContext = new BufferedGraphicsContext();

            formGraphicsBuffer = formGraphicsContext.Allocate(Graphics.FromImage(formDrawingSurface), rectBounds);

            formGraphicsBuffer.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            formGraphicsBuffer.Graphics.Clear(SystemColors.Control);

            int i = 0;

            //low pass filtering
            switch (e.Index)
            {
            case 0:
                xOut     = 0;
                xFilt[6] = e.Acceleration;
                for (i = 0; i < 6; i++)
                {
                    xFilt[i] = xFilt[i + 1];
                    xOut     = xOut + xFilt[i];
                }
                xOut        = xOut / 6;
                label6.Text = e.Acceleration.ToString();
                break;

            case 1:
                yOut     = 0;
                yFilt[6] = e.Acceleration;
                for (i = 0; i < 6; i++)
                {
                    yFilt[i] = yFilt[i + 1];
                    yOut     = yOut + yFilt[i];
                }
                yOut        = yOut / 6;
                label7.Text = e.Acceleration.ToString();
                break;

            case 2:
                zOut     = 0;
                zFilt[6] = e.Acceleration;
                for (i = 0; i < 6; i++)
                {
                    zFilt[i] = zFilt[i + 1];
                    zOut     = zOut + zFilt[i];
                }
                zOut        = zOut / 6;
                label8.Text = e.Acceleration.ToString();
                break;
            }

            x1Old = xCenter - (float)xOut * circleRadius;
            y1Old = yCenter + (float)yOut * circleRadius;

            formGraphicsBuffer.Graphics.DrawLine(xyAxisPen, xCenter, yCenter, x1Old, y1Old);
            formGraphicsBuffer.Graphics.DrawEllipse(circlePen, circleRectangle);

            if (accel.axes.Count == 3)
            {
                if (zOut > 0)
                {
                    formGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Red, 2),
                                                            new Rectangle((int)xCenter - (int)(circleRadius * zOut), (int)yCenter - (int)(circleRadius * zOut),
                                                                          (int)(circleDiameter * zOut), (int)(circleDiameter * zOut)));
                }
                else
                {
                    formGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Green, 2),
                                                            new Rectangle((int)xCenter - (int)(circleRadius * -zOut), (int)yCenter - (int)(circleRadius * -zOut),
                                                                          (int)(circleDiameter * -zOut), (int)(circleDiameter * -zOut)));
                }
            }

            formGraphicsBuffer.Render(panel1.CreateGraphics());

            formGraphicsBuffer.Dispose();

            formGraphicsContext.Dispose();
        }
示例#5
0
        //acceleration change event handler
        void accel_AccelerationChange(object sender, AccelerationChangeEventArgs e)
        {
            //get our graphics buffer going so we can draw to our panel
            accelGraphicsContext = new BufferedGraphicsContext();
            accelGraphicsBuffer = accelGraphicsContext.Allocate(Graphics.FromImage(accelDrawingSurface), boundsRectangle);
            accelGraphicsBuffer.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            accelGraphicsBuffer.Graphics.Clear(SystemColors.Control);

            Accelerometer attached = (Accelerometer)sender;

            //in this switch statement we will do a bit of simple low pass filtering to smooth out the motion of the graphical representation of the
            //acceleration data.  We will also write the raw data to the textbox for the appropriate axis.
            int i = 0;
            try
            {
                switch (e.Index)
                {
                    case 0:
                        xOut = 0;
                        xFilt[6] = e.Acceleration;
                        for (i = 0; i < 6; i++)
                        {
                            xFilt[i] = xFilt[i + 1];
                            xOut = xOut + xFilt[i];
                        }
                        xOut = xOut / 6;
                        axis1AccelTxt.Text = e.Acceleration.ToString();
                        break;
                    case 1:
                        yOut = 0;
                        yFilt[6] = e.Acceleration;
                        for (i = 0; i < 6; i++)
                        {
                            yFilt[i] = yFilt[i + 1];
                            yOut = yOut + yFilt[i];
                        }
                        yOut = yOut / 6;
                        axis2AccelTxt.Text = e.Acceleration.ToString();
                        break;
                    case 2:
                        zOut = 0;
                        zFilt[6] = e.Acceleration;
                        for (i = 0; i < 6; i++)
                        {
                            zFilt[i] = zFilt[i + 1];
                            zOut = zOut + zFilt[i];
                        }
                        zOut = zOut / 6;
                        axis3AccelTxt.Text = e.Acceleration.ToString();
                        break;
                }
            }
            catch (PhidgetException ex)
            {
                MessageBox.Show(ex.Description);
            }

            xOld = xCenter - (float)xOut * circleRadius;
            yOld = yCenter + (float)yOut * circleRadius;

            accelGraphicsBuffer.Graphics.DrawLine(xyAxisPen, xCenter, yCenter, xOld, yOld);
            accelGraphicsBuffer.Graphics.DrawEllipse(circlePen, circleRectangle);

            if (attached.axes.Count == 3)
            {
                if (zOut > 0)
                {
                    accelGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Red, 2),
                        new Rectangle((int)xCenter - (int)(circleRadius * zOut), (int)yCenter - (int)(circleRadius * zOut),
                        (int)(circleDiameter * zOut), (int)(circleDiameter * zOut)));
                }
                else
                {
                    accelGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Green, 2),
                        new Rectangle((int)xCenter - (int)(circleRadius * -zOut), (int)yCenter - (int)(circleRadius * -zOut),
                        (int)(circleDiameter * -zOut), (int)(circleDiameter * -zOut)));
                }
            }

            accelGraphicsBuffer.Render(panel1.CreateGraphics());

            accelGraphicsBuffer.Dispose();

            accelGraphicsContext.Dispose();
        }
 //Acceleration change event handler...Display which axis the device is
 //accelerating in as well as the measured acceleration value
 static void accel_AccelerationChange(object sender, 
                                         AccelerationChangeEventArgs e)
 {
     Console.WriteLine("Axes {0} Acceleration {1}", e.Index, e.Acceleration);
 }
示例#7
0
        //acceleration change event handler
        void accel_AccelerationChange(object sender, AccelerationChangeEventArgs e)
        {
            //get our graphics buffer going so we can draw to our panel
            accelGraphicsContext = new BufferedGraphicsContext();
            accelGraphicsBuffer  = accelGraphicsContext.Allocate(Graphics.FromImage(accelDrawingSurface), boundsRectangle);
            accelGraphicsBuffer.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            accelGraphicsBuffer.Graphics.Clear(SystemColors.Control);

            Accelerometer attached = (Accelerometer)sender;

            //in this switch statement we will do a bit of simple low pass filtering to smooth out the motion of the graphical representation of the
            //acceleration data.  We will also write the raw data to the textbox for the appropriate axis.
            int i = 0;

            try
            {
                switch (e.Index)
                {
                case 0:
                    xOut     = 0;
                    xFilt[6] = e.Acceleration;
                    for (i = 0; i < 6; i++)
                    {
                        xFilt[i] = xFilt[i + 1];
                        xOut     = xOut + xFilt[i];
                    }
                    xOut = xOut / 6;
                    axis1AccelTxt.Text = e.Acceleration.ToString();
                    break;

                case 1:
                    yOut     = 0;
                    yFilt[6] = e.Acceleration;
                    for (i = 0; i < 6; i++)
                    {
                        yFilt[i] = yFilt[i + 1];
                        yOut     = yOut + yFilt[i];
                    }
                    yOut = yOut / 6;
                    axis2AccelTxt.Text = e.Acceleration.ToString();
                    break;

                case 2:
                    zOut     = 0;
                    zFilt[6] = e.Acceleration;
                    for (i = 0; i < 6; i++)
                    {
                        zFilt[i] = zFilt[i + 1];
                        zOut     = zOut + zFilt[i];
                    }
                    zOut = zOut / 6;
                    axis3AccelTxt.Text = e.Acceleration.ToString();
                    break;
                }
            }
            catch (PhidgetException ex)
            {
                MessageBox.Show(ex.Description);
            }

            xOld = xCenter - (float)xOut * circleRadius;
            yOld = yCenter + (float)yOut * circleRadius;

            accelGraphicsBuffer.Graphics.DrawLine(xyAxisPen, xCenter, yCenter, xOld, yOld);
            accelGraphicsBuffer.Graphics.DrawEllipse(circlePen, circleRectangle);

            if (attached.axes.Count == 3)
            {
                if (zOut > 0)
                {
                    accelGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Red, 2),
                                                             new Rectangle((int)xCenter - (int)(circleRadius * zOut), (int)yCenter - (int)(circleRadius * zOut),
                                                                           (int)(circleDiameter * zOut), (int)(circleDiameter * zOut)));
                }
                else
                {
                    accelGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Green, 2),
                                                             new Rectangle((int)xCenter - (int)(circleRadius * -zOut), (int)yCenter - (int)(circleRadius * -zOut),
                                                                           (int)(circleDiameter * -zOut), (int)(circleDiameter * -zOut)));
                }
            }

            accelGraphicsBuffer.Render(panel1.CreateGraphics());

            accelGraphicsBuffer.Dispose();

            accelGraphicsContext.Dispose();
        }
示例#8
0
 void AccelerationChange(object sender, AccelerationChangeEventArgs e)
 {
     FChanged = true;
 }
        private void ChangeAcceleration(string[] acceleration)
        {
            AccelerationChangeEventArgs AccelerationEvents = new AccelerationChangeEventArgs(acceleration);

            // Now, raise the event by invoking the delegate. Pass in
            // the objects that initiated the event (this) as wel as
            // AccelerationChangeEventArgs.
            // The call must match the signature of the AccelerationChangeEventHandler.
            if (AccelerationChange != null)
            {
                AccelerationChange(this, AccelerationEvents);
            }
        }