C++ raspberry pi 3 b时钟问题使用.tv_usec
当.tv_usec替换为.tv_sec时,代码工作正常 需要更高的精度秒到小数点 如果这可能是pis时钟的问题,请使用措辞 代码最终用于计算bpm,但当前用于计算两次单击之间的时间C++ raspberry pi 3 b时钟问题使用.tv_usec,c++,raspberry-pi,clock,C++,Raspberry Pi,Clock,当.tv_usec替换为.tv_sec时,代码工作正常 需要更高的精度秒到小数点 如果这可能是pis时钟的问题,请使用措辞 代码最终用于计算bpm,但当前用于计算两次单击之间的时间 gboolean tapTemp(GtkButton *button, gpointer user_data) { //errorMsg = bmp; if(tapdown) { tapdown = false; clock_gettime(CLO
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;
}
}
tv\u nsec将每秒返回到零-以使持续递增的时间与tv\u秒相结合,例如ThistTime=beetTime.tv\u秒+0.001*(beetTime.tv\u nsec/1000000)以获得最接近的毫秒。您确定tv\u usec存在吗?我在这里找不到它的定义:。尝试改用tv\u nsec。抱歉,必须使用n秒输出错误的类型