static void u8g_init_data(u8g_t *u8g) { uint8_t i; u8g->font = NULL; u8g->cursor_font = NULL; u8g->cursor_bg_color = 0; u8g->cursor_fg_color = 1; u8g->cursor_encoding = 34; u8g->cursor_fn = (u8g_draw_cursor_fn)0; for( i = 0; i < U8G_PIN_LIST_LEN; i++ ) u8g->pin_list[i] = U8G_PIN_NONE; u8g_SetColorIndex(u8g, 1); u8g_SetFontPosBaseline(u8g); u8g->font_height_mode = U8G_FONT_HEIGHT_MODE_XTEXT; u8g->font_ref_ascent = 0; u8g->font_ref_descent = 0; u8g->font_line_spacing_factor = 64; /* 64 = 1.0, 77 = 1.2 line spacing factor */ u8g->line_spacing = 0; u8g->state_cb = u8g_state_dummy_cb; }
// Lua: u8g.setFontPosBaseline( self ) static int lu8g_setFontPosBaseline( lua_State *L ) { lu8g_userdata_t *lud; if ((lud = get_lud( L )) == NULL) return 0; u8g_SetFontPosBaseline( LU8G ); return 0; }
int main(void) { u8g_t u8g; u8g_Init(&u8g, &u8g_dev_sdl_1bit_h); u8g_FirstPage(&u8g); do { u8g_SetColorIndex(&u8g, 1); u8g_DrawPixel(&u8g,0,0); u8g_DrawPixel(&u8g,0,1); u8g_SetFont(&u8g, u8g_font_unifont); //u8g_SetFont(&u8g, u8g_font_10x20); //u8g_SetFont(&u8g, u8g_font_gdb17); u8g_SetFontRefHeightText(&u8g); //u8g_SetRefHeightAll(&u8g); //u8g_SetFontPosBaseline(&u8g); //u8g_SetFontPosCenter(&u8g); u8g_SetFontPosTop(&u8g); glyph(&u8g, 5,25, 'g'); u8g_SetFontPosCenter(&u8g); glyph(&u8g, 5+25,25, 'g'); u8g_SetFontPosBaseline(&u8g); glyph(&u8g, 5+2*25,25, 'g'); u8g_SetFontPosBottom(&u8g); glyph(&u8g, 5+3*25,25, 'g'); }while( u8g_NextPage(&u8g) ); while( u8g_sdl_get_key() < 0 ) ; return 0; }
ICACHE_FLASH_ATTR static void draw_normal(DrawingState *state) { uint8_t buf[50]; u8g_SetColorIndex(&(state->u8g), 1); drawingRefreshIcons(state); uint8_t iconWidth = 40; //current measured temperature u8g_SetFont(&(state->u8g), u8g_font_helvB18); u8g_SetFontPosTop(&(state->u8g)); os_sprintf(buf, "%d", state->currentTemp / 100); uint8_t currentTempWidth = u8g_GetStrWidth(&(state->u8g), buf); uint8_t cWidth = u8g_GetStrWidth(&(state->u8g), "C"); uint8_t strHeight = u8g_GetFontAscent(&(state->u8g)); u8g_SetFont(&(state->u8g), u8g_font_helvR08); u8g_SetFontPosBaseline(&(state->u8g)); os_sprintf(buf, "%02d", abs(state->currentTemp % 100)); uint8_t webTempWidth = u8g_GetStrWidth(&(state->u8g), buf); u8g_DrawStr(&(state->u8g), iconWidth + (128 - iconWidth) / 2 - (currentTempWidth + cWidth + webTempWidth) / 2 + currentTempWidth, 16 + strHeight, buf); u8g_SetFont(&(state->u8g), u8g_font_helvB18); u8g_SetFontPosTop(&(state->u8g)); os_sprintf(buf, "%d", state->currentTemp / 100); u8g_DrawStr(&(state->u8g), iconWidth + (128 - iconWidth) / 2 - (currentTempWidth + cWidth + webTempWidth) / 2, 16, buf); u8g_DrawStr(&(state->u8g), iconWidth + (128 - iconWidth) / 2 - (currentTempWidth + cWidth + webTempWidth) / 2 + currentTempWidth + webTempWidth, 16, "C"); //web text if (state->weather.code != 255) { u8g_SetFont(&(state->u8g), u8g_font_6x10); u8g_SetFontPosBottom(&(state->u8g)); os_sprintf(buf, "%s", state->weather.text); currentTempWidth = u8g_GetStrWidth(&(state->u8g), buf); strHeight = u8g_GetFontBBXHeight(&(state->u8g)); u8g_DrawStr(&(state->u8g), iconWidth + (128 - iconWidth) / 2 - currentTempWidth / 2, 64, buf); } //web temperature u8g_SetFont(&(state->u8g), u8g_font_6x10); u8g_SetFontPosBottom(&(state->u8g)); os_sprintf(buf, "%dC", state->weather.temp); uint8_t outsideTempWidth = u8g_GetStrWidth(&(state->u8g), buf); u8g_DrawStr(&(state->u8g), iconWidth + (128 - iconWidth) / 2 - outsideTempWidth / 2, 64 - strHeight, buf); u8g_SetFont(&(state->u8g), u8g_font_6x10); u8g_SetFontPosCenter(&(state->u8g)); if (state->temperatureMode == MANUAL) { os_sprintf(buf, "Manual: %d.%02dC", state->manualTemp / 100, abs(state->manualTemp % 100)); } else if (state->temperatureMode == AUTOMATIC) { if (state->automaticTempCurrentState == NULL) { os_sprintf(buf, "Auto"); } else { os_sprintf(buf, "A:%d.%02dC, %d:%02d", state->automaticTempCurrentState->temp / 100, abs(state->automaticTempCurrentState->temp % 100), state->automaticTempCurrentState->time / 60, state->automaticTempCurrentState->time % 60); } } u8g_DrawStr(&(state->u8g), 0, 8, buf); }