123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- #include <avr/pgmspace.h>
- #include "main.h"
- #include "display.h"
- #include "HD44780-I2C.h"
- #include "xprintf.h"
- __flash const unsigned char battery_states[][8] = {
- {
- 0b01110,
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111,
- },
- {
- 0b01110,
- 0b11111,
- 0b10001,
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111,
- },
- {
- 0b01110,
- 0b11111,
- 0b10001,
- 0b10001,
- 0b10001,
- 0b11111,
- 0b11111,
- 0b11111,
- },
- {
- 0b01110,
- 0b11111,
- 0b10001,
- 0b10001,
- 0b10001,
- 0b10001,
- 0b10001,
- 0b11111,
- },
- };
- void battery_state_display(void) {
- unsigned char i;
- unsigned char index;
- if (System.bat_volt > 4.0)
- index = 0;
- else if (System.bat_volt > 3.7)
- index = 1;
- else if (System.bat_volt > 3.4)
- index = 2;
- else
- index = 3;
-
- LCD_WriteCommand(0x40 + 0); // 0x00
- for(i=0; i<8; i++){
- LCD_WriteData(battery_states[index][i]);
- };
- }
- void display_refresh(unsigned char newstate) {
- static const char *line1, *line2;
- unsigned char changed = 0;
-
- switch (System.display_state) {
- case DISPLAY_STATE_STARTUP:
- line1 = PSTR("Uruchamianie...");
- break;
- case DISPLAY_STATE_POWEROFF_LOWBAT:
- line2 = PSTR("Bateria slaba!");
- /* fall through */
- case DISPLAY_STATE_POWEROFF:
- line1 = PSTR("Wylaczanie...");
- break;
- case DISPLAY_STATE_START_MESSAGE:
- line1 = PSTR("Start");
- switch(System.status){
- case STATUS_NO_POWER: case STATUS_OK: case STATUS_NO_GPS: line2 = NULL; break;
- case STATUS_NO_DISK: line2 = PSTR("Brak karty!"); break;
- case STATUS_DISK_ERROR: line2 = PSTR("Blad karty!"); break;
- case STATUS_FILE_WRITE_ERROR: line2 = PSTR("Blad zapisu!"); break;
- case STATUS_FILE_SYNC_ERROR: line2 = PSTR("Blad zapisu FAT!"); break;
- case STATUS_FILE_CLOSE_ERROR: line2 = PSTR("Blad zamk.pliku!"); break;
- case STATUS_FILE_OPEN_ERROR: line2 = PSTR("Blad otw. pliku!"); break;
- }
- break;
- case DISPLAY_STATE_CARD_OK:
- line1 = PSTR("Karta OK!");
- line2 = PSTR("Czekam na GPS...");
- break;
- case DISPLAY_STATE_FILE_OPEN:
- line2 = PSTR("Zapis aktywny");
- break;
- case DISPLAY_STATE_FILE_CLOSED:
- line2 = PSTR("Pliki zamkniete");
- break;
- }
- if (newstate)
- changed = 1;
- if (timer_expired(lcd)) {
- changed = 1;
- set_timer(lcd, 1000);
- }
- /* write to LCD */
- if (changed) {
- battery_state_display();
- unsigned char len;
- LCD_GoTo(0,0);
- if (line1) {
- len = strlen_P(line1);
- if (len > 15)
- xprintf(PSTR("Warning: too long line1=%d, mem addr %4x\r\n"), (int)len, (unsigned int)line1);
- LCD_WriteTextP(line1);
- while (len<15) {
- len++;
- LCD_WriteData(' ');
- }
- } else {
- for (len=0; len<15; len++)
- LCD_WriteData(' ');
- }
- LCD_GoTo(0,1);
- if (line2) {
- len = strlen_P(line2);
- if (len > 16)
- xprintf(PSTR("Warning: too long line2=%d, mem addr %4x\r\n"), (int)len, (unsigned int)line1);
- LCD_WriteTextP(line2);
- while (len<16) {
- len++;
- LCD_WriteData(' ');
- }
- } else {
- for (len=0; len<16; len++)
- LCD_WriteData(' ');
- }
- LCD_GoTo(15, 0);
- LCD_WriteData(0); /* battery symbol */
- }
- }
- void display_state(unsigned char newstate) {
- System.display_state = newstate;
- display_refresh(newstate);
- }
|