MUI: Added uint16 min/max variable numbers

This commit is contained in:
Eujean Snyman 2023-02-22 23:06:16 +02:00
parent 1bd25a7e65
commit 9e94c018a1
2 changed files with 319 additions and 0 deletions

View File

@ -931,6 +931,259 @@ uint8_t mui_u8g2_u8_min_max_wm_mud_pf(mui_t *ui, uint8_t msg)
return 0;
}
static void mui_u8g2_u16_vmm_draw_wm_pi(mui_t *ui) MUI_NOINLINE;
static void mui_u8g2_u16_vmm_draw_wm_pi(mui_t *ui)
{
u8g2_t *u8g2 = mui_get_U8g2(ui);
mui_u8g2_u16_min_max_t *vmm= (mui_u8g2_u16_min_max_t *)muif_get_data(ui->uif);
char buf[6] = "99999";
char *s = buf;
uint16_t *value = mui_u8g2_u16mm_get_valptr(vmm);
uint16_t min = mui_u8g2_u16mm_get_min(vmm);
uint16_t max = mui_u8g2_u16mm_get_max(vmm);
uint8_t cnt = 5;
if ( *value > max )
*value = max;
if ( *value <= min )
*value = min;
if ( max < 10000 )
{
s++;
cnt--;
}
if ( max < 1000 )
{
s++;
cnt--;
}
if ( max < 100 )
{
s++;
cnt--;
}
if ( max < 10 )
{
s++;
cnt--;
}
mui_u8g2_draw_button_pi(ui, u8g2_GetStrWidth(u8g2, s)+1, 1, u8x8_u16toa(*value, cnt));
}
uint8_t mui_u8g2_u16_min_max_wm_mse_pi(mui_t *ui, uint8_t msg)
{
mui_u8g2_u16_min_max_t *vmm= (mui_u8g2_u16_min_max_t *)muif_get_data(ui->uif);
uint16_t *value = mui_u8g2_u8mm_get_valptr(vmm);
uint16_t min = mui_u8g2_u8mm_get_min(vmm);
uint16_t max = mui_u8g2_u8mm_get_max(vmm);
switch(msg)
{
case MUIF_MSG_DRAW:
mui_u8g2_u16_vmm_draw_wm_pi(ui);
break;
case MUIF_MSG_FORM_START:
break;
case MUIF_MSG_FORM_END:
break;
case MUIF_MSG_CURSOR_ENTER:
break;
case MUIF_MSG_CURSOR_SELECT:
case MUIF_MSG_VALUE_INCREMENT:
(*value)++;
if ( *value > max ) *value = min;
break;
case MUIF_MSG_VALUE_DECREMENT:
if ( *value > min ) (*value)--; else *value = max;
break;
case MUIF_MSG_CURSOR_LEAVE:
break;
case MUIF_MSG_TOUCH_DOWN:
break;
case MUIF_MSG_TOUCH_UP:
break;
}
return 0;
}
uint8_t mui_u8g2_u16_min_max_wm_mud_pi(mui_t *ui, uint8_t msg)
{
mui_u8g2_u16_min_max_t *vmm= (mui_u8g2_u16_min_max_t *)muif_get_data(ui->uif);
uint16_t *value = mui_u8g2_u16mm_get_valptr(vmm);
uint16_t min = mui_u8g2_u16mm_get_min(vmm);
uint16_t max = mui_u8g2_u16mm_get_max(vmm);
switch(msg)
{
case MUIF_MSG_DRAW:
mui_u8g2_u16_vmm_draw_wm_pi(ui);
break;
case MUIF_MSG_FORM_START:
break;
case MUIF_MSG_FORM_END:
break;
case MUIF_MSG_CURSOR_ENTER:
break;
case MUIF_MSG_CURSOR_SELECT:
case MUIF_MSG_VALUE_INCREMENT:
case MUIF_MSG_VALUE_DECREMENT:
/* toggle between normal mode and capture next/prev mode */
ui->is_mud = !ui->is_mud;
break;
case MUIF_MSG_CURSOR_LEAVE:
break;
case MUIF_MSG_TOUCH_DOWN:
break;
case MUIF_MSG_TOUCH_UP:
break;
case MUIF_MSG_EVENT_NEXT:
if ( ui->is_mud )
{
(*value)++;
if ( *value > max )
*value = min;
return 1;
}
break;
case MUIF_MSG_EVENT_PREV:
if ( ui->is_mud )
{
if ( *value <= min )
*value = max;
else
(*value)--;
return 1;
}
break;
}
return 0;
}
static void mui_u8g2_u16_vmm_draw_wm_pf(mui_t *ui) MUI_NOINLINE;
static void mui_u8g2_u16_vmm_draw_wm_pf(mui_t *ui)
{
u8g2_t *u8g2 = mui_get_U8g2(ui);
mui_u8g2_u16_min_max_t *vmm= (mui_u8g2_u16_min_max_t *)muif_get_data(ui->uif);
char buf[6] = "99999";
char *s = buf;
uint16_t *value = mui_u8g2_u16mm_get_valptr(vmm);
uint16_t min = mui_u8g2_u16mm_get_min(vmm);
uint16_t max = mui_u8g2_u16mm_get_max(vmm);
uint8_t cnt = 5;
if ( *value > max )
*value = max;
if ( *value <= min )
*value = min;
if ( max < 10000 )
{
s++;
cnt--;
}
if ( max < 1000 )
{
s++;
cnt--;
}
if ( max < 100 )
{
s++;
cnt--;
}
if ( max < 10 )
{
s++;
cnt--;
}
mui_u8g2_draw_button_pf(ui, u8g2_GetStrWidth(u8g2, s)+1, 1, u8x8_u16toa(*value, cnt));
}
uint8_t mui_u8g2_u16_min_max_wm_mse_pf(mui_t *ui, uint8_t msg)
{
mui_u8g2_u16_min_max_t *vmm= (mui_u8g2_u16_min_max_t *)muif_get_data(ui->uif);
uint16_t *value = mui_u8g2_u16mm_get_valptr(vmm);
uint16_t min = mui_u8g2_u16mm_get_min(vmm);
uint16_t max = mui_u8g2_u16mm_get_max(vmm);
switch(msg)
{
case MUIF_MSG_DRAW:
mui_u8g2_u16_vmm_draw_wm_pf(ui);
break;
case MUIF_MSG_FORM_START:
break;
case MUIF_MSG_FORM_END:
break;
case MUIF_MSG_CURSOR_ENTER:
break;
case MUIF_MSG_CURSOR_SELECT:
case MUIF_MSG_VALUE_INCREMENT:
(*value)++;
if ( *value > max ) *value = min;
break;
case MUIF_MSG_VALUE_DECREMENT:
if ( *value > min ) (*value)--; else *value = max;
break;
case MUIF_MSG_CURSOR_LEAVE:
break;
case MUIF_MSG_TOUCH_DOWN:
break;
case MUIF_MSG_TOUCH_UP:
break;
}
return 0;
}
uint8_t mui_u8g2_u16_min_max_wm_mud_pf(mui_t *ui, uint8_t msg)
{
mui_u8g2_u16_min_max_t *vmm= (mui_u8g2_u16_min_max_t *)muif_get_data(ui->uif);
uint16_t *value = mui_u8g2_u16mm_get_valptr(vmm);
uint16_t min = mui_u8g2_u16mm_get_min(vmm);
uint16_t max = mui_u8g2_u16mm_get_max(vmm);
switch(msg)
{
case MUIF_MSG_DRAW:
mui_u8g2_u16_vmm_draw_wm_pf(ui);
break;
case MUIF_MSG_FORM_START:
break;
case MUIF_MSG_FORM_END:
break;
case MUIF_MSG_CURSOR_ENTER:
break;
case MUIF_MSG_CURSOR_SELECT:
case MUIF_MSG_VALUE_INCREMENT:
case MUIF_MSG_VALUE_DECREMENT:
/* toggle between normal mode and capture next/prev mode */
ui->is_mud = !ui->is_mud;
break;
case MUIF_MSG_CURSOR_LEAVE:
break;
case MUIF_MSG_TOUCH_DOWN:
break;
case MUIF_MSG_TOUCH_UP:
break;
case MUIF_MSG_EVENT_NEXT:
if ( ui->is_mud )
{
(*value)++;
if ( *value > max )
*value = min;
return 1;
}
break;
case MUIF_MSG_EVENT_PREV:
if ( ui->is_mud )
{
if ( *value <= min )
*value = max;
else
(*value)--;
return 1;
}
break;
}
return 0;
}
/*===============================================================================*/

