diff --git a/platformio.ini b/platformio.ini index 6739275e2..035ee96a4 100644 --- a/platformio.ini +++ b/platformio.ini @@ -61,7 +61,7 @@ lib_deps = https://github.com/rennancockles/MFRC522-I2C https://github.com/rennancockles/ESP-ChameleonUltra https://github.com/rennancockles/ESP-Amiibolink - https://github.com/whywilson/ESP-PN532BLE + https://github.com/whywilson/ESP-PN532BLE#1262a21 NTPClient Timezone ESP32Time diff --git a/ports/m5stack-cardputer/interface.cpp b/ports/m5stack-cardputer/interface.cpp index 2fdee3fc5..726e683c6 100644 --- a/ports/m5stack-cardputer/interface.cpp +++ b/ports/m5stack-cardputer/interface.cpp @@ -9,7 +9,7 @@ Keyboard_Class Keyboard; ** Location: main.cpp ** Description: initial setup for the device ***************************************************************************************/ -void _setup_gpio() { +void _setup_gpio() { Keyboard.begin(); pinMode(0, INPUT); pinMode(10, INPUT); // Pin that reads the @@ -24,7 +24,7 @@ void _setup_gpio() { ** location: display.cpp ** Description: Delivers the battery value from 1-100 ***************************************************************************************/ -int getBattery() { +int getBattery() { uint8_t percent; uint8_t _batAdcCh = ADC1_GPIO10_CHANNEL; uint8_t _batAdcUnit = 1; @@ -45,7 +45,7 @@ int getBattery() { return (percent < 0) ? 0 : (percent >= 100) ? 100 : percent; - } +} /********************************************************************* @@ -74,8 +74,7 @@ bool checkNextPress(){ } return true; } - - else return false; + else return false; } @@ -84,7 +83,7 @@ bool checkNextPress(){ ** location: mykeyboard.cpp ** Verifies Down Btn to go to next item **********************************************************************/ -bool checkPrevPress() { +bool checkPrevPress() { Keyboard.update(); if(Keyboard.isKeyPressed(',') || Keyboard.isKeyPressed(';')) { @@ -94,8 +93,7 @@ bool checkPrevPress() { } return true; } - - else return false; + else return false; } @@ -115,8 +113,7 @@ bool checkSelPress(){ } return true; } - - else return false; + else return false; } /********************************************************************* @@ -132,10 +129,10 @@ bool checkEscPress(){ delay(200); return false; } - returnToMenu=true; + returnToMenu = true; return true; } - else { return false; } + else return false; } @@ -144,11 +141,9 @@ bool checkEscPress(){ ** location: mykeyboard.cpp ** Verifies id any of the keys was pressed **********************************************************************/ -bool checkAnyKeyPress() { +bool checkAnyKeyPress() { Keyboard.update(); - if(Keyboard.isPressed()) - return true; - + if(Keyboard.isPressed()) return true; return false; } @@ -159,244 +154,242 @@ bool checkAnyKeyPress() { ** Starts keyboard to type data **********************************************************************/ String keyboard(String mytext, int maxSize, String msg) { - String _mytext = mytext; - - resetTftDisplay(); - bool caps=false; - int x=0; - int y=-1; - int x2=0; - int y2=0; - char keys[4][12][2] = { //4 lines, with 12 characteres, low and high caps - { - { '1', '!' },//1 - { '2', '@' },//2 - { '3', '#' },//3 - { '4', '$' },//4 - { '5', '%' },//5 - { '6', '^' },//6 - { '7', '&' },//7 - { '8', '*' },//8 - { '9', '(' },//9 - { '0', ')' },//10 - { '-', '_' },//11 - { '=', '+' } //12 - }, - { - { 'q', 'Q' },//1 - { 'w', 'W' },//2 - { 'e', 'E' },//3 - { 'r', 'R' },//4 - { 't', 'T' },//5 - { 'y', 'Y' },//6 - { 'u', 'U' },//7 - { 'i', 'I' },//8 - { 'o', 'O' },//9 - { 'p', 'P' },//10 - { '[', '{' },//11 - { ']', '}' } //12 - }, - { - { 'a', 'A' },//1 - { 's', 'S' },//2 - { 'd', 'D' },//3 - { 'f', 'F' },//4 - { 'g', 'G' },//5 - { 'h', 'H' },//6 - { 'j', 'J' },//7 - { 'k', 'K' },//8 - { 'l', 'L' },//9 - { ';', ':' },//10 - { '"', '\'' },//11 - { '|', '\\' } //12 - }, - { - { '\\', '|' },//1 - { 'z', 'Z' },//2 - { 'x', 'X' },//3 - { 'c', 'C' },//4 - { 'v', 'V' },//5 - { 'b', 'B' },//6 - { 'n', 'N' },//7 - { 'm', 'M' },//8 - { ',', '<' },//9 - { '.', '>' },//10 - { '?', '/' },//11 - { '/', '/' } //12 - } - }; - int _x = WIDTH/12; - int _y = (HEIGHT - 54)/4; - int _xo = _x/2-3; - - int i=0; - int j=-1; - bool redraw=true; - delay(200); - int cX =0; - int cY =0; - tft.fillScreen(bruceConfig.bgColor); - while(1) { - if(redraw) { - tft.setCursor(0,0); - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - //Draw the rectangles - if(y<0) { - tft.fillRect(0,1,WIDTH,22,bruceConfig.bgColor); - tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle - tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle - tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle - tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle - - - if(x==0 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("OK", 18, 4); - - - if(x==1 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(55,2,50,20,TFT_WHITE); } - else if(caps) { tft.fillRect(55,2,50,20,TFT_DARKGREY); tft.setTextColor(TFT_WHITE, TFT_DARKGREY); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("CAP", 64, 4); - - - if(x==2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(107,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("DEL", 115, 4); - - if(x>2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(159,2,74,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("SPACE", 168, 4); - } - - tft.setTextSize(FP); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.drawString(msg.substring(0,38), 3, 24); - - tft.setTextSize(FM); - - // reseta o quadrado do texto - if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,WIDTH-3,20,bruceConfig.bgColor); // mystring Rectangle - // escreve o texto - tft.setTextColor(TFT_WHITE); - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - tft.drawString(mytext.substring(0,38), 5, 34); - tft.drawString(mytext.substring(38,mytext.length()), 5, 42); + String _mytext = mytext; + + resetTftDisplay(); + bool caps=false; + int x=0; + int y=-1; + int x2=0; + int y2=0; + char keys[4][12][2] = { //4 lines, with 12 characteres, low and high caps + { + { '1', '!' },//1 + { '2', '@' },//2 + { '3', '#' },//3 + { '4', '$' },//4 + { '5', '%' },//5 + { '6', '^' },//6 + { '7', '&' },//7 + { '8', '*' },//8 + { '9', '(' },//9 + { '0', ')' },//10 + { '-', '_' },//11 + { '=', '+' } //12 + }, + { + { 'q', 'Q' },//1 + { 'w', 'W' },//2 + { 'e', 'E' },//3 + { 'r', 'R' },//4 + { 't', 'T' },//5 + { 'y', 'Y' },//6 + { 'u', 'U' },//7 + { 'i', 'I' },//8 + { 'o', 'O' },//9 + { 'p', 'P' },//10 + { '[', '{' },//11 + { ']', '}' } //12 + }, + { + { 'a', 'A' },//1 + { 's', 'S' },//2 + { 'd', 'D' },//3 + { 'f', 'F' },//4 + { 'g', 'G' },//5 + { 'h', 'H' },//6 + { 'j', 'J' },//7 + { 'k', 'K' },//8 + { 'l', 'L' },//9 + { ';', ':' },//10 + { '"', '\'' },//11 + { '|', '\\' } //12 + }, + { + { '\\', '|' },//1 + { 'z', 'Z' },//2 + { 'x', 'X' },//3 + { 'c', 'C' },//4 + { 'v', 'V' },//5 + { 'b', 'B' },//6 + { 'n', 'N' },//7 + { 'm', 'M' },//8 + { ',', '<' },//9 + { '.', '>' },//10 + { '?', '/' },//11 + { '/', '/' } //12 } - else { - tft.drawString(mytext, 5, 34); + }; + int _x = WIDTH/12; + int _y = (HEIGHT - 54)/4; + int _xo = _x/2-3; + + int i=0; + int j=-1; + bool redraw=true; + delay(200); + int cX =0; + int cY =0; + tft.fillScreen(bruceConfig.bgColor); + while(1) { + if(redraw) { + tft.setCursor(0,0); + tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); + tft.setTextSize(FM); + + //Draw the rectangles + if(y<0) { + tft.fillRect(0,1,WIDTH,22,bruceConfig.bgColor); + tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle + tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle + tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle + tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle + tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle + + + if(x==0 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } + else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); + tft.drawString("OK", 18, 4); + + + if(x==1 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(55,2,50,20,TFT_WHITE); } + else if(caps) { tft.fillRect(55,2,50,20,TFT_DARKGREY); tft.setTextColor(TFT_WHITE, TFT_DARKGREY); } + else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); + tft.drawString("CAP", 64, 4); + + + if(x==2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(107,2,50,20,TFT_WHITE); } + else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); + tft.drawString("DEL", 115, 4); + + if(x>2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(159,2,74,20,TFT_WHITE); } + else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); + tft.drawString("SPACE", 168, 4); + } + + tft.setTextSize(FP); + tft.setTextColor(TFT_WHITE, 0x5AAB); + tft.drawString(msg.substring(0,38), 3, 24); + + tft.setTextSize(FM); + + // reseta o quadrado do texto + if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,WIDTH-3,20,bruceConfig.bgColor); // mystring Rectangle + // escreve o texto + tft.setTextColor(TFT_WHITE); + if(mytext.length()>19) { + tft.setTextSize(FP); + if(mytext.length()>38) { + tft.drawString(mytext.substring(0,38), 5, 34); + tft.drawString(mytext.substring(38,mytext.length()), 5, 42); + } + else { + tft.drawString(mytext, 5, 34); + } + } else { + tft.drawString(mytext, 5, 34); + } + //desenha o retangulo colorido + tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle + + + tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); + tft.setTextSize(FM); + + for(i=0;i<4;i++) { + for(j=0;j<12;j++) { + //use last coordenate to paint only this letter + if(x2==j && y2==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,bruceConfig.bgColor);} + /* If selected, change font color and draw Rectangle*/ + if(x==j && y==i) { tft.setTextColor(bruceConfig.bgColor, ~bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,~bruceConfig.bgColor);} + + /* Print the letters */ + if(!caps) tft.drawChar(keys[i][j][0], (j*_x+_xo), (i*_y+56)); + else tft.drawChar(keys[i][j][1], (j*_x+_xo), (i*_y+56)); + + /* Return colors to normal to print the other letters */ + if(x==j && y==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); } + } + } + // save actual key coordenate + x2=x; + y2=y; + redraw = false; + #if defined(HAS_TOUCH) + TouchFooter(); + #endif } - } else { - tft.drawString(mytext, 5, 34); - } - //desenha o retangulo colorido - tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle - - - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - - for(i=0;i<4;i++) { - for(j=0;j<12;j++) { - //use last coordenate to paint only this letter - if(x2==j && y2==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,bruceConfig.bgColor);} - /* If selected, change font color and draw Rectangle*/ - if(x==j && y==i) { tft.setTextColor(bruceConfig.bgColor, ~bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,~bruceConfig.bgColor);} - - /* Print the letters */ - if(!caps) tft.drawChar(keys[i][j][0], (j*_x+_xo), (i*_y+56)); - else tft.drawChar(keys[i][j][1], (j*_x+_xo), (i*_y+56)); - - /* Return colors to normal to print the other letters */ - if(x==j && y==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); } + //cursor handler + if(mytext.length()>19) { + tft.setTextSize(FP); + if(mytext.length()>38) { + cY=42; + cX=5+(mytext.length()-38)*LW; + } + else { + cY=34; + cX=5+mytext.length()*LW; + } + } else { + cY=34; + cX=5+mytext.length()*LW*2; } - } - // save actual key coordenate - x2=x; - y2=y; - redraw = false; - #if defined(HAS_TOUCH) - TouchFooter(); - #endif - } - //cursor handler - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - cY=42; - cX=5+(mytext.length()-38)*LW; - } - else { - cY=34; - cX=5+mytext.length()*LW; - } - } else { - cY=34; - cX=5+mytext.length()*LW*2; - } - - /* When Select a key in keyboard */ - Keyboard.update(); - if (Keyboard.isPressed()) { - wakeUpScreen(); - tft.setCursor(cX,cY); - Keyboard_Class::KeysState status = Keyboard.keysState(); - - bool Fn = status.fn; - if(Fn && Keyboard.isKeyPressed('`')) { - mytext = _mytext; // return the old name - returnToMenu=true;// try to stop all the code - break; - } - - for (auto i : status.word) { - if(mytext.length() 0) { + // Handle backspace key + mytext.remove(mytext.length() - 1); + int fS=FM; + if(mytext.length()>19) { tft.setTextSize(FP); fS=FP; } + else tft.setTextSize(FM); + tft.setCursor((cX-fS*LW),cY); + tft.setTextColor(bruceConfig.priColor,bruceConfig.bgColor); + tft.print(" "); + tft.setTextColor(TFT_WHITE, 0x5AAB); + tft.setCursor(cX-fS*LW,cY); + cX=tft.getCursorX(); + cY=tft.getCursorY(); + if(mytext.length()==19) redraw = true; + if(mytext.length()==38) redraw = true; + } + if (status.enter) { + break; + } + delay(200); } - } - if (status.del && mytext.length() > 0) { - // Handle backspace key - mytext.remove(mytext.length() - 1); - int fS=FM; - if(mytext.length()>19) { tft.setTextSize(FP); fS=FP; } - else tft.setTextSize(FM); - tft.setCursor((cX-fS*LW),cY); - tft.setTextColor(bruceConfig.priColor,bruceConfig.bgColor); - tft.print(" "); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.setCursor(cX-fS*LW,cY); - cX=tft.getCursorX(); - cY=tft.getCursorY(); - if(mytext.length()==19) redraw = true; - if(mytext.length()==38) redraw = true; - } - if (status.enter) { - break; - } - delay(200); - } - if(checkSelPress()) break; - } + if(checkSelPress()) break; + } - //Resets screen when finished writing - tft.fillRect(0,0,WIDTH,HEIGHT,bruceConfig.bgColor); - resetTftDisplay(); + //Resets screen when finished writing + tft.fillRect(0,0,WIDTH,HEIGHT,bruceConfig.bgColor); + resetTftDisplay(); - return mytext; + return mytext; } @@ -424,24 +417,24 @@ void checkReboot() { } ** location: mykeyboard.cpp ** returns the key from the keyboard **********************************************************************/ -keyStroke _getKeyPress() { - keyStroke key; - Keyboard.update(); - if (Keyboard.isPressed()) { - wakeUpScreen(); - Keyboard_Class::KeysState status = Keyboard.keysState(); - for (auto i : status.hid_keys) key.hid_keys.push_back(i); - for (auto i : status.word) { - key.word.push_back(i); - if(i=='`') key.exit_key=true; // key pressed to try to exit - } - for (auto i : status.modifier_keys) key.modifier_keys.push_back(i); - if (status.del) key.del=true; - if (status.enter) key.enter=true; - if (status.fn) key.fn=true; - key.pressed=true; - } else key.pressed=false; - return key; +keyStroke _getKeyPress() { + keyStroke key; + Keyboard.update(); + if (Keyboard.isPressed()) { + wakeUpScreen(); + Keyboard_Class::KeysState status = Keyboard.keysState(); + for (auto i : status.hid_keys) key.hid_keys.push_back(i); + for (auto i : status.word) { + key.word.push_back(i); + if(i=='`') key.exit_key=true; // key pressed to try to exit + } + for (auto i : status.modifier_keys) key.modifier_keys.push_back(i); + if (status.del) key.del=true; + if (status.enter) key.enter=true; + if (status.fn) key.fn=true; + key.pressed=true; + } else key.pressed=false; + return key; } @@ -461,7 +454,7 @@ bool _checkNextPagePress() { ** location: mykeyboard.cpp ** returns the key from the keyboard **********************************************************************/ -bool _checkPrevPagePress() { +bool _checkPrevPagePress() { Keyboard.update(); if(Keyboard.isKeyPressed(',')) return true; // left arrow return false; diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 5874f1732..caca5f34a 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -101,8 +101,7 @@ void setBrightnessMenu() { void setSleepMode() { sleepModeOn(); while (1) { - if (checkAnyKeyPress()) - { + if (checkAnyKeyPress()) { sleepModeOff(); returnToMenu = true; break; @@ -302,12 +301,14 @@ void setClock() { options = { {"NTP Timezone", [&]() { auto_mode=true; }}, {"Manually set", [&]() { auto_mode=false; }}, - {"Main Menu", [=]() { backToMenu(); }}, + {"Main Menu", [=]() { backToMenu(); }}, }; delay(200); loopOptions(options); delay(200); + if (returnToMenu) return; + if (auto_mode) { if(!wifiConnected) wifiConnectMenu(); @@ -330,6 +331,9 @@ void setClock() { delay(200); loopOptions(options); delay(200); + + if (returnToMenu) return; + timeClient.setTimeOffset(bruceConfig.tmz * 3600); timeClient.begin(); timeClient.update();