For a correct reading of the input values an internal state machine handles debouncing and counting.
Files | |
| file | input.c |
| Button routines for input status of eWicht. | |
| file | input.h |
| Input module defines and global function prototypes for eWicht. | |
Defines | |
| #define | BTN_COUNT 0x09 |
| The count of buttons. | |
| #define | ENC_ENDSTOP_MASK 0x01 |
| Flag for configuring the state machine (SM) of the rotary encoder button. | |
| #define | ENC_TURBO_MASK 0x02 |
| Flag for configuring the state machine (SM) of the rotary encoder button. | |
| #define | ENC_NOCHANGE_MASK 0x04 |
| Flag for configuring the state machine (SM) of the rotary encoder button. | |
| #define | BTN_LONG_PUSH_TIME (100u) |
| This value is used to measure the first push time (unit is the cycle call time of the InputMain routine) of a button after a reset of the appropriate state machine and the first push. | |
| #define | BTN_DOUBLE_PUSH_TIME (60u) |
| A button state machine waits between to single pushes until this time is elapsed (unit is the cycle call time of the InputMain routine). | |
Enumerations | |
| enum | eButtonID { PWR_BTN = 0, SEL_BTN, ACC_BTN, FL_BTN, F1_BTN, F2_BTN, F3_BTN, F4_BTN, ENC_BTN, ALL_BTN } |
| IDs for accessing the buttons. More... | |
Functions | |
| void | InputInit (void) |
| Initializes the input module. | |
| void | InputMain (void) |
| The input state machines are feeded, handled and checked. | |
| void | InputButtonReset (eButtonID eBtn) |
| The state machine of the given button will be reseted or all if ALL_BTN is the parameter. | |
| void | InputResetPowerButton (void) |
| The power button state machine is something special and can be reset by this function. | |
| void | InputResetButtonPush (eButtonID eBtn) |
| This function can be used to reset single push events in the state machine. | |
| BOOL | bInputButtonPushedOnce (eButtonID eBtn) |
| The application can ask the input module for a given button if there was a single push since the last call of InputButtonReset. | |
| BOOL | bInputButtonPushedTwice (eButtonID eBtn) |
| The application can ask the input module for a given button if there was a double push since the last call of InputButtonReset or InputInit. | |
| BOOL | bInputButtonPushedLong (eButtonID eBtn) |
| The application can ask the input module for a given button if there was a long push since the last call of InputButtonReset or InputInit. | |
| BOOL | bInputButtonPushed (eButtonID eBtn) |
| This function combines the functions bInputButtonPushedLong, bInputButtonPushedOnce and bInputButtonPushedTwice. | |
| SHORT | s16InputEncoderGetValue (void) |
| This function returns the actual value of rotary encoder state machine. | |
| void | InputEncoderInit (SHORT s16Val, SHORT s16Min, SHORT s16Max, BYTE u8Flags) |
| This function initializes the rotary encoder. | |
| BOOL | bInputEncoderValueChanged (void) |
| This function returns TRUE if the value of rotary encoder state machine has changed after the last call of s16InputEncoderGetValue. | |
| void | InputEncoderSetValue (short s16NewVal, BOOL bRemember) |
| The function sets the internal encoder value to the given value. | |
| void | InputForceChangedEncoderValue (void) |
| After calling this function the function bInputEncoderValueChanged delivers a TRUE when calling after this function call. | |
| BOOL | InputEncoderGetDirection (void) |
| This function delivers the current or last rotary direction of the encoder button. | |
| BYTE | u8InputButtonQuickPushed (void) |
| The function delivers the ID of any pushed quick button (F1-F4). | |
| BOOL | bInputButtonPressed (eButtonID eBtn) |
| The function checks whether the requested button is currently pressed or released. | |
| BOOL | IsEncoderTurning (void) |
| The function checks whether the input encoder is turning. | |
| void | InputInterruptHandler (void) |
| This function handles the periodic requested interrupts. | |
| #define BTN_DOUBLE_PUSH_TIME (60u) |
A button state machine waits between to single pushes until this time is elapsed (unit is the cycle call time of the InputMain routine).
If the time is shorter the SM sets a flag for a double push requestable by bInputButtonPushedTwice.
| #define BTN_LONG_PUSH_TIME (100u) |
This value is used to measure the first push time (unit is the cycle call time of the InputMain routine) of a button after a reset of the appropriate state machine and the first push.
If this time has elapsed, a flag for a long push is set and can requested by bInputButtonPushedLong.
| #define ENC_ENDSTOP_MASK 0x01 |
Flag for configuring the state machine (SM) of the rotary encoder button.
In case the SM detects an over- or underflow it stops the decrement or increment if the ENDSTOP flag is set. If the flag is not set, the encoder value rolls over from maximum to minimum (in case of overflow) or from minimum to maximum (in case of underflow).
| #define ENC_NOCHANGE_MASK 0x04 |
Flag for configuring the state machine (SM) of the rotary encoder button.
In case the flag is set a bInputEncoderValueChanged() call returns FALSE afterwards.
| #define ENC_TURBO_MASK 0x02 |
| enum eButtonID |
IDs for accessing the buttons.
| BOOL bInputButtonPressed | ( | eButtonID | eBtn | ) |
The function checks whether the requested button is currently pressed or released.
The request is done independently of the button state machine due the direct button value access.
| TRUE | The requested button is currently pressed. | |
| FALSE | The requested button is currently released. |
| BOOL bInputButtonPushed | ( | eButtonID | eBtn | ) |
This function combines the functions bInputButtonPushedLong, bInputButtonPushedOnce and bInputButtonPushedTwice.
The caller can test for a push button event if the detailed source is not important.
| eBtn | The button state machine which should be checked for any push. The value ALL_BTN checks if any of the buttons was pushed. |
| TRUE | There was a push since the last InputButtonReset. | |
| FALSE | There was no push since the last InputButtonReset. |
| BOOL bInputButtonPushedLong | ( | eButtonID | eBtn | ) |
The application can ask the input module for a given button if there was a long push since the last call of InputButtonReset or InputInit.
A long push is detected if a button was pushed at least BTN_LONG_PUSH_TIME ms.
| eBtn | The button state machine which should be checked for the long push. The return value for ALL_BTN is meaningless and the behaviour is undefined. |
| TRUE | There was a long push since the last InputButtonReset. | |
| FALSE | There was no long push since the last InputButtonReset. |
| BOOL bInputButtonPushedOnce | ( | eButtonID | eBtn | ) |
The application can ask the input module for a given button if there was a single push since the last call of InputButtonReset.
A single push is detected if a button was pushed at least 8 ms and released afterwards.
| eBtn | The button state machine which should be checked for the single push. The return value for ALL_BTN is meaningless and the behaviour is undefined. |
| TRUE | There was a single push since the last InputButtonReset. | |
| FALSE | There was no single push since the last InputButtonReset. |
| BOOL bInputButtonPushedTwice | ( | eButtonID | eBtn | ) |
The application can ask the input module for a given button if there was a double push since the last call of InputButtonReset or InputInit.
A double push is detected if the state machine has seen two single pushes inbetween a time of BTN_DOUBLE_PUSH_TIME ms.
| eBtn | The button state machine which should be checked for the double push. The return value for ALL_BTN is meaningless and the behaviour is undefined. |
| TRUE | There was a double push since the last InputButtonReset. | |
| FALSE | There was no double push since the last InputButtonReset. |
| BOOL bInputEncoderValueChanged | ( | void | ) |
This function returns TRUE if the value of rotary encoder state machine has changed after the last call of s16InputEncoderGetValue.
| TRUE | The value has changed. | |
| FALSE | The value has not changed. |
| void InputButtonReset | ( | eButtonID | eBtn | ) |
The state machine of the given button will be reseted or all if ALL_BTN is the parameter.
The state machine processes basic inputs like short single pushes (requestable with bInputButtonPushedOnce), single long pushes (requestable with bInputButtonPushedLong) and double short pushes (requestable with bInputButtonPushedTwice). To reset this occured button events the application must call this function.
| eBtn | The button state machine which should be reset. |
| BOOL InputEncoderGetDirection | ( | void | ) |
This function delivers the current or last rotary direction of the encoder button.
| TRUE | The current (or last) rotary direction of the encoder button is right. | |
| FALSE | The current (or last) rotary direction of the encoder button is left. |
| void InputEncoderInit | ( | SHORT | s16Val, | |
| SHORT | s16Min, | |||
| SHORT | s16Max, | |||
| BYTE | u8Flags | |||
| ) |
This function initializes the rotary encoder.
The state machine of the rotary encoder can be configured in some flags, value range and the start value as well.
| s16Val | Thats the initial start value of the rotary encoder. If the user do not move the encoder after the initialization a call of s16InputEncoderGetValue would return this value. | |
| s16Min | The minimum value of the encoder. The state machine checks for this value to prevent an underflow. | |
| s16Max | The maximum value of the encoder. The state machine checks for this value to prevent an overflow. | |
| u8Flags | Some flags which configure the behaviour on over- and underflow situations. See ENC_ENDSTOP_MASK, ENC_NOCHANGE_MASK and ENC_TURBO_MASK for details. |
| void InputEncoderSetValue | ( | short | s16NewVal, | |
| BOOL | bRemember | |||
| ) |
The function sets the internal encoder value to the given value.
| s16NewVal | The new value for the encoder. | |
| bRemember | If TRUE the function bInputEncoderValueChanged delivers a TRUE when calling after this function call. |
| void InputForceChangedEncoderValue | ( | void | ) |
After calling this function the function bInputEncoderValueChanged delivers a TRUE when calling after this function call.
| void InputInit | ( | void | ) |
| void InputInterruptHandler | ( | void | ) |
| void InputMain | ( | void | ) |
| void InputResetButtonPush | ( | eButtonID | eBtn | ) |
This function can be used to reset single push events in the state machine.
Other events like long and double pushes are not affected. If the application also waits for this events it should use InputButtonReset rather than this function to prevent missing them.
| eBtn | The button state machine which single push flag should be reset. The return value for ALL_BTN is meaningless and the behaviour not defined. |
| void InputResetPowerButton | ( | void | ) |
The power button state machine is something special and can be reset by this function.
The power button is not only used for normal application. The input module has a special state machine for this button to react on long pushes. After a long push was noticed by the state machine and processed by the application it should acknowledged and reseted by call of InputResetPowerButton. In fact the power button has two state machines. The first one is handled like the other push buttons and can be reset due a call of InputButtonReset. The second one handles only single long pushes which are used by eWicht to handle power on and off. This SM is divorced from the first SM to prevent missing long pushes. Single and double pushes are not affected.
| BOOL IsEncoderTurning | ( | void | ) |
| SHORT s16InputEncoderGetValue | ( | void | ) |
This function returns the actual value of rotary encoder state machine.
| BYTE u8InputButtonQuickPushed | ( | void | ) |
The function delivers the ID of any pushed quick button (F1-F4).
1.5.5