setDisplayRotation, better flip mode example

This commit is contained in:
olikraus 2016-05-04 18:56:42 +02:00
parent b3f11823f2
commit 0250659fa7
4 changed files with 50 additions and 16 deletions

View File

@ -80,6 +80,10 @@ class U8G2 : public Print
void setContrast(uint8_t value) {
u8g2_SetContrast(&u8g2, value); }
void setDisplayRotation(const u8g2_cb_t *u8g2_cb) {
u8g2_SetDisplayRotation(&u8g2, u8g2_cb); }
void begin(void) {
initDisplay(); clearDisplay(); setPowerSave(0); }

View File

@ -359,6 +359,7 @@ extern const u8g2_cb_t u8g2_cb_r3;
*/
void u8g2_SetupBuffer(u8g2_t *u8g2, uint8_t *buf, uint8_t tile_buf_height, u8g2_draw_ll_hvline_cb ll_hvline_cb, const u8g2_cb_t *u8g2_cb);
void u8g2_SetDisplayRotation(u8g2_t *u8g2, const u8g2_cb_t *u8g2_cb);
/*==========================================*/
/* u8g2_d_memory.c generated code start */

View File

@ -57,6 +57,16 @@ void u8g2_SetupBuffer(u8g2_t *u8g2, uint8_t *buf, uint8_t tile_buf_height, u8g2_
#endif
}
/*
Usually the display rotation is set initially, but it could be done later also
u8g2_cb can be U8G2_R0..U8G2_R3
*/
void u8g2_SetDisplayRotation(u8g2_t *u8g2, const u8g2_cb_t *u8g2_cb)
{
u8g2->cb = u8g2_cb;
u8g2->cb->update(u8g2);
}
/*============================================*/
/*

View File

@ -65,26 +65,45 @@ void setup(void) {
u8g2.setFont(u8g2_font_helvB12_tr);
}
void loop(void) {
u8g2.setFlipMode(1);
void draw(const char *s)
{
u8g2.firstPage();
do {
u8g2.drawStr(0,24,"Hello World!");
u8g2.drawStr(0,24,"Hello World!");
u8g2.drawStr(0,44,s);
u8g2.drawFrame(0,0,u8g2.getDisplayWidth(),u8g2.getDisplayHeight() );
} while ( u8g2.nextPage() );
delay(2000);
u8g2.setFlipMode(0);
u8g2.firstPage();
do {
u8g2.drawStr(0,24,"Hello World!");
u8g2.drawFrame(0,0,u8g2.getDisplayWidth(),u8g2.getDisplayHeight() );
} while ( u8g2.nextPage() );
delay(400);
delay(1000);
}
void loop(void) {
u8g2.setDisplayRotation(U8G2_R0);
u8g2.setFlipMode(0);
draw("R0, F0");
u8g2.setFlipMode(1);
draw("R0, F1");
u8g2.setDisplayRotation(U8G2_R1);
u8g2.setFlipMode(0);
draw("R1, F0");
u8g2.setFlipMode(1);
draw("R1, F1");
u8g2.setDisplayRotation(U8G2_R2);
u8g2.setFlipMode(0);
draw("R2, F0");
u8g2.setFlipMode(1);
draw("R2, F1");
u8g2.setDisplayRotation(U8G2_R3);
u8g2.setFlipMode(0);
draw("R3, F0");
u8g2.setFlipMode(1);
draw("R3, F1");
}