acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
ArduinoVNC.ino (7481B)
1 /******************************************************************************* 2 * Arduino VNC 3 * This is a simple VNC sample 4 * 5 * Dependent libraries: 6 * ArduinoVNC: https://github.com/moononournation/arduinoVNC.git 7 * 8 * Touch libraries: 9 * FT6X36: https://github.com/strange-v/FT6X36.git 10 * GT911: https://github.com/TAMCTec/gt911-arduino.git 11 * XPT2046: https://github.com/PaulStoffregen/XPT2046_Touchscreen.git 12 * 13 * Setup steps: 14 * 1. Fill your own SSID_NAME, SSID_PASSWORD, VNC_IP, VNC_PORT and VNC_PASSWORD 15 * 2. Change your LCD parameters in Arduino_GFX setting 16 ******************************************************************************/ 17 18 /* WiFi settings */ 19 const char *SSID_NAME = "YourAP"; 20 const char *SSID_PASSWORD = "PleaseInputYourPasswordHere"; 21 22 const char *VNC_IP = "192.168.12.34"; 23 const uint16_t VNC_PORT = 5901; 24 const char *VNC_PASSWORD = "PleaseInputYourPasswordHere"; 25 26 /******************************************************************************* 27 * Please config the touch panel in touch.h 28 ******************************************************************************/ 29 #include "touch.h" 30 31 /******************************************************************************* 32 * Please config the optional keyboard in keyboard.h 33 ******************************************************************************/ 34 #include "keyboard.h" 35 36 /******************************************************************************* 37 * Start of Arduino_GFX setting 38 * 39 * Arduino_GFX try to find the settings depends on selected board in Arduino IDE 40 * Or you can define the display dev kit not in the board list 41 * Defalult pin list for non display dev kit: 42 * Arduino Nano, Micro and more: CS: 9, DC: 8, RST: 7, BL: 6, SCK: 13, MOSI: 11, MISO: 12 43 * ESP32 various dev board : CS: 5, DC: 27, RST: 33, BL: 22, SCK: 18, MOSI: 23, MISO: nil 44 * ESP32-C3 various dev board : CS: 7, DC: 2, RST: 1, BL: 3, SCK: 4, MOSI: 6, MISO: nil 45 * ESP32-S2 various dev board : CS: 34, DC: 38, RST: 33, BL: 21, SCK: 36, MOSI: 35, MISO: nil 46 * ESP32-S3 various dev board : CS: 40, DC: 41, RST: 42, BL: 48, SCK: 36, MOSI: 35, MISO: nil 47 * ESP8266 various dev board : CS: 15, DC: 4, RST: 2, BL: 5, SCK: 14, MOSI: 13, MISO: 12 48 * Raspberry Pi Pico dev board : CS: 17, DC: 27, RST: 26, BL: 28, SCK: 18, MOSI: 19, MISO: 16 49 * RTL8720 BW16 old patch core : CS: 18, DC: 17, RST: 2, BL: 23, SCK: 19, MOSI: 21, MISO: 20 50 * RTL8720_BW16 Official core : CS: 9, DC: 8, RST: 6, BL: 3, SCK: 10, MOSI: 12, MISO: 11 51 * RTL8722 dev board : CS: 18, DC: 17, RST: 22, BL: 23, SCK: 13, MOSI: 11, MISO: 12 52 * RTL8722_mini dev board : CS: 12, DC: 14, RST: 15, BL: 13, SCK: 11, MOSI: 9, MISO: 10 53 * Seeeduino XIAO dev board : CS: 3, DC: 2, RST: 1, BL: 0, SCK: 8, MOSI: 10, MISO: 9 54 * Teensy 4.1 dev board : CS: 39, DC: 41, RST: 40, BL: 22, SCK: 13, MOSI: 11, MISO: 12 55 ******************************************************************************/ 56 #include <Arduino_GFX_Library.h> 57 58 #define GFX_BL DF_GFX_BL // default backlight pin, you may replace DF_GFX_BL to actual backlight pin 59 60 /* More dev device declaration: https://github.com/moononournation/Arduino_GFX/wiki/Dev-Device-Declaration */ 61 #if defined(DISPLAY_DEV_KIT) 62 Arduino_GFX *gfx = create_default_Arduino_GFX(); 63 #else /* !defined(DISPLAY_DEV_KIT) */ 64 65 /* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */ 66 Arduino_DataBus *bus = create_default_Arduino_DataBus(); 67 68 /* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */ 69 Arduino_GFX *gfx = new Arduino_ILI9341(bus, DF_GFX_RST, 3 /* rotation */, false /* IPS */); 70 71 #endif /* !defined(DISPLAY_DEV_KIT) */ 72 /******************************************************************************* 73 * End of Arduino_GFX setting 74 ******************************************************************************/ 75 76 #if defined(ESP32) 77 #include <WiFi.h> 78 #elif defined(ESP8266) 79 #include <ESP8266WiFi.h> 80 #elif defined(ARDUINO_RASPBERRY_PI_PICO_W) 81 #include <WiFi.h> 82 #elif defined(RTL8722DM) 83 #include <WiFi.h> 84 #endif 85 86 #include "VNC_GFX.h" 87 #include <VNC.h> 88 89 VNC_GFX *vnc_gfx = new VNC_GFX(gfx); 90 arduinoVNC vnc = arduinoVNC(vnc_gfx); 91 92 void TFTnoWifi(void) 93 { 94 gfx->fillScreen(BLACK); 95 gfx->setCursor(0, ((gfx->height() / 2) - (5 * 8))); 96 gfx->setTextColor(RED); 97 gfx->setTextSize(5); 98 gfx->println("NO WIFI!"); 99 gfx->setTextSize(2); 100 gfx->println(); 101 } 102 103 void TFTnoVNC(void) 104 { 105 gfx->fillScreen(BLACK); 106 gfx->setCursor(0, ((gfx->height() / 2) - (4 * 8))); 107 gfx->setTextColor(GREEN); 108 gfx->setTextSize(4); 109 gfx->println("connect VNC"); 110 gfx->setTextSize(2); 111 gfx->println(); 112 gfx->print(VNC_IP); 113 gfx->print(":"); 114 gfx->println(VNC_PORT); 115 } 116 117 void handle_touch() 118 { 119 if (touch_has_signal()) 120 { 121 if (touch_touched()) 122 { 123 vnc.mouseEvent(touch_last_x, touch_last_y, 0b001); 124 } 125 else if (touch_released()) 126 { 127 vnc.mouseEvent(touch_last_x, touch_last_y, 0b000); 128 } 129 } 130 } 131 132 void handle_keyboard() 133 { 134 int key = keyboard_get_key(); 135 if (key > 0) 136 { 137 // Serial.println(key); 138 switch (key) 139 { 140 case 8: 141 key = 0xff08; // BackSpace 142 break; 143 case 9: 144 key = 0xff09; // Tab 145 break; 146 case 13: 147 key = 0xff0d; // Return or Enter 148 break; 149 case 27: 150 key = 0xff1b; // Escape 151 break; 152 case 180: 153 key = 0xff51; // Left 154 break; 155 case 181: 156 key = 0xff52; // Up 157 break; 158 case 182: 159 key = 0xff54; // Down 160 break; 161 case 183: 162 key = 0xff53; // Right 163 break; 164 } 165 vnc.keyEvent(key, 0b001); 166 vnc.keyEvent(key, 0b000); 167 } 168 } 169 170 void setup(void) 171 { 172 Serial.begin(115200); 173 // Serial.setDebugOutput(true); 174 // while(!Serial); 175 Serial.println("Arduino VNC"); 176 177 #ifdef GFX_EXTRA_PRE_INIT 178 GFX_EXTRA_PRE_INIT(); 179 #endif 180 181 // Init keyboard device 182 keyboard_init(); 183 184 Serial.println("Init display"); 185 gfx->begin(); 186 gfx->fillScreen(BLACK); 187 188 #ifdef GFX_BL 189 pinMode(GFX_BL, OUTPUT); 190 digitalWrite(GFX_BL, HIGH); 191 #endif 192 193 // Init touch device 194 touch_init(gfx->width(), gfx->height(), gfx->getRotation()); 195 196 TFTnoWifi(); 197 198 Serial.println("Init WiFi"); 199 gfx->println("Init WiFi"); 200 #if defined(ESP32) 201 WiFi.mode(WIFI_STA); 202 WiFi.begin(SSID_NAME, SSID_PASSWORD); 203 #elif defined(ESP8266) 204 // disable sleep mode for better data rate 205 WiFi.setSleepMode(WIFI_NONE_SLEEP); 206 WiFi.mode(WIFI_STA); 207 WiFi.begin(SSID_NAME, SSID_PASSWORD); 208 #elif defined(ARDUINO_RASPBERRY_PI_PICO_W) 209 WiFi.mode(WIFI_STA); 210 WiFi.begin(SSID_NAME, SSID_PASSWORD); 211 #elif defined(RTL8722DM) 212 WiFi.begin((char *)SSID_NAME, (char *)SSID_PASSWORD); 213 #endif 214 while (WiFi.status() != WL_CONNECTED) 215 { 216 delay(500); 217 Serial.print("."); 218 gfx->print("."); 219 } 220 Serial.println(" CONNECTED"); 221 gfx->println(" CONNECTED"); 222 Serial.println("IP address: "); 223 gfx->println("IP address: "); 224 Serial.println(WiFi.localIP()); 225 gfx->println(WiFi.localIP()); 226 TFTnoVNC(); 227 228 Serial.println(F("[SETUP] VNC...")); 229 230 #ifdef SEPARATE_DRAW_TASK 231 draw_task_setup(); 232 #endif 233 234 vnc.begin(VNC_IP, VNC_PORT); 235 vnc.setPassword(VNC_PASSWORD); // optional 236 } 237 238 void loop() 239 { 240 if (WiFi.status() != WL_CONNECTED) 241 { 242 vnc.reconnect(); 243 TFTnoWifi(); 244 delay(100); 245 } 246 else 247 { 248 if (vnc.connected()) 249 { 250 handle_touch(); 251 handle_keyboard(); 252 } 253 vnc.loop(); 254 if (!vnc.connected()) 255 { 256 TFTnoVNC(); 257 // some delay to not flood the server 258 delay(5000); 259 } 260 } 261 }