display.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #include <avr/pgmspace.h>
  2. #include "main.h"
  3. #include "display.h"
  4. #include "HD44780-I2C.h"
  5. #include "xprintf.h"
  6. __flash const unsigned char battery_states[][8] = {
  7. {
  8. 0b01110,
  9. 0b11111,
  10. 0b11111,
  11. 0b11111,
  12. 0b11111,
  13. 0b11111,
  14. 0b11111,
  15. 0b11111,
  16. },
  17. {
  18. 0b01110,
  19. 0b11111,
  20. 0b10001,
  21. 0b11111,
  22. 0b11111,
  23. 0b11111,
  24. 0b11111,
  25. 0b11111,
  26. },
  27. {
  28. 0b01110,
  29. 0b11111,
  30. 0b10001,
  31. 0b10001,
  32. 0b10001,
  33. 0b11111,
  34. 0b11111,
  35. 0b11111,
  36. },
  37. {
  38. 0b01110,
  39. 0b11111,
  40. 0b10001,
  41. 0b10001,
  42. 0b10001,
  43. 0b10001,
  44. 0b10001,
  45. 0b11111,
  46. },
  47. };
  48. void battery_state_display(void) {
  49. unsigned char i;
  50. unsigned char index;
  51. if (System.bat_volt > 4.0)
  52. index = 0;
  53. else if (System.bat_volt > 3.7)
  54. index = 1;
  55. else if (System.bat_volt > 3.4)
  56. index = 2;
  57. else
  58. index = 3;
  59. LCD_WriteCommand(0x40 + 0); // 0x00
  60. for(i=0; i<8; i++){
  61. LCD_WriteData(battery_states[index][i]);
  62. };
  63. }
  64. void display_refresh(unsigned char newstate) {
  65. static const char *line1, *line2;
  66. unsigned char changed = 0;
  67. switch (System.display_state) {
  68. case DISPLAY_STATE_STARTUP:
  69. line1 = PSTR("Uruchamianie...");
  70. break;
  71. case DISPLAY_STATE_POWEROFF_LOWBAT:
  72. line2 = PSTR("Bateria slaba!");
  73. /* fall through */
  74. case DISPLAY_STATE_POWEROFF:
  75. line1 = PSTR("Wylaczanie...");
  76. break;
  77. case DISPLAY_STATE_START_MESSAGE:
  78. line1 = PSTR("Start");
  79. switch(System.status){
  80. case STATUS_NO_POWER: case STATUS_OK: case STATUS_NO_GPS: line2 = NULL; break;
  81. case STATUS_NO_DISK: line2 = PSTR("Brak karty!"); break;
  82. case STATUS_DISK_ERROR: line2 = PSTR("Blad karty!"); break;
  83. case STATUS_FILE_WRITE_ERROR: line2 = PSTR("Blad zapisu!"); break;
  84. case STATUS_FILE_SYNC_ERROR: line2 = PSTR("Blad zapisu FAT!"); break;
  85. case STATUS_FILE_CLOSE_ERROR: line2 = PSTR("Blad zamk.pliku!"); break;
  86. case STATUS_FILE_OPEN_ERROR: line2 = PSTR("Blad otw. pliku!"); break;
  87. }
  88. break;
  89. case DISPLAY_STATE_CARD_OK:
  90. line1 = PSTR("Karta OK!");
  91. line2 = PSTR("Czekam na GPS...");
  92. break;
  93. case DISPLAY_STATE_FILE_OPEN:
  94. line2 = PSTR("Zapis aktywny");
  95. break;
  96. case DISPLAY_STATE_FILE_CLOSED:
  97. line2 = PSTR("Pliki zamkniete");
  98. break;
  99. }
  100. if (newstate)
  101. changed = 1;
  102. if (timer_expired(lcd)) {
  103. changed = 1;
  104. set_timer(lcd, 1000);
  105. }
  106. /* write to LCD */
  107. if (changed) {
  108. battery_state_display();
  109. unsigned char len;
  110. LCD_GoTo(0,0);
  111. if (line1) {
  112. len = strlen_P(line1);
  113. if (len > 15)
  114. xprintf(PSTR("Warning: too long line1=%d, mem addr %4x\r\n"), (int)len, (unsigned int)line1);
  115. LCD_WriteTextP(line1);
  116. while (len<15) {
  117. len++;
  118. LCD_WriteData(' ');
  119. }
  120. } else {
  121. for (len=0; len<15; len++)
  122. LCD_WriteData(' ');
  123. }
  124. LCD_GoTo(0,1);
  125. if (line2) {
  126. len = strlen_P(line2);
  127. if (len > 16)
  128. xprintf(PSTR("Warning: too long line2=%d, mem addr %4x\r\n"), (int)len, (unsigned int)line1);
  129. LCD_WriteTextP(line2);
  130. while (len<16) {
  131. len++;
  132. LCD_WriteData(' ');
  133. }
  134. } else {
  135. for (len=0; len<16; len++)
  136. LCD_WriteData(' ');
  137. }
  138. LCD_GoTo(15, 0);
  139. LCD_WriteData(0); /* battery symbol */
  140. }
  141. }
  142. void display_state(unsigned char newstate) {
  143. System.display_state = newstate;
  144. display_refresh(newstate);
  145. }