#include #include "Display.h" static const char *DISP = "display"; Display::Display(RTC_DS3231 &rtc, uint8_t address, uint8_t columns, uint8_t rows):rtc_(rtc) { _lcd = new LiquidCrystal_I2C(address, columns, rows); _address = address; _columns = columns; _rows = rows; } bool Display::begin(TwoWire *wire) { wire->begin(); wire->beginTransmission(_address); if (wire->endTransmission() != 0) { return false; // brak odpowiedzi — error } // Inicjalizacja LCD _lcd->begin(_columns, _rows); _lcd->backlight(); _lcd->clear(); delay(100); return true; } void Display::initMeasure(bool measure, bool run, bool runmes, uint16_t pause, uint8_t duration, bool connect, long counter, String gdate, String gtime) { clear(); textCenter(0, "** Measure params **"); String conting = measure ? "yes":"no"; String st2 = "Continous:"; String allt = st2 + conting; textCenter(1, allt.c_str()); String type = "Sample:" + String(duration) + "s Pause:" + String(pause/1000)+"s"; textCenter(2, type.c_str()); textCenter(3, String("Time:" + gtime).c_str()); textStatus("initialisation"); } void Display::clear() { _lcd->clear(); } void Display::textCenter(uint8_t line, const char *txt){ if (line >= _rows) { ESP_LOGE(DISP, "Line >= max rows!"); return; } _lcd->setCursor(0, line); int len = strlen(txt); if (len < _columns) { int pad = (_columns - len) / 2; for (int i = 0; i < pad; i++) { _lcd->print(" "); } } _lcd->print(txt); } void Display::text(uint8_t line, const char *text) { if (line >= _rows) { ESP_LOGE(DISP, "Line >= max rows!"); return; } _lcd->setCursor(0, line); _lcd->print(text); } void Display::welcomeScreen() { ESP_LOGI(DISP, "Info screen"); clear(); textCenter(0, "** Vibra Dude **"); textCenter(1, "WMT Stalowa Wola"); String firm = String(VERSION); firm.trim(); textCenter(2, firm.c_str()); //_lcd->print(VERSION); } void Display::mainScreen(){ ESP_LOGI(DISP, "Main screen"); clear(); textCenter(0, "** Vibra Dude **"); textCenter(1, "WMT Stalowa Wola"); //String firm = String(VERSION).trim(); //textCenter(2, firm.c_str()); //_lcd->print(VERSION); ESP_LOGI(DISP, "Finish main screen"); } void Display::clearRow(uint16_t line){ _lcd->setCursor(0, line); _lcd->print(" "); _lcd->setCursor(0, line); } void Display::textStatus(const char *text){ clearRow(3); _lcd->setCursor(0, 3); _lcd->print(text); } void Display::updateNetwork(String ip, bool connected) { // przykładowa prosta implementacja: // clear(); // text(0, connected ? "NET: OK" : "NET: OFF"); // _lcd->setCursor(0, 1); // _lcd->print(ip); } void Display::updateBarWiFi(long signal, bool connected) { // tu możesz wykorzystać np. init_bargraph / draw_horizontal_graph // (void)signal; // (void)connected; } void Display::textStyle(const uint8_t st, String text) { // miejsce na różne style tekstu //(void)st; // clear(); //text(0, text.c_str()); } void Display::message(String text) { // clear(); //text(0, text.c_str()); } void Display::print(String text) { _lcd->print(text); } void Display::println(String text) { _lcd->print(text); _lcd->print("\n"); } void Display::setCursor(int16_t x, int16_t y) { _lcd->setCursor((uint8_t)x, (uint8_t)y); } void Display::showAccel(float a, float b, float c) { clear(); // _lcd->setCursor(0, 0); // _lcd->print("Ax: "); // _lcd->print(a, 2); // _lcd->setCursor(0, 1); // _lcd->print("Ay: "); // _lcd->print(b, 2); // _lcd->setCursor(0, 2); // _lcd->print("Az: "); // _lcd->print(c, 2); } void Display::displayOffline(bool measure, uint8_t count, float freeSpace, long licznik, bool refresh){ if(refresh){ oyear, omonth, oday, ohour, omin, osec, ospace, oadxlcnt = 100; _lcd->clear(); _lcd->setCursor(0, 0); } DateTime now = rtc_.now(); uint16_t year = now.year(); uint8_t month = now.month(); uint8_t day = now.day(); uint8_t hour = now.hour(); uint8_t min = now.minute(); uint8_t sec = now.second(); // DEBUG //ESP_LOGI(DISP, "RTC: %d:%d:%d %d:%d:%d", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second()); //ESP_LOGI(DISP, "RTC: %d:%d:%d %d:%d:%d", oday, omonth, oyear, ohour, omin, osec); if ((hour != ohour) || (refresh)) { ohour = hour; _lcd->setCursor(0, 0); if (hour < 10) _lcd->print('0'); _lcd->print(hour); _lcd->setCursor(2, 0); _lcd->print(':'); } if ((min != omin) || (refresh)) { omin = min; _lcd->setCursor(3, 0); if (min < 10) _lcd->print('0'); _lcd->print(min); _lcd->print(':'); } if ((sec != osec) || (refresh)) { _lcd->setCursor(6, 0); osec = sec; if (sec < 10) _lcd->print('0'); _lcd->print(sec); } if ((day != oday || month != omonth || year != oyear) || (refresh)){ _lcd->setCursor(10, 0); if (day < 10) _lcd->print('0'); _lcd->print(day); _lcd->print('.'); if (month < 10) _lcd->print('0'); _lcd->print(month); _lcd->print('.'); _lcd->print(year); oday = day; omonth = month; oyear = year; if(!config.measure) textStatus("OK: Start MEASURE"); else textStatus("Wait for NEXT"); } if((freeSpace != ospace) || (refresh)){ ospace = freeSpace; _lcd->setCursor(0, 1); _lcd->print("FREE:"); _lcd->print(freeSpace); _lcd->print("GB"); } if((count != oadxlcnt) || (omode != config.measure) || (refresh)){ oadxlcnt = count; omode = config.measure; _lcd->setCursor(0, 2); _lcd->print("ADXL:"); _lcd->print(count); _lcd->print(" MODE:"); _lcd->print(config.measure ? "AUTO ":"MANUAL "); } } // Podczas pomiaru void Display::displayOnOffM(bool measure, String myDir, String myFile) { clear(); _lcd->setCursor(0, 0); _lcd->print(measure ? "MEASURE STARTED" : "MEASURE STOPPED"); _lcd->setCursor(0, 1); _lcd->print("DIR: " + myDir); //_lcd->print(myDir); //_lcd->setCursor(0, 2); //_lcd->print("FILE:"); //_lcd->setCursor(0, 3); _lcd->setCursor(0, 2); _lcd->print(myFile); } /* Podsumowanie po pomiarze: ramki, sampling, etc. */ void Display::displaySampleRateSummary(uint32_t reccount, uint32_t captureSeconds, float khz, String filename){ clear(); _lcd->setCursor(0, 0); if (captureSeconds == 0) { _lcd->print("Sampling time 0!"); delay(1000); return; } float fs = (float)reccount / (float)captureSeconds; // Hz (ramki/s) float fs_kHz = fs / 1000.0f; _lcd->setCursor(0,0); _lcd->print("Frames:"); _lcd->print((unsigned)reccount); _lcd->setCursor(0,1); _lcd->print("Time:"); _lcd->print((unsigned)captureSeconds); _lcd->print("s."); _lcd->setCursor(0,2); _lcd->print("Rate:"); _lcd->print(fs_kHz); _lcd->print("kHz"); _lcd->setCursor(0,3); _lcd->print(filename); }