【问题标题】:how to make the keyboard LED's blink using a linux driver? [closed]如何使用 linux 驱动程序使键盘 LED 闪烁? [关闭]
【发布时间】:2013-06-24 02:20:26
【问题描述】:

我对 linux 驱动程序开发非常陌生。请发布一个代码 sn-p 它将说明 linux 驱动程序以捕获任何键盘按下,这将使 capslk 或 scrllok 或 numlok LED 闪烁。我正在使用带有内核版本 3.5 的 ubuntu 3。提前致谢。

【问题讨论】:

  • 先贴出你试过的代码!
  • @hacks: sree 已经声明他/她对该主题的理解为零。那么,她/他怎么可能在不知道实际要做什么或在哪里查找信息的情况下编写一行代码。
  • 我认为这是一个合理的问题。有人手头有一个明确的特定任务(通过在 Linux 内核下运行的程序使输入设备 LED 闪烁)。但是这个人不知道在哪里寻找信息,使用哪些 API。反对票完全下落不明,并且由于离题而关闭问题是不可接受的。这个问题可以很好的回答。
  • @datenwolf;好的,投票补偿 -ve 票..

标签: c linux keyboard kernel driver


【解决方案1】:

所有相关信息都可以在 Linux 内核源代码树文档中找到。最重要的是$KERNELSRC/Documentation/input/input.txt

5. Event interface
~~~~~~~~~~~~~~~~~~
Should you want to add event device support into any application (X, gpm,
svgalib ...) I <vojtech@ucw.cz> will be happy to provide you any help I
can. Here goes a description of the current state of things, which is going
to be extended, but not changed incompatibly as time goes:

You can use blocking and nonblocking reads, also select() on the
/dev/input/eventX devices, and you'll always get a whole number of input
events on a read. Their layout is:

struct input_event {
  struct timeval time;
  unsigned short type;
  unsigned short code;
  unsigned int value;
};

'time' is the timestamp, it returns the time at which the event happened.
Type is for example EV_REL for relative moment, EV_KEY for a keypress or
release. More types are defined in include/linux/input.h.

'code' is event code, for example REL_X or KEY_BACKSPACE, again a complete
list is in include/linux/input.h.

'value' is the value the event carries. Either a relative change for
EV_REL, absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for
release, 1 for keypress and 2 for autorepeat.

事件代码在 $KERNELSRC/Documentation/input/event-codes.txt

LED 有特殊的事件代码,您不仅可以从/dev/event… 中读取,也可以对其进行写入,使用 LED 事件代码来设置 LED 状态。

【讨论】:

    猜你喜欢
    • 2020-02-02
    • 2021-03-12
    • 2020-01-24
    • 2010-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-17
    相关资源
    最近更新 更多