KIR Mode1 Functions.ino
There are 5 modes pre-defined in the reference firmware. (1 to 5). The number of modes used is defined in the file [KIR_header.h] in definition modeCount. The offset definition for MODE1 is 0 and each subsequent mode is offset by an additional 49. See definitions for MODE1-5 in the same header file.
At the top of each MODE file, there is a ‘#define’ similar to:
#define DFN(b) fn##b##m1 // e.g. this expands to fnPOWERm1, below for POWER button
- b is the button ID as defined in the header file above (e.g. POWER - without the leading 'b' in bPOWER).
- DFN is a macro which converts an easy to maintain pseudo function name and translates it to a unique function name for that MODE.
- So DFN(POWER) for MODE1 gets converted to fnPOWERm1 (m1 denotes Mode1, POWER is the button id and fn indicates a function). You should just use the easy to read DFN(POWER) style at all times.
- These function definitions are used in the Mode files and also the KIR_buttons.ino file (where they are called from, based on the button ID & mode # offset = using an array of function pointers).
Each defined/configured mode has its own file for the 49 functions called when each button is pressed.
KIR_Mode1_Funtions.ino KIR_Mode2_Funtions.ino KIR_Mode3_Funtions.ino KIR_Mode4_Funtions.ino KIR_Mode5_Funtions.ino
If you want to add more modes/devices:
- Create a new file, KIR_Mode6_Functions.ino etc
- Set DMODE to 6 etc in this file
- Change modeCount to 6 etc (KIR_header.h)
- In file KIR_buttons.ino, add in the following lines
// MODE6 function pointer definitions FN6(POWER), FN6(DVD), FN6(SAT), FN6(TV), FN6(MUTE), FN6(TVAV), FN6(BRIGHTUP), // Col 1 FN6(BRIGHTDOWN), FN6(PNS), FN6(FWD), FN6(REW), FN6(PROGUP), FN6(PREV), FN6(VOLUP), // Col 2 FN6(PROGDOWN), FN6(NEXT), FN6(VOLDOWN), FN6(LR), FN6(UPR), FN6(UPL), FN6(MENU), // Col 3 FN6(RIGHTU), FN6(OK), FN6(LEFTU), FN6(RIGHTD), FN6(LEFTD), FN6(DOWNR), FN6(DOWNL), // Col 4 FN6(EXIT), FN6(CANCEL), FN6(CLOCK), FN6(INFO), FN6(ZOOM), FN6(BLUE), FN6(YELLOW), // Col 5 FN6(GREEN), FN6(RED), FN6(b3), FN6(b2), FN6(b1), FN6(b6), FN6(b5), // Col 6 FN6(b4), FN6(b9), FN6(b8), FN6(b7), FN6(RETURN), FN6(b0), FN6(TENPLUS) // Col 7
- Pay attention to add a comma to the previous line in the array
- Also add in a line at the top of the file to define FN6
#define FN6(b) fn##b##m6 //e.g. this expands to fnPOWERm6, below for POWER button
- Update all of the functions in KIR_Mode6_Functions to operate as you require, usually to send your own set of signals.
For Mode 1 only, there is a special function included called fnNULL which is associated with any button that is not programmed for action when pressed. This NULL function essentially does nothing (except in debug mode where a message is output over serial). The same function fnNULL is called in any/all mode(s) when pressing a button does not require any action.
Also, for Mode 1 only - there are 4 special buttons 1,3,7,9 which are used when pressed in sequence to stop the device form sleeping. This allows the bootloader to activate reliably. This feature is only active when powered from USB and does not operate when running from 2xAAA batteries. Ensure that this feature is retained in Mode1.
Switching Mode / Device
In the reference firmware there are 3 special buttons to change modes (or devices):
- TV button
- SAT button
- DVD button
In simple terms, pressing TV sets MODE1, pressing SAT sets MODE2 and pressing DVD sets MODE3. (The term Mode is interchangeable with Device for KontroLIR). However we have extended this such that if SAT is pressed in MODE2 then MODE4 is set and pressing DVD in MODE3 sets MODE5. Users can extend this logic further as desired and use other buttons to set modes as well. In all modes pressing TV sets Mode1, making it easy to get back to a known mode.
The image above shows the new mode entered when one of the mode buttons are pressed in each mode. Users are free to extend this as required using any buttons or combinations.
So as a simple walk thru, pressing SAT in Mode1 runs the following code:
(KIR_Mode1_Functions.ino): altMode = MODE2;
This sets the mode to Mode 2. Once in Mode2 pressing SAT again executes the following code:
(KIR_Mode2_Functions.ino): altMode = MODE4;
This sets the mode to MODE4.
Once in Mode4 pressing SAT again executes the following code:
(KIR_Mode4_Functions.ino): altMode = MODE2;
This sets the mode back to Mode2.
Of course all of the code above is placed within the relevant function for that mode and button.