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
11 changed files with 50 additions and 40 deletions

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); }
};