Commit 48cfae4b authored by Pavel Semerad's avatar Pavel Semerad
Browse files

change value of momentary buttons only when state changes, for 2-state keys...

change value of momentary buttons only when state changes, for 2-state keys remember last state of buttons and switch it depending on that state
parent b27ac1a9
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
added globally settable key long-press delay added globally settable key long-press delay
when using trims, longer beep at value reset and short pause ignoring keys when using trims, longer beep at value reset and short pause ignoring keys
momentary trims/keys now sets value only when state of buttons changed
(previously it always forced value to reflect button state), so it is
possible to map momentary and non-momentary keys to the same
channel/mix value
*0.2.0 (9 Jun 2011) *0.2.0 (9 Jun 2011)
......
2-state keys 2-state keys
add possibility of set value/return to previous value add possibility of set value/return to previous value
add DIG as key function, also for SWItch allow set reverse for SWItch allow set reverse
trims add DIG as key function
when momentary, add possibility return to previous value
MOMentary trims/keys
change value only when state of button change
add multi-position add multi-position
select channel select channel
...@@ -24,7 +20,6 @@ Some suggestions taken from manuals of other radios: ...@@ -24,7 +20,6 @@ Some suggestions taken from manuals of other radios:
timer - up/down/lap/lap navigate - buttons LAP START, LAP RESET timer - up/down/lap/lap navigate - buttons LAP START, LAP RESET
--- ---
? multi-speed transmission - ability to set exact positions
? CH3-8 position settable from menu ? CH3-8 position settable from menu
programmable mixes programmable mixes
throttle speed 1-3 SPEED 1-100%, trigger points 1-100 throttle speed 1-3 SPEED 1-100%, trigger points 1-100
......
...@@ -89,11 +89,11 @@ typedef struct { // unused parts are to match with config_key_map_s ...@@ -89,11 +89,11 @@ typedef struct { // unused parts are to match with config_key_map_s
typedef struct { typedef struct {
u8 function:6; u8 function:6;
u8 momentary:1; u8 reverse:1;
u8 is_trim:1; u8 is_trim:1;
u8 function_long:6; u8 function_long:6;
u8 reverse:1; u8 reverse_long:1;
u8 unused:1; u8 momentary:1;
} config_key_map_s; } config_key_map_s;
#define NUM_TRIMS 4 #define NUM_TRIMS 4
......
...@@ -108,7 +108,8 @@ void menu_load_model(void) { ...@@ -108,7 +108,8 @@ void menu_load_model(void) {
menu_4WS_crab = 0; menu_4WS_crab = 0;
menu_DIG_mix = 0; menu_DIG_mix = 0;
// set other values: mixers, ... // set state of buttons to do initialize
menu_buttons_initialize();
// apply config to radio setting // apply config to radio setting
apply_model_config(); apply_model_config();
......
...@@ -66,6 +66,19 @@ extern s8 menu_4WS_mix; // mix -100..100 ...@@ -66,6 +66,19 @@ extern s8 menu_4WS_mix; // mix -100..100
extern _Bool menu_4WS_crab; // when 1, crab steering extern _Bool menu_4WS_crab; // when 1, crab steering
extern s8 menu_DIG_mix; // mix -100..100 extern s8 menu_DIG_mix; // mix -100..100
extern @near u8 menu_buttons_state[]; // last state of button
#define MBS_INITIALIZE 0xff
// for momentary keys
#define MBS_RELEASED 0x01
#define MBS_PRESSED 0x02
#define MBS_MIDDLE 0x03
// for momentary trims
#define MBS_LEFT 0x04
#define MBS_RIGHT 0x05
// for switched keys
#define MBS_ON 0x40
#define MBS_ON_LONG 0x80
...@@ -107,6 +120,7 @@ extern const u16 et_buttons[][2]; ...@@ -107,6 +120,7 @@ extern const u16 et_buttons[][2];
extern void menu_mix(void); extern void menu_mix(void);
extern void menu_key_mapping(void); extern void menu_key_mapping(void);
extern void menu_key_mapping_prepare(void); extern void menu_key_mapping_prepare(void);
extern void menu_buttons_initialize(void);
#endif #endif
......
...@@ -378,6 +378,7 @@ void menu_key_mapping(void) { ...@@ -378,6 +378,7 @@ void menu_key_mapping(void) {
lcd_set_blink(LMENU, LB_OFF); lcd_set_blink(LMENU, LB_OFF);
config_model_save(); config_model_save();
apply_model_config(); apply_model_config();
menu_buttons_initialize();
} }
......
...@@ -32,6 +32,16 @@ ...@@ -32,6 +32,16 @@
// last state of buttons
@near u8 menu_buttons_state[NUM_KEYS + 2 * NUM_TRIMS];
// set state of buttons to do initialize
void menu_buttons_initialize(void) {
memset(menu_buttons_state, MBS_INITIALIZE, NUM_KEYS + 2 * NUM_TRIMS);
}
// ********************* TRIMS **************************** // ********************* TRIMS ****************************
...@@ -194,16 +204,23 @@ static u8 menu_popup_et(u8 trim_id) { ...@@ -194,16 +204,23 @@ static u8 menu_popup_et(u8 trim_id) {
// if keys are momentary, show nothing, but set value // if keys are momentary, show nothing, but set value
if (etm->buttons == ETB_MOMENTARY) { if (etm->buttons == ETB_MOMENTARY) {
u8 *mbs = &menu_buttons_state[NUM_KEYS + 2 * trim_id];
if (btns(btn_l)) { if (btns(btn_l)) {
// left // left
if (*mbs == MBS_LEFT) return 0; // already was left
*mbs = MBS_LEFT;
AVAL(etm->reverse ? etf->max : etf->min); AVAL(etm->reverse ? etf->max : etf->min);
} }
else if (btns(btn_r)) { else if (btns(btn_r)) {
// right // right
if (*mbs == MBS_RIGHT) return 0; // already was right
*mbs = MBS_RIGHT;
AVAL(etm->reverse ? etf->min : etf->max); AVAL(etm->reverse ? etf->min : etf->max);
} }
else { else {
// center // center
if (*mbs == MBS_RELEASED) return 0; // already was center
*mbs = MBS_RELEASED;
AVAL(etf->reset); AVAL(etf->reset);
} }
return 0; return 0;
...@@ -397,10 +414,11 @@ typedef struct { ...@@ -397,10 +414,11 @@ typedef struct {
#define KF_NONE 0 #define KF_NONE 0
#define KF_2STATE 0b00000001 #define KF_2STATE 0b00000001
// func flags bits // func flags bits
#define FF_SET 0b00000001 #define FF_NONE 0
#define FF_ON 0b00000010 #define FF_ON 0b00000001
#define FF_REVERSE 0b00000100 #define FF_REVERSE 0b00000010
#define FF_MID 0b00001000 #define FF_MID 0b00000100
#define FF_HAS_MID 0b00001000
#define FF_SHOW 0b10000000 #define FF_SHOW 0b10000000
...@@ -415,20 +433,12 @@ static void kf_set_switch(u8 *id, u8 *param, u8 flags) { ...@@ -415,20 +433,12 @@ static void kf_set_switch(u8 *id, u8 *param, u8 flags) {
if (!etf) return; if (!etf) return;
RVAL(val); RVAL(val);
if (flags & FF_SET) { if (flags & FF_ON)
// set value based on state val = (s8)(flags & FF_REVERSE ? etf->min : etf->max);
if (flags & FF_ON) else
val = (s8)(flags & FF_REVERSE ? etf->min : etf->max); val = (s8)(flags & FF_REVERSE ? etf->max : etf->min);
else // check CH3 midle position
val = (s8)(flags & FF_REVERSE ? etf->max : etf->min); if (flags & FF_MID) val = etf->reset;
// check CH3 midle position
if (flags & FF_MID) val = etf->reset;
}
else {
// switch to opposite value
if (val > etf->reset) val = etf->min;
else val = etf->max;
}
AVAL(val); AVAL(val);
if (flags & FF_SHOW) { if (flags & FF_SHOW) {
...@@ -460,14 +470,11 @@ static void kf_reset(u8 *id, u8 *param, u8 flags) { ...@@ -460,14 +470,11 @@ static void kf_reset(u8 *id, u8 *param, u8 flags) {
// change 4WS crab/no-crab // change 4WS crab/no-crab
static void kf_4ws(u8 *id, u8 *param, u8 flags) { static void kf_4ws(u8 *id, u8 *param, u8 flags) {
if (flags & FF_SET) { if (flags & FF_ON)
if (flags & FF_ON) menu_4WS_crab = (u8)(flags & FF_REVERSE ? 0 : 1);
menu_4WS_crab = (u8)(flags & FF_REVERSE ? 0 : 1);
else
menu_4WS_crab = (u8)(flags & FF_REVERSE ? 1 : 0);
}
else else
menu_4WS_crab ^= 1; menu_4WS_crab = (u8)(flags & FF_REVERSE ? 1 : 0);
if (flags & FF_SHOW) { if (flags & FF_SHOW) {
lcd_7seg(4); lcd_7seg(4);
lcd_chars(menu_4WS_crab ? "CRB" : "NOC"); lcd_chars(menu_4WS_crab ? "CRB" : "NOC");
...@@ -537,6 +544,7 @@ static u8 menu_popup_key(u8 key_id) { ...@@ -537,6 +544,7 @@ static u8 menu_popup_key(u8 key_id) {
key_functions_s *kfl; key_functions_s *kfl;
u8 flags; u8 flags;
u8 is_long = 0; u8 is_long = 0;
u8 *mbs = &menu_buttons_state[key_id];
// do nothing when both short and long set to OFF // do nothing when both short and long set to OFF
if (!km->function && !km->function_long) return 0; if (!km->function && !km->function_long) return 0;
...@@ -547,20 +555,44 @@ static u8 menu_popup_key(u8 key_id) { ...@@ -547,20 +555,44 @@ static u8 menu_popup_key(u8 key_id) {
// check momentary setting // check momentary setting
if (km->function && (kf->flags & KF_2STATE) && km->momentary) { if (km->function && (kf->flags & KF_2STATE) && km->momentary) {
flags = FF_SET; static @near u8 ch3_has_middle; // set to 1 if ch3 have middle state
if (btns(btnx)) flags |= FF_ON; u8 state = MBS_RELEASED; // new button state
if (km->reverse) flags |= FF_REVERSE; flags = FF_NONE;
if (key_id == 0 && adc_ch3_last > 256 && adc_ch3_last < 768)
flags |= FF_MID; if (btns(btnx)) {
kf->func(kf->name, kf->param, flags); // set value to state flags |= FF_ON;
state = MBS_PRESSED;
}
if (key_id == 0 && adc_ch3_last > 256 && adc_ch3_last < 768) {
flags |= FF_MID;
state = MBS_MIDDLE;
ch3_has_middle = 1;
}
// return if button state didn't changed
if (state == *mbs) return 0;
*mbs = state;
if (km->reverse) flags |= FF_REVERSE;
if (ch3_has_middle) flags |= FF_HAS_MID;
// call function to set value
kf->func(kf->name, kf->param, flags);
return 0; return 0;
} }
kfl = &key_functions[km->function_long];
// if button is not initialized, do it
if (*mbs == MBS_INITIALIZE) {
if (km->function && (kf->flags & KF_2STATE))
kf->func(kf->name, kf->param, (u8)(km->reverse ? FF_REVERSE : 0));
if (km->function_long && (kfl->flags & KF_2STATE))
kfl->func(kfl->name, kfl->param,
(u8)(km->reverse_long ? FF_REVERSE : 0));
*mbs = 0; // both are OFF
}
// return when key was not pressed // return when key was not pressed
if (!btn(btnx)) return 0; if (!btn(btnx)) return 0;
kfl = &key_functions[km->function_long];
// remember buttons state // remember buttons state
buttons_state_last = buttons_state & ~btnx; buttons_state_last = buttons_state & ~btnx;
...@@ -578,14 +610,40 @@ static u8 menu_popup_key(u8 key_id) { ...@@ -578,14 +610,40 @@ static u8 menu_popup_key(u8 key_id) {
if (km->function_long && btnl(btnx)) { if (km->function_long && btnl(btnx)) {
// long key press // long key press
key_beep(); key_beep();
kfl->func(kfl->name, kfl->param, FF_SHOW); // switch value flags = FF_SHOW;
if (kfl->flags & KF_2STATE) { // ON/OFF is only for 2-state
if (*mbs & MBS_ON_LONG) {
// is ON, switch to OFF
*mbs &= (u8)~MBS_ON_LONG;
}
else {
// is OFF, switch to ON
*mbs |= MBS_ON_LONG;
flags |= FF_ON;
}
if (km->reverse_long) flags |= FF_REVERSE;
}
kfl->func(kfl->name, kfl->param, flags); // switch value
lcd_update(); lcd_update();
is_long = 1; is_long = 1;
} }
else if (km->function && btn(btnx)) { else if (km->function && btn(btnx)) {
// short key press // short key press
key_beep(); key_beep();
kf->func(kf->name, kf->param, FF_SHOW); // switch value flags = FF_SHOW;
if (kf->flags & KF_2STATE) { // ON/OFF is only for 2-state
if (*mbs & MBS_ON) {
// is ON, switch to OFF
*mbs &= (u8)~MBS_ON;
}
else {
// is OFF, switch to ON
*mbs |= MBS_ON;
flags |= FF_ON;
}
if (km->reverse) flags |= FF_REVERSE;
}
kf->func(kf->name, kf->param, flags); // switch value
lcd_update(); lcd_update();
} }
else { else {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment