3个帖子/ 0新
最后一篇
Liuluan002.
离线
最后一次露面:3个月2周前
加入:2015-11-27 14:24
按钮按时间

嗨对话框,

我正在制作一个检测按钮的应用程序(我需要知道按下按钮的时间)。你有解决方案吗?

我填写了以下代码:
空白_Button(空白)
{
if(getBits16(sys_stat_reg,per_is_down))
periph_init();

if((!(getword16(p0_data_reg)&(1 << 0)))))))))
{
keyint_mstime = loop_timer_gettime();
button_flag = 3;
}
wkupct_register_callback(按_Button);
wkupct_enable_irq(0x000001,0x000001,1,0x14);
if(button_flag == 3)
{
#if debug_log3.
printf_string(“flag == 2 \ r \ n”);
UART2_INIT(UART_BAUDRATE_115K2,3);
#万一
}
}

void user_app_init(void)
{
mnf_data_init();
default_app_on_init();
wkupct_register_callback(按_Button);
wkupct_enable_irq(0x000001,0x000001,1,0x14);
}

设备:
mt_dialog.
离线
最后一次露面:5天6小时前
职员
加入:2015-06-08 11:34
嗨Liuluan002,

嗨Liuluan002,

There is an example for a long time press button in the Smart Tag application with a kernel timer if that doens't suit you, i suppose that you can use a h/w timer starting when you hit the button and stopping when release it, the problem is that you will have to stay awake in order for the timer to keep counting, the only timer that is counting while the device is in sleep mode are the kernel timers.

在您放置的代码中,您可以启用中断,当按下按钮时触发,但我不会看到您如何测量时间(loop_timer_gettime?),我想你可以在计时器10ms的最低分辨率下按下按钮时设置一个计时器,并在按钮释放时,计算时间段回调中的时间,您可以读取从计时器增加的值并获得按下按钮的时间。

谢谢mt_dialog.

MAX44
离线
最后一次露面:7个月5天前
加入:2016-02-08 15:58
我会补充一点,我是字段

我会补充一下,我现在是现场测试,现在具有5秒唤醒时间的设备。它的起作用很好地实现它,就像内核定时器建议的MT一样。从用户的角度来看,通过按住按钮直到LED闪烁,您唤醒。在唤醒按钮回调中,我启动1秒钟计时器。在计时器回调中,我检查是否仍然抑制该按钮。如果是,我重新启动计时器并递增第二计数。如果按钮在按钮定时器回调中不活动,则我重置计数器并退出而不重新启动定时器。我处于延长的睡眠模式,所以我只是回去睡觉了。当第二个定时器回调到达五秒计数时,我闪烁LED并继续发射BLE唤醒。

我注意到的一件事是,在我设置的5秒计数中,LED对闪光信号唤醒开始的LED可能明显超过5秒。我假设这是由于处于睡眠模式和一些滞后时间,必须检测并开始处理唤醒按钮。对我来说,这不是问题。它很容易调整定时器和计数器,无论您需要什么。