Checkpoint

- combined lcd_show_three_choices_prompt_P and lcd_show_two_choices_prompt_P into one function called lcd_show_choices_prompt_P
- Removed third_col parameter
- Added an enum to make the button selection result more readable
This commit is contained in:
Guðni Már Gilbert 2022-05-13 06:29:51 +00:00 committed by D.R.racer
parent 8dbb883971
commit 37bfd8ecd1
3 changed files with 41 additions and 48 deletions

View File

@ -67,12 +67,11 @@ back_to_choices:
two_choices ? nullptr : btnMore,
two_choices ?
10 // If two choices, allow the first choice to have more characters
: 7,
13
: 7
);
if ((two_choices && choice_selected == 1) // Two choices and middle button selected
|| (!two_choices && choice_selected == 2)) // Three choices and right most button selected
if ((two_choices && choice_selected == MIDDLE_BUTTON_CHOICE) // Two choices and middle button selected
|| (!two_choices && choice_selected == RIGHT_BUTTON_CHOICE)) // Three choices and right most button selected
{
// 'More' show error description
lcd_show_fullscreen_message_and_wait_P(
@ -81,7 +80,7 @@ back_to_choices:
// Return back to the choice menu
goto back_to_choices;
} else if(choice_selected == 1) {
} else if(choice_selected == MIDDLE_BUTTON_CHOICE) {
// TODO: User selected middle choice, not sure what to do.
// At the moment just return to the status screen
switch (button_high_nibble)

View File

@ -3196,30 +3196,29 @@ int8_t lcd_show_multiscreen_message_yes_no_and_wait_P(const char *msg, bool allo
return lcd_show_multiscreen_message_with_choices_and_wait_P(msg, allow_timeouting, default_yes, _T(MSG_YES), _T(MSG_NO), nullptr, 10);
}
//! @brief Show a two-choice prompt on the last line of the LCD
//! @param first_selected Show first choice as selected if true, the second otherwise
//! @param selected Show first choice as selected if true, the second otherwise
//! @param first_choice text caption of first possible choice
//! @param second_choice text caption of second possible choice
void lcd_show_two_choices_prompt_P(uint8_t first_selected, const char *first_choice, const char *second_choice, uint8_t second_col)
//! @param second_col column on LCD where second choice is rendered. If third choice is set, this value is hardcoded to 7
//! @param third_choice text caption of third, optional, choice.
void lcd_show_choices_prompt_P(uint8_t selected, const char *first_choice, const char *second_choice, uint8_t second_col, const char *third_choice = nullptr)
{
lcd_set_cursor(0, 3);
lcd_print(first_selected == 0 ? '>': ' ');
lcd_print(selected == LEFT_BUTTON_CHOICE ? '>': ' ');
lcd_puts_P(first_choice);
lcd_set_cursor(second_col, 3);
lcd_print(first_selected == 1 ? '>': ' ');
lcd_puts_P(second_choice);
}
void lcd_show_three_choices_prompt_P(uint8_t selected, const char *first_choice, const char *second_choice, const char *third_choice, uint8_t second_col, uint8_t third_col)
{
lcd_set_cursor(0, 3);
lcd_print(selected == 0 ? '>': ' ');
lcd_puts_P(first_choice);
lcd_set_cursor(second_col, 3);
lcd_print(selected == 1 ? '>': ' ');
lcd_puts_P(second_choice);
lcd_set_cursor(third_col, 3);
lcd_print(selected == 2 ? '>': ' ');
lcd_puts_P(third_choice);
if (third_choice)
{
lcd_set_cursor(7, 3);
lcd_print(selected == MIDDLE_BUTTON_CHOICE ? '>': ' ');
lcd_puts_P(second_choice);
lcd_set_cursor(13, 3);
lcd_print(selected == RIGHT_BUTTON_CHOICE ? '>': ' ');
lcd_puts_P(third_choice);
} else {
lcd_set_cursor(second_col, 3);
lcd_print(selected == MIDDLE_BUTTON_CHOICE ? '>': ' ');
lcd_puts_P(second_choice);
}
}
//! @brief Show single or multiple screen message with two possible choices and wait with possible timeout
@ -3230,27 +3229,21 @@ void lcd_show_three_choices_prompt_P(uint8_t selected, const char *first_choice,
//! @param second_choice text caption of second possible choice. Must be in PROGMEM
//! @param third_choice text caption of second possible choice. Must be in PROGMEM. When not set to nullptr first_choice and second_choice may not be more than 5 characters long.
//! @param second_col column on LCD where second_choice starts
//! @param third_col column on LCD where second_choice starts
//! @retval 0 first choice selected by user
//! @retval 1 first choice selected by user
//! @retval 2 third choice selected by user
//! @retval -1 screen timed out (only possible if allow_timeouting is true)
int8_t lcd_show_multiscreen_message_with_choices_and_wait_P(const char *msg, bool allow_timeouting, bool default_first,
const char *first_choice, const char *second_choice, const char *third_choice, uint8_t second_col, uint8_t third_col)
const char *first_choice, const char *second_choice, const char *third_choice, uint8_t second_col)
{
const char *msg_next = msg ? lcd_display_message_fullscreen_P(msg) : NULL;
bool multi_screen = msg_next != NULL;
lcd_set_custom_characters_nextpage();
// Initial status/prompt on single-screen messages
uint8_t yes = default_first ? 1 : 0;
uint8_t yes = default_first ? MIDDLE_BUTTON_CHOICE : LEFT_BUTTON_CHOICE;
if (!msg_next) {
if (third_choice)
{ // third_choice is not nullptr, safe to dereference
lcd_show_three_choices_prompt_P(yes, first_choice, second_choice, third_choice, second_col, third_col);
} else {
lcd_show_two_choices_prompt_P(yes, first_choice, second_choice, second_col);
}
lcd_show_choices_prompt_P(yes, first_choice, second_choice, second_col, third_choice);
}
// Wait for user confirmation or a timeout.
unsigned long previous_millis_cmd = _millis();
@ -3271,24 +3264,23 @@ int8_t lcd_show_multiscreen_message_with_choices_and_wait_P(const char *msg, boo
if (msg_next == NULL) {
if (third_choice)
{ // third_choice is not nullptr, safe to dereference
if (enc_dif > lcd_encoder_diff && yes != 0) {
if (enc_dif > lcd_encoder_diff && yes != LEFT_BUTTON_CHOICE) {
// Rotating knob counter clockwise
yes = yes - 1;
} else if (enc_dif < lcd_encoder_diff && yes != 2) {
} else if (enc_dif < lcd_encoder_diff && yes != RIGHT_BUTTON_CHOICE) {
// Rotating knob clockwise
yes = yes + 1;
}
lcd_show_three_choices_prompt_P(yes, first_choice, second_choice, third_choice, second_col, third_col);
} else {
if (enc_dif > lcd_encoder_diff && yes != 0) {
if (enc_dif > lcd_encoder_diff && yes != LEFT_BUTTON_CHOICE) {
// Rotating knob counter clockwise
yes = 0;
} else if (enc_dif < lcd_encoder_diff && yes != 1) {
yes = LEFT_BUTTON_CHOICE;
} else if (enc_dif < lcd_encoder_diff && yes != MIDDLE_BUTTON_CHOICE) {
// Rotating knob clockwise
yes = 1;
yes = MIDDLE_BUTTON_CHOICE;
}
lcd_show_two_choices_prompt_P(yes, first_choice, second_choice, second_col);
}
lcd_show_choices_prompt_P(yes, first_choice, second_choice, second_col, third_choice);
enc_dif = lcd_encoder_diff;
Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
}
@ -3315,12 +3307,7 @@ int8_t lcd_show_multiscreen_message_with_choices_and_wait_P(const char *msg, boo
msg_next = lcd_display_message_fullscreen_P(msg_next);
}
if (msg_next == NULL) {
if (third_choice)
{ // third_choice is not nullptr, safe to dereference
lcd_show_three_choices_prompt_P(yes, first_choice, second_choice, third_choice, second_col, third_col);
} else {
lcd_show_two_choices_prompt_P(yes, first_choice, second_choice, second_col);
}
lcd_show_choices_prompt_P(yes, first_choice, second_choice, second_col, third_choice);
}
}
}

View File

@ -64,6 +64,13 @@ void lcd_crash_detect_enable();
void lcd_crash_detect_disable();
#endif
enum ButtonChoice
{
LEFT_BUTTON_CHOICE = 0,
MIDDLE_BUTTON_CHOICE = 1,
RIGHT_BUTTON_CHOICE = 2,
};
extern const char* lcd_display_message_fullscreen_P(const char *msg, uint8_t &nlines);
extern const char* lcd_display_message_fullscreen_P(const char *msg);
@ -76,7 +83,7 @@ extern int8_t lcd_show_yes_no_and_wait(bool allow_timeouting = true, bool defaul
// 0: no, 1: yes, -1: timeouted
extern int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting = true, bool default_yes = false);
extern int8_t lcd_show_multiscreen_message_with_choices_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes,
const char *first_choice, const char *second_choice, const char *third_choice = nullptr, uint8_t second_col = 7, uint8_t third_col = 13);
const char *first_choice, const char *second_choice, const char *third_choice = nullptr, uint8_t second_col = 7);
extern int8_t lcd_show_multiscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting = true, bool default_yes = false);
// Ask the user to move the Z axis up to the end stoppers and let
// the user confirm that it has been done.