KIR buttons.ino

From AnalysIR WiKi
Revision as of 04:52, 25 October 2019 by AnalysIR (talk | contribs)
Jump to navigation Jump to search

> KontroLIR Home > back

These functions are related to the up-to 49 buttons on the KontroLIR remote control. In general only the last function below needs to be changed and only if you are changing the number of devices or modes supported from the default of 5. It is OK to leave as is even if you are using less than 5 devices.

initButtons

This function is called during setup, to initialise the GPIOs for all of the row/col matrix pins. Each row/col combination represents one button on the remote. There are 7 rows and 7 columns for a total of up-to 49 buttons on the KontroLIR remote control. COLs are set to INPUT_PULLUP which presents a HIGH on these pins. Rows are set to OUTPUT/LOW such that when a button is pressed a PCINT interrupt is generated on a col pin which wakes the MCU from sleep to allow processing of the functionality programmed for that button press. (Note: After a button is pressed the pinMode of the rows is temporarily changed to figure out which particular button has been pressed.)

isButtonPressed

When the MCU wakes from sleep this function is called to determine if a button has been pressed. The logic as written sets the first button detected as the only button that has been pressed and ignores other buttons when multiple buttons have been pressed together. (Users could extend the logic to support multiple simultaneous button presses if desired).

The first part of this function determines which button has been pressed by setting all ROW pins to INPUT and then setting each row in-turn to LOW to determine which row/col combination (i.e. button) has been pressed. Once detected all of the ROWS are reset to OUTPUT/LOW for the next button press.

If no button press is detected then it is ignored. (Theoretically this could occur if a brief press occurred, of the order of uSecs or less. Under normal circumstances this should not occur.)

Finaly, the scanCode is calculated based on the Row, Col and Device Mode. Once the scanCode is set the function exits.

doButtonPressed

In the main loop, if a button press is detected, the indicator LED is turned ON and this function is called to process the button press. Once this function is completed the LED is turned OFF.

Inside this function we define a flash based array of function pointers, pointing to the function to be called for each button press in each of the configured modes. So for the default 5 modes we have 5*49 pointer entries. This array is laid out in blocks separated by comments for easy editing. There is one block for each configured device mode (49 entries each). The block for mode1 uses FN1, mode 2 uses FN2 etc. If you want to add a 6th block then add in an extra block using FN6 etc. Also, make sure to define FN6 etc. for any additional blocks. (You will also need to add an additional mode file for any extra mode)

> KontroLIR Home > back