Jump to navigation Jump to search
Here we provide some commentary about the variables/contants defined in KIR_Vars.h Essentially, all non-local variables are defined here.
- rowPins/colPins - provides a mapping from row/col number (1-7) to Arduino pins. The index is zero based, such that Col1 is at offset 0.
- scanCode - is set in function isButtonPressed every time a button is pressed. It contains a unique code for each logical button made up from col/row number plus the Device Mode offset (altMode). The default of 0xFFFF signifies an invalid button press which will be ignored.
- altMode - This contains the offset for each mode. MODE1 is 0, MODE2 is 49, MODE3 is 93(49*2) etc. These values are pre-configured in KIR_header.h. The value is updated everytime a device mode is changed. This value is used as an offset into the functionPointer array for each button.
- col - contains the value of the col (0-6 for col 1-7). Set in function isButtonPressed every time a button is pressed.
- row - contains the value of the row (0-6 for row 1-7). Set in function isButtonPressed every time a button is pressed.
- toggleFlag - is used to manage signal toggling for subsequent presses of the same button, if the protocol uses toggling. We have demonstrated several uses of this toggle in some extensions to IRremote in file KIR_Infrared_Tx.ino (e.g. for RC5, RC6, MSRC6 etc). If you encounter another protocol using a toggle bit, you can use the same approach and re-use this variable.
- pcIntCol - this is set by the PCINT ISR to indicate the col that caused the latest interrupt. This information is later used in isButtonPressed function to determine which Row was pressed, which then uniquely identifies the button on the remote.
- maxRepeats - this is essentially an array or table of values, one for each remote button and device mode combination. One set of 49 values must be configured for each mode defined (5 in the reference firmware). As can be seen most values are zero, which means that if that button is kept pressed only one IR signal will be sent for each press. If the value is not zero, the signal will be repeated up to that number of times, provided the button is kept pressed. This is a clever way of ensuring that only buttons that need a repeat are repeated and also serves to save battery life, if the remote is left down the side of a couch with pressure on the buttons.
- rptCount - used to keep track of repeat signals sent during a button press.
- KIR_sigTime - used to keep track of elapsed time when sending a signal (compensates for code delays and provides much more accurate signal transmission)
- bootFlag - used to control correct (button press) sequence for signalling that we want to allow extra time for bootloader to kick in.
- usbPowered - used to indicate if we are powered by USB (true) or battery (false).
- vccValue - Keep a record of our VCC. If greater than 4.0V (value of 40) then we are not running on batteries. Otherwise we assume battery operation.
- lowBatteryCheck - contains a counter that means we check for a low battery every n times a button is pressed. Each time it is decremented by 1 and when it reaches zero, we check the battery level and reset the value (to lbCheck which is defined in KIR_header.h). If the battery is too low (bateryLowThreshold) we put KontroLIR to permanent sleep to avoid any potential flash corruption etc.