简体   繁体   中英

raspberry pi 3 b clock problems using .tv_usec

code works fine when .tv_usec is replaced with .tv_sec

need more accuracy seconds to at lest to decimal points

wording if this my be an issue with the pis clock

code eventually to be used to calculate bpm but currently used to calculate time between clicks

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_nsec将每秒回绕为零-与tv_sec结合使时间不断增加,例如thistime = beetTime.tv_secs + 0.001 *(beetTime.tv_nsec / 1000000)以获取最接近的毫秒数。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM