void gui_lable(const char* txt, uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t bg, uint8_t border) { SSD1306_DrawFilledRectangle(x, y, w, h, bg); if(border) SSD1306_DrawRectangle(x, y, w, h, !bg); uint8_t max_x = x + border; SSD1306_GotoXY(x+border, y+border + (h - GUI_DefFont.FontHeight)/2 + 1); while(*txt && max_x + GUI_DefFont.FontWidth < SSD1306_WIDTH && max_x + GUI_DefFont.FontWidth < x + w) { max_x += GUI_DefFont.FontWidth; SSD1306_Putc(*txt, &GUI_DefFont, !bg); txt++; } }
void gui_text(const char* txt, uint8_t x, uint8_t y, uint8_t col) { SSD1306_GotoXY(x, y + 1); SSD1306_Puts(txt, &GUI_DefFont, col); }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_I2C1_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ uint8_t res = SSD1306_Init(); printf("OLED init: %d\n", res); SSD1306_GotoXY(10,27); SSD1306_Puts("OLED inited", &Font_7x10, 1); SSD1306_GotoXY(10,52); SSD1306_Puts("Lutsai Alexander", &Font_7x10, 1); SSD1306_UpdateScreen(); //display HAL_Delay(1000); SSD1306_Fill(0); //clear oled int y1 = 64, y2 = 0; while(y1 > 0) { SSD1306_DrawLine(0, y1, 128, y2, 1); SSD1306_UpdateScreen(); y1 -= 2; y2 += 2; } HAL_Delay(1000); SSD1306_Fill(1); //clear oled SSD1306_UpdateScreen(); SSD1306_DrawCircle(64, 32, 25, 0); SSD1306_UpdateScreen(); SSD1306_DrawCircle(128, 32, 25, 0); SSD1306_UpdateScreen(); SSD1306_DrawCircle(0, 32, 25, 0); SSD1306_UpdateScreen(); SSD1306_DrawCircle(32, 32, 25, 0); SSD1306_UpdateScreen(); SSD1306_DrawCircle(96, 32, 25, 0); SSD1306_UpdateScreen(); HAL_Delay(1000); SSD1306_Fill(0); //clear oled SSD1306_UpdateScreen(); int32_t i = -100; char buf[10]; while(i<=100) { memset(&buf[0], 0, sizeof(buf)); sprintf(buf, "%d", i); SSD1306_GotoXY(50,27); SSD1306_Puts(buf, &Font_7x10, 1); SSD1306_DrawLine(64, 10, (i+100)*128/200, (i+100)*64/200, 1); SSD1306_UpdateScreen(); SSD1306_Fill(0); //clear oled i++; } SSD1306_GotoXY(50,27); sprintf(buf, "END"); SSD1306_Puts(buf, &Font_7x10, 1); SSD1306_GotoXY(10,52); SSD1306_Puts("Lutsai Alexander", &Font_7x10, 1); SSD1306_UpdateScreen(); SSD1306_Fill(0); //clear oled HAL_Delay(1000); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ uint32_t lst = 0, cu; while (1) { /* USER CODE END WHILE */ cu = HAL_GetTick(); SSD1306_GotoXY(30,27); sprintf(buf, "fps: %f", 1000.0 / (double)(cu - lst)); SSD1306_Puts(buf, &Font_7x10, 1); SSD1306_GotoXY(7,52); SSD1306_Puts("Lutsai Alexander", &Font_7x10, 1); SSD1306_UpdateScreen(); SSD1306_Fill(0); //clear oled lst = cu; /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
void gui_lable_multiline(const char* txt, uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t bg, uint8_t border) { SSD1306_DrawFilledRectangle(x, y, w, h, bg); uint8_t max_x = x + border, cy = y + border; SSD1306_GotoXY(x+border, cy); while(*txt) { if(max_x + GUI_DefFont.FontWidth > SSD1306_WIDTH || max_x + GUI_DefFont.FontWidth > x + w || *txt == '\n' || *txt == '\r') { cy += GUI_DefFont.FontHeight; SSD1306_GotoXY(x+border, cy); max_x = x + border; if(cy + GUI_DefFont.FontHeight > y + h - border) { if(border) SSD1306_DrawRectangle(x, y, w, h, !bg); return; } } max_x += GUI_DefFont.FontWidth; if(*txt != '\n' && *txt != '\r') SSD1306_Putc(*txt, &GUI_DefFont, !bg); txt++; } if(border) SSD1306_DrawRectangle(x, y, w, h, !bg); }