如何保存不断变化的变量的当前值?

How to save current value of constantly changing variable?

我在 WPF 应用程序的双精度类型变量中存储来自传感器的度数读数,degreeOutput 来自 Thalmic Lab 的 Myo 传感器。存储在变量中的值随着用户移动他们的手臂而不断变化,但我想在人做出 fist 姿势而不是不断变化的值时存储运动中某个点的度数读数。

在我当前的实现中,我触发 degreeOutput 的值显示在 painfulArcStartTbx 中以表示我要测量的弧的起始值,但这不起作用计划中。

相反,当握住拳头时,角度值会输出到文本框,但会不断变化。

我只想在握拳时输出初始读数,而不是之后的任何读数。

弧线的结束读数应该在拳头姿势松开后输出,但我得到与上面相同的行为。

有没有人对我如何只存储握拳时的当前值和放开拳头姿势时的当前值有任何建议?

这是处理度数输出的方法:

private void Myo_OrientationDataAcquired(object sender, OrientationDataEventArgs e)
        {
           App.Current.Dispatcher.Invoke((Action)(() =>
            {

                //need to record degree reading when pose made that
                //signifies begining of painful arc.
                //then specify a second pose that signals the end of
                //painful arc and store arc reading, eg 92dg - 108dg


                //myo indicator must be facing down or degrees will be inverted.
                degreeOutput = ((e.Pitch + PITCH_MIN) * CALLIBRATION_FACTOR);

                degreeOfAbductionTbx.Text = "Degree: " + degreeOutput;

                if(e.Myo.Pose == Pose.Fist)
                {
                    //get the start reading of the painful arc
                    painfulArcStartTbx.Text = "start: " + degreeOutput;

                }
                //then get the finish reading of the painful arc
                //after the fist pose has been let go, indicating
                //end of pain in movement
                else
                {

                    painfulArcEndTbx.Text = "end: " + degreeOutput;

                }




            })); 

        }

我在这里可能完全错了,因为我不知道那个传感器是什么,但你似乎遗漏了一些非常基本的东西:

       private string startingDegree;
       private string endDegree;  
       private void Myo_OrientationDataAcquired(object sender, OrientationDataEventArgs e)
    {
       App.Current.Dispatcher.Invoke((Action)(() =>
        {

            //need to record degree reading when pose made that
            //signifies begining of painful arc.
            //then specify a second pose that signals the end of
            //painful arc and store arc reading, eg 92dg - 108dg


            //myo indicator must be facing down or degrees will be inverted.
            degreeOutput = ((e.Pitch + PITCH_MIN) * CALLIBRATION_FACTOR);

            degreeOfAbductionTbx.Text = "Degree: " + degreeOutput;

            if(e.Myo.Pose == Pose.Fist)
            {
               endDegree = string.Empty;
               if(string.IsNullOrEmpty(startingDegree))
                {
                    startingDegree = "start: " + degreeOutput;
                }

                //get the start reading of the painful arc
                painfulArcStartTbx.Text = startingDegree;

            }
            //then get the finish reading of the painful arc
            //after the fist pose has been let go, indicating
            //end of pain in movement
            else
            {
                startingDegree = string.Empty;
                if(string.IsNullOrEmpty(endDegree))
                {
                    endDegree = "end: " + degreeOutput;
                }
                painfulArcEndTbx.Text = endDegree;

            }




        })); 

    }