I'm delighted that this worked exactly as it seemed it ought to. Just like we did in Part 3, we track the pins states and only push them when there's been a change. But now, when we push the changed pins, we toggle the irq.
When we initialize the state machine, we bind a function, "printFromGet" to the state machine irq. When the irq is toggled, this function is called, and a pointer to the state machine is passed to the function. Then we can call sm.get() to read the new pins values. This is fantastic because python doesn't need to spin checking the pins using the gpio library wasting cpu cycles. When we press a key, python is detoured momentarily to our needed function to handle the pin press, and once it returns, python can resume whatever else it was working on!
Here's a more complete code from the last couple examples.
The last thing I might want to do is sort of look up which pin changed and push an integer value corresponding with the addr of the changed pin so each time I do a get() in python, I get the number of the changed pin.
No comments:
Post a Comment