int me_cb_scale_1_7(menu_t *menu, const me_t *me, uint8_t msg) { u8g2_uint_t x; uint8_t val = *(uint8_t *)(me->val); if ( val <= 0 ) val = 1; x = me->x+(val-1)*5; switch(msg) { case ME_MSG_IS_FOCUS: return 1; case ME_MSG_DRAW_FOCUS: /* u8g2_SetFont(menu->u8g2, MENU_BIG_NUM); menu_DrawBoxFocus(menu, me->x+MENU_BIG_NUM_FOCUS_XO, me->y - u8g2_GetAscent(menu->u8g2)-1, u8g2_GetGlyphWidth(menu->u8g2, '0')+MENU_BIG_NUM_FOCUS_EXTRAX, u8g2_GetAscent(menu->u8g2) + 2); */ u8g2_DrawBox(menu->u8g2, x-2 , me->y-2, 5, 5); return 1; case ME_MSG_SELECT: { val++; if ( val > 7 ) val = 1; *(uint8_t *)(me->val) = val; } return 1; case ME_MSG_DRAW: set_contrast(); /* give user feedback... not so nice: We assume *(uint8_t *)(me->val) points to gui_data.contrast */ //u8g2_SetFont(menu->u8g2, MENU_NORMAL_FONT); //u8g2_DrawGlyph(menu->u8g2, me->x, me->y-2, *(uint8_t *)(me->val) + '0'); u8g2_DrawHLine(menu->u8g2, me->x, me->y, 6*5+1); u8g2_DrawVLine(menu->u8g2, me->x, me->y-2, 5); //u8g2_DrawVLine(menu->u8g2, me->x+1*5, me->y-1, 3); //u8g2_DrawVLine(menu->u8g2, me->x+2*5, me->y-1, 3); u8g2_DrawVLine(menu->u8g2, me->x+3*5, me->y-2, 5); //u8g2_DrawVLine(menu->u8g2, me->x+4*5, me->y-1, 3); //u8g2_DrawVLine(menu->u8g2, me->x+5*5, me->y-1, 3); u8g2_DrawVLine(menu->u8g2, me->x+6*5, me->y-2, 5); u8g2_DrawFrame(menu->u8g2, x-3 , me->y-3, 7, 7); u8g2_SetDrawColor(menu->u8g2, 0); u8g2_DrawBox(menu->u8g2, x-2 , me->y-2, 5, 5); /* draw color is set to 1 in the following function */ menu_ClearEdgePixel(menu, x-3 , me->y-3, 7, 7); menu_DrawEdgePixel(menu, x-2 , me->y-3+1, 5, 5); return 1; } return 0; }
void menu_ClearEdgePixel(menu_t *menu, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h) { u8g2_SetDrawColor(menu->u8g2, 0); menu_DrawEdgePixel(menu, x, y, w, h); u8g2_SetDrawColor(menu->u8g2, 1); }
void menu_DrawBoxFocus(menu_t *menu, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h) { u8g2_SetDrawColor(menu->u8g2, 2); u8g2_DrawBox(menu->u8g2, x, y, w, h); menu_ClearEdgePixel(menu, x, y, w, h); }
int main(void) { uint32_t screen = 0; u8g2_t u8g2; /* initialize to stdout */ #if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_STDOUT puts("initializing to stdout."); u8g2_SetupBuffer_Utf8(&u8g2, U8G2_R0); #endif /* initialize to virtual SDL (native only) */ #if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_SDL puts("initializing to SDL."); u8g2_SetupBuffer_SDL_128x64_4(&u8g2, U8G2_R0); #endif /* initialize to SPI */ #if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_SPI puts("initializing to SPI."); TEST_U8G2_DISPLAY(&u8g2, U8G2_R0, u8x8_byte_riotos_hw_spi, u8x8_gpio_and_delay_riotos); u8g2_SetPins(&u8g2, pins, pins_enabled); u8g2_SetDevice(&u8g2, TEST_U8G2_SPI); #endif /* initialize to I2C */ #if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_I2C puts("initializing to I2C."); TEST_U8G2_DISPLAY(&u8g2, U8G2_R0, u8x8_byte_riotos_hw_i2c, u8x8_gpio_and_delay_riotos); u8g2_SetPins(&u8g2, pins, pins_enabled); u8g2_SetDevice(&u8g2, TEST_U8G2_I2C); u8g2_SetI2CAddress(&u8g2, TEST_U8G2_ADDR); #endif /* initialize the display */ puts("Initializing display."); u8g2_InitDisplay(&u8g2); u8g2_SetPowerSave(&u8g2, 0); /* start drawing in a loop */ puts("Drawing on screen."); while (true) { u8g2_FirstPage(&u8g2); do { u8g2_SetDrawColor(&u8g2, 1); u8g2_SetFont(&u8g2, u8g2_font_helvB12_tf); if (screen == 0) { u8g2_DrawStr(&u8g2, 12, 22, "THIS"); } else if (screen == 1) { u8g2_DrawStr(&u8g2, 24, 22, "IS"); } else if (screen == 2) { u8g2_DrawBitmap(&u8g2, 0, 0, 8, 32, logo); } } while (u8g2_NextPage(&u8g2)); #if TEST_U8G2_OUTPUT == TEST_U8G2_OUTPUT_STDOUT /* transfer screen buffer to stdout */ utf8_show(); #endif /* show screen in next iteration */ screen = (screen + 1) % 3; /* sleep a little */ xtimer_sleep(1); } return 0; }