为什么鼠标的p-> dx和p-> dy总是为零?

时间:2013-04-14 14:38:56

标签: linux kernel

我在mousedev_packet()的Linux内核源代码中添加了一些跟踪(在mousedev.c中)。当我从内核printk移动鼠标时,我想看到坐标发生变化。但这似乎有点奇怪。

static void mousedev_packet(struct mousedev_client *client,
                signed char *ps2_data)
{
    struct mousedev_motion *p = &client->packets[client->tail];
    int val;
    printk(KERN_WARNING "..................tomxue: case 19.................");

    ps2_data[0] = 0x08 |
        ((p->dx < 0) << 4) | ((p->dy < 0) << 5) | (p->buttons & 0x07);
    ps2_data[1] = mousedev_limit_delta(p->dx, 127);
    ps2_data[2] = mousedev_limit_delta(p->dy, 127);
    p->dx -= ps2_data[1];
    p->dy -= ps2_data[2];
    val = p->dx;
    printk(KERN_WARNING "mousedev_packet: ps2_data[1]=%d ps2_data[2] =%d.................", ps2_data[1], ps2_data[2]);
    printk(KERN_WARNING "mousedev_packet: p->dx=%d p->dy=%d p=%p val=%d.................", p->dx, p->dy, p, val);

dmesg如下:

[  105.631164] mousedev_packet: p->dx=0 p->dy=0 p=dd9b6a10 val=0.................
[  105.631195] mousedev_read data=�s�$......................
[  105.639160] mousedev_packet: ps2_data[1]=-25 ps2_data[2] =3.................
[  105.639160] mousedev_packet: p->dx=0 p->dy=0 p=dd9b6a10 val=0.................
[  105.639190] mousedev_read data=�s�$......................
[  105.647155] mousedev_packet: ps2_data[1]=-26 ps2_data[2] =3.................
[  105.647155] mousedev_packet: p->dx=0 p->dy=0 p=dd9b6a10 val=0.................
[  105.647186] mousedev_read data=�s�$......................
[  105.655151] mousedev_packet: ps2_data[1]=-24 ps2_data[2] =5.................
[  105.655181] mousedev_packet: p->dx=0 p->dy=0 p=dd9b6a10 val=0.................
[  105.655212] mousedev_read data=�s�$......................
[  105.663543] mousedev_packet: ps2_data[1]=-19 ps2_data[2] =6.................
[  105.663543] mousedev_packet: p->dx=0 p->dy=0 p=dd9b6a10 val=0.................
[  105.663574] mousedev_read data=�s�$......................
[  105.671142] mousedev_packet: ps2_data[1]=-17 ps2_data[2] =6.................
[  105.671173] mousedev_packet: p->dx=0 p->dy=0 p=dd9b6a10 val=0.................
[  105.671173] mousedev_read data=�s�$......................
[  105.679168] mousedev_packet: ps2_data[1]=-13 ps2_data[2] =5.................
[  105.679168] mousedev_packet: p->dx=0 p->dy=0 p=dd9b6a10 val=0.................
[  105.679199] mousedev_read data=�s�$......................
[  105.687133] mousedev_packet: ps2_data[1]=-8 ps2_data[2] =3.................
[  105.687164] mousedev_packet: p->dx=0 p->dy=0 p=dd9b6a10 val=0.................
[  105.687194] mousedev_read data=�s�$......................
[  105.695190] mousedev_packet: ps2_data[1]=-4 ps2_data[2] =1.................
[  105.695190] mousedev_packet: p->dx=0 p->dy=0 p=dd9b6a10 val=0.................
[  105.695220] mousedev_read data=�s�$......................
[  105.703155] mousedev_packet: ps2_data[1]=-5 ps2_data[2] =0.................
[  105.703186] mousedev_packet: p->dx=0 p->dy=0 p=dd9b6a10 val=0.................
[  105.703186] mousedev_read data=�......................
[  106.047302] mousedev_packet: ps2_data[1]=0 ps2_data[2] =1.................
[  106.047302] mouMinicom2.5Minicom2.5Minicom2.5sedev_packet: p->dx=0 p->dy=0 p=dd9b6a10 val=0.................
[  106.047332] mousedev_read data......................

正如您所看到的,p->dxp->dy始终为零,为什么?

1 个答案:

答案 0 :(得分:0)

对我有意义。

看看这个输出:

[  105.639160] mousedev_packet: ps2_data[1]=-25 ps2_data[2] =3.................
[  105.639160] mousedev_packet: p->dx=0 p->dy=0 p=dd9b6a10 val=0.................

似乎在这一行

ps2_data[1] = mousedev_limit_delta(p->dx, 127);

p->dx-25,您也将ps2_data[1]设为-25

然后在这一行:

p->dx -= ps2_data[1];

您将p->dx设为p->dx - ps2_data[1]。或者,-25 - -250