[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
|
#endif
|
||||||
|
|
||||||
if (s_editMode>0 && event==EVT_ROTARY_RIGHT) {
|
if (s_editMode>0 && event==EVT_ROTARY_RIGHT) {
|
||||||
do {
|
newval += min<int>(rotencSpeed, i_max-val);
|
||||||
if (IS_KEY_REPT(event) && (i_flags & INCDEC_REP10)) {
|
while (isValueAvailable && !isValueAvailable(newval) && newval<=i_max) {
|
||||||
newval += min(10, i_max-val);
|
newval++;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
newval++;
|
|
||||||
}
|
|
||||||
} while (isValueAvailable && !isValueAvailable(newval) && newval<=i_max);
|
|
||||||
if (newval > i_max) {
|
if (newval > i_max) {
|
||||||
newval = val;
|
newval = val;
|
||||||
AUDIO_KEY_ERROR();
|
AUDIO_KEY_ERROR();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (s_editMode>0 && event==EVT_ROTARY_LEFT) {
|
else if (s_editMode>0 && event==EVT_ROTARY_LEFT) {
|
||||||
do {
|
newval -= min<int>(rotencSpeed, val-i_min);
|
||||||
if (IS_KEY_REPT(event) && (i_flags & INCDEC_REP10)) {
|
while (isValueAvailable && !isValueAvailable(newval) && newval>=i_min) {
|
||||||
newval -= min(10, val-i_min);
|
newval--;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
newval--;
|
|
||||||
}
|
|
||||||
} while (isValueAvailable && !isValueAvailable(newval) && newval>=i_min);
|
|
||||||
if (newval < i_min) {
|
if (newval < i_min) {
|
||||||
newval = val;
|
newval = val;
|
||||||
AUDIO_KEY_ERROR();
|
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_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))
|
#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 int32_t rotencValue;
|
||||||
|
extern uint32_t rotencSpeed;
|
||||||
|
#define ROTENC_LOWSPEED 1
|
||||||
|
#define ROTENC_MIDSPEED 10
|
||||||
|
#define ROTENC_HIGHSPEED 100
|
||||||
void checkRotaryEncoder(void);
|
void checkRotaryEncoder(void);
|
||||||
|
|
||||||
// WDT driver
|
// WDT driver
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* Copyright (C) OpenTX
|
* Copyright (C) OpenTX
|
||||||
*
|
*
|
||||||
* Based on code named
|
* 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
|
* er9x - http://code.google.com/p/er9x
|
||||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||||
*
|
*
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../../opentx.h"
|
#include "opentx.h"
|
||||||
|
|
||||||
uint32_t readKeys()
|
uint32_t readKeys()
|
||||||
{
|
{
|
||||||
@@ -91,6 +91,11 @@ uint8_t keyDown()
|
|||||||
|
|
||||||
int32_t rotencValue;
|
int32_t rotencValue;
|
||||||
uint32_t rotencPosition;
|
uint32_t rotencPosition;
|
||||||
|
uint32_t rotencSpeed = ROTENC_LOWSPEED;
|
||||||
|
|
||||||
|
#define ROTENC_DELAY_MIDSPEED 10
|
||||||
|
#define ROTENC_DELAY_HIGHSPEED 5
|
||||||
|
|
||||||
void checkRotaryEncoder()
|
void checkRotaryEncoder()
|
||||||
{
|
{
|
||||||
register uint32_t newpos = ROTARY_ENCODER_POSITION();
|
register uint32_t newpos = ROTARY_ENCODER_POSITION();
|
||||||
@@ -119,6 +124,7 @@ void readKeysAndTrims()
|
|||||||
static rotenc_t rePreviousValue;
|
static rotenc_t rePreviousValue;
|
||||||
rotenc_t reNewValue = (rotencValue / 2);
|
rotenc_t reNewValue = (rotencValue / 2);
|
||||||
int8_t scrollRE = reNewValue - rePreviousValue;
|
int8_t scrollRE = reNewValue - rePreviousValue;
|
||||||
|
static uint32_t lastTick = 0;
|
||||||
if (scrollRE) {
|
if (scrollRE) {
|
||||||
rePreviousValue = reNewValue;
|
rePreviousValue = reNewValue;
|
||||||
if (scrollRE < 0) {
|
if (scrollRE < 0) {
|
||||||
@@ -127,6 +133,14 @@ void readKeysAndTrims()
|
|||||||
else {
|
else {
|
||||||
putEvent(EVT_ROTARY_RIGHT);
|
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();
|
in = readTrims();
|
||||||
|
|||||||
Reference in New Issue
Block a user