我有一个hardware device,提供它的供应商提供了一些C代码来监听使用ioctl的按钮按下。该设备有一个SSD1289控制器。在Push buttons require no additional pins, their status canbe read over SPI.
这就是我想要的,看看是哪个按钮被按下的。在
我正试图在Python中为我自己的应用程序复制这个脚本,但IOR和ioctl的要求让我很困惑。在#include
#include
#include
#include
#include
#include
#define SSD1289_GET_KEYS _IOR('keys', 1, unsigned char *)
void get_keys(int fd)
{
unsigned char keys;
if (ioctl(fd, SSD1289_GET_KEYS, &keys) == -1)
{
perror("_apps ioctl get");
}
else
{
printf("Keys : %2x\n", keys);
}
}
int main(int argc, char *argv[])
{
char *file_name = "/dev/fb1";
int fd;
fd = open(file_name, O_RDWR);
if (fd == -1)
{
perror("_apps open");
return 2;
}
while(1)
get_keys(fd);
printf("Ioctl Number: (int)%d (hex)%x\n", SSD1289_GET_KEYS, SSD1289_GET_KEYS);
close (fd);
return 0;
}
现在我知道Python有一个ioctl模块,在某个时候我应该调用
^{pr2}$
我不知道SSD1289_GET_KEYS应该是什么。我怎么得到这个,什么是_IOR?在
另外,如果这是一个错误的方法,知道这将是一个帮助。有一些像spidev这样的库应该是针对SPI的,但是我不知道用它读什么。在
@alexis在下面提供了一些有用的步骤,让我走到了这一步:import fcntl
import array
file = open("/dev/fb1")
buf = array.array('h', [0])
fcntl.ioctl(file, -444763391, buf, 1)
现在,按一个按钮改变buf的值,如果我保持上面的循环。在