Switch Matrix Software Problem

This is the English forum for all topics related to IO-Warrior. Please post in English only

Moderator: Guido Körber

Post Reply
pcrichton
Posts: 13
Joined: Thu Jun 18, 2009 5:21 pm

Switch Matrix Software Problem

Post by pcrichton »

I have created a program to read from a matrix of 2x2 switches. I have set it that on the press of a button the program uses IowKitRead to wait for an input from the 2x2 switch matrix that I have built. The program will not go any further without a press from a switch, which I expected to happen, and after a switch is pressed a message box is displayed informing me which switch was pressed. However after that message box is closed, if I then press the button again, the IowKitRead does not wait on the user pressing the button it just steps over it, reading a report ID of 0x19 and setting all elements in the Bytes array to 0x00. This then results in my error message box displaying due to the fact that there is not any data within any of the $19 inputs. When I close that though, the program then runs as normal again, the error seems to only be occurring every two presses of the button, does anyone have any ideas regarding what is causing this??

Thanks, Paul.
Guido Körber
Site Admin
Posts: 2856
Joined: Tue Nov 25, 2003 10:25 pm
Location: Germany/Berlin
Contact:

Re: Switch Matrix Software Problem

Post by Guido Körber »

The key matrix function sends data on changes of the matrix status. Releasing a button is a change in the matrix status, so logically it will send a data set indicating that all buttons are released.
pcrichton
Posts: 13
Joined: Thu Jun 18, 2009 5:21 pm

Re: Switch Matrix Software Problem

Post by pcrichton »

Ofcourse, I get it now. If that is the case, is there any way to clear the memory of the IO warrior so that after the button is pressed and the first message indicating which button has been pressed, the IO warrior is reset and does not remember the changing of state associated with the releasing of the depressed button?

Also, if I were to use a timer along with the IowKitReadNonBlocking, am I correct in saying that this problem would not exist.

Paul
Guido Körber
Site Admin
Posts: 2856
Joined: Tue Nov 25, 2003 10:25 pm
Location: Germany/Berlin
Contact:

Re: Switch Matrix Software Problem

Post by Guido Körber »

Writing your code to properly handle the state changes would be the logical solution, just clearing events is the road to losing the status.
pcrichton
Posts: 13
Joined: Thu Jun 18, 2009 5:21 pm

Re: Switch Matrix Software Problem

Post by pcrichton »

I have another problem with the switch matrix, when I press two switches simultaneously, if they correspond to the same location in the input report, eg. Location 1: [Y0 - X0, Y0 - X1], the report adds the returned values of 01 and 02 in location 1 together, in this case giving the location 1 in the report the value 03, therefore when the timer is called the program thinks that it is reading a different switch input. Is there an easy way to solve this problem. I did notice on the ALL-IN-ONE software, in the switch matrix part, when I press the same two switches simultaneously, it does also return the value 03, but the indicators display the two switches being pressed rather than a different switch, I am assuming it is possible but is something to do with the software, can anyone help?

Thanks,

Paul
Guido Körber
Site Admin
Posts: 2856
Joined: Tue Nov 25, 2003 10:25 pm
Location: Germany/Berlin
Contact:

Re: Switch Matrix Software Problem

Post by Guido Körber »

Do you know what a bitfield is?

The switch matrix data is reported as a packed array of bool. This is the only logical way to handle such data.
pcrichton
Posts: 13
Joined: Thu Jun 18, 2009 5:21 pm

Re: Switch Matrix Software Problem

Post by pcrichton »

I am not very familiar with bit fields, I have a rough idea what they are.

For my program I have used a variable 'report' of type IOWKIT56_SPECIAL_REPORT. I then check with a timer the report.Bytes ( i = 0 .. 7) values read from the switch matrix, then using an if statement I output to a text label which button has been pressed, but when doing so the pressing of two switches simultaneously gives a report of a completely different switch.

Am I going about this the wrong way?
Guido Körber
Site Admin
Posts: 2856
Joined: Tue Nov 25, 2003 10:25 pm
Location: Germany/Berlin
Contact:

Re: Switch Matrix Software Problem

Post by Guido Körber »

Yes, every single bit of the data returned by the switch matrix is an independend data entity. By comparing whole bytes (char) you can only determine IF one or more of the eight buttons reported in that byte has changed. You need to use logical operations to find out which one did actually change. Or you can typecast the data into a packed array of bool.
Post Reply