Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom page selection for paged display #990

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cppsrc/U8g2lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ class U8G2 : public Print
/* u8g2_buffer.c */
void sendBuffer(void) { u8g2_SendBuffer(&u8g2); }
void clearBuffer(void) { u8g2_ClearBuffer(&u8g2); }


uint8_t customPage(uint8_t page) { return u8g2_CustomPage(&u8g2, page); }
void firstPage(void) { u8g2_FirstPage(&u8g2); }
uint8_t nextPage(void) { return u8g2_NextPage(&u8g2); }

Expand Down
1 change: 1 addition & 0 deletions csrc/u8g2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,7 @@ void u8g2_ClearBuffer(u8g2_t *u8g2);

void u8g2_SetBufferCurrTileRow(u8g2_t *u8g2, uint8_t row) U8G2_NOINLINE;

uint8_t u8g2_CustomPage(u8g2_t * const u8g2, uint8_t const page);
void u8g2_FirstPage(u8g2_t *u8g2);
uint8_t u8g2_NextPage(u8g2_t *u8g2);

Expand Down
30 changes: 30 additions & 0 deletions csrc/u8g2_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,34 @@ void u8g2_SetBufferCurrTileRow(u8g2_t *u8g2, uint8_t row)
u8g2->cb->update_page_win(u8g2);
}

/* Calculates the first row of the specified page - does not detect overflows
* or pages out of scope for the current display. */
uint8_t u8g2_PageFirstRow(u8g2_t const * const u8g2, uint8_t const page)
{
return u8g2->tile_buf_height * page;
}

/* Sets the current buffer to the page specified.
* Returns 0 in case the page is invalid - otherwise 1. */
uint8_t u8g2_CustomPage(u8g2_t * const u8g2, uint8_t const page)
{
uint8_t const row = u8g2_PageFirstRow(u8g2, page);
if ( row > ( u8g2_GetU8x8(u8g2)->display_info->tile_height - u8g2->tile_buf_height ) )
{
return 0;
}
else
{
if ( u8g2->is_auto_page_clear )
{
u8g2_ClearBuffer(u8g2);
}
u8g2_SetBufferCurrTileRow(u8g2, row);
return 1;
}
}

/* Specialization [faster!] for setting the current buffer to the first page. */
void u8g2_FirstPage(u8g2_t *u8g2)
{
if ( u8g2->is_auto_page_clear )
Expand All @@ -113,6 +141,8 @@ void u8g2_FirstPage(u8g2_t *u8g2)
u8g2_SetBufferCurrTileRow(u8g2, 0);
}

/* Sends the current buffer to the display and attempts to set the buffer to the next page.
* Returns 0 in case the next page is invalid - otherwise 1 */
uint8_t u8g2_NextPage(u8g2_t *u8g2)
{
uint8_t row;
Expand Down