[UWP] [C#] c#UWP常数,持续3秒 [英] [UWP][C#]c# UWP constant number for 3 seconds

查看:154
本文介绍了[UWP] [C#] c#UWP常数,持续3秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 DataReader r = DataReader.FromBuffer(result.Value);
                    Byte[] b = new byte[result.Value.Length];
                    r.ReadBytes(b);
                    String s = Encoding.ASCII.GetString(b);

                    String[] vals = s.Split(';');
                    String o = "X=" + vals[0] + "  Y=" + vals[1] + "  Z=" + vals[2];


我目前有这个代码显示我的陀螺仪x,y,z三维值。通常,如果设备连接不正确,则所有三个值都将显示为225.0。我如何实现一个代码"如果所有3个值显示225秒3秒,那么它将显示
一个文本,说'正确连接设备'" ?

I have this code currently to display my gyroscope x,y,z 3-dimensional values. Usually, if the device is not connected properly, all three values will show 225.0. How do I implement a code that "if all 3 values shows 225 for 3 seconds, then it will display a text saying 'Connect device properly' " ?

推荐答案

一种方法是使用"deadman timer"。 创建一个每秒一次的计时器。 创建一个整数变量,该变量保存自上次有效数据以来的秒数。 当您获得良好的数据时,您可以设置"deadman"。到0:

One way is to use a "deadman timer".  Create a one-per-second timer.  Create an integer variable that holds the number of seconds since the last valid data.  When you get good data, you set "deadman" to 0:

    if(vals [0]!=" 225.0")

        deadman = 0;

    if( vals[0] != "225.0" )
        deadman = 0;

然后,您的计时器处理程序可以是:

    deadman + = 1;

    if(deadman> = 3)

    {

        textTimeout.Text ="正确连接设备。" ;;
    }

Then, your timer handler can be something like:
    deadman += 1;
    if( deadman >= 3 )
    {
        textTimeout.Text = "Connect device properly.";
    }


这篇关于[UWP] [C#] c#UWP常数,持续3秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