Example #1
0
void draw(void) {
  // graphic commands to redraw the complete screen should be placed here  
  u8g_SetFont(&u8g, u8g_font_helvR08);
  u8g_SetFontPosTop(&u8g);
  
  u8g_DrawStr( &u8g, 0, 0, "Hello World!");

  // Try with/ without below lines

  u8g_SetFont(&u8g, u8g_font_profont11);
  u8g_SetFontPosTop(&u8g);
  u8g_DrawStr( &u8g, 32, 25, "see yah!");
  u8g_DrawPixel(&u8g, 32, 25);
}
Example #2
0
void drawMainMenu(uint8_t menuPosition){
	char *mainMenuStrings[MAIN_MENU_ITEMS] = {"Last swim", "New Swim"};
	uint8_t i, h;
	u8g_uint_t w, d;
	u8g_SetFont(&u8g, u8g_font_6x13);
	u8g_SetFontRefHeightText(&u8g);
	u8g_SetFontPosTop(&u8g);
	h = u8g_GetFontAscent(&u8g) - u8g_GetFontDescent(&u8g);
	w = u8g_GetWidth(&u8g);
	
	char vccChar[10];
	my_itoa(vcc, vccChar, 10);

	// Doing the actual drawing
	u8g_FirstPage(&u8g);
	do{
		
		for (i = 0; i < MAIN_MENU_ITEMS; i++){
			d = (w - u8g_GetStrWidth(&u8g, mainMenuStrings[i])) / 2;
			u8g_SetDefaultForegroundColor(&u8g);
			if (i == menuPosition){
				u8g_DrawBox(&u8g, 0, i*h+1, w, h);
				u8g_SetDefaultBackgroundColor(&u8g);
			}
			u8g_DrawStr(&u8g, d, i*h, mainMenuStrings[i]);
		}
		u8g_SetDefaultForegroundColor(&u8g);
		u8g_DrawFrame(&u8g, 0, 0, 128, 64);
		
		u8g_DrawStr(&u8g, 5, 50, vccChar);
	} while (u8g_NextPage(&u8g));
}
Example #3
0
// Lua: u8g.setFontPosTop( self )
static int lu8g_setFontPosTop( lua_State *L )
{
    lu8g_userdata_t *lud;

    if ((lud = get_lud( L )) == NULL)
        return 0;

    u8g_SetFontPosTop( LU8G );

    return 0;
}
Example #4
0
void menu_draw(menu_t *menu, u8g_t *u8g)
{
	uint8_t i, h;
	static char ramstr[32];
	menu_buttons_t *b;
	u8g_uint_t w, d;
	
	if(!menu)
		return;
	
	// Calculate text size
	u8g_SetFont(u8g, u8g_font_5x7);
	u8g_SetFontRefHeightText(u8g);
	u8g_SetFontPosTop(u8g);
	h = u8g_GetFontAscent(u8g)-u8g_GetFontDescent(u8g);
	w = u8g_GetWidth(u8g);
	for( i = 0;; i++ ) {        // draw all menu items
		// Copy string from program memory to a work string in RAM
		strncpy_P(ramstr, (PGM_P)pgm_read_word(&(menu->strings[i])), sizeof(ramstr));
		ramstr[31] = 0;
		// Zero length string marks end of string list. 
		if(!ramstr[0])
			break;
		// Get its length in pixels
		d = (w-u8g_GetStrWidth(u8g, ramstr))/2;
		// Set foreground color
		u8g_SetDefaultForegroundColor(u8g);
		// If item selected
		if ( i == menu->selected ) {            // current selected menu item
			u8g_DrawBox(u8g, 0, i*h+1, w, h);   // draw cursor bar
			u8g_SetDefaultBackgroundColor(u8g);
		}
		// Display the string
		u8g_DrawStr(u8g, d, i*h, ramstr);
	}
	
	// Remember menu item count
	menu->item_count = i;
	
	// Ensure text and background are set back to normal
	u8g_SetDefaultForegroundColor(u8g);
	
	// If there are soft buttons, draw them here
	if(menu->buttons){	
		for(b = menu->buttons; b; b = b->next){
			strncpy_P(ramstr, b->label, sizeof(ramstr));
			ramstr[31] = 0;
			u8g_DrawStr(u8g, b->col, b->row, ramstr);
		}
	}
}
Example #5
0
void display_init(void)
{
  /* select minimal prescaler (max system speed) */
  CLKPR = 0xFF;
                                                           // SCK    MOSI      CS       D/C
   u8g_InitSPI(&u8g, &u8g_dev_ssd1325_nhd27oled_2x_gr_sw_spi, PN(5, 6), PN(5, 5), PN(4, 7),PN(5,7), PN(4,6));
   u8g_SetRot180(&u8g);

   /* assign default color value */
   u8g_SetColorIndex(&u8g, 3);         /* max intensity */
 //  u8g_SetColorIndex(&u8g, 1);         /* pixel on */

  u8g_SetFont(&u8g, u8g_font_profont11);
  u8g_SetFontRefHeightExtendedText(&u8g);
  u8g_SetDefaultForegroundColor(&u8g);
  u8g_SetFontPosTop(&u8g);


}
Example #6
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;
}
Example #7
0
File: menu.c Project: gnkarn/u8glib
void draw_menu(void)
{
    uint8_t i, h;
    u8g_uint_t w, d;

    u8g_SetFont(&u8g, u8g_font_6x13);
    u8g_SetFontRefHeightText(&u8g);
    u8g_SetFontPosTop(&u8g);

    h = u8g_GetFontAscent(&u8g)-u8g_GetFontDescent(&u8g);
    w = u8g_GetWidth(&u8g);
    for( i = 0; i < MENU_ITEMS; i++ )
    {
        d = (w-u8g_GetStrWidth(&u8g, menu_strings[i]))/2;
        u8g_SetDefaultForegroundColor(&u8g);
        if ( i == menu_current )
        {
            u8g_DrawBox(&u8g, 0, i*h+1, w, h);
            u8g_SetDefaultBackgroundColor(&u8g);
        }
        u8g_DrawStr(&u8g, d, i*h, menu_strings[i]);
    }
}
Example #8
0
void u8g_prepare(void) {
    u8g_SetFont(&u8g, u8g_font_6x10);
    u8g_SetFontRefHeightExtendedText(&u8g);
    u8g_SetDefaultForegroundColor(&u8g);
    u8g_SetFontPosTop(&u8g);
}
Example #9
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);

}