Fix SD card reselect when scrolled (#13624)

- Change encoder position to 16-bit integer.
- Fix `SD_REPRINT_LAST_SELECTED_FILE` when the screen is scrolled.
This commit is contained in:
Scott Lahteine 2019-04-08 21:10:41 -05:00 committed by GitHub
parent 0e3c9e726d
commit 321a5e6580
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 50 additions and 40 deletions

View File

@ -263,7 +263,7 @@ void InvadersGame::game_screen() {
if (ui.first_page) {
// Update Cannon Position
int32_t ep = (int32_t)ui.encoderPosition;
int16_t ep = int16_t(ui.encoderPosition);
ep = constrain(ep, 0, (LCD_PIXEL_WIDTH - (CANNON_W)) / (CANNON_VEL));
ui.encoderPosition = ep;

View File

@ -66,11 +66,11 @@ uint8_t screen_history_depth = 0;
bool screen_changed;
// Value Editing
PGM_P editLabel;
void *editValue;
int32_t minEditValue, maxEditValue;
screenFunc_t callbackFunc;
bool liveEdit;
PGM_P MenuItemBase::editLabel;
void* MenuItemBase::editValue;
int16_t MenuItemBase::minEditValue, MenuItemBase::maxEditValue;
screenFunc_t MenuItemBase::callbackFunc;
bool MenuItemBase::liveEdit;
// Prevent recursion into screen handlers
bool no_reentry = false;
@ -131,8 +131,8 @@ void MenuItem_gcode::action(PGM_P pgcode) { enqueue_and_echo_commands_P(pgcode);
*/
void MenuItemBase::edit(strfunc_t strfunc, loadfunc_t loadfunc) {
ui.encoder_direction_normal();
if ((int32_t)ui.encoderPosition < 0) ui.encoderPosition = 0;
if ((int32_t)ui.encoderPosition > maxEditValue) ui.encoderPosition = maxEditValue;
if (int16_t(ui.encoderPosition) < 0) ui.encoderPosition = 0;
if (int16_t(ui.encoderPosition) > maxEditValue) ui.encoderPosition = maxEditValue;
if (ui.should_draw())
draw_edit_screen(editLabel, strfunc(ui.encoderPosition + minEditValue));
if (ui.lcd_clicked || (liveEdit && ui.should_draw())) {
@ -142,7 +142,7 @@ void MenuItemBase::edit(strfunc_t strfunc, loadfunc_t loadfunc) {
}
}
void MenuItemBase::init(PGM_P const el, void * const ev, const int32_t minv, const int32_t maxv, const uint32_t ep, const screenFunc_t cs, const screenFunc_t cb, const bool le) {
void MenuItemBase::init(PGM_P const el, void * const ev, const int16_t minv, const int16_t maxv, const uint16_t ep, const screenFunc_t cs, const screenFunc_t cb, const bool le) {
ui.save_previous_screen();
ui.refresh();
editLabel = el;
@ -193,7 +193,7 @@ bool printer_busy() {
/**
* General function to go directly to a screen
*/
void MarlinUI::goto_screen(screenFunc_t screen, const uint32_t encoder/*=0*/, const uint8_t top/*=0*/, const uint8_t items/*=0*/) {
void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, const uint8_t top/*=0*/, const uint8_t items/*=0*/) {
if (currentScreen != screen) {
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
@ -364,7 +364,7 @@ void MarlinUI::completion_feedback(const bool good/*=true*/) {
#endif
ui.encoder_direction_normal();
if (ui.encoderPosition) {
const int16_t babystep_increment = (int32_t)ui.encoderPosition * (BABYSTEP_MULTIPLICATOR);
const int16_t babystep_increment = int16_t(ui.encoderPosition) * (BABYSTEP_MULTIPLICATOR);
ui.encoderPosition = 0;
const float diff = planner.steps_to_mm[Z_AXIS] * babystep_increment,
@ -438,7 +438,7 @@ void _lcd_draw_homing() {
void do_select_screen(PGM_P const yes, PGM_P const no, bool &yesno, PGM_P const pref, const char * const string, PGM_P const suff) {
if (ui.encoderPosition) {
yesno = int32_t(ui.encoderPosition) > 0;
yesno = int16_t(ui.encoderPosition) > 0;
ui.encoderPosition = 0;
}
draw_select_screen(yes, no, yesno, pref, string, suff);

View File

@ -156,10 +156,16 @@ class MenuItem_function {
////////////////////////////////////////////
class MenuItemBase {
private:
static PGM_P editLabel;
static void *editValue;
static int16_t minEditValue, maxEditValue;
static screenFunc_t callbackFunc;
static bool liveEdit;
protected:
typedef char* (*strfunc_t)(const int32_t);
typedef void (*loadfunc_t)(void *, const int32_t);
static void init(PGM_P const el, void * const ev, const int32_t minv, const int32_t maxv, const uint32_t ep, const screenFunc_t cs, const screenFunc_t cb, const bool le);
typedef char* (*strfunc_t)(const int16_t);
typedef void (*loadfunc_t)(void *, const int16_t);
static void init(PGM_P const el, void * const ev, const int16_t minv, const int16_t maxv, const uint16_t ep, const screenFunc_t cs, const screenFunc_t cb, const bool le);
static void edit(strfunc_t, loadfunc_t);
};
@ -169,12 +175,12 @@ class TMenuItem : MenuItemBase {
typedef typename NAME::type_t type_t;
static inline float unscale(const float value) { return value * (1.0f / NAME::scale); }
static inline float scale(const float value) { return value * NAME::scale; }
static void load(void *ptr, const int32_t value) { *((type_t*)ptr) = unscale(value); }
static char* to_string(const int32_t value) { return NAME::strfunc(unscale(value)); }
static void load(void *ptr, const int16_t value) { *((type_t*)ptr) = unscale(value); }
static char* to_string(const int16_t value) { return NAME::strfunc(unscale(value)); }
public:
static void action_edit(PGM_P const pstr, type_t * const ptr, const type_t minValue, const type_t maxValue, const screenFunc_t callback=NULL, const bool live=false) {
const int32_t minv = scale(minValue);
init(pstr, ptr, minv, int32_t(scale(maxValue)) - minv, int32_t(scale(*ptr)) - minv, edit, callback, live);
const int16_t minv = scale(minValue);
init(pstr, ptr, minv, int16_t(scale(maxValue)) - minv, int16_t(scale(*ptr)) - minv, edit, callback, live);
}
static void edit() { MenuItemBase::edit(to_string, load); }
};

View File

@ -120,7 +120,7 @@
// Encoder knob or keypad buttons adjust the Z position
//
if (ui.encoderPosition) {
const float z = current_position[Z_AXIS] + float((int32_t)ui.encoderPosition) * (MESH_EDIT_Z_STEP);
const float z = current_position[Z_AXIS] + float(int16_t(ui.encoderPosition)) * (MESH_EDIT_Z_STEP);
line_to_z(constrain(z, -(LCD_PROBE_Z_RANGE) * 0.5f, (LCD_PROBE_Z_RANGE) * 0.5f));
ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
ui.encoderPosition = 0;

View File

@ -44,7 +44,7 @@
ui.encoder_direction_normal();
ENCODER_RATE_MULTIPLY(true);
if (ui.encoderPosition != 0) {
mixer.gradient.start_z += float((int)ui.encoderPosition) * 0.1;
mixer.gradient.start_z += float(int16_t(ui.encoderPosition)) * 0.1;
ui.encoderPosition = 0;
NOLESS(mixer.gradient.start_z, 0);
NOMORE(mixer.gradient.start_z, Z_MAX_POS);
@ -69,7 +69,7 @@
ui.encoder_direction_normal();
ENCODER_RATE_MULTIPLY(true);
if (ui.encoderPosition != 0) {
mixer.gradient.end_z += float((int)ui.encoderPosition) * 0.1;
mixer.gradient.end_z += float(int16_t(ui.encoderPosition)) * 0.1;
ui.encoderPosition = 0;
NOLESS(mixer.gradient.end_z, 0);
NOMORE(mixer.gradient.end_z, Z_MAX_POS);
@ -185,7 +185,7 @@ void lcd_mixer_mix_edit() {
#elif DUAL_MIXING_EXTRUDER
if (ui.encoderPosition != 0) {
mixer.mix[0] += (int)ui.encoderPosition;
mixer.mix[0] += int16_t(ui.encoderPosition);
ui.encoderPosition = 0;
if (mixer.mix[0] < 0) mixer.mix[0] += 101;
if (mixer.mix[0] > 100) mixer.mix[0] -= 101;

View File

@ -121,16 +121,16 @@ static void _lcd_move_xyz(PGM_P name, AxisEnum axis) {
#endif
// Get the new position
const float diff = float((int32_t)ui.encoderPosition) * move_menu_scale;
const float diff = float(int16_t(ui.encoderPosition)) * move_menu_scale;
#if IS_KINEMATIC
manual_move_offset += diff;
if ((int32_t)ui.encoderPosition < 0)
if (int16_t(ui.encoderPosition) < 0)
NOLESS(manual_move_offset, min - current_position[axis]);
else
NOMORE(manual_move_offset, max - current_position[axis]);
#else
current_position[axis] += diff;
if ((int32_t)ui.encoderPosition < 0)
if (int16_t(ui.encoderPosition) < 0)
NOLESS(current_position[axis], min);
else
NOMORE(current_position[axis], max);
@ -161,7 +161,7 @@ static void _lcd_move_e(
ui.encoder_direction_normal();
if (ui.encoderPosition) {
if (!ui.processing_manual_move) {
const float diff = float((int32_t)ui.encoderPosition) * move_menu_scale;
const float diff = float(int16_t(ui.encoderPosition)) * move_menu_scale;
#if IS_KINEMATIC
manual_move_offset += diff;
#else

View File

@ -47,10 +47,11 @@ void lcd_sd_updir() {
#if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
uint32_t last_sdfile_encoderPosition = 0xFFFF;
uint16_t sd_encoder_position = 0xFFFF;
int8_t sd_top_line, sd_items;
void MarlinUI::reselect_last_file() {
if (last_sdfile_encoderPosition == 0xFFFF) return;
if (sd_encoder_position == 0xFFFF) return;
//#if HAS_GRAPHICAL_LCD
// // This is a hack to force a screen update.
// ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
@ -61,8 +62,8 @@ void lcd_sd_updir() {
// ui.drawing_screen = screen_changed = true;
//#endif
goto_screen(menu_sdcard, last_sdfile_encoderPosition);
last_sdfile_encoderPosition = 0xFFFF;
goto_screen(menu_sdcard, sd_encoder_position, sd_top_line, sd_items);
sd_encoder_position = 0xFFFF;
defer_status_screen();
@ -99,7 +100,10 @@ class MenuItem_sdfile {
public:
static void action(CardReader &theCard) {
#if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
last_sdfile_encoderPosition = ui.encoderPosition; // Save which file was selected for later use
// Save menu state for the selected file
sd_encoder_position = ui.encoderPosition;
sd_top_line = ui.encoderTopLine;
sd_items = ui.screen_items;
#endif
#if ENABLED(SD_MENU_CONFIRM_START)
do_print_file = false;

View File

@ -75,7 +75,7 @@
if (ui.use_click()) return ui.goto_previous_screen_no_defer();
ui.encoder_direction_normal();
if (ui.encoderPosition) {
const int16_t steps = (int32_t)ui.encoderPosition * (BABYSTEP_MULTIPLICATOR);
const int16_t steps = int16_t(ui.encoderPosition) * (BABYSTEP_MULTIPLICATOR);
ui.encoderPosition = 0;
ui.refresh(LCDVIEW_REDRAW_NOW);
babystep.add_steps(axis, steps);

View File

@ -471,7 +471,7 @@ void _lcd_ubl_output_map_lcd() {
ui.encoder_direction_normal();
if (ui.encoderPosition) {
step_scaler += (int32_t)ui.encoderPosition;
step_scaler += int16_t(ui.encoderPosition);
x_plot += step_scaler / (ENCODER_STEPS_PER_MENU_ITEM);
ui.encoderPosition = 0;
ui.refresh(LCDVIEW_REDRAW_NOW);

View File

@ -118,7 +118,7 @@ millis_t next_button_update_ms;
// Encoder Handling
#if HAS_ENCODER_ACTION
uint32_t MarlinUI::encoderPosition;
uint16_t MarlinUI::encoderPosition;
volatile int8_t encoderDiff; // Updated in update_buttons, added to encoderPosition every LCD update
#endif
@ -480,13 +480,13 @@ void MarlinUI::status_screen() {
#if ENABLED(ULTIPANEL_FEEDMULTIPLY)
const int16_t old_frm = feedrate_percentage;
int16_t new_frm = old_frm + (int32_t)encoderPosition;
int16_t new_frm = old_frm + int16_t(encoderPosition);
// Dead zone at 100% feedrate
if (old_frm == 100) {
if ((int32_t)encoderPosition > ENCODER_FEEDRATE_DEADZONE)
if (int16_t(encoderPosition) > ENCODER_FEEDRATE_DEADZONE)
new_frm -= ENCODER_FEEDRATE_DEADZONE;
else if ((int32_t)encoderPosition < -(ENCODER_FEEDRATE_DEADZONE))
else if (int16_t(encoderPosition) < -(ENCODER_FEEDRATE_DEADZONE))
new_frm += ENCODER_FEEDRATE_DEADZONE;
else
new_frm = old_frm;

View File

@ -421,7 +421,7 @@ public:
static void synchronize(PGM_P const msg=NULL);
static screenFunc_t currentScreen;
static void goto_screen(const screenFunc_t screen, const uint32_t encoder=0, const uint8_t top=0, const uint8_t items=0);
static void goto_screen(const screenFunc_t screen, const uint16_t encoder=0, const uint8_t top=0, const uint8_t items=0);
static void save_previous_screen();
static void goto_previous_screen();
static void return_to_status();
@ -496,7 +496,7 @@ public:
static void wait_for_release();
#endif
static uint32_t encoderPosition;
static uint16_t encoderPosition;
#if ENABLED(REVERSE_ENCODER_DIRECTION)
#define ENCODERBASE -1