Implements the post-acquisition filtering and decoding of the mTouch sensors. More...
#include "mTouch.h"
Go to the source code of this file.
Defines | |
#define | MTOUCH_SENSOR_state (*sensor).state |
#define | MTOUCH_SENSOR_timer (*sensor).timer |
#define | MTOUCH_SENSOR_debounce (*sensor).debounce |
#define | MTOUCH_SENSOR_timeout (*sensor).timeout |
Functions | |
void | mTouch_Init (void) |
Main initialization routine for all mTouch framework modules including the built-in communication module, if enabled. | |
void | mTouch_Decode (void) |
Updates the state of each active-mode sensor using the latest acquisition value. | |
void | mTouch_UpdateBaseline (void) |
Updates the baseline for the given sensor with the given value. | |
void | mTouch_ChangeState (void) |
uint8_t | mTouch_ButtonStateMachine (void) |
Variables | |
Global Sensor Variables | |
These variables store information about the current state of the sensors. They should only ever be updated by the mTouch framework, but may be read globally so that special actions can be taken based on the sensors' status. Refer to the mTouch.h file for more information about these variables. | |
mTouch_State | mTouch_state |
Tracks the state of the mTouch algorithm. | |
mTouch_StateVariables | mTouch_stateVars |
Stores all state-temporary variables to be reinitialized each mode change. | |
uint16_t | mTouch_average [MTOUCH_NUMBER_SENSORS] |
Array to track the unpressed value of each sensor. | |
Constant Threshold Arrays | |
These arrays are stored in program memory at compile time, so they do not require RAM. The downside to this implementation is that their values cannot be updated at runtime. If this is something your application requires, further editing will be needed. | |
const uint16_t | mTouch_pressThreshold [MTOUCH_NUMBER_SENSORS] = PRESS_THRESHOLD_INIT |
Constant array containing the press threshold for each sensor. | |
const uint16_t | mTouch_releaseThreshold [MTOUCH_NUMBER_SENSORS] = RELEASE_THRESHOLD_INIT |
Constant array containing the release threshold for each sensor. |
Implements the post-acquisition filtering and decoding of the mTouch sensors.
Definition in file mTouch.c.
#define MTOUCH_SENSOR_debounce (*sensor).debounce |
#define MTOUCH_SENSOR_state (*sensor).state |
#define MTOUCH_SENSOR_timeout (*sensor).timeout |
#define MTOUCH_SENSOR_timer (*sensor).timer |
uint8_t mTouch_ButtonStateMachine | ( | void | ) |
The default state of all sensors on power up. Once sensors leave this state, they do not return. Initialization begins by decrementing the timer variable for the sensor. If timer has not yet reached 0, the areInitialized and allReleased flags are cleared to prevent any advanced decoding logic, such as sliders and wheels, or communications from occuring. Once timer reaches 0, the sensor transitions to the MTOUCH_RELEASED state, the debounce counter is reset to the value needed to enter the pressed state, and the baseline is updated to equal to the current sensor value.
This state can be entered from either the MTOUCH_INITIALIZING or MTOUCH_PRESSED state. The only way to leave this state is by creating enough consecutive positive shifts of the reading above the baseline to overflow the debounce variable for the sensor. Once this is done, the sensor will enter the pressed state.
The code for this section begins by checking to see if the latest reading is greater than the baseline by at least the press threshold. If it is, the debounce variable is decremented. Once the debounce value has been reached 0, the sensor will change to the MTOUCH_PRESSED state, reset the debounce counter, initialize the press timer (if enabled), toggle the toggle bit, and clear the 'allReleased' flag.
If the threshold has not been crossed, the debounce counter is reset to the initial press debounce value and the baseline is updated.
A sensor can only enter this state from the MTOUCH_RELEASED state, but there are two ways to leave: First, by being in the state for too long and allowing the press timer to run out. Second, by having a the delta value smaller than the release threshold on enough consecutive scans to cause the debounce counter to reach 0.
The code for this section begins by decrementing and checking the timer variable to see if it has reached 0. If so, the sensor transfers to the MTOUCH_RELEASED state, the debounce counter is reset and the baseline is re-initialized to the sensor's current reading. The baseline is reset to allow for a quick recovery if some environmental condition caused the sensor to become stuck. See the NEGATIVE_CAPACITANCE configuration option for the different behaviors that can be implemented to quickly allow the baseline to re-settle to the unpressed value.
If the timer has not yet reached 0, the reading is checked against the release threshold. If the difference between the sensor's reading and the baseline (delta) is less than the release threshold, the debounce variable is decremented in the same manner as the press timer. When it reaches 0, the sensor enters the MTOUCH_RELEASED state and the debounce counter is set to debounce value required to enter the pressed state. If it has not crossed the threshold (meaning: the delta value is still large enough to register as a press), the debounce counter is reset to the release debounce value.
Definition at line 579 of file mTouch.c.
void mTouch_ChangeState | ( | void | ) |
void mTouch_Init | ( | void | ) |
Main initialization routine for all mTouch framework modules including the built-in communication module, if enabled.
1. Loop through all enabled, active sensors and initialize their variables.
2. Loop through all enabled sliders and initialize the slider's output value.
3. Initialize mode variables and flags
4. Initialize non-array system variables
5. Initialize the DACOUT pin when it is used as a guard ring.
6. Initialize the ADC module for mTouch operation.
7. Initialization complete - enable active-mode mTouch scanning.
Definition at line 258 of file mTouch.c.
uint16_t mTouch_average[MTOUCH_NUMBER_SENSORS] |
const uint16_t mTouch_pressThreshold[MTOUCH_NUMBER_SENSORS] = PRESS_THRESHOLD_INIT |
const uint16_t mTouch_releaseThreshold[MTOUCH_NUMBER_SENSORS] = RELEASE_THRESHOLD_INIT |