Advertisement
kuzznya

DisComSystem.ino

Mar 23rd, 2023
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 17.69 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Adafruit_GFX.h>
  3. #include <Adafruit_PCD8544.h>
  4. #include <WiFiEsp.h>
  5. #include <SD.h>
  6. #include <Wire.h>
  7. #include <RTClib.h>
  8.  
  9. Adafruit_PCD8544 display = Adafruit_PCD8544(32, 30, 28, 26, 24);
  10.  
  11. RTC_DS1307 RTC;
  12.  
  13. int errorCode = 0;
  14. #define SDCardError 1
  15. #define WiFiErrorInit 2
  16. #define WiFiErrorConnect 3
  17. #define FTPServerError 4
  18. #define FileError 5
  19.  
  20. const int POT = 0;
  21. int val = 0;
  22. const int ButtonBACK = 23;
  23. const int ButtonOK = 25;
  24. const int ButtonLANG = 27;
  25. const int ButtonOPTIONS = 29;
  26. const int RTC_POW_PIN = A6;
  27. const int RTC_GND_PIN = A5;
  28. boolean lastBACK = LOW;
  29. boolean lastOK = LOW;
  30. boolean lastLANG = LOW;
  31. boolean lastOPTIONS = LOW;
  32. boolean currentBACK = LOW;
  33. boolean currentOK = LOW;
  34. boolean currentLANG = LOW;
  35. boolean currentOPTIONS = LOW;
  36.  
  37. int pos = 0;
  38. #define ENG 0
  39. #define RUS 1
  40. #define SYM 2
  41. String symbols[3] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ_", "", "_.,?!1234567890-+=:;()/"};
  42. const int symLen[3] = {26, 32, 22};
  43. int lang = RUS;
  44.  
  45. static const unsigned char PROGMEM menu_icons[][128] = {
  46.   { 0x00, 0x00, 0x00, 0x00,
  47.     0x1F, 0xFF, 0xFF, 0xFF,
  48.     0x18, 0x00, 0x00, 0x03,
  49.     0x14, 0x00, 0x00, 0x05,
  50.     0x12, 0x00, 0x00, 0x09,
  51.     0x11, 0x00, 0x00, 0x11,
  52.     0x10, 0x80, 0x00, 0x21,
  53.     0x10, 0x40, 0x00, 0x41,
  54.     0x10, 0x20, 0x00, 0x81,
  55.     0x10, 0x10, 0x01, 0x01,
  56.     0x10, 0x08, 0x02, 0x01,
  57.     0x10, 0x04, 0x04, 0x01,
  58.     0x10, 0x02, 0x08, 0x01,
  59.     0x10, 0x01, 0x10, 0x01,
  60.     0x10, 0x00, 0xE4, 0x01,
  61.     0x10, 0x00, 0x0C, 0x01,
  62.     0x10, 0x00, 0x1F, 0xF9,
  63.     0x10, 0x00, 0x3F, 0xF9,
  64.     0x10, 0x00, 0x7F, 0xF9,
  65.     0xF0, 0x00, 0x3F, 0xF9,
  66.     0x10, 0x00, 0x1F, 0xF9,
  67.     0x10, 0x00, 0x0C, 0x01,
  68.     0xF0, 0x00, 0x04, 0x41,
  69.     0x10, 0x00, 0x00, 0x61,
  70.     0x10, 0x00, 0x3F, 0xF1,
  71.     0xF0, 0x00, 0x3F, 0xF9,
  72.     0x10, 0x00, 0x3F, 0xFD,
  73.     0x10, 0x00, 0x3F, 0xF9,
  74.     0xF0, 0x00, 0x3F, 0xF1,
  75.     0x10, 0x00, 0x00, 0x61,
  76.     0x1F, 0xFF, 0xFF, 0x4F,
  77.     0x00, 0x00, 0x00, 0x00,
  78.   },
  79.   { 0x00, 0x00, 0x00, 0x00,
  80.     0x0F, 0xFF, 0xFF, 0xF0,
  81.     0x08, 0x00, 0x00, 0x10,
  82.     0x08, 0x00, 0x00, 0x10,
  83.     0x08, 0x00, 0x00, 0x10,
  84.     0x08, 0x00, 0x00, 0x10,
  85.     0x09, 0xFF, 0xFF, 0x90,
  86.     0x08, 0x00, 0x00, 0x10,
  87.     0x08, 0x00, 0x00, 0x10,
  88.     0x09, 0xFF, 0xFF, 0x90,
  89.     0x08, 0x00, 0x00, 0x10,
  90.     0x08, 0x00, 0x00, 0x10,
  91.     0x09, 0xFF, 0xFF, 0x90,
  92.     0x08, 0x00, 0x00, 0x10,
  93.     0x08, 0x00, 0x00, 0x10,
  94.     0x09, 0xFF, 0xFF, 0x90,
  95.     0x08, 0x00, 0x00, 0x10,
  96.     0x08, 0x00, 0x00, 0x10,
  97.     0x09, 0xFF, 0xFF, 0x90,
  98.     0x08, 0x00, 0x00, 0x10,
  99.     0x08, 0x00, 0x00, 0x10,
  100.     0x09, 0xFF, 0xFF, 0x90,
  101.     0x08, 0x00, 0x00, 0x10,
  102.     0x08, 0x00, 0x00, 0x10,
  103.     0x09, 0xFF, 0xFF, 0x90,
  104.     0x08, 0x00, 0x00, 0x10,
  105.     0x08, 0x00, 0x00, 0x10,
  106.     0x09, 0xFF, 0xFF, 0x90,
  107.     0x08, 0x00, 0x00, 0x10,
  108.     0x08, 0x00, 0x00, 0x10,
  109.     0x0F, 0xFF, 0xFF, 0xF0,
  110.     0x00, 0x00, 0x00, 0x00,
  111.   },
  112.   { 0x00, 0x00, 0x00, 0x00,
  113.     0x00, 0x00, 0x00, 0x00,
  114.     0x00, 0x00, 0x00, 0x00,
  115.     0x00, 0x40, 0x00, 0x00,
  116.     0x00, 0xE0, 0x00, 0x00,
  117.     0x01, 0xF0, 0x00, 0x00,
  118.     0x03, 0xF8, 0x00, 0x00,
  119.     0x07, 0xFC, 0x00, 0x10,
  120.     0x0F, 0xF8, 0x00, 0x20,
  121.     0x1F, 0xF0, 0x00, 0x40,
  122.     0x3F, 0xE0, 0x00, 0x80,
  123.     0x7F, 0xC0, 0x01, 0x00,
  124.     0x3F, 0xE0, 0x02, 0x00,
  125.     0x1F, 0x30, 0x04, 0x00,
  126.     0x0E, 0x18, 0x08, 0x00,
  127.     0x04, 0x0C, 0x10, 0x00,
  128.     0x00, 0x06, 0x20, 0x00,
  129.     0x00, 0x03, 0x40, 0x00,
  130.     0x00, 0x01, 0x80, 0x00,
  131.     0x00, 0x01, 0xC0, 0x00,
  132.     0x00, 0x0E, 0x60, 0x00,
  133.     0x00, 0x1E, 0x30, 0x00,
  134.     0x00, 0x3E, 0x18, 0x00,
  135.     0x00, 0x7C, 0x0C, 0x00,
  136.     0x00, 0xF8, 0x06, 0x00,
  137.     0x01, 0xF0, 0x03, 0x00,
  138.     0x03, 0xE0, 0x01, 0x80,
  139.     0x07, 0xC0, 0x00, 0xC0,
  140.     0x07, 0x80, 0x00, 0x60,
  141.     0x07, 0x00, 0x00, 0x00,
  142.     0x00, 0x00, 0x00, 0x00,
  143.     0x00, 0x00, 0x00, 0x00,
  144.   }
  145. };
  146. String menu_strings[3];
  147.  
  148. static const unsigned char PROGMEM newMsgIcon[] = {0xFF,
  149. 0xC3,
  150. 0xA5,
  151. 0x99,
  152. 0x81,
  153. 0x81,
  154. 0x81,
  155. 0xFF,
  156. };
  157.  
  158. WiFiEspClient client;
  159. WiFiEspClient dclient;
  160.  
  161. int status = WL_IDLE_STATUS;
  162.  
  163. IPAddress server( 192, 168, 8, 102 );
  164.  
  165. char outBuf[128];
  166. char outCount;
  167.  
  168. String senderName;
  169.  
  170. boolean debounce(const int ButtonPIN, boolean last) {
  171.   boolean current = digitalRead(ButtonPIN);
  172.   if (last != current)
  173.   {
  174.     delay(5);
  175.     current = digitalRead(ButtonPIN);
  176.     return current;
  177.   }
  178.   return last;
  179. }
  180.  
  181. void buttonsRead() {
  182.   currentBACK = debounce(ButtonBACK, lastBACK);
  183.   currentOK = debounce(ButtonOK, lastOK);
  184.   currentLANG = debounce(ButtonLANG, lastLANG);
  185.   currentOPTIONS = debounce(ButtonOPTIONS, lastOPTIONS);
  186.   if (lastBACK != currentBACK || lastOK != currentOK || lastLANG != currentLANG || lastOPTIONS != currentOPTIONS) {
  187.     delay(200);
  188.   }
  189. }
  190.  
  191. String stringCut(String source) {
  192.   String target;
  193.   if (source.length() > 1) {
  194.     for (int i = 0; i < source.length() - 1; i++)
  195.     {
  196.       target += source[i];
  197.     }
  198.     return target;
  199.   }
  200.   else {
  201.     return "";
  202.   }
  203. }
  204.  
  205. String encrypt(String source) {
  206.   int key = 38522863;
  207.   String target;
  208.   String currentResult;
  209.   for (int i = 0; i < source.length(); i++)
  210.   {
  211.     currentResult += source[i] * key;
  212.     for (int j = 0; j < currentResult.length(); j++)
  213.     {
  214.       target += atoi(currentResult[j]);
  215.     }
  216.   }
  217.   return target;
  218. }
  219.  
  220. String encrypt(String source, int key) {
  221.   String target;
  222.   String currentResult;
  223.   for (int i = 0; i < source.length(); i++)
  224.   {
  225.     currentResult += source[i] * key;
  226.     for (int j = 0; j < currentResult.length(); j++)
  227.     {
  228.       target += atoi(currentResult[j]);
  229.     }
  230.   }
  231.   return target;
  232. }
  233.  
  234. boolean connectToSSID() {
  235.   File SSIDs = SD.open("SSIDS.TXT", FILE_READ);
  236.   if (!SSIDs) {
  237.     errorCode = WiFiErrorConnect;
  238.     return false;
  239.   }
  240.   int len;
  241.   while (SSIDs.available()) {
  242.     SSIDs.read();
  243.     len++;
  244.   }
  245.   SSIDs.close();
  246.   SSIDs = SD.open("SSIDS.TXT", FILE_READ);
  247.   if (!SSIDs) {
  248.     errorCode = WiFiErrorConnect;
  249.     return false;
  250.   }
  251.   char* ssid[len];
  252.   char* password[len];
  253.   char buf;
  254.   int counter = 0;
  255.   boolean isName = true;
  256.   while (SSIDs.available()) {
  257.     buf = SSIDs.read();
  258.     if (buf == '@') {
  259.       isName = !isName;
  260.       if (isName) counter++;
  261.     }
  262.     else if (isName && buf != '\n' && buf != '\r') {
  263.       ssid[counter] += buf;
  264.     }
  265.     else if (buf != '\n' && buf != '\r') {
  266.       password[counter] += buf;
  267.     }
  268.   }
  269.   SSIDs.close();
  270.   if (status != WL_CONNECTED) {
  271.     for (int i = 0; i < sizeof(ssid); i++)
  272.     {
  273.       /*char ssidChar[ssid[i].length()];
  274.         char passwordChar[password[i].length()];
  275.         ssidChar = ssid + '\n';
  276.         passwordChar = password + '\n';*/
  277.       status = WiFi.begin(ssid[i], password[i]);
  278.       if (status == WL_CONNECTED) {
  279.         return true;
  280.       }
  281.     }
  282.   }
  283.   return false;
  284. }
  285.  
  286. void setup() {
  287.   symbols[1] = utf8rus("АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ_");
  288.   menu_strings[0] = utf8rus("Сообщения");
  289.   menu_strings[1] = utf8rus("Информация");
  290.   menu_strings[2] = utf8rus("Настройки");
  291.  
  292.   display.begin();              // Инициализация дисплея
  293.   display.setContrast(60);      // Устанавливаем контраст
  294.   display.setTextColor(BLACK);  // Устанавливаем цвет текста
  295.   display.setTextSize(1);       // Устанавливаем размер текста
  296.   display.clearDisplay();       // Очищаем дисплей
  297.   display.setCursor(display.width() / 2 - 10 * 2.8, display.height() / 2 + 8);
  298.   display.print("Loading...");
  299.   display.display();
  300.  
  301.   Serial.begin(115200);
  302.   Serial1.begin(115200);
  303.  
  304.   pinMode(RTC_POW_PIN, OUTPUT);
  305.   pinMode(RTC_GND_PIN, OUTPUT);
  306.   digitalWrite(RTC_POW_PIN, HIGH);
  307.   digitalWrite(RTC_GND_PIN, LOW);
  308.   Serial.println("RTC initializing started");
  309.   RTC.begin();
  310.   if (!RTC.isrunning()) {
  311.     RTC.adjust(DateTime(__DATE__, __TIME__));
  312.   }
  313.  
  314.   Serial.println("SD initializing started");
  315.   if (!SD.begin(10)) {
  316.     errorCode = SDCardError;
  317.     Serial.println("SD initializing error");
  318.     return;
  319.   }
  320.   Serial.println("SD initialized");
  321.   Serial.println("WiFi initializing started");
  322.   WiFi.init(&Serial1);
  323.   if (WiFi.status() == WL_NO_SHIELD) {
  324.     errorCode = WiFiErrorInit;
  325.     Serial.println("WiFi initializing error");
  326.     return;
  327.   }
  328.   Serial.println("WiFi initialized");
  329.   delay(3000);
  330.   if (status != WL_CONNECTED)
  331.   {
  332.     if (!connectToSSID()) {
  333.       errorCode = WiFiErrorConnect;
  334.       Serial.println("Error connecting to SSID");
  335.     }
  336.   }
  337.   Serial.println("FTP connecting started");
  338.   if (!client.connect(server, 21)) {
  339.     errorCode = FTPServerError;
  340.     Serial.println("FTP connecting error");
  341.     return;
  342.   }
  343.   if(!eRcv()) return;
  344.  
  345.   client.println(F("USER Anonymous"));
  346.  
  347.   if(!eRcv()) return;
  348.  
  349.   /*client.println(F("PASS 123"));
  350.  
  351.   if(!eRcv()) return;*/
  352.  
  353.   client.println(F("SYST"));
  354.  
  355.   if(!eRcv()) return;
  356.  
  357.   client.println(F("Type I"));
  358.  
  359.   if(!eRcv()) return;
  360.  
  361.   client.println(F("PASV"));
  362.  
  363.   if(!eRcv()) return;
  364.  
  365.   char *tStr = strtok(outBuf,"(,");
  366.   int array_pasv[6];
  367.   for ( int i = 0; i < 6; i++) {
  368.     tStr = strtok(NULL,"(,");
  369.     array_pasv[i] = atoi(tStr);
  370.     if(tStr == NULL)
  371.     {
  372.       Serial.println(F("Bad PASV Answer"));
  373.     }
  374.   }
  375.  
  376.   unsigned int hiPort,loPort;
  377.  
  378.   hiPort = array_pasv[4] << 8;
  379.   loPort = array_pasv[5] & 255;
  380.  
  381.   Serial.println(F("Data port: "));
  382.   hiPort = hiPort | loPort;
  383.   Serial.println(hiPort);
  384.  
  385.   if (dclient.connect(server,hiPort)) {
  386.     Serial.println(F("Data connected"));
  387.   }
  388.   else {
  389.     Serial.println(F("Data connection failed"));
  390.     client.stop();
  391.     return;
  392.   }
  393. }
  394.  
  395. void MsgToContact(String contactName) {
  396.  
  397. }
  398.  
  399. String inputText(boolean NO_BACK = false) {
  400.   String inputString;
  401.   while (true) {
  402.     buttonsRead();
  403.     if (lastBACK == LOW && currentBACK == HIGH)
  404.     {
  405.       inputString = stringCut(inputString);
  406.     }
  407.     if (lastOK == LOW && currentOK == HIGH)
  408.     {
  409.       inputString += symbols[lang][val];
  410.     }
  411.     if (lastLANG == LOW && currentLANG == HIGH)
  412.     {
  413.       lang++;
  414.       if (lang > 2) lang = 0;
  415.       else if (lang < 0) lang = 2;
  416.     }
  417.     if (lastOPTIONS == LOW && currentOPTIONS == HIGH)
  418.     {
  419.       int result;
  420.       if (!NO_BACK) {
  421.         String params[] = {utf8rus("Ввод"), utf8rus("Отменить")};
  422.         result = optionsList(params, 2);
  423.       }
  424.       else {
  425.         String params[] = {utf8rus("Ввод"), };
  426.         result = optionsList(params, 1);
  427.       }
  428.       switch (result) {
  429.       case 0:
  430.         return inputString;
  431.       case 1:
  432.         return "";
  433.       }
  434.     }
  435.     lastBACK = currentBACK;
  436.     lastOK = currentOK;
  437.     lastLANG = currentLANG;
  438.     lastOPTIONS = currentOPTIONS;
  439.     display.clearDisplay();
  440.     display.setCursor(0, 1);
  441.     if (inputString.length() <= 42)
  442.     {
  443.       for (int i = 0; i <= inputString.length(); i++)
  444.       {
  445.         display.print(inputString[i]);
  446.       }
  447.     }
  448.     else
  449.     {
  450.       for (int i = inputString.length() - 42; i <= inputString.length(); i++)
  451.       {
  452.         display.print(inputString[i]);
  453.       }
  454.     }
  455.     display.drawFastHLine(0, 32, display.width() - 1, BLACK);
  456.     display.setCursor(0, 34);
  457.     val = analogRead(POT);
  458.     val = map(val, 1, 1015, symLen[lang], 0);
  459.     val = constrain(val, 0, symLen[lang]);
  460.     pos = 0;
  461.     if (val > pos + 12) pos = val - 12;
  462.     else if (val < pos) pos = val;
  463.     for (int i = pos; i < val; i++)
  464.     {
  465.       display.print(symbols[lang][i]);
  466.     }
  467.     display.setTextSize(2);
  468.     display.print(symbols[lang][val]);
  469.     display.setTextSize(1);
  470.     for (int i = val + 1; i <= pos + 12; i++)
  471.     {
  472.       display.print(symbols[lang][i]);
  473.     }
  474.     display.display();
  475.   }
  476.   return inputString;
  477. }
  478.  
  479. void Messages() {
  480.   File contacts = SD.open("CONTACTS.TXT", FILE_READ);
  481.   if (!contacts) {
  482.     errorCode = FileError;
  483.     return;
  484.   }
  485.   String* contactList;
  486.   char buf;
  487.   int count = 0;
  488.   while (contacts.available()) {
  489.     buf = contacts.read();
  490.     if (buf == '@') count++;
  491.     else if (buf != '\n' && buf != '\r') contactList[count] += buf;
  492.   }
  493.   contacts.close();
  494.   Serial.println("Contacts were read from SD");
  495.   while (true) {
  496.     if (!checkForErrors()) return;
  497.     display.clearDisplay();
  498.     statusBar();
  499.     buttonsRead();
  500.     if (lastOK == LOW && currentOK == HIGH) {
  501.       MsgToContact(contactList[val]);
  502.     }
  503.     else if (lastBACK == LOW && currentBACK == HIGH) {
  504.       return;
  505.     }
  506.     else if (lastOPTIONS == LOW && currentOPTIONS == HIGH) {
  507.       String params[] = {utf8rus("Удалить"), utf8rus("Добавить")};
  508.       int result = optionsList(params, 2);
  509.       if (result == 0) {
  510.         String* newContactList;
  511.         for (int i = 0; i < val; i++) newContactList[i] = contactList[i];
  512.         for (int i = val + 1;i < count; i++) newContactList[i - 1] = contactList[i];
  513.         contactList = newContactList;
  514.         count--;
  515.         SD.remove("CONTACTS.TXT");
  516.         contacts = SD.open("CONTACTS.TXT", FILE_WRITE);
  517.         for (int i = 0; i < count; i++)
  518.         {
  519.           contacts.println(contactList[i] + '@');
  520.         }
  521.       }
  522.       else if (result == 1) {
  523.         String newName = inputText(true);
  524.         if (newName.length() > 8) {
  525.           display.clearDisplay();
  526.           statusBar();
  527.           display.setCursor(0, 8);
  528.           display.print(utf8rus("Ошибка: длина не должна превышать 8"));
  529.           display.display();
  530.           delay(3000);
  531.           goto a;
  532.         }
  533.         String* newContactList;
  534.         for (int i = 0; i <= val; i++) newContactList[i] = contactList[i];
  535.         newContactList[val] = newName;
  536.         for (int i = val + 1; i < count; i++) newContactList[i + 1] = contactList[i];
  537.         contactList = newContactList;
  538.         count++;
  539.         SD.remove("CONTACTS.TXT");
  540.         contacts = SD.open("CONTACTS.TXT", FILE_WRITE);
  541.         for (int i = 0; i < count; i++)
  542.         {
  543.           contacts.println(contactList[i] + '@');
  544.         }
  545. a: count = count;
  546.       }
  547.     }
  548.     val = analogRead(POT);
  549.     val = map(val, 100, 1000, 2, 0);
  550.     val = constrain(val, 0, count - 1);
  551.   }
  552. }
  553.  
  554. void Status() {
  555.   while (true) {
  556.  
  557.   }
  558. }
  559.  
  560. void Settings() {
  561.   while (true) {
  562.  
  563.   }
  564. }
  565.  
  566. int optionsList(String options[], int len) {
  567.   while (true) {
  568.     if (!checkForErrors) return -1;
  569.     buttonsRead();
  570.     if (lastBACK == LOW && currentBACK == HIGH) return -1;
  571.     else if (lastOK == LOW && currentOK == HIGH) return val;
  572.     display.clearDisplay();
  573.     statusBar();
  574.     val = analogRead(POT);
  575.     val = map(val, 1, 1015, len, 0);
  576.     val = constrain(val, 0, len);
  577.     pos = 0;
  578.     if (val > pos + 5) pos = val - 5;
  579.     else if (val < pos) pos = val;
  580.     for (int i = pos; i < val; i++)
  581.     {
  582.       for (int j = 0; j < options[i].length(); j++)
  583.       {
  584.         display.print(options[i][j]);
  585.       }
  586.       display.display();
  587.       display.println();
  588.     }
  589.   }
  590. }
  591.  
  592. boolean checkForErrors() {
  593.   switch (errorCode)
  594.   {
  595.     case 1:
  596.       SDCardErrorFunc();
  597.     case 2:
  598.       WiFiErrorInitFunc();
  599.     case 3:
  600.       WiFiErrorConnectFunc();
  601.     case 4:
  602.       FTPServerErrorFunc();
  603.     case 5:
  604.       FileErrorFunc();
  605.   }
  606.   if (errorCode && errorCode != WiFiErrorConnect) return false;
  607.   return true;
  608. }
  609.  
  610. boolean checkForNewMessages() {
  611.   if (status != WL_CONNECTED) {
  612.     Serial.println("WiFi is not connected");
  613.     return false;
  614.   }
  615.  
  616. }
  617.  
  618. void statusBar() {
  619.   display.drawFastHLine(0, 1, display.width() - 1, BLACK);
  620.   display.setCursor(display.width() - 10, 0);
  621.   DateTime dateTime = RTC.now();
  622.   display.print(String(dateTime.hour(), DEC) + ":" + String(dateTime.minute(), DEC));
  623.   display.display();
  624. }
  625.  
  626. void loop() {
  627.   if (!checkForErrors) return;
  628.   buttonsRead();
  629.   if (lastOK == LOW && currentOK == HIGH)
  630.   {
  631.     switch (val)
  632.     {
  633.       case 0:
  634.         Messages();
  635.       case 1:
  636.         Status();
  637.       case 2:
  638.         Settings();
  639.     }
  640.   }
  641.   lastBACK = currentBACK;
  642.   lastOK = currentOK;
  643.   lastLANG = currentLANG;
  644.   lastOPTIONS = currentOPTIONS;
  645.   display.clearDisplay();
  646.   val = analogRead(POT);
  647.   val = map(val, 1, 800, 2, 0);
  648.   val = constrain(val, 0, 2);
  649.   statusBar();
  650.   display.drawBitmap(display.width() / 2 - 16, display.height() / 2 - 21, menu_icons[val], 32, 32, 1);
  651.   display.setCursor(display.width() / 2 - menu_strings[val].length() * 2.8, display.height() / 2 + 11);
  652.   display.print(menu_strings[val]);
  653.   display.display();
  654. }
  655.  
  656. boolean SDCardErrorFunc() {
  657.   if (!SD.begin(10))
  658.   {
  659.     display.clearDisplay();
  660.     display.setCursor(display.width() / 2 - 13 * 2.8, display.height() / 2 + 8);
  661.     display.print("SD Card ERROR");
  662.     display.display();
  663.     Serial.println("SD error");
  664.     delay(5000);
  665.     return false;
  666.   }
  667.   errorCode = 0;
  668.   return true;
  669. }
  670. boolean WiFiErrorInitFunc() {
  671.   WiFi.init(&Serial1);
  672.   if (WiFi.status() == WL_NO_SHIELD)
  673.   {
  674.     display.clearDisplay();
  675.     display.setCursor(display.width() / 2 - 15 * 2.8, display.height() / 2 + 8);
  676.     display.print("WiFi Init ERROR");
  677.     display.display();
  678.     Serial.println("WiFi error init");
  679.     delay(5000);
  680.     return false;
  681.   }
  682.   errorCode = 0;
  683.   return true;
  684. }
  685. boolean WiFiErrorConnectFunc() {
  686.   if (!connectToSSID) {
  687.     display.clearDisplay();
  688.     display.setCursor(0, display.height() / 2 + 8);
  689.     display.print("No connection with SSID");
  690.     display.display();
  691.     Serial.println("WiFi error connect");
  692.     delay(5000);
  693.     return false;
  694.   }
  695.   errorCode = 0;
  696.   return true;
  697. }
  698. boolean FTPServerErrorFunc() {
  699.   Serial.println("FTP server error");
  700.   return false;
  701. }
  702. boolean FileErrorFunc() {
  703.   display.clearDisplay();
  704.   display.setCursor(display.width() / 2 - 10 * 2.8, display.height() / 2 + 8);
  705.   display.print("File ERROR");
  706.   display.display();
  707.   Serial.println("File error");
  708.   delay(5000);
  709.   return false;
  710. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement