Note that there are some explanatory texts on larger screens.

plurals
  1. POPython - How can I read input from a device using ioctl or spidev?
    text
    copied!<p>I have a <a href="http://www.raspberrypi.org/phpBB3/viewtopic.php?t=56131&amp;f=93" rel="nofollow">hardware device</a> and the vendor that supplied it gave a bit of C code to listen for button presses which uses <code>ioctl</code>. The device has an SSD1289 controller.</p> <blockquote> <p>Push buttons require no additional pins, their status canbe read over SPI.</p> </blockquote> <p>That's what I want, to read which push button was pressed.</p> <p>I am trying to replicate this script in Python for my own application, but the _IOR and ioctl requirements are throwing me off. </p> <pre><code>#include &lt;stdio.h&gt; #include &lt;sys/types.h&gt; #include &lt;fcntl.h&gt; #include &lt;unistd.h&gt; #include &lt;string.h&gt; #include &lt;sys/ioctl.h&gt; #define SSD1289_GET_KEYS _IOR('keys', 1, unsigned char *) void get_keys(int fd) { unsigned char keys; if (ioctl(fd, SSD1289_GET_KEYS, &amp;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; } </code></pre> <p>Now I know that Python has an <a href="http://docs.python.org/2/library/fcntl.html" rel="nofollow">ioctl</a> module, and at some point I should be calling</p> <pre><code>file = open("/dev/fb1") buf = array.array('h', [0]) fcntl.ioctl(file, ????, buf, 1) </code></pre> <p>I can't figure out what the <code>SSD1289_GET_KEYS</code> is supposed to be. How do I get this and what is <code>_IOR</code>? </p> <p>Also, if this is the wrong approach, knowing that would be a help too. There are libraries such as <a href="http://tightdev.net/SpiDev_Doc.pdf" rel="nofollow">spidev</a> which are supposedly for SPI, but I don't know what to read using it. </p> <hr> <p>@alexis provided some useful steps below, which got me to this point:</p> <pre><code>import fcntl import array file = open("/dev/fb1") buf = array.array('h', [0]) fcntl.ioctl(file, -444763391, buf, 1) </code></pre> <p>Now, pressing a button changes the value of buf if I keep the above in a loop.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload