2021-08-28 16:10:38 +08:00
/*
mui_u8g2 . h
Monochrome minimal user interface : Glue code between mui and u8g2 .
Universal 8 bit Graphics Library ( https : //github.com/olikraus/u8g2/)
2021-09-05 17:09:02 +08:00
Copyright ( c ) 2021 , olikraus @ gmail . com
2021-08-28 16:10:38 +08:00
All rights reserved .
Redistribution and use in source and binary forms , with or without modification ,
are permitted provided that the following conditions are met :
* Redistributions of source code must retain the above copyright notice , this list
of conditions and the following disclaimer .
* Redistributions in binary form must reproduce the above copyright notice , this
list of conditions and the following disclaimer in the documentation and / or other
materials provided with the distribution .
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS " AS IS " AND ANY EXPRESS OR IMPLIED WARRANTIES ,
INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL ,
SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT
NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT ,
STRICT LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE )
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*/
2021-08-09 00:49:36 +08:00
2021-08-29 16:50:01 +08:00
# ifndef MUI_U8G2_H
# define MUI_U8G2_H
2021-09-20 12:41:00 +08:00
# include "mui.h"
2021-09-12 16:15:14 +08:00
2021-08-29 16:50:01 +08:00
/*==========================================*/
/* C++ compatible */
# ifdef __cplusplus
extern " C " {
# endif
2021-08-09 00:49:36 +08:00
2021-09-12 16:15:14 +08:00
# define MUI_U8G2_COMMA ,
typedef const char * ( * mui_u8g2_get_list_element_cb ) ( void * data , uint16_t index ) ;
typedef uint16_t ( * mui_u8g2_get_list_count_cb ) ( void * data ) ;
struct mui_u8g2_list_struct
{
uint16_t * selection ;
void * data ;
mui_u8g2_get_list_element_cb get_list_element ;
mui_u8g2_get_list_count_cb get_list_count ;
} MUI_PROGMEM ;
typedef const struct mui_u8g2_list_struct mui_u8g2_list_t ;
# if defined(__GNUC__) && defined(__AVR__)
# define mui_u8g2_list_get_selection_ptr(list) ((uint16_t *)mui_pgm_wread(&((list)->selection)))
# define mui_u8g2_list_get_data_ptr(list) ((void *)mui_pgm_wread(&((list)->data)))
# define mui_u8g2_list_get_element_cb(list) ((mui_u8g2_get_list_element_cb)mui_pgm_wread(&((list)->get_list_element)))
# define mui_u8g2_list_get_count_cb(list) ((mui_u8g2_get_list_count_cb)mui_pgm_wread(&((list)->get_list_count)))
# else
# define mui_u8g2_list_get_selection_ptr(list) ((list)->selection)
# define mui_u8g2_list_get_data_ptr(list) ((list)->data)
# define mui_u8g2_list_get_element_cb(list) ((list)->get_list_element)
# define mui_u8g2_list_get_count_cb(list) ((list)->get_list_count)
# endif
2021-09-11 06:32:23 +08:00
struct mui_u8g2_u8_min_max_struct
{
uint8_t * value ;
uint8_t min ;
uint8_t max ;
2021-09-12 16:15:14 +08:00
} MUI_PROGMEM ;
2021-09-11 16:27:40 +08:00
typedef const struct mui_u8g2_u8_min_max_struct mui_u8g2_u8_min_max_t ;
# if defined(__GNUC__) && defined(__AVR__)
# define mui_u8g2_u8mm_get_min(u8mm) mui_pgm_read(&((u8mm)->min))
# define mui_u8g2_u8mm_get_max(u8mm) mui_pgm_read(&((u8mm)->max))
# define mui_u8g2_u8mm_get_valptr(u8mm) ((uint8_t *)mui_pgm_wread(&((u8mm)->value)))
# else
# define mui_u8g2_u8mm_get_min(u8mm) ((u8mm)->min)
# define mui_u8g2_u8mm_get_max(u8mm) ((u8mm)->max)
# define mui_u8g2_u8mm_get_valptr(u8mm) ((u8mm)->value)
# endif
2021-09-11 06:32:23 +08:00
2021-09-12 16:15:14 +08:00
2021-08-28 18:44:34 +08:00
/* helper functions */
u8g2_uint_t mui_get_x ( mui_t * ui ) ;
u8g2_uint_t mui_get_y ( mui_t * ui ) ;
u8g2_t * mui_get_U8g2 ( mui_t * ui ) ;
2021-09-07 05:51:26 +08:00
u8g2_uint_t mui_u8g2_get_draw_button_pi_flags ( mui_t * ui ) MUI_NOINLINE ;
void mui_u8g2_draw_button_utf ( mui_t * ui , u8g2_uint_t flags , u8g2_uint_t width , u8g2_uint_t padding_h , u8g2_uint_t padding_v , const char * text ) MUI_NOINLINE ;
2021-09-26 04:59:59 +08:00
void mui_u8g2_draw_button_utf_pi ( mui_t * ui , u8g2_uint_t width , u8g2_uint_t padding_h , const char * text ) ;
2021-09-07 05:51:26 +08:00
2021-08-28 18:44:34 +08:00
2021-08-16 06:06:52 +08:00
2021-08-21 19:31:11 +08:00
/* ready to use field functions */
2021-08-15 22:23:17 +08:00
2021-09-05 17:20:52 +08:00
uint8_t mui_u8g2_draw_text ( mui_t * ui , uint8_t msg ) ;
2021-09-22 04:43:01 +08:00
uint8_t mui_u8g2_btn_goto_wm_fi ( mui_t * ui , uint8_t msg ) ;
uint8_t mui_u8g2_btn_goto_w2_fi ( mui_t * ui , uint8_t msg ) ;
2021-09-26 04:59:59 +08:00
2021-09-22 04:43:01 +08:00
uint8_t mui_u8g2_btn_goto_w1_pi ( mui_t * ui , uint8_t msg ) ;
2021-09-26 04:59:59 +08:00
uint8_t mui_u8g2_btn_goto_w1_fi ( mui_t * ui , uint8_t msg ) ;
2021-09-04 20:46:42 +08:00
2021-09-05 17:20:52 +08:00
uint8_t mui_u8g2_btn_exit_wm_fi ( mui_t * ui , uint8_t msg ) ;
2021-09-05 05:25:20 +08:00
2021-09-27 04:33:16 +08:00
uint8_t mui_u8g2_u8_chkbox_wm_pi ( mui_t * ui , uint8_t msg ) ; /* MUIF_VARIABLE, MUI_XY */
uint8_t mui_u8g2_u8_radio_wm_pi ( mui_t * ui , uint8_t msg ) ; /* MUIF_VARIABLE,MUI_XYAT */
2021-09-11 06:32:23 +08:00
2021-09-27 04:33:16 +08:00
uint8_t mui_u8g2_u8_opt_line_wa_mse_pi ( mui_t * ui , uint8_t msg ) ; /* MUIF_VARIABLE,MUI_XYAT */
uint8_t mui_u8g2_u8_opt_line_wa_mud_pi ( mui_t * ui , uint8_t msg ) ; /* MUIF_VARIABLE,MUI_XYAT */
2021-09-04 20:46:42 +08:00
2021-09-12 23:05:54 +08:00
uint8_t mui_u8g2_u8_opt_parent_wm_mse_pi ( mui_t * ui , uint8_t msg ) ;
2021-09-19 21:58:55 +08:00
uint8_t mui_u8g2_u8_opt_radio_child_wm_mse_pi ( mui_t * ui , uint8_t msg ) ;
uint8_t mui_u8g2_u8_opt_radio_child_w1_mse_pi ( mui_t * ui , uint8_t msg ) ;
2021-09-26 17:16:14 +08:00
uint8_t mui_u8g2_u8_opt_child_wm_mse_pi ( mui_t * ui , uint8_t msg ) ; /* like mui_u8g2_u8_opt_radio_child_wm_mse_pi, but without radio button */
uint8_t mui_u8g2_goto_parent ( mui_t * ui , uint8_t msg ) ; /* MUIF_RO */
uint8_t mui_u8g2_goto_child_w1_mse_pi ( mui_t * ui , uint8_t msg ) ; /* MUIF_BUTTON, MUI_XYA */
2021-08-09 00:49:36 +08:00
2021-08-23 00:22:25 +08:00
2021-09-05 05:25:20 +08:00
2021-09-05 17:20:52 +08:00
uint8_t mui_u8g2_u8_char_wm_mud_pi ( mui_t * ui , uint8_t msg ) ;
2021-09-05 05:25:20 +08:00
2021-09-12 23:05:54 +08:00
/*===== data = mui_u8g2_u8_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_U8_MIN_MAX(id, valptr, min, max, muif) \
MUIF ( id , MUIF_CFLAG_IS_CURSOR_SELECTABLE , \
( void * ) ( ( mui_u8g2_u8_min_max_t [ ] ) { { ( valptr ) MUI_U8G2_COMMA ( min ) MUI_U8G2_COMMA ( max ) } } ) , \
( muif ) )
uint8_t mui_u8g2_u8_min_max_wm_mse_pi ( mui_t * ui , uint8_t msg ) ; // data: mui_u8g2_u8_min_max_t *
uint8_t mui_u8g2_u8_min_max_wm_mud_pi ( mui_t * ui , uint8_t msg ) ; // data: mui_u8g2_u8_min_max_t *
2021-09-26 04:59:59 +08:00
uint8_t mui_u8g2_u8_min_max_wm_mse_pf ( mui_t * ui , uint8_t msg ) ;
uint8_t mui_u8g2_u8_min_max_wm_mud_pf ( mui_t * ui , uint8_t msg ) ;
2021-09-12 23:05:54 +08:00
/*===== data = mui_u8g2_list_t* =====*/
2021-09-13 05:43:19 +08:00
# define MUIF_U8G2_U16_LIST(id, valptr, dataptr, getcb, cntcb, muif) \
2021-09-12 16:15:14 +08:00
MUIF ( id , MUIF_CFLAG_IS_CURSOR_SELECTABLE , \
2021-09-13 05:43:19 +08:00
( void * ) ( ( mui_u8g2_list_t [ ] ) { { ( valptr ) MUI_U8G2_COMMA ( dataptr ) MUI_U8G2_COMMA ( getcb ) MUI_U8G2_COMMA ( cntcb ) } } ) , \
2021-09-12 23:05:54 +08:00
( muif ) )
uint8_t mui_u8g2_u16_list_line_wa_mse_pi ( mui_t * ui , uint8_t msg ) ;
uint8_t mui_u8g2_u16_list_line_wa_mud_pi ( mui_t * ui , uint8_t msg ) ;
2021-09-12 16:15:14 +08:00
2021-09-12 23:05:54 +08:00
uint8_t mui_u8g2_u16_list_parent_wm_mse_pi ( mui_t * ui , uint8_t msg ) ;
uint8_t mui_u8g2_u16_list_child_w1_mse_pi ( mui_t * ui , uint8_t msg ) ;
2021-09-12 16:15:14 +08:00
2021-09-20 04:25:52 +08:00
uint8_t mui_u8g2_u16_list_goto_w1_mse_pi ( mui_t * ui , uint8_t msg ) ; /* first char of the string denotes the target form */
2021-09-12 16:15:14 +08:00
2021-08-29 16:50:01 +08:00
# ifdef __cplusplus
}
# endif
2021-08-23 00:22:25 +08:00
2021-08-29 16:50:01 +08:00
# endif /* MUI_U8G2_H */
2021-08-21 04:50:29 +08:00