/** * linedisp_scroll() - scroll the display by a character * @t: really a pointer to the private data structure * * Scroll the current message along the display by one character, rearming the * timer if required.
*/ staticvoid linedisp_scroll(struct timer_list *t)
{ struct linedisp *linedisp = timer_container_of(linedisp, t, timer); unsignedint i, ch = linedisp->scroll_pos; unsignedint num_chars = linedisp->num_chars;
/* update the current message string */ for (i = 0; i < num_chars;) { /* copy as many characters from the string as possible */ for (; i < num_chars && ch < linedisp->message_len; i++, ch++)
linedisp->buf[i] = linedisp->message[ch];
/* wrap around to the start of the string */
ch = 0;
}
/* update the display */
linedisp->ops->update(linedisp);
/* move on to the next character */
linedisp->scroll_pos++;
linedisp->scroll_pos %= linedisp->message_len;
/* rearm the timer */ if (linedisp->message_len > num_chars && linedisp->scroll_rate)
mod_timer(&linedisp->timer, jiffies + linedisp->scroll_rate);
}
/** * linedisp_display() - set the message to be displayed * @linedisp: pointer to the private data structure * @msg: the message to display * @count: length of msg, or -1 * * Display a new message @msg on the display. @msg can be longer than the * number of characters the display can display, in which case it will begin * scrolling across the display. * * Return: 0 on success, -ENOMEM on memory allocation failure
*/ staticint linedisp_display(struct linedisp *linedisp, constchar *msg,
ssize_t count)
{ char *new_msg;
/* stop the scroll timer */
timer_delete_sync(&linedisp->timer);
if (count == -1)
count = strlen(msg);
/* if the string ends with a newline, trim it */ if (msg[count - 1] == '\n')
count--;
/* update the display */
linedisp_scroll(&linedisp->timer);
return 0;
}
/** * message_show() - read message via sysfs * @dev: the display device * @attr: the display message attribute * @buf: the buffer to read the message into * * Read the current message being displayed or scrolled across the display into * @buf, for reads from sysfs. * * Return: the number of characters written to @buf
*/ static ssize_t message_show(struct device *dev, struct device_attribute *attr, char *buf)
{ struct linedisp *linedisp = container_of(dev, struct linedisp, dev);
/** * message_store() - write a new message via sysfs * @dev: the display device * @attr: the display message attribute * @buf: the buffer containing the new message * @count: the size of the message in @buf * * Write a new message to display or scroll across the display from sysfs. * * Return: the size of the message on success, else -ERRNO
*/ static ssize_t message_store(struct device *dev, struct device_attribute *attr, constchar *buf, size_t count)
{ struct linedisp *linedisp = container_of(dev, struct linedisp, dev); int err;
/** * linedisp_register - register a character line display * @linedisp: pointer to character line display structure * @parent: parent device * @num_chars: the number of characters that can be displayed * @ops: character line display operations * * Return: zero on success, else a negative error code.
*/ int linedisp_register(struct linedisp *linedisp, struct device *parent, unsignedint num_chars, conststruct linedisp_ops *ops)
{ int err;
/** * linedisp_unregister - unregister a character line display * @linedisp: pointer to character line display structure registered previously * with linedisp_register()
*/ void linedisp_unregister(struct linedisp *linedisp)
{
device_del(&linedisp->dev);
timer_delete_sync(&linedisp->timer);
put_device(&linedisp->dev);
}
EXPORT_SYMBOL_NS_GPL(linedisp_unregister, "LINEDISP");
MODULE_DESCRIPTION("Character line display core support");
MODULE_LICENSE("GPL");
Messung V0.5
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.