Skip to content

Commit 9870334

Browse files
jefflessardandy-shev
authored andcommitted
auxdisplay: linedisp: display static message when length <= display size
Currently, when a message shorter than the display size is written, the content wraps around (e.g., "123" on a 4-digit display shows "1231") without scrolling, which is confusing and unintuitive. Change behavior to display short messages statically with space padding (e.g. "123 ") while only scrolling messages longer than the display width. This provides more natural behavior that aligns with user expectations and current linedisp_display() kernel-doc. The scroll logic is also consolidated into a helper function for clarity. No API changes are introduced. Signed-off-by: Jean-François Lessard <jefflessard3@gmail.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
1 parent 66c9380 commit 9870334

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

drivers/auxdisplay/line-display.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ static struct linedisp *to_linedisp(struct device *dev)
3636
return container_of(dev, struct linedisp, dev);
3737
}
3838

39+
static inline bool should_scroll(struct linedisp *linedisp)
40+
{
41+
return linedisp->message_len > linedisp->num_chars && linedisp->scroll_rate;
42+
}
43+
3944
/**
4045
* linedisp_scroll() - scroll the display by a character
4146
* @t: really a pointer to the private data structure
@@ -67,8 +72,7 @@ static void linedisp_scroll(struct timer_list *t)
6772
linedisp->scroll_pos %= linedisp->message_len;
6873

6974
/* rearm the timer */
70-
if (linedisp->message_len > num_chars && linedisp->scroll_rate)
71-
mod_timer(&linedisp->timer, jiffies + linedisp->scroll_rate);
75+
mod_timer(&linedisp->timer, jiffies + linedisp->scroll_rate);
7276
}
7377

7478
/**
@@ -118,8 +122,16 @@ static int linedisp_display(struct linedisp *linedisp, const char *msg,
118122
linedisp->message_len = count;
119123
linedisp->scroll_pos = 0;
120124

121-
/* update the display */
122-
linedisp_scroll(&linedisp->timer);
125+
if (should_scroll(linedisp)) {
126+
/* display scrolling message */
127+
linedisp_scroll(&linedisp->timer);
128+
} else {
129+
/* display static message */
130+
memset(linedisp->buf, ' ', linedisp->num_chars);
131+
memcpy(linedisp->buf, linedisp->message,
132+
umin(linedisp->num_chars, linedisp->message_len));
133+
linedisp->ops->update(linedisp);
134+
}
123135

124136
return 0;
125137
}
@@ -186,12 +198,12 @@ static ssize_t scroll_step_ms_store(struct device *dev,
186198
if (err)
187199
return err;
188200

201+
timer_delete_sync(&linedisp->timer);
202+
189203
linedisp->scroll_rate = msecs_to_jiffies(ms);
190-
if (linedisp->message && linedisp->message_len > linedisp->num_chars) {
191-
timer_delete_sync(&linedisp->timer);
192-
if (linedisp->scroll_rate)
193-
linedisp_scroll(&linedisp->timer);
194-
}
204+
205+
if (should_scroll(linedisp))
206+
linedisp_scroll(&linedisp->timer);
195207

196208
return count;
197209
}

0 commit comments

Comments
 (0)