[Horus] Rotary encoder now has 3 speeds. To be ported to X9E if it's good
This commit is contained in:
@@ -150,28 +150,20 @@ int checkIncDec(evt_t event, int val, int i_min, int i_max, unsigned int i_flags
|
||||
#endif
|
||||
|
||||
if (s_editMode>0 && event==EVT_ROTARY_RIGHT) {
|
||||
do {
|
||||
if (IS_KEY_REPT(event) && (i_flags & INCDEC_REP10)) {
|
||||
newval += min(10, i_max-val);
|
||||
}
|
||||
else {
|
||||
newval++;
|
||||
}
|
||||
} while (isValueAvailable && !isValueAvailable(newval) && newval<=i_max);
|
||||
newval += min<int>(rotencSpeed, i_max-val);
|
||||
while (isValueAvailable && !isValueAvailable(newval) && newval<=i_max) {
|
||||
newval++;
|
||||
}
|
||||
if (newval > i_max) {
|
||||
newval = val;
|
||||
AUDIO_KEY_ERROR();
|
||||
}
|
||||
}
|
||||
else if (s_editMode>0 && event==EVT_ROTARY_LEFT) {
|
||||
do {
|
||||
if (IS_KEY_REPT(event) && (i_flags & INCDEC_REP10)) {
|
||||
newval -= min(10, val-i_min);
|
||||
}
|
||||
else {
|
||||
newval--;
|
||||
}
|
||||
} while (isValueAvailable && !isValueAvailable(newval) && newval>=i_min);
|
||||
newval -= min<int>(rotencSpeed, val-i_min);
|
||||
while (isValueAvailable && !isValueAvailable(newval) && newval>=i_min) {
|
||||
newval--;
|
||||
}
|
||||
if (newval < i_min) {
|
||||
newval = val;
|
||||
AUDIO_KEY_ERROR();
|
||||
|
||||
@@ -196,6 +196,10 @@ uint32_t readTrims(void);
|
||||
#define DBLKEYS_PRESSED_RGT_UP(in) ((in & (KEYS_GPIO_PIN_RIGHT + KEYS_GPIO_PIN_UP)) == (KEYS_GPIO_PIN_RIGHT + KEYS_GPIO_PIN_UP))
|
||||
#define DBLKEYS_PRESSED_LFT_DWN(in) ((in & (KEYS_GPIO_PIN_LEFT + KEYS_GPIO_PIN_DOWN)) == (KEYS_GPIO_PIN_LEFT + KEYS_GPIO_PIN_DOWN))
|
||||
extern int32_t rotencValue;
|
||||
extern uint32_t rotencSpeed;
|
||||
#define ROTENC_LOWSPEED 1
|
||||
#define ROTENC_MIDSPEED 10
|
||||
#define ROTENC_HIGHSPEED 100
|
||||
void checkRotaryEncoder(void);
|
||||
|
||||
// WDT driver
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
@@ -18,7 +18,7 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "../../opentx.h"
|
||||
#include "opentx.h"
|
||||
|
||||
uint32_t readKeys()
|
||||
{
|
||||
@@ -91,6 +91,11 @@ uint8_t keyDown()
|
||||
|
||||
int32_t rotencValue;
|
||||
uint32_t rotencPosition;
|
||||
uint32_t rotencSpeed = ROTENC_LOWSPEED;
|
||||
|
||||
#define ROTENC_DELAY_MIDSPEED 10
|
||||
#define ROTENC_DELAY_HIGHSPEED 5
|
||||
|
||||
void checkRotaryEncoder()
|
||||
{
|
||||
register uint32_t newpos = ROTARY_ENCODER_POSITION();
|
||||
@@ -119,6 +124,7 @@ void readKeysAndTrims()
|
||||
static rotenc_t rePreviousValue;
|
||||
rotenc_t reNewValue = (rotencValue / 2);
|
||||
int8_t scrollRE = reNewValue - rePreviousValue;
|
||||
static uint32_t lastTick = 0;
|
||||
if (scrollRE) {
|
||||
rePreviousValue = reNewValue;
|
||||
if (scrollRE < 0) {
|
||||
@@ -127,6 +133,14 @@ void readKeysAndTrims()
|
||||
else {
|
||||
putEvent(EVT_ROTARY_RIGHT);
|
||||
}
|
||||
uint32_t delay = get_tmr10ms() - lastTick;
|
||||
lastTick = get_tmr10ms();
|
||||
if (delay < ROTENC_DELAY_HIGHSPEED)
|
||||
rotencSpeed = ROTENC_HIGHSPEED;
|
||||
else if (delay < ROTENC_DELAY_MIDSPEED)
|
||||
rotencSpeed = ROTENC_MIDSPEED;
|
||||
else
|
||||
rotencSpeed = ROTENC_LOWSPEED;
|
||||
}
|
||||
|
||||
in = readTrims();
|
||||
|
||||
Reference in New Issue
Block a user