Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //<File !Start!>
- // FILE: [Basis1.ino]
- // Created by GUIslice Builder version: [0.13.b013]
- //
- // GUIslice Builder Generated File
- //
- // For the latest guides, updates and support view:
- // https://github.com/ImpulseAdventure/GUIslice
- //
- //<File !End!>
- //
- // ARDUINO NOTES:
- // - GUIslice_config.h must be edited to match the pinout connections
- // between the Arduino CPU and the display controller (see ADAGFX_PIN_*).
- //
- // ------------------------------------------------
- // SD Card Includes
- // ------------------------------------------------
- #include <SPI.h>
- #include <SD.h>
- // ------------------------------------------------
- // GPS Includes
- // ------------------------------------------------
- //#include <SoftwareSerial.h>
- #include "HardwareSerial.h"
- #include <TinyGPS++.h>
- // ------------------------------------------------
- // ESP Now Includes
- // ------------------------------------------------
- #include <esp_now.h>
- #include <WiFi.h>
- // ------------------------------------------------
- // Headers to include
- // ------------------------------------------------
- #include "GUIslice.h"
- #include "GUIslice_drv.h"
- // Include any extended elements
- //<Includes !Start!>
- // Include extended elements
- #include "elem/XKeyPad_Num.h"
- #include "elem/XSlider.h"
- #include "elem/XTextbox.h"
- // Ensure optional features are enabled in the configuration
- #if !(GSLC_FEATURE_COMPOUND)
- #error "Config: GSLC_FEATURE_COMPOUND required for this program but not enabled. Please update GUIslice/config."
- #endif
- //<Includes !End!>
- // ------------------------------------------------
- // Headers and Defines for fonts
- // Note that font files are located within the Adafruit-GFX library folder:
- // ------------------------------------------------
- //<Fonts !Start!>
- #if !defined(DRV_DISP_TFT_ESPI)
- #error Builder config "Edit->Options->General->Target Platform" should be "arduino"
- #endif
- #include <TFT_eSPI.h>
- //<Fonts !End!>
- // ------------------------------------------------
- // Defines for resources
- // ------------------------------------------------
- //<Resources !Start!>
- //<Resources !End!>
- // ------------------------------------------------
- // Enumerations for pages, elements, fonts, images
- // ------------------------------------------------
- //<Enum !Start!>
- enum {E_PG_MAIN,E_PG_BLANK,E_POP_KEYPAD};
- enum {E_ELEM_BTN_BACKLIGHT,E_ELEM_DATUMINFO,E_ELEM_GPSINFO
- ,E_ELEM_TBSENSOREN,E_ELEM_TEXTDATUM,E_ELEM_TEXTGPS
- ,E_ELEM_TEXTTRID,E_ELEM_TITLE,E_ELEM_TRID,E_TXTSCROLL1
- ,E_ELEM_KEYPAD};
- // Must use separate enum for fonts with MAX_FONT at end to use gslc_FontSet.
- enum {E_FONT_MONOB12,E_FONT_TXT5,MAX_FONT};
- //<Enum !End!>
- // ------------------------------------------------
- // Instantiate the GUI
- // ------------------------------------------------
- // ------------------------------------------------
- // Define the maximum number of elements and pages
- // ------------------------------------------------
- //<ElementDefines !Start!>
- #define MAX_PAGE 3
- #define MAX_ELEM_PG_MAIN 10 // # Elems total on page
- #define MAX_ELEM_PG_MAIN_RAM MAX_ELEM_PG_MAIN // # Elems in RAM
- #define MAX_ELEM_PG_BLANK 1 // # Elems total on page
- #define MAX_ELEM_PG_BLANK_RAM MAX_ELEM_PG_BLANK // # Elems in RAM
- //<ElementDefines !End!>
- // ------------------------------------------------
- // Create element storage
- // ------------------------------------------------
- gslc_tsGui m_gui;
- gslc_tsDriver m_drv;
- gslc_tsFont m_asFont[MAX_FONT];
- gslc_tsPage m_asPage[MAX_PAGE];
- //<GUI_Extra_Elements !Start!>
- gslc_tsElem m_asPage1Elem[MAX_ELEM_PG_MAIN_RAM];
- gslc_tsElemRef m_asPage1ElemRef[MAX_ELEM_PG_MAIN];
- gslc_tsElem m_asPage2Elem[MAX_ELEM_PG_BLANK_RAM];
- gslc_tsElemRef m_asPage2ElemRef[MAX_ELEM_PG_BLANK];
- gslc_tsElem m_asKeypadElem[1];
- gslc_tsElemRef m_asKeypadElemRef[1];
- gslc_tsXKeyPad_Num m_sKeyPad;
- gslc_tsXTextbox m_sTextbox1;
- char m_acTextboxBuf1[616]; // NRows=14 NCols=44
- gslc_tsXSlider m_sTextScroll1;
- #define MAX_STR 100
- //<GUI_Extra_Elements !End!>
- // ------------------------------------------------
- // Program Globals
- // ------------------------------------------------
- // Save some element references for direct access
- //<Save_References !Start!>
- gslc_tsElemRef* m_pElemOutTxt4 = NULL;
- gslc_tsElemRef* m_pElemOutTxt6 = NULL;
- gslc_tsElemRef* m_pElemTextbox1 = NULL;
- gslc_tsElemRef* m_pElemVal1 = NULL;
- gslc_tsElemRef* m_pTextSlider1 = NULL;
- gslc_tsElemRef* m_pElemKeyPad = NULL;
- //<Save_References !End!>
- // Define debug message function
- static int16_t DebugOut(char ch) { if (ch == (char)'\n') Serial.println(""); else Serial.write(ch); return 0; }
- //-------------------------------------------------
- // SD Globals
- //-------------------------------------------------
- File myFile;
- File root;
- //-------------------------------------------------
- // GPS Globals
- //-------------------------------------------------
- static const int RX2Pin = 17, TX2Pin = 16;
- TinyGPSPlus gps;
- //SoftwareSerial gpsSerial(RX2Pin, TX2Pin);
- HardwareSerial gpsSerial(2);
- //-------------------------------------------------
- // ESP Now Globals
- //-------------------------------------------------
- const char* ssid = "PTB_Station";
- const char* password = "ptb_station_2020";
- #define CHANNEL 1
- // keep in sync with sensor struct
- struct SENSOR_DATA {
- float temp;
- float hum;
- float t;
- float pressure;
- };
- // ------------------------------------------------
- // Callback Methods
- // ------------------------------------------------
- // Common Button callback
- bool CbBtnCommon(void* pvGui,void *pvElemRef,gslc_teTouch eTouch,int16_t nX,int16_t nY)
- {
- gslc_tsElemRef* pElemRef = (gslc_tsElemRef*)(pvElemRef);
- gslc_tsElem* pElem = pElemRef->pElem;
- if ( eTouch == GSLC_TOUCH_UP_IN ) {
- // From the element's ID we can determine which button was pressed.
- switch (pElem->nId) {
- //<Button Enums !Start!>
- case E_ELEM_TRID:
- //TODO- Check the code to see what else you may need to add
- // Clicked on edit field, so show popup box and associate with this text field
- gslc_ElemXKeyPadTargetIdSet(&m_gui, m_pElemKeyPad, E_ELEM_TRID);
- gslc_PopupShow(&m_gui, E_POP_KEYPAD, true);
- // Preload current value
- gslc_ElemXKeyPadValSet(&m_gui, m_pElemKeyPad, gslc_ElemGetTxtStr(&m_gui, m_pElemVal1));
- break;
- case E_ELEM_BTN_BACKLIGHT:
- //TODO- Replace with button handling code
- break;
- //<Button Enums !End!>
- default:
- break;
- }
- }
- return true;
- }
- //<Checkbox Callback !Start!>
- //<Checkbox Callback !End!>
- // KeyPad Input Ready callback
- bool CbKeypad(void* pvGui, void *pvElemRef, int16_t nState, void* pvData)
- {
- gslc_tsElemRef* pElemRef = (gslc_tsElemRef*)(pvElemRef);
- gslc_tsElem* pElem = pElemRef->pElem;
- gslc_tsGui* pGui = (gslc_tsGui*)pvGui;
- // From the pvData we can get the ID element that is ready.
- int16_t nTargetElemId = gslc_ElemXKeyPadDataTargetIdGet(pGui, pvData);
- if (nState == XKEYPAD_CB_STATE_DONE) {
- // User clicked on Enter to leave popup
- // - If we have a popup active, pass the return value directly to
- // the corresponding value field
- switch (nTargetElemId) {
- //<Keypad Enums !Start!>
- case E_ELEM_TRID:
- gslc_ElemSetTxtStr(pGui, m_pElemVal1, gslc_ElemXKeyPadDataValGet(pGui, pvData));
- gslc_PopupHide(&m_gui);
- break;
- //<Keypad Enums !End!>
- default:
- break;
- }
- } else if (nState == XKEYPAD_CB_STATE_CANCEL) {
- // User escaped from popup, so don't update values
- gslc_PopupHide(&m_gui);
- }
- return true;
- }
- //<Spinner Callback !Start!>
- //<Spinner Callback !End!>
- //<Listbox Callback !Start!>
- //<Listbox Callback !End!>
- //<Draw Callback !Start!>
- //<Draw Callback !End!>
- // Callback function for when a slider's position has been updated
- bool CbSlidePos(void* pvGui,void* pvElemRef,int16_t nPos)
- {
- gslc_tsGui* pGui = (gslc_tsGui*)(pvGui);
- gslc_tsElemRef* pElemRef = (gslc_tsElemRef*)(pvElemRef);
- gslc_tsElem* pElem = pElemRef->pElem;
- int16_t nVal;
- // From the element's ID we can determine which slider was updated.
- switch (pElem->nId) {
- //<Slider Enums !Start!>
- case E_TXTSCROLL1:
- // Fetch the slider position
- nVal = gslc_ElemXSliderGetPos(pGui,m_pTextSlider1);
- //TODO- Replace with slider handling code
- break;
- //<Slider Enums !End!>
- default:
- break;
- }
- return true;
- }
- //<Tick Callback !Start!>
- //<Tick Callback !End!>
- // ------------------------------------------------
- // Create page elements
- // ------------------------------------------------
- bool InitGUI()
- {
- gslc_tsElemRef* pElemRef = NULL;
- //<InitGUI !Start!>
- gslc_PageAdd(&m_gui,E_PG_MAIN,m_asPage1Elem,MAX_ELEM_PG_MAIN_RAM,m_asPage1ElemRef,MAX_ELEM_PG_MAIN);
- gslc_PageAdd(&m_gui,E_PG_BLANK,m_asPage2Elem,MAX_ELEM_PG_BLANK_RAM,m_asPage2ElemRef,MAX_ELEM_PG_BLANK);
- gslc_PageAdd(&m_gui,E_POP_KEYPAD,m_asKeypadElem,1,m_asKeypadElemRef,1); // KeyPad
- // NOTE: The current page defaults to the first page added. Here we explicitly
- // ensure that the main page is the correct page no matter the add order.
- gslc_SetPageCur(&m_gui,E_PG_MAIN);
- // Set Background to a flat color
- gslc_SetBkgndColor(&m_gui,GSLC_COL_BLACK);
- // -----------------------------------
- // PAGE: E_PG_MAIN
- // Create E_ELEM_TITLE text label
- pElemRef = gslc_ElemCreateTxt(&m_gui,E_ELEM_TITLE,E_PG_MAIN,(gslc_tsRect){10,10,168,33},
- (char*)"PTB Sensoren",0,E_FONT_MONOB12);
- gslc_ElemSetTxtCol(&m_gui,pElemRef,GSLC_COL_BLUE_LT4);
- // Create E_ELEM_TRID numeric input field
- static char m_sInputNumber1[11] = "";
- pElemRef = gslc_ElemCreateTxt(&m_gui,E_ELEM_TRID,E_PG_MAIN,(gslc_tsRect){250,80,60,10},
- (char*)m_sInputNumber1,11,E_FONT_TXT5);
- gslc_ElemSetTxtCol(&m_gui,pElemRef,GSLC_COL_WHITE);
- gslc_ElemSetCol(&m_gui,pElemRef,GSLC_COL_GRAY,GSLC_COL_BLACK,GSLC_COL_BLACK);
- gslc_ElemSetFrameEn(&m_gui,pElemRef,true);
- gslc_ElemSetClickEn(&m_gui, pElemRef, true);
- gslc_ElemSetTouchFunc(&m_gui, pElemRef, &CbBtnCommon);
- m_pElemVal1 = pElemRef;
- // Create E_ELEM_TEXTTRID text label
- pElemRef = gslc_ElemCreateTxt(&m_gui,E_ELEM_TEXTTRID,E_PG_MAIN,(gslc_tsRect){170,80,72,10},
- (char*)"Transport ID",0,E_FONT_TXT5);
- gslc_ElemSetTxtCol(&m_gui,pElemRef,GSLC_COL_BLUE_LT4);
- // Create wrapping box for textbox E_ELEM_TBSENSOREN and scrollbar
- pElemRef = gslc_ElemCreateBox(&m_gui,GSLC_ID_AUTO,E_PG_MAIN,(gslc_tsRect){10,100,297,127});
- gslc_ElemSetCol(&m_gui,pElemRef,GSLC_COL_GRAY,GSLC_COL_BLACK,GSLC_COL_BLACK);
- // Create textbox
- pElemRef = gslc_ElemXTextboxCreate(&m_gui,E_ELEM_TBSENSOREN,E_PG_MAIN,&m_sTextbox1,
- (gslc_tsRect){10+2,100+4,297-23,127-7},E_FONT_TXT5,
- (char*)&m_acTextboxBuf1,14,44);
- gslc_ElemXTextboxWrapSet(&m_gui,pElemRef,false);
- gslc_ElemSetTxtCol(&m_gui,pElemRef,GSLC_COL_WHITE);
- gslc_ElemSetCol(&m_gui,pElemRef,GSLC_COL_GRAY,GSLC_COL_BLACK,GSLC_COL_BLACK);
- m_pElemTextbox1 = pElemRef;
- // Create vertical scrollbar for textbox
- pElemRef = gslc_ElemXSliderCreate(&m_gui,E_TXTSCROLL1,E_PG_MAIN,&m_sTextScroll1,
- (gslc_tsRect){10+297-21,100+4,20,127-8},0,100,0,5,true);
- gslc_ElemSetCol(&m_gui,pElemRef,GSLC_COL_GRAY,GSLC_COL_BLACK,GSLC_COL_GRAY);
- gslc_ElemXSliderSetPosFunc(&m_gui,pElemRef,&CbSlidePos);
- m_pTextSlider1 = pElemRef;
- // Create E_ELEM_TEXTGPS text label
- pElemRef = gslc_ElemCreateTxt(&m_gui,E_ELEM_TEXTGPS,E_PG_MAIN,(gslc_tsRect){10,40,54,15},
- (char*)"Position:",0,E_FONT_TXT5);
- gslc_ElemSetTxtCol(&m_gui,pElemRef,GSLC_COL_BLUE_LT4);
- // Create E_ELEM_GPSINFO runtime modifiable text
- static char m_sDisplayText4[31] = "...";
- pElemRef = gslc_ElemCreateTxt(&m_gui,E_ELEM_GPSINFO,E_PG_MAIN,(gslc_tsRect){100,40,174,10},
- (char*)m_sDisplayText4,31,E_FONT_TXT5);
- gslc_ElemSetTxtCol(&m_gui,pElemRef,GSLC_COL_WHITE);
- m_pElemOutTxt4 = pElemRef;
- // Create E_ELEM_TEXTDATUM text label
- pElemRef = gslc_ElemCreateTxt(&m_gui,E_ELEM_TEXTDATUM,E_PG_MAIN,(gslc_tsRect){10,60,84,15},
- (char*)"Datum / Zeit: ",0,E_FONT_TXT5);
- gslc_ElemSetTxtCol(&m_gui,pElemRef,GSLC_COL_BLUE_LT4);
- // Create E_ELEM_DATUMINFO runtime modifiable text
- static char m_sDisplayText6[31] = "...";
- pElemRef = gslc_ElemCreateTxt(&m_gui,E_ELEM_DATUMINFO,E_PG_MAIN,(gslc_tsRect){100,60,204,10},
- (char*)m_sDisplayText6,31,E_FONT_TXT5);
- gslc_ElemSetTxtCol(&m_gui,pElemRef,GSLC_COL_WHITE);
- m_pElemOutTxt6 = pElemRef;
- // -----------------------------------
- // PAGE: E_PG_BLANK
- // create E_ELEM_BTN_BACKLIGHT button with text label
- pElemRef = gslc_ElemCreateBtnTxt(&m_gui,E_ELEM_BTN_BACKLIGHT,E_PG_BLANK,
- (gslc_tsRect){10,10,300,215},(char*)"An",0,E_FONT_TXT5,&CbBtnCommon);
- gslc_ElemSetTxtCol(&m_gui,pElemRef,GSLC_COL_WHITE);
- gslc_ElemSetCol(&m_gui,pElemRef,GSLC_COL_BLACK,GSLC_COL_BLACK,GSLC_COL_BLACK);
- // -----------------------------------
- // PAGE: E_POP_KEYPAD
- gslc_tsXKeyPadCfg sCfg = gslc_ElemXKeyPadCfgInit_Num();
- gslc_ElemXKeyPadCfgSetFloatEn(&sCfg, true);
- gslc_ElemXKeyPadCfgSetSignEn(&sCfg, true);
- gslc_ElemXKeyPadCfgSetButtonSz(&sCfg, 20, 20);
- gslc_ElemXKeyPadCfgSetRoundEn(&sCfg, false);
- m_pElemKeyPad = gslc_ElemXKeyPadCreate_Num(&m_gui, E_ELEM_KEYPAD, E_POP_KEYPAD,
- &m_sKeyPad, 65, 80, E_FONT_TXT5, &sCfg);
- gslc_ElemXKeyPadValSetCb(&m_gui, m_pElemKeyPad, &CbKeypad);
- //<InitGUI !End!>
- return true;
- }
- //---------------------------------------------------
- // SD Funktions
- //---------------------------------------------------
- void initSDCard()
- {
- // Update Textbox
- gslc_tsElemRef* pElemTextbox = gslc_PageFindElemById(&m_gui,E_PG_MAIN,E_ELEM_TBSENSOREN);
- if (!SD.begin(5)) {
- Serial.println("Card Mount Failed");
- gslc_ElemXTextboxAdd(&m_gui,pElemTextbox,(char*)"SD Kartenslot konnte nicht initialisiert\n werden!\n");
- return;
- }
- uint8_t cardType = SD.cardType();
- if (cardType == CARD_NONE) {
- Serial.println("No SD card attached");
- gslc_ElemXTextboxAdd(&m_gui,pElemTextbox,(char*)"Es wurde keine SD Karte gefunden!\n");
- return;
- }
- gslc_ElemXTextboxAdd(&m_gui,pElemTextbox,(char*)"SD Karte wurde eingelesen\n");
- if (!SD.exists("/tid.txt")) {
- myFile = SD.open("/tid.txt", FILE_WRITE);
- gslc_ElemXTextboxAdd(&m_gui,pElemTextbox,(char*)"tid.txt erstellt\n");
- myFile.close();
- }
- char tid[15] = {0};
- // re-open the file for reading:
- myFile = SD.open("/tid.txt");
- if (myFile) {
- Serial.println("tid.txt:");
- // read from the file until there's nothing else in it:
- int counter = 0;
- while (myFile.available()) {
- char ltr = myFile.read();
- if (ltr != '\n') {
- tid[counter] = ltr;
- }
- counter ++;
- }
- Serial.println(tid);
- gslc_ElemXTextboxAdd(&m_gui,pElemTextbox,(char*)"Transport-ID: ");
- gslc_ElemXTextboxAdd(&m_gui,pElemTextbox,tid);
- gslc_ElemXTextboxAdd(&m_gui,pElemTextbox,(char*)"\n");
- gslc_ElemSetTxtStr(&m_gui, m_pElemVal1, tid);
- // close the file:
- myFile.close();
- } else {
- // if the file didn't open, print an error:
- Serial.println("tid.txt konnte nicht geöffnet werden!");
- }
- root = SD.open("/");
- printDirectory(root, 0);
- }
- void printDirectory(File dir, int numTabs) {
- while (true) {
- File entry = dir.openNextFile();
- if (! entry) {
- // no more files
- break;
- }
- for (uint8_t i = 0; i < numTabs; i++) {
- Serial.print('\t');
- }
- Serial.print(entry.name());
- if (entry.isDirectory()) {
- Serial.println("/");
- printDirectory(entry, numTabs + 1);
- } else {
- // files have sizes, directories do not
- Serial.print("\t\t");
- Serial.println(entry.size(), DEC);
- }
- entry.close();
- }
- }
- //---------------------------------------------------
- // GPS Functions
- //---------------------------------------------------
- char* stringToCharArray(String str){
- // Length (with one extra character for the null terminator)
- int str_len = str.length() + 1;
- // Prepare the character array (the buffer)
- char char_array[str_len];
- // Copy it over
- str.toCharArray(char_array, str_len);
- return char_array;
- }
- void checkGPS() {
- while (gpsSerial.available() > 0)
- if (gps.encode(gpsSerial.read())){
- //showGPSData();
- serialGPSData();
- }
- if (millis() > 5000 && gps.charsProcessed() < 10)
- {
- Serial.println(F("No GPS detected: check wiring."));
- while(true);
- }
- }
- void showGPSData()
- {
- if (gps.location.isValid()){
- //GPS Coords
- String serialData = "";
- serialData = String(gps.location.lat())+","+String(gps.location.lng());
- gslc_ElemSetTxtStr(&m_gui, m_pElemOutTxt4, stringToCharArray(serialData));
- } else {
- gslc_ElemSetTxtStr(&m_gui, m_pElemOutTxt4, (char*)"GPS Koordinaten nicht gefunden");
- //gslc_ElemXTextboxAdd(&m_gui,pElemTextbox, (char*)"kein GPS Signal gefunden\n");
- }
- //Date / Time
- String serialData2 = "";
- if (gps.date.isValid())
- {
- serialData2 = String(gps.date.day())+"."+String(gps.date.month())+"."+String(gps.date.year())+" / ";
- }
- else
- {
- serialData2 = String(millis())+" / ";
- }
- if (gps.time.isValid())
- {
- if (gps.time.hour() < 10) serialData2 += "0";
- serialData2 += String(gps.time.hour());
- serialData2 += ":";
- if (gps.time.minute() < 10) serialData2 += "0";
- serialData2 += String(gps.time.minute());
- serialData2 += ":";
- if (gps.time.second() < 10) serialData2 += "0";
- serialData2 += String(gps.time.second());
- } else {
- serialData2 += String(millis());
- }
- //Serial.println(serialData2);
- char __serialdata2[31];
- serialData2.toCharArray(__serialdata2, sizeof(__serialdata2));
- gslc_ElemSetTxtStr(&m_gui, m_pElemOutTxt6, __serialdata2);
- }
- void serialGPSData()
- {
- Serial.print(F("Location: "));
- if (gps.location.isValid())
- {
- Serial.print(gps.location.lat(), 6);
- Serial.print(F(","));
- Serial.print(gps.location.lng(), 6);
- }
- else
- {
- Serial.print(F("INVALID"));
- }
- Serial.print(F(" Date/Time: "));
- if (gps.date.isValid())
- {
- Serial.print(gps.date.month());
- Serial.print(F("/"));
- Serial.print(gps.date.day());
- Serial.print(F("/"));
- Serial.print(gps.date.year());
- }
- else
- {
- Serial.print(F("INVALID"));
- }
- Serial.print(F(" "));
- if (gps.time.isValid())
- {
- if (gps.time.hour() < 10) Serial.print(F("0"));
- Serial.print(gps.time.hour());
- Serial.print(F(":"));
- if (gps.time.minute() < 10) Serial.print(F("0"));
- Serial.print(gps.time.minute());
- Serial.print(F(":"));
- if (gps.time.second() < 10) Serial.print(F("0"));
- Serial.print(gps.time.second());
- Serial.print(F("."));
- if (gps.time.centisecond() < 10) Serial.print(F("0"));
- Serial.print(gps.time.centisecond());
- }
- else
- {
- Serial.print(F("INVALID"));
- }
- Serial.println();
- }
- //---------------------------------------------------
- // ESP Now Functions
- //---------------------------------------------------
- // Init ESP Now with fallback
- void InitESPNow() {
- WiFi.disconnect();
- if (esp_now_init() == ESP_OK) {
- Serial.println("ESPNow Init Success");
- //gslc_ElemXTextboxAdd(&m_gui,m_pElemTextbox1,(char*)"Netzwerk initialisiert\n");
- }
- else {
- Serial.println("ESPNow Failed");
- //gslc_ElemXTextboxAdd(&m_gui,m_pElemTextbox1,(char*)"Netzwerk konnte nicht initalisiert werden!\n");
- // Retry InitESPNow, add a counte and then restart?
- // InitESPNow();
- // or Simply Restart
- ESP.restart();
- }
- }
- void configDeviceAP() {
- String Prefix = "Slave:";
- String Mac = WiFi.macAddress();
- String SSID = Prefix + Mac;
- String Password = "123456789";
- bool result = WiFi.softAP(SSID.c_str(), Password.c_str(), CHANNEL, 0);
- if (!result) {
- Serial.println("AP Config failed.");
- //gslc_ElemXTextboxAdd(&m_gui,m_pElemTextbox1,(char*)"AP Konfiguration fehlgeschlagen\n");
- } else {
- Serial.println("AP Config Success. Broadcasting with AP: " + String(SSID));
- //gslc_ElemXTextboxAdd(&m_gui,m_pElemTextbox1,(char*)"AP Konfiguration erfolgreich\n");
- char __ca[sizeof(SSID)];
- SSID.toCharArray(__ca, sizeof(__ca));
- //gslc_ElemXTextboxAdd(&m_gui,m_pElemTextbox1,__ca);
- }
- }
- // callback when data is recv from Master
- void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len) {
- char macStr[18];
- snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
- mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
- Serial.print("Last Packet Recv from: "); Serial.println(macStr);
- Serial.print("Last Packet Recv Data: "); Serial.println(*data);
- Serial.println("");
- }
- //---------------------------------------------------
- // SETUP
- void setup()
- {
- // ------------------------------------------------
- // Initialize
- // ------------------------------------------------
- Serial.begin(9600);
- gpsSerial.begin(9600, SERIAL_8N1, RX2Pin, TX2Pin);
- //LED Background
- pinMode(25, OUTPUT);
- digitalWrite(25, HIGH);
- //WiFi
- Serial.println("Wifi Config");
- WiFi.mode(WIFI_AP);
- configDeviceAP();
- String MacAd = WiFi.softAPmacAddress();
- char __ca[sizeof(MacAd)];
- MacAd.toCharArray(__ca, sizeof(__ca));
- Serial.println ("MacAd "+MacAd);
- /*gslc_ElemXTextboxAdd(&m_gui,m_pElemTextbox1,(char*)"AP MAC: ");
- gslc_ElemXTextboxAdd(&m_gui,m_pElemTextbox1,__ca);
- gslc_ElemXTextboxAdd(&m_gui,m_pElemTextbox1,(char*)"\n");
- InitESPNow();
- // Once ESPNow is successfully Init, we will register for recv CB to
- // get recv packer info.
- esp_now_register_recv_cb(OnDataRecv);*/
- // Wait for USB Serial
- //delay(1000); // NOTE: Some devices require a delay after Serial.begin() before serial port can be used
- gslc_InitDebug(&DebugOut);
- if (!gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,m_asFont,MAX_FONT)) { return; }
- // ------------------------------------------------
- // Load Fonts
- // ------------------------------------------------
- //<Load_Fonts !Start!>
- if (!gslc_FontSet(&m_gui,E_FONT_MONOB12,GSLC_FONTREF_PTR,&FreeMonoBold12pt7b,1)) { return; }
- if (!gslc_FontSet(&m_gui,E_FONT_TXT5,GSLC_FONTREF_PTR,NULL,1)) { return; }
- //<Load_Fonts !End!>
- // ------------------------------------------------
- // Create graphic elements
- // ------------------------------------------------
- InitGUI();
- //non GuiSlice Inits
- initSDCard();
- //<Startup !Start!>
- //<Startup !End!>
- }
- // -----------------------------------
- // Main event loop
- // -----------------------------------
- void loop()
- {
- checkGPS();
- // ------------------------------------------------
- // Update GUI Elements
- // ------------------------------------------------
- //TODO - Add update code for any text, gauges, or sliders
- // - Transport ID speichern
- // - Speicherplatz für ESP32 überprüfen in den Config Dateien für Arduino IDE
- // - ESP Now als Slave
- // - ESP Now in den Sensoren als Master
- // - Daten ausgeben in Textbox
- // - Daten speichern in File
- // - Bildschirm ausschalten (switch zu anderen Bildschirm)
- // - Button wieder zurück zu eigentlichem Bildschirm
- // - Checkbox für konstant an
- // ------------------------------------------------
- // Periodically call GUIslice update function
- // ------------------------------------------------
- gslc_Update(&m_gui);
- delay(5000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement