2023-10-16 14:29:23 -07:00
|
|
|
/*
|
2023-10-19 16:20:41 -07:00
|
|
|
* userio.c: reacting when you fiddle with buttons, switches, and knobs
|
2023-10-16 14:29:23 -07:00
|
|
|
*
|
|
|
|
* mode switch: modes are changed only when the button is not being
|
|
|
|
* pushed, as button being pushed negates the mode switch response.
|
|
|
|
* for the mode to change, the mode switch must be in the new position
|
|
|
|
* without wavering for at least 3 rounds. this will prevent the
|
|
|
|
* mode from changing by someone fucking around with the button or
|
|
|
|
* when the button is used normally.
|
|
|
|
*
|
|
|
|
* button: is connected to mode switch ADC. if below threshold, then
|
|
|
|
* we can be certain button is pushed. we still wait a debounce
|
|
|
|
* round to ensure button is pushed. our code can fire events on
|
|
|
|
* either button being held or button being released. the actual
|
|
|
|
* push event does not do anything with this code.
|
|
|
|
*
|
|
|
|
* settings knobs: these are used by the settings module which works
|
|
|
|
* with the other modules and the button for setting user settings.
|
|
|
|
* the values are scaled from the ADC value, with bounds being set
|
|
|
|
* on the low and high ends and further scaled for usability.
|
|
|
|
* please read the manual if you want to know what settings do.
|
|
|
|
*
|
|
|
|
* file creation: 20231015 0122
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MODE_CONT 0
|
2023-10-19 16:20:41 -07:00
|
|
|
#define MODE_CONT_TARGET (4096 * (1 - (1 / 4)))
|
2023-10-16 14:29:23 -07:00
|
|
|
|
|
|
|
#define MODE_FUN 1
|
2023-10-19 16:20:41 -07:00
|
|
|
#define MODE_FUN_TARGET (4096 * (1 - (1 / 3)))
|
2023-10-16 14:29:23 -07:00
|
|
|
|
|
|
|
#define MODE_DIODE 2
|
2023-10-19 16:20:41 -07:00
|
|
|
#define MODE_DIODE_TARGET (4096 * (1 - (1 / 2)))
|
2023-10-16 14:29:23 -07:00
|
|
|
|
2023-10-19 16:20:41 -07:00
|
|
|
#define MODE_HYSTERESIS 60 // 3x worst case expected (1% tol)
|
2023-10-16 14:29:23 -07:00
|
|
|
|
2023-10-19 16:20:41 -07:00
|
|
|
#define MODE_ANALOG_MIN 20
|
2023-10-16 14:29:23 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-19 16:20:41 -07:00
|
|
|
uint8_t mode;
|
|
|
|
uint8_t mode_next;
|
|
|
|
uint8_t mode_count;
|
|
|
|
static const uint16_t mode_targets[] = {
|
|
|
|
MODE_CONT_TARGET, MODE_FUN_TARGET, MODE_DIODE_TARGET
|
|
|
|
};
|
2023-10-16 14:29:23 -07:00
|
|
|
|
|
|
|
uint8_t knob[2];
|
|
|
|
|
|
|
|
uint8_t btn = 0;
|
|
|
|
uint16_t btn_held = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-19 16:20:41 -07:00
|
|
|
void userio_update()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-10-16 14:29:23 -07:00
|
|
|
void userio_parse()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|