View File

@ -95,6 +95,25 @@ typedef const struct mui_u8g2_u8_min_max_struct mui_u8g2_u8_min_max_t;
# define mui_u8g2_u8mm_get_valptr(u8mm) ((u8mm)->value)
#endif
struct mui_u8g2_u16_min_max_struct
{
uint16_t *value;
uint16_t min;
uint16_t max;
} MUI_PROGMEM;
typedef const struct mui_u8g2_u16_min_max_struct mui_u8g2_u16_min_max_t;
#if defined(__GNUC__) && defined(__AVR__)
# define mui_u8g2_u16mm_get_min(u16mm) mui_pgm_read(&((u16mm)->min))
# define mui_u8g2_u16mm_get_max(u16mm) mui_pgm_read(&((u16mm)->max))
# define mui_u8g2_u16mm_get_valptr(u16mm) ((uint16_t *)mui_pgm_wread(&((u16mm)->value)))
#else
# define mui_u8g2_u16mm_get_min(u16mm) ((u16mm)->min)
# define mui_u8g2_u16mm_get_max(u16mm) ((u16mm)->max)
# define mui_u8g2_u16mm_get_valptr(u16mm) ((u16mm)->value)
#endif
struct mui_u8g2_u8_min_max_step_struct
{
@ -121,6 +140,31 @@ typedef const struct mui_u8g2_u8_min_max_step_struct mui_u8g2_u8_min_max_step_t;
# define mui_u8g2_u8mms_get_valptr(u8mm) ((u8mm)->value)
#endif
struct mui_u8g2_u16_min_max_step_struct
{
uint16_t *value;
uint16_t min;
uint16_t max;
uint16_t step;
uint8_t flags;
} MUI_PROGMEM;
typedef const struct mui_u8g2_u16_min_max_step_struct mui_u8g2_u16_min_max_step_t;
#if defined(__GNUC__) && defined(__AVR__)
# define mui_u8g2_u16mms_get_step(u16mm) mui_pgm_read(&((u16mm)->step))
# define mui_u8g2_u8mms_get_flags(u8mm) mui_pgm_read(&((u8mm)->flags))
# define mui_u8g2_u16mms_get_min(u16mm) mui_pgm_read(&((u16mm)->min))
# define mui_u8g2_u16mms_get_max(u16mm) mui_pgm_read(&((u16mm)->max))
# define mui_u8g2_u16mms_get_valptr(u16mm) ((uint8_t *)mui_pgm_wread(&((u16mm)->value)))
#else
# define mui_u8g2_u16mms_get_step(u16mm) ((u16mm)->step)
# define mui_u8g2_u8mms_get_flags(u8mm) ((u8mm)->flags)
# define mui_u8g2_u16mms_get_min(u16mm) ((u16mm)->min)
# define mui_u8g2_u16mms_get_max(u16mm) ((u16mm)->max)
# define mui_u8g2_u16mms_get_valptr(u16mm) ((u16mm)->value)
#endif
/* helper functions */
@ -213,6 +257,20 @@ uint8_t mui_u8g2_u8_min_max_wm_mud_pi(mui_t *ui, uint8_t msg); /* GIF, MUIF_U8G
uint8_t mui_u8g2_u8_min_max_wm_mse_pf(mui_t *ui, uint8_t msg); /* GIF, MUIF_U8G2_U8_MIN_MAX, MUI_XY */
uint8_t mui_u8g2_u8_min_max_wm_mud_pf(mui_t *ui, uint8_t msg); /* GIF, MUIF_U8G2_U8_MIN_MAX, MUI_XY */
/*===== data = mui_u8g2_u16_min_max_t* =====*/
/* gcc note: the macro uses array compound literals to extend the lifetime in C++, see last section in https://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html */
#define MUIF_U8G2_U16_MIN_MAX(id, valptr, min, max, muif) \
MUIF(id, MUIF_CFLAG_IS_CURSOR_SELECTABLE, \
(void *)((mui_u8g2_u16_min_max_t [] ) {{ (valptr) MUI_U8G2_COMMA (min) MUI_U8G2_COMMA (max)}}), \
(muif))
uint8_t mui_u8g2_u16_min_max_wm_mse_pi(mui_t *ui, uint8_t msg); /* GIF, MUIF_U8G2_U16_MIN_MAX, MUI_XY */
uint8_t mui_u8g2_u16_min_max_wm_mud_pi(mui_t *ui, uint8_t msg); /* GIF, MUIF_U8G2_U16_MIN_MAX, MUI_XY */
uint8_t mui_u8g2_u16_min_max_wm_mse_pf(mui_t *ui, uint8_t msg); /* GIF, MUIF_U8G2_U16_MIN_MAX, MUI_XY */
uint8_t mui_u8g2_u16_min_max_wm_mud_pf(mui_t *ui, uint8_t msg); /* GIF, MUIF_U8G2_U16_MIN_MAX, MUI_XY */
/*===== data = mui_u8g2_u8_min_max_step_t* =====*/
/* gcc note: the macro uses array compound literals to extend the lifetime in C++, see last section in https://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html */
@ -220,6 +278,14 @@ uint8_t mui_u8g2_u8_min_max_wm_mud_pf(mui_t *ui, uint8_t msg); /* GIF, MUIF_U8G
MUIF(id, MUIF_CFLAG_IS_CURSOR_SELECTABLE, \
(void *)((mui_u8g2_u8_min_max_step_t [] ) {{ (valptr) MUI_U8G2_COMMA (min) MUI_U8G2_COMMA (max) MUI_U8G2_COMMA (step) MUI_U8G2_COMMA (flags) }}), \
(muif))
/*===== data = mui_u8g2_u16_min_max_step_t* =====*/
/* gcc note: the macro uses array compound literals to extend the lifetime in C++, see last section in https://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html */
#define MUIF_U8G2_U16_MIN_MAX_STEP(id, valptr, min, max, step, flags, muif) \
MUIF(id, MUIF_CFLAG_IS_CURSOR_SELECTABLE, \
(void *)((mui_u8g2_u16_min_max_step_t [] ) {{ (valptr) MUI_U8G2_COMMA (min) MUI_U8G2_COMMA (max) MUI_U8G2_COMMA (step) MUI_U8G2_COMMA (flags) }}), \
(muif))
#define MUI_MMS_2X_BAR 0x01
#define MUI_MMS_4X_BAR 0x02