Skip to content

Commit

Permalink
Add support for a pointer to user data.
Browse files Browse the repository at this point in the history
This PR adds ucg_GetUserPtr and ucg_SetUserPtr to store
user data. This feature is disabled by default, and can
be enabled by adding WITH_USER_PTR.

If enabled, the ucg_t structure is extended with an
additional void* user_ptr.
  • Loading branch information
basilfx committed Jan 12, 2020
1 parent 73affe0 commit c5b9b50
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cppsrc/Ucglib.h
Expand Up @@ -89,6 +89,10 @@ class Ucglib : public Print
ucg_int_t getWidth(void) { return ucg_GetWidth(&ucg); }
ucg_int_t getHeight(void) { return ucg_GetHeight(&ucg); }

#ifdef WITH_USER_PTR
void *getUserPtr() { return ucg_GetUserPtr(&ucg); }
void setUserPtr(void *p) { ucg_SetUserPtr(&ucg, p); }
#endif

void setFontRefHeightText(void) { ucg_SetFontRefHeightText(&ucg); }
void setFontRefHeightExtendedText(void) { ucg_SetFontRefHeightExtendedText(&ucg); }
Expand Down
14 changes: 14 additions & 0 deletions csrc/ucg.h
Expand Up @@ -96,6 +96,9 @@ extern "C"
#endif
#endif

/* Define this for an additional user pointer inside the ucg data struct */
//#define WITH_USER_PTR

#ifdef __GNUC__
# define UCG_NOINLINE __attribute__((noinline))
# define UCG_SECTION(name) __attribute__ ((section (name)))
Expand Down Expand Up @@ -411,6 +414,10 @@ struct _ucg_t
int8_t font_ref_ascent;
int8_t font_ref_descent;

#ifdef WITH_USER_PTR
void *user_ptr;
#endif

/* only for Arduino/C++ Interface */
#ifdef USE_PIN_LIST
uint8_t pin_list[UCG_PIN_COUNT];
Expand All @@ -422,6 +429,8 @@ struct _ucg_t

#endif



/*
Small amount of RAM for the com interface (com_cb).
Might be unused on unix systems, where the com sub system is
Expand All @@ -437,6 +446,11 @@ struct _ucg_t
#define ucg_GetWidth(ucg) ((ucg)->dimension.w)
#define ucg_GetHeight(ucg) ((ucg)->dimension.h)

#ifdef WITH_USER_PTR
#define ucg_GetUserPtr(ucg) ((ucg)->user_ptr)
#define ucg_SetUserPtr(ucg, p) ((ucg)->user_ptr = (p))
#endif

#define UCG_MSG_DEV_POWER_UP 10
#define UCG_MSG_DEV_POWER_DOWN 11
#define UCG_MSG_SET_CLIP_BOX 12
Expand Down

0 comments on commit c5b9b50

Please sign in to comment.