代码工作正常
需要更精确的秒数至小数点
如果这是我的pis时钟的问题
的措辞代码最终用于计算bpm,但目前用于计算点击之间的时间
gboolean tapTemp(GtkButton *button, gpointer user_data)
{
//errorMsg = bmp;
if(tapdown)
{
tapdown = false;
clock_gettime(CLOCK_REALTIME, &beetTime);
time_difference = beetTime.tv_nsec;// - start_time;
bpm = time_difference - start_time; //time_difference;
errorMsg = bpm;
}
else
{
tapdown = true;
clock_gettime(CLOCK_REALTIME, &beetTime);
start_time = beetTime.tv_nsec;
errorMsg2 = start_time;
}
}
答案 0 :(得分:0)
tv_nsec将每秒回绕到零 - 以与tv_sec结合的连续递增时间,例如, thistime = beetTime.tv_secs + 0.001 *(beetTime.tv_nsec / 1000000)得到最接近的毫秒。