~audio-recorder/audio-recorder/trunk

« back to all changes in this revision

Viewing changes to src/timer.c

  • Committer: Osmo Antero Maatta
  • Date: 2011-01-23 23:07:10 UTC
  • Revision ID: osmoma@gmail.com-20110123230710-fxko85ouv8rflcaw
Better test for clock-time in timer.c

Show diffs side-by-side

added added

removed removed

Lines of Context:
640
640
    LOG_TIMER("Test clock time: current time is %02d:%02d:%02d  timer setting is %02.0f:%02.0f:%02.0f (day_of_year:%d/%d) diff in seconds:%d\n", 
641
641
               tmp->tm_hour, tmp->tm_min, tmp->tm_sec, tr->val[0], tr->val[1], tr->val[2], tmp->tm_yday, tr->day_of_year, (timer_secs - clock_secs)); 
642
642
 
643
 
    if (clock_secs >= timer_secs && tr->day_of_year != tmp->tm_yday) {
 
643
    // Note:
 
644
    // Do NOT fire if current clock time is 60 minutes or more over the timer value.
 
645
    // Eg. Do not fire if clock time is 14:00:00, and timer setting is:12:10:00 pm. We will assume here that user means 12:10pm tomorrow, not to day.
 
646
 
 
647
    gint64 diff_secs = (clock_secs - timer_secs);
 
648
 
 
649
    gboolean do_action = (diff_secs > 0 && diff_secs < (60 * 60)/*1 HOUR HARD-CODED*/);
 
650
 
 
651
    if (do_action && tr->day_of_year != tmp->tm_yday) {
644
652
 
645
653
        action = tr->action;
646
654
 
647
655
        // Save day_of_year so we know when the clock turns around (to the next day).
648
 
        // This timer command will become valid and fire again.
 
656
        // Then this timer command will become valid and fire again.
649
657
        tr->day_of_year = tmp->tm_yday;
650
658
    }
651
659