//this will spit out a new stats object every 10 seconds of activity but if there is 1 hour of inactivity that will only be represented in 1 stats object
        public void ProcessRawData(RawData data, int[] offset, int thres)
        {
            data.accel_x = data.accel_x - offset[0];
            data.accel_y = data.accel_y - offset[1];
            data.accel_z = data.accel_z - offset[2];

            //before it quit last time this was called it moved the data forward in the buffer
            buff[4] = data;

            for (int i = 0; i < 5; i++)
            {
                if (buff[i] == null)
                {
                    buff[i] = new RawData(0, 0, 0, (long)0); ;
                }
            }

            if (buff[0].accel_z > thres && buff[4].accel_z > thres && (buff[1].accel_z < -1 * thres || buff[2].accel_z < -1 * thres || buff[3].accel_z < -1 * thres))
            {
                int max_cur = Math.Max(buff[0].accel_z, buff[4].accel_z);
                if (buff[1].accel_z < max_cur)
                {
                    buff[1].accel_z = max_cur;
                }
                if (buff[2].accel_z < max_cur)
                {
                    buff[2].accel_z = max_cur;
                }
                if (buff[3].accel_z < max_cur)
                {
                    buff[3].accel_z = max_cur;
                }
            }

            if (buff[0].accel_z < 0)
            {
                buff[0].accel_z = 0;
            }

            //%Second processing cycle on the five samples.
            //%Similar to the first but attempts to remove areas where the accel dropped
            //%below the threshold/2 but is surrounded on either side by values above the
            //%threshold.

            if (buff[0].accel_z >= thres / 2 && buff[4].accel_z >= thres / 2 && (buff[1].accel_z < thres / 2 || buff[2].accel_z < thres / 2 || buff[3].accel_z < thres / 2))
            {
                int max_cur = Math.Max(buff[0].accel_z, buff[4].accel_z);

                if (buff[1].accel_z < max_cur)
                {
                    buff[1].accel_z = max_cur;
                }
                if (buff[2].accel_z < max_cur)
                {
                    buff[2].accel_z = max_cur;
                }
                if (buff[3].accel_z < max_cur)
                {
                    buff[3].accel_z = max_cur;
                }
            }

            //%If the buff point is a value below half the threshold it is set to zero.
            if (buff[0].accel_z < thres / 2)
            {
                buff[0].accel_z = 0;
            }

            //%If there are five zero readings in a row count the next positive reading
            //% as a setp.
            if (zero_count >= 5 && buff[0].accel_z > 0)
            {
                //GUI Update function call.
                if ( StepOccurred != null )
                    StepOccurred(this, new EventArgs());

                StepEventTrigger(buff[0].time, true);
                zero_count = 0;
            }
            else
                StepEventTrigger(buff[0].time, false);

            if (buff[0].accel_z == 0)
            {
                zero_count = zero_count + 1;
            }

            //%Pop the first element off of the Array and move all the elements
            //%up one cell.
            for (int i = 0; i < 4; i++)
            {
                buff[i] = buff[i + 1];
            }
        }
        /// <summary>
        /// If the wii-remotes status changes it means there is a new
        /// accelerometer reading to put on the Queue.
        /// </summary>
        /// <param name="sender">Object initiating the function call.</param>
        /// <param name="args">The wii status message.</param>
        private void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
        {
            RawData sample = new RawData();
            sample.accel_x = args.WiimoteState.AccelState.RawValues.X - args.WiimoteState.AccelCalibrationInfo.X0;
            sample.accel_y = args.WiimoteState.AccelState.RawValues.Y - args.WiimoteState.AccelCalibrationInfo.Y0;
            sample.accel_z = args.WiimoteState.AccelState.RawValues.Z - args.WiimoteState.AccelCalibrationInfo.Z0;

            //get the unix timestamp.
            TimeSpan span = (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime());
            sample.time = (long)span.TotalMilliseconds;

            //Lock the queue while the next sample is added.
            lock (rawDataQueue)
            {
                rawDataQueue.Enqueue(sample);
            }
        }
Beispiel #3
0
        //this will spit out a new stats object every 10 seconds of activity but if there is 1 hour of inactivity that will only be represented in 1 stats object
        public void ProcessRawData(RawData data, int[] offset, int thres)
        {
            data.accel_x = data.accel_x - offset[0];
            data.accel_y = data.accel_y - offset[1];
            data.accel_z = data.accel_z - offset[2];

            //before it quit last time this was called it moved the data forward in the buffer
            buff[4] = data;

            for (int i = 0; i < 5; i++)
            {
                if (buff[i] == null)
                {
                    buff[i] = new RawData(0, 0, 0, (long)0);;
                }
            }


            if (buff[0].accel_z > thres && buff[4].accel_z > thres && (buff[1].accel_z < -1 * thres || buff[2].accel_z < -1 * thres || buff[3].accel_z < -1 * thres))
            {
                int max_cur = Math.Max(buff[0].accel_z, buff[4].accel_z);
                if (buff[1].accel_z < max_cur)
                {
                    buff[1].accel_z = max_cur;
                }
                if (buff[2].accel_z < max_cur)
                {
                    buff[2].accel_z = max_cur;
                }
                if (buff[3].accel_z < max_cur)
                {
                    buff[3].accel_z = max_cur;
                }
            }

            if (buff[0].accel_z < 0)
            {
                buff[0].accel_z = 0;
            }


            //%Second processing cycle on the five samples.
            //%Similar to the first but attempts to remove areas where the accel dropped
            //%below the threshold/2 but is surrounded on either side by values above the
            //%threshold.

            if (buff[0].accel_z >= thres / 2 && buff[4].accel_z >= thres / 2 && (buff[1].accel_z < thres / 2 || buff[2].accel_z < thres / 2 || buff[3].accel_z < thres / 2))
            {
                int max_cur = Math.Max(buff[0].accel_z, buff[4].accel_z);

                if (buff[1].accel_z < max_cur)
                {
                    buff[1].accel_z = max_cur;
                }
                if (buff[2].accel_z < max_cur)
                {
                    buff[2].accel_z = max_cur;
                }
                if (buff[3].accel_z < max_cur)
                {
                    buff[3].accel_z = max_cur;
                }
            }

            //%If the buff point is a value below half the threshold it is set to zero.
            if (buff[0].accel_z < thres / 2)
            {
                buff[0].accel_z = 0;
            }


            //%If there are five zero readings in a row count the next positive reading
            //% as a setp.
            if (zero_count >= 5 && buff[0].accel_z > 0)
            {
                //GUI Update function call.
                if (StepOccurred != null)
                {
                    StepOccurred(this, new EventArgs());
                }

                StepEventTrigger(buff[0].time, true);
                zero_count = 0;
            }
            else
            {
                StepEventTrigger(buff[0].time, false);
            }

            if (buff[0].accel_z == 0)
            {
                zero_count = zero_count + 1;
            }

            //%Pop the first element off of the Array and move all the elements
            //%up one cell.
            for (int i = 0; i < 4; i++)
            {
                buff[i] = buff[i + 1];
            }
        }