0

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;
    }

 }

1 Answers1

0

tv_nsec will wrap back to zero every second - to make a continually incrementing time combine with tv_sec, e.g. thistime = beetTime.tv_secs+0.001*(beetTime.tv_nsec/1000000) to get the nearest millisecond.