mirror of
https://github.com/semerad/gt3b.git
synced 2026-02-19 19:11:23 +01:00
lap timer fixups, menu_common() removes all symbols always
This commit is contained in:
17
menu.c
17
menu.c
@@ -187,13 +187,12 @@ static void menu_channel_func(u8 action, menu_channel_t *p) {
|
||||
case MCA_ADC_PRE:
|
||||
menu_set_adc_direction(menu_id);
|
||||
return; // show nothing at ADC_PRE
|
||||
break;
|
||||
case MCA_ADC_POST:
|
||||
// do nothing if left-right didn't changed
|
||||
if (p->last_direction == menu_adc_direction) return;
|
||||
// else show value
|
||||
// else flag it to show value
|
||||
menu_id_set = 1; // flag that new value is showed
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
// show value
|
||||
@@ -202,14 +201,10 @@ static void menu_channel_func(u8 action, menu_channel_t *p) {
|
||||
if (action != MCA_SET_CHG) p->func(menu_id, 0); // skip if changed
|
||||
if (menu_adc_wakeup) {
|
||||
// show arrow
|
||||
if (menu_adc_direction) {
|
||||
if (menu_adc_direction)
|
||||
lcd_segment(LS_SYM_RIGHT, LS_ON);
|
||||
lcd_segment(LS_SYM_LEFT, LS_OFF);
|
||||
}
|
||||
else {
|
||||
else
|
||||
lcd_segment(LS_SYM_LEFT, LS_ON);
|
||||
lcd_segment(LS_SYM_RIGHT, LS_OFF);
|
||||
}
|
||||
}
|
||||
p->last_direction = menu_adc_direction;
|
||||
}
|
||||
@@ -435,10 +430,8 @@ static void sf_speed(u8 channel, u8 change) {
|
||||
cm.thspd_onlyfwd ^= 1;
|
||||
else *addr = (u8)menu_change_val(*addr, 1, 100, SPEED_FAST, 0);
|
||||
}
|
||||
if (thfwdonly) {
|
||||
if (thfwdonly)
|
||||
lcd_chars(cm.thspd_onlyfwd ? "OFF" : "ON ");
|
||||
lcd_segment(LS_SYM_PERCENT, LS_OFF);
|
||||
}
|
||||
else {
|
||||
lcd_char_num3(*addr);
|
||||
lcd_segment(LS_SYM_PERCENT, LS_ON);
|
||||
|
||||
15
menu.h
15
menu.h
@@ -149,13 +149,14 @@ extern u8 menu_blink; // what of chars should blink
|
||||
typedef void (*menu_common_t)(u8 action, void *params);
|
||||
void menu_common(menu_common_t func, void *params, u8 flags);
|
||||
// menu_common_t actions, all shows actual values
|
||||
#define MCA_INIT 0
|
||||
#define MCA_SET_CHG 1
|
||||
#define MCA_SET_NEXT 2
|
||||
#define MCA_ID_CHG 3
|
||||
#define MCA_ADC_PRE 4
|
||||
#define MCA_ADC_POST 5
|
||||
#define MCA_SWITCH 6
|
||||
#define MCA_SHOW 0
|
||||
#define MCA_INIT 1
|
||||
#define MCA_SET_CHG 2
|
||||
#define MCA_SET_NEXT 3
|
||||
#define MCA_ID_CHG 4
|
||||
#define MCA_ADC_PRE 5
|
||||
#define MCA_ADC_POST 6
|
||||
#define MCA_SWITCH 7
|
||||
|
||||
|
||||
// common list menu, given by list of functions, one for each menu item
|
||||
|
||||
@@ -183,17 +183,22 @@ u8 menu_id; // id of selected menu
|
||||
_Bool menu_id_set; // 0 = in menu-id, 1 = in menu-setting
|
||||
u8 menu_blink; // what of chars should blink
|
||||
|
||||
void menu_common(menu_common_t func, void *params, u8 flags) {
|
||||
menu_id_set = flags & MCF_SET_ONLY ? 1 : 0;
|
||||
menu_set = 0; // now in menu_id
|
||||
menu_id = 0; // first menu item
|
||||
menu_blink = 0xff; // bit for each char to blink
|
||||
static void func_init(u8 flags) {
|
||||
// blink all
|
||||
menu_blink = 0xff;
|
||||
|
||||
// clear display symbols
|
||||
menu_clear_symbols();
|
||||
if (flags & MCF_LOWPWR) lcd_segment(LS_SYM_LOWPWR, LS_OFF);
|
||||
}
|
||||
|
||||
void menu_common(menu_common_t func, void *params, u8 flags) {
|
||||
menu_id_set = flags & MCF_SET_ONLY ? 1 : 0;
|
||||
menu_set = 0; // now in menu_id
|
||||
menu_id = 0; // first menu item
|
||||
|
||||
// init and show setting
|
||||
func_init(flags);
|
||||
func(MCA_INIT, params);
|
||||
if (menu_id_set) {
|
||||
lcd_chars_blink_mask(LB_SPC, menu_blink);
|
||||
@@ -220,7 +225,7 @@ void menu_common(menu_common_t func, void *params, u8 flags) {
|
||||
// rotate encoder changed, change menu-id or value
|
||||
if (btn(BTN_ROT_ALL)) {
|
||||
if (menu_id_set) {
|
||||
// change selected menu setting
|
||||
func_init(flags);
|
||||
func(MCA_SET_CHG, params);
|
||||
lcd_chars_blink_mask(LB_SPC, menu_blink);
|
||||
}
|
||||
@@ -230,13 +235,9 @@ void menu_common(menu_common_t func, void *params, u8 flags) {
|
||||
// reset some variables
|
||||
menu_adc_wakeup = 0;
|
||||
menu_force_value_channel = 0;
|
||||
menu_blink = 0xff; // default to all chars
|
||||
|
||||
// remove possible showed symbols
|
||||
menu_clear_symbols();
|
||||
if (flags & MCF_LOWPWR) lcd_segment(LS_SYM_LOWPWR, LS_OFF);
|
||||
|
||||
// select new menu id and show it
|
||||
func_init(flags);
|
||||
func(MCA_ID_CHG, params); // do own change based on BTN_ROT
|
||||
|
||||
if (menu_blink & MCB_7SEG) lcd_set_blink(L7SEG, LB_SPC);
|
||||
@@ -250,11 +251,7 @@ void menu_common(menu_common_t func, void *params, u8 flags) {
|
||||
key_beep();
|
||||
if (flags & MCF_SWITCH) {
|
||||
// switch will be done by function
|
||||
menu_blink = 0xff; // default to all chars
|
||||
// remove possible showed symbols
|
||||
menu_clear_symbols();
|
||||
if (flags & MCF_LOWPWR) lcd_segment(LS_SYM_LOWPWR, LS_OFF);
|
||||
// select next menu setting
|
||||
func_init(flags);
|
||||
func(MCA_SWITCH, params);
|
||||
if (menu_set == 255) break; // exit menu when requested
|
||||
// blinking
|
||||
@@ -269,11 +266,8 @@ void menu_common(menu_common_t func, void *params, u8 flags) {
|
||||
lcd_update();
|
||||
}
|
||||
else if (menu_id_set) {
|
||||
menu_blink = 0xff; // default to all chars
|
||||
// remove possible showed symbols
|
||||
menu_clear_symbols();
|
||||
if (flags & MCF_LOWPWR) lcd_segment(LS_SYM_LOWPWR, LS_OFF);
|
||||
// select next menu setting
|
||||
func_init(flags);
|
||||
func(MCA_SET_NEXT, params);
|
||||
if (menu_set || (flags & MCF_SET_ONLY)) {
|
||||
// some > 0 menu setting
|
||||
@@ -296,14 +290,18 @@ void menu_common(menu_common_t func, void *params, u8 flags) {
|
||||
}
|
||||
}
|
||||
|
||||
// if menu ADC was activated, call func to for example show other
|
||||
// value when left-right position changed
|
||||
// if menu ADC was activated, call func to check if to show for example
|
||||
// other value when left-right position changed
|
||||
if (menu_adc_wakeup) {
|
||||
u8 mis = menu_id_set; // save value
|
||||
menu_id_set = 0; // func will set it to 1 when new val showed
|
||||
menu_id_set = 0; // func will set it to 1 when show call needed
|
||||
func(MCA_ADC_POST, params);
|
||||
if (menu_id_set) {
|
||||
if (mis) {
|
||||
menu_id_set = mis;
|
||||
// show changed value
|
||||
func_init(flags);
|
||||
func(MCA_SHOW, params);
|
||||
if (menu_id_set) {
|
||||
lcd_chars_blink_mask(LB_SPC, menu_blink);
|
||||
}
|
||||
else {
|
||||
@@ -311,7 +309,7 @@ void menu_common(menu_common_t func, void *params, u8 flags) {
|
||||
}
|
||||
lcd_update();
|
||||
}
|
||||
menu_id_set = mis;
|
||||
else menu_id_set = mis;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,8 +317,7 @@ void menu_common(menu_common_t func, void *params, u8 flags) {
|
||||
if (menu_id_set) func(MCA_SET_NEXT, params);
|
||||
|
||||
// cleanup display
|
||||
menu_clear_symbols();
|
||||
if (flags & MCF_LOWPWR) lcd_segment(LS_SYM_LOWPWR, LS_OFF);
|
||||
func_init(flags);
|
||||
|
||||
// reset variables
|
||||
menu_adc_wakeup = 0;
|
||||
@@ -341,11 +338,9 @@ static void menu_list_func(u8 action, menu_list_params_t *p) {
|
||||
case MCA_SET_CHG:
|
||||
func(MLA_CHG);
|
||||
return; // value already showed
|
||||
break;
|
||||
case MCA_SET_NEXT:
|
||||
func(MLA_NEXT);
|
||||
return; // value already showed
|
||||
break;
|
||||
case MCA_ID_CHG:
|
||||
menu_id = (u8)menu_change_val(menu_id, 0, p->nitems - 1, 1, 1);
|
||||
func = p->funcs[menu_id];
|
||||
|
||||
@@ -146,7 +146,6 @@ static void km_trim(u8 action) {
|
||||
}
|
||||
|
||||
// show value of menu_set
|
||||
lcd_segment(LS_SYM_VOLTS, LS_OFF);
|
||||
switch (menu_set) {
|
||||
case 0:
|
||||
// function
|
||||
@@ -311,7 +310,6 @@ static void km_key(u8 action) {
|
||||
}
|
||||
|
||||
// show value of menu_set
|
||||
lcd_segment(LS_SYM_VOLTS, LS_OFF);
|
||||
switch (menu_set) {
|
||||
case 0:
|
||||
// function
|
||||
@@ -375,7 +373,6 @@ static const u8 key_ids[] = {
|
||||
void menu_key_mapping_func(u8 action, void *p) {
|
||||
if (action == MCA_SET_CHG) {
|
||||
km_trim_key(1);
|
||||
return; // value already showed
|
||||
}
|
||||
else if (action == MCA_SET_NEXT) {
|
||||
km_trim_key(2);
|
||||
@@ -408,7 +405,8 @@ void menu_key_mapping_func(u8 action, void *p) {
|
||||
// left trim key
|
||||
lcd_segment(LS_SYM_LEFT, LS_ON);
|
||||
}
|
||||
if (action != MCA_SET_NEXT) km_trim_key(0);
|
||||
if (action != MCA_SET_NEXT && action != MCA_SET_CHG)
|
||||
km_trim_key(0);
|
||||
}
|
||||
|
||||
void menu_key_mapping(void) {
|
||||
|
||||
106
menu_timer.c
106
menu_timer.c
@@ -48,6 +48,7 @@ static @near u8 timer_lap_count[TIMER_NUM];
|
||||
static @near menu_timer_s timer_lap_time[TIMER_NUM][TIMER_MAX_LAPS];
|
||||
// time when lap button can be pressed (to eliminate double-clicks)
|
||||
static @near u16 next_timer_sec[TIMER_NUM];
|
||||
static @near u16 next_timer_sec_display[TIMER_NUM];
|
||||
|
||||
|
||||
|
||||
@@ -135,18 +136,41 @@ void menu_timer_show(u8 tid) {
|
||||
|
||||
case TIMER_LAP:
|
||||
// if several seconds from last LAP press, show actual timer value
|
||||
if (time_sec >= next_timer_sec[tid]) {
|
||||
if (time_sec >= next_timer_sec_display[tid]) {
|
||||
timer_value(pt);
|
||||
break;
|
||||
}
|
||||
// show last lap time for several seconds
|
||||
lap = timer_lap_count[tid];
|
||||
if (lap) {
|
||||
if (lap > 1) {
|
||||
menu_timer_s *pt2, tm;
|
||||
s16 hdr;
|
||||
// to last lap id
|
||||
lap--; // to last lap id
|
||||
while (lap >= TIMER_MAX_LAPS) lap -= TIMER_MAX_LAPS;
|
||||
timer_value(&timer_lap_time[tid][lap]);
|
||||
// calculate lap time as difference between lap and lap -1
|
||||
if (lap) pt2 = &timer_lap_time[tid][lap - 1];
|
||||
else pt2 = &timer_lap_time[tid][TIMER_MAX_LAPS - 1];
|
||||
pt = &timer_lap_time[tid][lap];
|
||||
tm.sec = pt->sec - pt2->sec;
|
||||
hdr = pt->hdr - pt2->hdr;
|
||||
if (hdr < 0) {
|
||||
tm.sec--;
|
||||
hdr += 100;
|
||||
}
|
||||
tm.hdr = (u8)hdr;
|
||||
timer_value(&tm);
|
||||
}
|
||||
else timer_value(NULL);
|
||||
else if (lap)
|
||||
// first lap
|
||||
timer_value(&timer_lap_time[tid][0]);
|
||||
else
|
||||
// no lap
|
||||
timer_value(NULL);
|
||||
// blink this last lap time
|
||||
lcd_set_blink(L7SEG, LB_SPC);
|
||||
lcd_chars_blink(LB_SPC);
|
||||
break;
|
||||
|
||||
case TIMER_LAPCNT:
|
||||
@@ -164,12 +188,6 @@ void menu_timer_show(u8 tid) {
|
||||
|
||||
|
||||
|
||||
// lap times clear
|
||||
static void lap_times_clear(u8 tid) {
|
||||
timer_lap_count[tid] = 0;
|
||||
memset(&timer_lap_time[tid], 0, TIMER_MAX_LAPS * sizeof(menu_timer_s));
|
||||
}
|
||||
|
||||
// clear timer
|
||||
void menu_timer_clear(u8 tid, u8 laps) {
|
||||
menu_timer_s *pt = &menu_timer[tid];
|
||||
@@ -182,8 +200,10 @@ void menu_timer_clear(u8 tid, u8 laps) {
|
||||
// zero values, laps only when requested
|
||||
pt->hdr = 0;
|
||||
menu_timer_alarmed &= (u8)~tbit;
|
||||
if (laps == 1 || (laps == 2 && type != TIMER_DOWN))
|
||||
lap_times_clear(tid);
|
||||
if (laps == 1 || (laps == 2 && type != TIMER_DOWN)) {
|
||||
timer_lap_count[tid] = 0;
|
||||
memset(&timer_lap_time[tid], 0, TIMER_MAX_LAPS * sizeof(menu_timer_s));
|
||||
}
|
||||
|
||||
// set alarm
|
||||
if (type == TIMER_LAPCNT)
|
||||
@@ -247,7 +267,7 @@ static void timer_setup_alarm(u8 action) {
|
||||
}
|
||||
|
||||
static const u8 timer_type_labels[][4] = {
|
||||
"OFF", "UP ", "DWN", "LPT", "LPC"
|
||||
"OFF", "UP ", "DWN", "LAP", "LPC"
|
||||
};
|
||||
static void timer_setup_type(u8 action) {
|
||||
u8 tid = timer_id; // compiler hack
|
||||
@@ -275,6 +295,10 @@ static const menu_list_t timer_setup_funcs[] = {
|
||||
};
|
||||
|
||||
void menu_timer_setup(u8 tid) {
|
||||
// stop timer
|
||||
menu_timer_running &= (u8)~(u8)(1 << tid);
|
||||
next_timer_sec_display[tid] = 0; // display last value
|
||||
// set timer_id for subfunctions
|
||||
timer_id = tid;
|
||||
menu_list(timer_setup_funcs, sizeof(timer_setup_funcs) / sizeof(void *), MCF_NONE);
|
||||
config_global_save();
|
||||
@@ -310,13 +334,13 @@ static void lap_times_func(u8 action, u8 *ptid) {
|
||||
case MCA_ID_CHG:
|
||||
// change to other lap, skip TOT ang AVG for down timer
|
||||
menu_id = (u8)menu_change_val(menu_id, 0,
|
||||
laps + (type != TIMER_DOWN ? 2 : 0), LAP_SHOW_FAST, 0);
|
||||
laps + (type != TIMER_DOWN ? 2 : 0), LAP_SHOW_FAST, 1);
|
||||
break;
|
||||
case MCA_SWITCH:
|
||||
// switch between lap numbers and times
|
||||
if (menu_id == laps) {
|
||||
// if RESset selected, delete all values end exit
|
||||
lap_times_clear(tid);
|
||||
menu_timer_clear(tid, 1);
|
||||
menu_set = 255; // flag to exit
|
||||
return;
|
||||
}
|
||||
@@ -328,16 +352,26 @@ static void lap_times_func(u8 action, u8 *ptid) {
|
||||
// show value
|
||||
menu_blink = 0; // no blinking
|
||||
timer_show_id(tid);
|
||||
// blink arrow to indicate lap times viewing
|
||||
lcd_segment_blink(LS_SYM_LEFT, LB_SPC);
|
||||
lcd_segment_blink(LS_SYM_RIGHT, LB_SPC);
|
||||
|
||||
// show lap number
|
||||
if (!menu_id_set) {
|
||||
lcd_7seg('L');
|
||||
lcd_7seg(L7_L);
|
||||
if (menu_id == laps)
|
||||
lcd_chars("RES");
|
||||
else if (menu_id == laps + 1)
|
||||
lcd_chars("AVG");
|
||||
else if (menu_id == laps + 2)
|
||||
lcd_chars("TOT");
|
||||
else if (menu_id > laps) {
|
||||
u8 laps10 = (u8)(laps / 10);
|
||||
// show ID Average/Total
|
||||
if (menu_id == laps + 1) lcd_char(LCHR1, 'A'); // average
|
||||
else lcd_char(LCHR1, 'T'); // total
|
||||
// show number of laps
|
||||
if (laps10 == 10) lcd_char(LCHR2, LCHAR_ONE_ZERO);
|
||||
else if (laps10 == 0) lcd_char(LCHR2, ' ');
|
||||
else lcd_char(LCHR2, (u8)(laps10 + '0'));
|
||||
lcd_char(LCHR3, (u8)(laps % 10 + '0'));
|
||||
}
|
||||
else lcd_char_num3(menu_id + 1);
|
||||
return;
|
||||
}
|
||||
@@ -350,10 +384,25 @@ static void lap_times_func(u8 action, u8 *ptid) {
|
||||
return;
|
||||
}
|
||||
else if (menu_id == laps + 1) {
|
||||
// average XXX
|
||||
lcd_set(L7SEG, LB_EMPTY);
|
||||
lcd_chars("NDY");
|
||||
return;
|
||||
// average lap times
|
||||
if (laps) {
|
||||
// we have at least one lap
|
||||
u32 tot;
|
||||
pt = &timer_lap_time[tid][laps - 1];
|
||||
// count in hundredths
|
||||
tot = (u32)pt->sec * 100 + pt->hdr;
|
||||
// average
|
||||
tot = (tot + laps / 2) / laps;
|
||||
// assign to timer val
|
||||
tm.sec = (u16)(tot / 100);
|
||||
tm.hdr = (u8)(tot % 100);
|
||||
}
|
||||
else {
|
||||
// no laps, show zero
|
||||
tm.sec = 0;
|
||||
tm.hdr = 0;
|
||||
}
|
||||
pt = &tm;
|
||||
}
|
||||
else if (menu_id == laps + 2)
|
||||
// total, read time of last lap
|
||||
@@ -366,9 +415,9 @@ static void lap_times_func(u8 action, u8 *ptid) {
|
||||
}
|
||||
else {
|
||||
// show lap time
|
||||
if (menu_id == 0)
|
||||
// first lap
|
||||
pt = &timer_lap_time[tid][0];
|
||||
if (menu_id == 0 || type == TIMER_DOWN)
|
||||
// first lap or down timer
|
||||
pt = &timer_lap_time[tid][menu_id];
|
||||
else {
|
||||
// calculate lap time as difference between lap and lap -1
|
||||
menu_timer_s *pt2 = &timer_lap_time[tid][menu_id - 1];
|
||||
@@ -467,15 +516,19 @@ void kf_menu_timer_start(u8 *id, u8 *param, u8 flags, s16 *pv) {
|
||||
// when not running, start it
|
||||
if (!(menu_timer_running & tbit)) {
|
||||
menu_timer_running |= tbit;
|
||||
next_timer_sec_display[tid] = 0; // display running value
|
||||
break;
|
||||
}
|
||||
// when alarmed already, stop timer
|
||||
if (menu_timer_alarmed & tbit) {
|
||||
menu_timer_running &= (u8)~tbit;
|
||||
menu_timer_throttle &= (u8)~tbit;
|
||||
next_timer_sec_display[tid] = 0; // display last value
|
||||
timer_lap_time_save(tid);
|
||||
break;
|
||||
}
|
||||
// save to lap times
|
||||
next_timer_sec_display[tid] = time_sec + 3;
|
||||
timer_lap_time_save(tid);
|
||||
break;
|
||||
|
||||
@@ -532,6 +585,7 @@ void kf_menu_timer_reset(u8 *id, u8 *param, u8 flags, s16 *pv) {
|
||||
// stop timer
|
||||
menu_timer_running &= (u8)~tbit;
|
||||
menu_timer_throttle &= (u8)~tbit;
|
||||
next_timer_sec_display[tid] = 0; // display last value
|
||||
break;
|
||||
|
||||
case TIMER_LAPCNT:
|
||||
|
||||
Reference in New Issue
Block a user