Start New Discussion within our Software Development Community

I have a project where I'm building a motion-sensing controller. It has around a dozen buttons plus the motion sensors. I'm having it wireless transmit the status of the buttons and sensors to the base station.

I know interrupts are better than polling, but most people seem to recommend polling inside an interrupt to handle updating all buttons. My only issue with that idea is it seems inefficient since those button presses will generate interrupts of their own that become redundant when you've already polled the button.

I was wondering if anyone knows a way to get all the interrupts currently waiting - for example if 2 buttons are pressed at the same time - and process them all at once, then set them all to handled and move on.

And just so no one asks, I don't have any code written. I'm looking for a method, not debugging help.

You need to have almost to threads (or processes) to handle this situation
1) You'll need an interrup server for each source that will receive each interrupt and add the relevant info into a list. During the process of the interrupt you need to discard any other call to the same interrupt using a processing flag.
2) The second will verify if the list is not empty to get the info from position 0 in the list, remove this position from it and process the relevant interrupt (maybe you need a backgroud worker for that process). In this thread, do not forget to call as many DoEvents as you can.

In order to manage the list, you will need an object (generic) to be locked by each process to access the list, then free it.

The list can be an inmemory list or, if you need persistence, and the response time is enough fast, you can use a table in a database to handle the list.

Hope that those ideas help you.

This article has been dead for over six months. Start a new discussion instead.