From 3433c9d0f61ba7376484e5721e0b02aa300a5ee5 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Sat, 2 Aug 2008 03:17:14 +0000 Subject: [PATCH] Adjust LED update interval according to need Add new routine compute_redraw_interval, which returns the appropriate interval in milliseconds for updating the LED panel, namely 100ms if there are any downloads, 1000 if the clock is enabled (with a TODO noted to check whether the date format includes seconds), or 0 otherwise to indicate that the LED paanel need not be updated Use the new compute_redraw_interval routine in draw_leds and redraw_leds. This fixes bug 973, "LED indicators wake system up every 100ms". --- src/bfu/leds.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/bfu/leds.c b/src/bfu/leds.c index 8118d52f..a85f2e89 100644 --- a/src/bfu/leds.c +++ b/src/bfu/leds.c @@ -31,8 +31,6 @@ #include "util/time.h" #include "viewer/timer.h" -#define LEDS_REFRESH_DELAY ((milliseconds_T) 100) - /* Current leds allocation: * 0 - SSL connection indicator * 1 - Insert-mode indicator @@ -187,6 +185,21 @@ draw_clock(struct terminal *term, int xpos, int ypos, struct color_pair *color) } #endif +static milliseconds_T +compute_redraw_interval(void) +{ + if (are_there_downloads()) + return 100; + + /* TODO: Check whether the time format includes seconds. If not, + * return milliseconds to next minute. */ + + if (get_leds_clock_enable()) + return 1000; + + return 0; +} + void draw_leds(struct session *ses) { @@ -238,8 +251,12 @@ draw_leds(struct session *ses) end: /* Redraw each 100ms. */ - if (!drawing && redraw_timer == TIMER_ID_UNDEF) - install_timer(&redraw_timer, LEDS_REFRESH_DELAY, redraw_leds, NULL); + if (!drawing && redraw_timer == TIMER_ID_UNDEF) { + milliseconds_T delay = compute_redraw_interval(); + + if (delay) + install_timer(&redraw_timer, delay, redraw_leds, NULL); + } } /* Determine if leds redrawing is necessary. Returns non-zero if so. */ @@ -302,15 +319,18 @@ static void redraw_leds(void *xxx) { struct terminal *term; + milliseconds_T delay; + + redraw_timer = TIMER_ID_UNDEF; if (!get_leds_panel_enable() && get_opt_int("ui.timer.enable", NULL) != 2) { - redraw_timer = TIMER_ID_UNDEF; return; } - install_timer(&redraw_timer, LEDS_REFRESH_DELAY, redraw_leds, NULL); - /* The expired timer ID has now been erased. */ + delay = compute_redraw_interval(); + if (delay) + install_timer(&redraw_timer, delay, redraw_leds, NULL); if (drawing) return; drawing = 1;