Help with itimer...

This is a discussion on Help with itimer... within the C Programming forums, part of the General Programming Boards category; I'm trying to get a timer working in C, it was working but the frame rate was hard coded. Now, ...

  1. #1
    Unregistered
    Guest

    Help with itimer...

    I'm trying to get a timer working in C, it was working but the frame rate was hard coded. Now, changing it being read in as an env variable I'm having problems. It's probably something simple =/

    THE WAY IT WAS:

    /* Initialize */
    struct itimerval Frame = {0, 33000, 0, 33000}; /* 30 Hz */

    .....

    setitimer(0, &Frame, (void*) NULL);

    THE WAY IT NEEDS TO BE

    /* Initialize */
    struct itimerval Frame;
    const char *frame_rate_env = "FRAME_RATE";
    long int frame_rate;

    .....

    frame_rate = (1/atoi(getenv (frame_rate_env))) * 1000000;
    Frame = {0, frame_rate, 0, frame_rate} ** I GET A COMPILE PARSE ERROR ON THIS LINE **
    setitimer(0, &Frame, (void*) NULL);

  2. #2
    Unregistered
    Guest
    bah, figured it out, told ya it was simple ;p

    you can't put information into a structure like I tried unless you're initializing it.

    This worked though:

    Frame.it_interval.tv_sec = 0;
    Frame.it_interval.tv_usec = frame_rate;
    Frame.it_value.tv_sec = 0;
    Frame.it_value.tv_usec = frame_rate;


    If someone knows a cleaner way of doing this, let me know please.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21