lcd.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "lcd.h"
  2. #ifdef LCD_ENABLE
  3. #include "jlx12864.h"
  4. static uint32_t utf8_strlen(const char *str)
  5. {
  6. uint32_t len = 0;
  7. while (*str) {
  8. len += (*str++ & 0xc0) != 0x80;
  9. }
  10. return len;
  11. }
  12. void LCD_Init()
  13. {
  14. init_lcd();
  15. clear_screen();
  16. }
  17. void LCD_PrintRow(uint8_t row, uint8_t y, char *text)
  18. {
  19. LCD_PutText(row * FONTSIZE_X, y, FONT_1X, COLOR_BLACK, text);
  20. LCD_LoadData();
  21. }
  22. void LCD_ClearRow(uint8_t row)
  23. {
  24. clear_page(row);
  25. }
  26. void LCD_PrintAligned(uint8_t row, align_t align, char *text)
  27. {
  28. uint8_t x = 0;
  29. switch (align) {
  30. case alignLEFT:
  31. x = 0;
  32. break;
  33. case alignCENTER:
  34. x = (LCD_WIDTH - FONTSIZE_X * utf8_strlen(text)) / 2;
  35. break;
  36. case alignRIGHT:
  37. x = LCD_WIDTH - FONTSIZE_X * utf8_strlen(text);
  38. break;
  39. default:
  40. break;
  41. }
  42. LCD_ClearRow(row);
  43. LCD_PutText(x, row * FONTSIZE_Y, FONT_1X, COLOR_BLACK, text);
  44. LCD_LoadData();
  45. }
  46. void LCD_PrintBar(uint8_t row, uint8_t progress)
  47. {
  48. const uint8_t x1 = 5;
  49. const uint8_t x2 = LCD_WIDTH - 10;
  50. const uint8_t y1 = row * FONTSIZE_Y;
  51. const uint8_t y2 = y1 + FONTSIZE_Y - 1;
  52. if (progress > 100) progress == 100;
  53. const uint8_t len = (x2 - x1 - 3) * progress / 100;
  54. LCD_ClearRow(row);
  55. LCD_DrawLine(x1, y1, x2, y1, COLOR_BLACK);
  56. LCD_DrawLine(x1, y2, x2, y2, COLOR_BLACK);
  57. LCD_DrawLine(x1, y1, x1, y2, COLOR_BLACK);
  58. LCD_DrawLine(x2, y1, x2, y2, COLOR_BLACK);
  59. LCD_FillRegion(x1 + 2, y1 + 2, len, 4, COLOR_BLACK);
  60. LCD_LoadData();
  61. }
  62. #endif /* LCD_ENABLE */