└── KeyboardMF ├── KeyboardMF.ino └── Matouch7.h /KeyboardMF/KeyboardMF.ino: -------------------------------------------------------------------------------- 1 | #define LGFX_USE_V1 2 | #include 3 | #include 4 | #include 5 | #include "Matouch7.h" 6 | #include "EspUsbHost.h" 7 | #include 8 | 9 | #define SCREEN_HD 10 | #ifdef SCREEN_HD 11 | #define SCREEN_W 1024 12 | #define SCREEN_H 600 13 | #endif 14 | 15 | // microSD card 16 | #define PIN_SD_CMD 11 17 | #define PIN_SD_CLK 12 18 | #define PIN_SD_D0 13 19 | 20 | const uint16_t PixelCount = 8; // number of pixels in strip 21 | const uint8_t PixelPin = 18; // pin for NeoPixel 22 | NeoPixelBus strip(PixelCount, PixelPin); 23 | 24 | LGFX lcd; 25 | LGFX_Sprite sprite(&lcd); 26 | LGFX_Sprite spr(&lcd); 27 | 28 | int brightnes[6]={50,90,120,160,200,250}; 29 | int b=2; 30 | int n=0; 31 | 32 | String fileName="fileName.txt"; 33 | String txt[16]; 34 | String spaces[16]={"|","|","|","|","|","|","|","|","|","|","|","|","|","|","|","|"}; 35 | int lineCount = 0; 36 | bool mode=0; // 0 is esit file name, 1 is edit text 37 | bool openMenu=false; 38 | unsigned short modeColor[2]={TFT_RED,0x0016}; 39 | bool drawLine=true; 40 | int line=0; 41 | int maxLine=0; 42 | int keyC; 43 | String asc=""; 44 | bool capsLock=false; 45 | int lineLength=0; 46 | 47 | const int maxFiles = 32; // Define maximum number of files to store 48 | String fileNames[maxFiles]; // Array to store file names 49 | int fileCount = 0; 50 | int chosenFile; 51 | 52 | void draw() 53 | { 54 | if(drawLine) 55 | sprite.fillSprite(1); 56 | else 57 | sprite.fillSprite(0); 58 | sprite.setTextSize(2); 59 | sprite.setTextColor(4); 60 | sprite.drawString("#"+String(line+1)+".",4,10); 61 | sprite.setTextColor(7); 62 | if(drawLine) 63 | sprite.drawString(spaces[line],64,10); 64 | sprite.setTextColor(2); 65 | sprite.drawString(txt[line],64,10); 66 | sprite.pushSprite(65,70+(line*30)); 67 | } 68 | 69 | void drawName() 70 | { 71 | 72 | spr.fillSprite(0); 73 | spr.setTextColor(1); 74 | spr.setTextSize(3); 75 | spr.drawString(fileName,8,8); 76 | spr.pushSprite(110,6); 77 | } 78 | 79 | void listFilesInArray(const char * dirname) { 80 | File root = SD_MMC.open(dirname); 81 | fileCount=0; 82 | if (!root || !root.isDirectory()) { 83 | Serial.println("Failed to open directory or not a directory"); 84 | return; 85 | } 86 | 87 | File file = root.openNextFile(); 88 | while (file) { 89 | if (!file.isDirectory() && fileCount < maxFiles) { 90 | // Store the file name in the array 91 | fileNames[fileCount] = String(file.name()); 92 | fileCount++; // Increment file counter 93 | } 94 | file = root.openNextFile(); // Move to the next file 95 | } 96 | } 97 | 98 | class MyEspUsbHost : public EspUsbHost { 99 | void onKeyboardKey(uint8_t ascii, uint8_t keycode, uint8_t modifier) { 100 | 101 | 102 | // if F2 103 | if(keycode==59) 104 | { 105 | openMenu=true; 106 | resetAll(); 107 | listFilesInArray("/"); 108 | lcd.setTextSize(2); 109 | for(int i=0;i0) 174 | { 175 | lcd.fillRect(70,83+chosenFile*30,10,10,TFT_BLACK); 176 | chosenFile--; 177 | lcd.fillRect(70,83+chosenFile*30,10,10,TFT_YELLOW); 178 | } 179 | } 180 | } 181 | 182 | if(mode==1 && openMenu==false){ 183 | keyC=keycode; 184 | if ('!' <= ascii && ascii <= '~') { 185 | txt[line]=txt[line]+String((char)(ascii-capsLock*32)); 186 | spaces[line]=" "+spaces[line];} 187 | 188 | 189 | 190 | 191 | // if F4 192 | if(keycode==61) 193 | saveFile(); 194 | 195 | //IF F5 196 | if(keycode==62){ 197 | b++; if(b==6) b=0; 198 | lcd.setBrightness(brightnes[b]);} 199 | 200 | //IF SPACE 201 | if(keycode==44){ 202 | txt[line]=txt[line]+" "; 203 | spaces[line]=" "+spaces[line];} 204 | 205 | //IF TAB 206 | if(keycode==43){ 207 | txt[line]=txt[line]+" "; 208 | spaces[line]=" "+spaces[line];} 209 | 210 | //IF BACKSPACE 211 | if(keycode==42) 212 | { 213 | txt[line]=txt[line].substring(0,txt[line].length()-1); 214 | spaces[line]=spaces[line].substring(1,spaces[line].length()); 215 | } 216 | 217 | //IF DEL 218 | if(keycode==76) 219 | { 220 | txt[line]=""; 221 | spaces[line]="|"; 222 | } 223 | 224 | // IF caps loc 225 | 226 | 227 | // if up 228 | if(keycode==82) 229 | { 230 | if(line>0) 231 | { 232 | drawLine=0; 233 | draw(); 234 | line--; 235 | drawLine=1; 236 | } 237 | } 238 | 239 | //if down 240 | if(keycode==81) 241 | { 242 | if(line 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | class LGFX : public lgfx::LGFX_Device 10 | { 11 | public: 12 | 13 | lgfx::Bus_RGB _bus_instance; 14 | lgfx::Panel_RGB _panel_instance; 15 | lgfx::Light_PWM _light_instance; 16 | lgfx::Touch_GT911 _touch_instance; 17 | 18 | LGFX(void) 19 | { 20 | { 21 | auto cfg = _panel_instance.config(); 22 | 23 | #if defined ( LGFX_MAKERFABS_MATOUCH_1024X768 ) 24 | cfg.memory_width = 1024; 25 | cfg.panel_width = 1024; 26 | cfg.memory_height = 600; 27 | cfg.panel_height = 600; 28 | #else 29 | cfg.memory_width = 800; 30 | cfg.panel_width = 800; 31 | cfg.memory_height = 480; 32 | cfg.panel_height = 480; 33 | #endif 34 | 35 | cfg.offset_x = 0; 36 | cfg.offset_y = 0; 37 | 38 | _panel_instance.config(cfg); 39 | } 40 | 41 | { 42 | auto cfg = _panel_instance.config_detail(); 43 | 44 | cfg.use_psram = 1; 45 | 46 | _panel_instance.config_detail(cfg); 47 | } 48 | 49 | { 50 | auto cfg = _bus_instance.config(); 51 | cfg.panel = &_panel_instance; 52 | cfg.pin_d0 = GPIO_NUM_8; // B0 53 | cfg.pin_d1 = GPIO_NUM_3; // B1 54 | cfg.pin_d2 = GPIO_NUM_46; // B2 55 | cfg.pin_d3 = GPIO_NUM_9; // B3 56 | cfg.pin_d4 = GPIO_NUM_1; // B4 57 | cfg.pin_d5 = GPIO_NUM_5; // G0 58 | cfg.pin_d6 = GPIO_NUM_6; // G1 59 | cfg.pin_d7 = GPIO_NUM_7; // G2 60 | cfg.pin_d8 = GPIO_NUM_15; // G3 61 | cfg.pin_d9 = GPIO_NUM_16; // G4 62 | cfg.pin_d10 = GPIO_NUM_4; // G5 63 | cfg.pin_d11 = GPIO_NUM_45; // R0 64 | cfg.pin_d12 = GPIO_NUM_48; // R1 65 | cfg.pin_d13 = GPIO_NUM_47; // R2 66 | cfg.pin_d14 = GPIO_NUM_21; // R3 67 | cfg.pin_d15 = GPIO_NUM_14; // R4 68 | 69 | cfg.pin_henable = GPIO_NUM_40; 70 | cfg.pin_vsync = GPIO_NUM_41; 71 | cfg.pin_hsync = GPIO_NUM_39; 72 | cfg.pin_pclk = GPIO_NUM_42; 73 | cfg.freq_write = 16000000; 74 | 75 | cfg.hsync_polarity = 0; 76 | cfg.hsync_front_porch = 80; 77 | cfg.hsync_pulse_width = 4; 78 | cfg.hsync_back_porch = 16; 79 | cfg.vsync_polarity = 0; 80 | cfg.vsync_front_porch = 22; 81 | cfg.vsync_pulse_width = 4; 82 | cfg.vsync_back_porch = 4; 83 | cfg.pclk_idle_high = 1; 84 | _bus_instance.config(cfg); 85 | } 86 | _panel_instance.setBus(&_bus_instance); 87 | 88 | { 89 | auto cfg = _light_instance.config(); 90 | cfg.pin_bl = GPIO_NUM_10; 91 | cfg.invert = true; 92 | _light_instance.config(cfg); 93 | } 94 | _panel_instance.light(&_light_instance); 95 | 96 | { 97 | auto cfg = _touch_instance.config(); 98 | cfg.x_min = 0; 99 | cfg.y_min = 0; 100 | cfg.bus_shared = false; 101 | cfg.offset_rotation = 0; 102 | // I2C接続 103 | cfg.i2c_port = I2C_NUM_1; 104 | cfg.pin_sda = GPIO_NUM_17; 105 | cfg.pin_scl = GPIO_NUM_18; 106 | cfg.pin_int = GPIO_NUM_NC; 107 | cfg.pin_rst = GPIO_NUM_38; 108 | #if defined ( LGFX_MAKERFABS_MATOUCH_1024X768 ) 109 | cfg.x_max = 1024; 110 | cfg.y_max = 768; 111 | #else 112 | cfg.x_max = 800; 113 | cfg.y_max = 480; 114 | #endif 115 | cfg.freq = 400000; 116 | _touch_instance.config(cfg); 117 | _panel_instance.setTouch(&_touch_instance); 118 | } 119 | 120 | setPanel(&_panel_instance); 121 | } 122 | }; --------------------------------------------------------------------------------