display.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. #include <avr/pgmspace.h>
  2. #include "main.h"
  3. #include "display.h"
  4. #include "xprintf.h"
  5. #include "working_modes.h"
  6. #include "timec.h"
  7. #ifndef LCD_GRAPHIC
  8. __flash const unsigned char battery_states[][8] = {
  9. {
  10. 0b01110,
  11. 0b11111,
  12. 0b11111,
  13. 0b11111,
  14. 0b11111,
  15. 0b11111,
  16. 0b11111,
  17. 0b11111,
  18. },
  19. {
  20. 0b01110,
  21. 0b11111,
  22. 0b10001,
  23. 0b11111,
  24. 0b11111,
  25. 0b11111,
  26. 0b11111,
  27. 0b11111,
  28. },
  29. {
  30. 0b01110,
  31. 0b11111,
  32. 0b10001,
  33. 0b10001,
  34. 0b10001,
  35. 0b11111,
  36. 0b11111,
  37. 0b11111,
  38. },
  39. {
  40. 0b01110,
  41. 0b11111,
  42. 0b10001,
  43. 0b10001,
  44. 0b10001,
  45. 0b10001,
  46. 0b10001,
  47. 0b11111,
  48. },
  49. };
  50. __flash const unsigned char custom_chars[] = {
  51. 0b00000, /* 0x01 down arrow */
  52. 0b00100,
  53. 0b00100,
  54. 0b00100,
  55. 0b10101,
  56. 0b01110,
  57. 0b00100,
  58. 0b00000,
  59. 0b00000, /* 0x02 up arrow */
  60. 0b00100,
  61. 0b01110,
  62. 0b10101,
  63. 0b00100,
  64. 0b00100,
  65. 0b00100,
  66. 0b00000,
  67. };
  68. #endif /* LCD_GRAPHIC */
  69. struct disp_s disp;
  70. void disp_init(void) { /* send custom characters starting with 0x01 */
  71. #ifndef LCD_GRAPHIC
  72. unsigned char i;
  73. LCD_WriteCommand(0x40 + 8); // 0x01
  74. for(i=0; i<sizeof(custom_chars); i++){
  75. LCD_WriteData(custom_chars[i]);
  76. };
  77. #endif /* LCD_GRAPHIC */
  78. }
  79. void battery_state_display(void) {
  80. unsigned char index;
  81. if (System.bat_volt > 4.0)
  82. index = 0;
  83. else if (System.bat_volt > 3.7)
  84. index = 1;
  85. else if (System.bat_volt > 3.4)
  86. index = 2;
  87. else
  88. index = 3;
  89. #ifdef LCD_GRAPHIC
  90. LCD_GoTo(15,0);
  91. LCD_WriteChar(0x82 + index);
  92. #else
  93. unsigned char i;
  94. LCD_WriteCommand(0x40 + 0); // 0x00
  95. for(i=0; i<8; i++){
  96. LCD_WriteData(battery_states[index][i]);
  97. };
  98. #endif /* LCD_GRAPHIC */
  99. }
  100. static inline void disp_line(unsigned char i, __flash const char *text) {
  101. switch(i) {
  102. case 2: strcpy_P(disp.line2, text); break;
  103. case 1: strcpy_P(disp.line1, text); break;
  104. }
  105. }
  106. void disp_line1(__flash const char *text) {
  107. disp_line(1, text);
  108. }
  109. void disp_line2(__flash const char *text) {
  110. disp_line(2, text);
  111. }
  112. __flash const char _gps_wait[] = "Czekam na GPS...";
  113. __flash const char _gps_ok[] = "GPS OK!";
  114. __flash const char _card_ok[] = "Karta OK!";
  115. __flash const char _logging_active[] = "Zapis aktywny";
  116. __flash const char _logging_paused[] = "Zapis wstrzymany";
  117. __flash const char _starting[] = "Uruchamianie...";
  118. __flash const char _battery_low[] = "Bateria slaba!";
  119. __flash const char _shutting_down[] = "Wylaczanie...";
  120. __flash const char _no_card[] = "Brak karty!";
  121. __flash const char _card_error[] = "Blad karty!";
  122. __flash const char _write_error[] = "Blad zapisu!";
  123. __flash const char _fat_write_error[] = "Blad zapisu FAT!";
  124. __flash const char _file_close_error[] = "Blad zamk.pliku!";
  125. __flash const char _file_open_error[] = "Blad otw. pliku!";
  126. __flash const char _files_closed[] = "Pliki zamkniete";
  127. __flash const char _files_open[] = "Pliki otwarte";
  128. __flash const char _tracking_paused[] = "Wstrzymano!";
  129. __flash const char _tracking_resumed[] = "Wznowiono!";
  130. __flash const char _point_saved[] = "Zapisano!";
  131. __flash const char _point_not_saved[] = "Nie zapisano!";
  132. __flash const char _logging_auto_paused[] = "Autom. wstrzym.";
  133. __flash const char _sat_count_low[] = "Za malo satelit";
  134. void display_event(unsigned char event) { /* overrides display with current messages */
  135. switch (event) {
  136. case DISPLAY_EVENT_STARTUP:
  137. disp_line1(_starting);
  138. break;
  139. case DISPLAY_EVENT_LOW_BATTERY:
  140. disp_line2(_battery_low);
  141. /* fall through */
  142. case DISPLAY_EVENT_POWEROFF:
  143. disp_line1(_shutting_down);
  144. break;
  145. case DISPLAY_EVENT_INITIALIZED:
  146. disp_line1(PSTR("Start"));
  147. switch(System.status){
  148. case STATUS_NO_POWER: case STATUS_OK: case STATUS_NO_GPS: disp.line2[0] = '\0'; break;
  149. case STATUS_NO_DISK: disp_line2(_no_card); break;
  150. case STATUS_DISK_ERROR: disp_line2(_card_error); break;
  151. case STATUS_FILE_WRITE_ERROR: disp_line2(_write_error); break;
  152. case STATUS_FILE_SYNC_ERROR: disp_line2(_fat_write_error); break;
  153. case STATUS_FILE_CLOSE_ERROR: disp_line2(_file_close_error); break;
  154. case STATUS_FILE_OPEN_ERROR: disp_line2(_file_open_error); break;
  155. }
  156. break;
  157. case DISPLAY_EVENT_CARD_INITIALIZED:
  158. disp_line1(_card_ok);
  159. disp_line2(_gps_wait);
  160. break;
  161. case DISPLAY_EVENT_FILE_CLOSED:
  162. disp_line2(_files_closed);
  163. break;
  164. case DISPLAY_EVENT_FILE_OPEN:
  165. disp_line2(_files_open);
  166. break;
  167. case DISPLAY_EVENT_TRACKING_PAUSED:
  168. disp_line2(_tracking_paused);
  169. break;
  170. case DISPLAY_EVENT_TRACKING_RESUMED:
  171. disp_line2(_tracking_resumed);
  172. break;
  173. case DISPLAY_EVENT_POINT_SAVED:
  174. disp_line2(_point_saved);
  175. break;
  176. case DISPLAY_EVENT_POINT_NOT_SAVED:
  177. disp_line2(_point_not_saved);
  178. break;
  179. }
  180. display_refresh(1);
  181. }
  182. void disp_func_main_default(void) {
  183. if (FLAGS & F_FILEOPEN) {
  184. if (System.tracking_paused) {
  185. disp_line1(_logging_paused);
  186. } else if (System.tracking_auto_paused) {
  187. disp_line1(_logging_auto_paused);
  188. } else {
  189. disp_line1(_logging_active);
  190. }
  191. } else
  192. disp_line1(_card_ok);
  193. if (FLAGS & F_GPSOK) {
  194. if (System.sat_count_low)
  195. disp_line2(_sat_count_low);
  196. else
  197. disp_line2(_gps_ok);
  198. } else {
  199. disp_line2(_gps_wait);
  200. }
  201. }
  202. void disp_func_coord(void) {
  203. if (System.location_valid == LOC_INVALID) {
  204. disp_line1(PSTR("??? N/S"));
  205. disp_line2(PSTR("??? E/W"));
  206. return;
  207. }
  208. xsprintf(disp.line1, PSTR("%2.6f%c"), (location.lat < 0)?(-location.lat):location.lat, (location.lat < 0)?'S':'N');
  209. xsprintf(disp.line2, PSTR("%3.6f%c"), (location.lon < 0)?(-location.lon):location.lon, (location.lon < 0)?'W':'E');
  210. }
  211. void disp_func_ele_sat(void) {
  212. if (System.location_valid == LOC_INVALID) {
  213. disp_line1(PSTR("ele = ???"));
  214. } else {
  215. xsprintf(disp.line1, PSTR("ele = %.1fm"), location.alt);
  216. }
  217. xsprintf(disp.line2, PSTR("%2d satelit"), System.satellites_used);
  218. if (System.sbas)
  219. strcat_P(disp.line2, PSTR(", DGPS"));
  220. }
  221. void disp_distance_and_time(void) {
  222. xsprintf(disp.line1, PSTR("%.2f km"), (float)System.distance / 100000.0);
  223. if (utc > 0 && System.time_start > 0) {
  224. xsprintf(disp.line2, PSTR("t=%u s"), (unsigned int)(utc - System.time_start));
  225. } else {
  226. disp_line2(PSTR("Czas nieznany"));
  227. }
  228. }
  229. void disp_speed(void) {
  230. disp_line1(PSTR("Predkosc:"));
  231. if (utc > 0 && System.time_start > 0) {
  232. xsprintf(disp.line2, PSTR("%.2f km/h"), (float)System.distance / (float)(utc - System.time_start) * 0.036);
  233. } else {
  234. disp_line2(PSTR("nieznana"));
  235. }
  236. }
  237. void disp_time(void) {
  238. if (utc == 0) {
  239. disp_line1(PSTR("?"));
  240. disp_line2(PSTR("?"));
  241. return;
  242. }
  243. time_t time = utc;
  244. time += local_time_diff(time) * (signed int)3600;
  245. struct tm *ct = gmtime(&time);
  246. xsprintf(disp.line1, PSTR("%d.%02d.%4d"), ct->tm_mday, ct->tm_mon+1, ct->tm_year+1900);
  247. xsprintf(disp.line2, PSTR("%d:%02d:%02d"), ct->tm_hour, ct->tm_min, ct->tm_sec);
  248. }
  249. void disp_func_temperature(void) {
  250. disp_line1(PSTR("Temperatura"));
  251. if (System.temperature_ok) {
  252. xsprintf(disp.line2, PSTR("%.1f stC"), System.temperature);
  253. } else {
  254. disp_line2(PSTR("Blad!"));
  255. }
  256. }
  257. void display_refresh(unsigned char changed) {
  258. if (timer_expired(lcd)) {
  259. changed = 1;
  260. }
  261. /* write to LCD */
  262. if (changed) {
  263. set_timer(lcd, 1000);
  264. battery_state_display();
  265. unsigned char len;
  266. LCD_GoTo(0,0);
  267. len = strlen(disp.line1);
  268. LCD_WriteText(disp.line1);
  269. while (len<15) {
  270. len++;
  271. LCD_WriteData(' ');
  272. }
  273. #ifndef LCD_GRAPHIC
  274. LCD_WriteData(0); /* battery symbol */
  275. #endif
  276. LCD_GoTo(0,1);
  277. len = strlen(disp.line2);
  278. LCD_WriteText(disp.line2);
  279. while (len<16) {
  280. len++;
  281. LCD_WriteData(' ');
  282. }
  283. }
  284. }