-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eric
committed
Oct 16, 2022
1 parent
973da2a
commit 5bdb6e5
Showing
6 changed files
with
285 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "LovyanGFX_VNCDriver.h" | ||
|
||
VNCDriver::VNCDriver(LGFX *lgfx) { | ||
_lcd = lgfx; | ||
_lcd->setRotation(1); | ||
_lcd->setBrightness(255); | ||
_lcd->fillScreen(TFT_BLACK); | ||
} | ||
|
||
VNCDriver::~VNCDriver() { | ||
delete _lcd; | ||
} | ||
|
||
bool VNCDriver::hasCopyRect(void) { | ||
return false; | ||
} | ||
|
||
uint32_t VNCDriver::getHeight(void) { | ||
return _lcd->height(); | ||
} | ||
|
||
uint32_t VNCDriver::getWidth(void) { | ||
return _lcd->width(); | ||
} | ||
|
||
void VNCDriver::draw_area(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t *data) { | ||
_lcd->pushImage(x, y, w, h, (uint16_t *)data); | ||
} | ||
|
||
void VNCDriver::draw_rect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint16_t color) { | ||
_lcd->fillRect(x, y, w, h, ((((color)&0xff) << 8) | (((color) >> 8)))); | ||
} | ||
|
||
void VNCDriver::copy_rect(uint32_t src_x, uint32_t src_y, uint32_t dest_x, uint32_t dest_y, uint32_t w, uint32_t h) { | ||
} | ||
|
||
void VNCDriver::area_update_start(uint32_t x, uint32_t y, uint32_t w, uint32_t h) { | ||
_lcd->setAddrWindow(x, y, w, h); | ||
} | ||
|
||
void VNCDriver::area_update_data(char *data, uint32_t pixel) { | ||
_lcd->pushPixels((uint16_t *)data, pixel); | ||
} | ||
|
||
void VNCDriver::area_update_end(void) { | ||
_lcd->endWrite(); | ||
} | ||
|
||
void VNCDriver::vnc_options_override(dfb_vnc_options *opt) { | ||
opt->client.bigendian = 1; | ||
} | ||
|
||
void VNCDriver::print_screen(String title, String msg, int color) { | ||
_lcd->fillScreen(TFT_BLACK); | ||
_lcd->setCursor(0, _lcd->height() / 3); | ||
_lcd->setTextColor(color); | ||
_lcd->setTextSize(5); | ||
_lcd->println(title); | ||
_lcd->setTextSize(3); | ||
_lcd->println(msg); | ||
} | ||
|
||
void VNCDriver::print(String text) { | ||
_lcd->print(text); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#pragma once | ||
#include "VNC_config.h" | ||
#include "VNC.h" | ||
#define LGFX_USE_V1 | ||
#include <LovyanGFX.hpp> | ||
|
||
class LGFX : public lgfx::LGFX_Device { | ||
lgfx::Panel_ST7796 _panel_instance; | ||
lgfx::Bus_SPI _bus_instance; | ||
lgfx::Light_PWM _light_instance; | ||
lgfx::Touch_FT5x06 _touch_instance; | ||
|
||
public: | ||
LGFX(void) { | ||
{ | ||
auto cfg = _bus_instance.config(); | ||
cfg.spi_host = HSPI_HOST; | ||
cfg.spi_mode = 0; | ||
cfg.freq_write = 80000000; | ||
cfg.freq_read = 16000000; | ||
cfg.spi_3wire = false; | ||
cfg.use_lock = true; | ||
cfg.dma_channel = 1; | ||
cfg.pin_sclk = 14; | ||
cfg.pin_mosi = 13; | ||
cfg.pin_miso = 12; | ||
cfg.pin_dc = 21; | ||
_bus_instance.config(cfg); | ||
_panel_instance.setBus(&_bus_instance); | ||
} | ||
|
||
{ | ||
auto cfg = _panel_instance.config(); | ||
cfg.pin_cs = 15; | ||
cfg.pin_rst = 22; | ||
cfg.pin_busy = -1; | ||
cfg.memory_width = 320; | ||
cfg.memory_height = 480; | ||
cfg.panel_width = 320; | ||
cfg.panel_height = 480; | ||
cfg.offset_x = 0; | ||
cfg.offset_y = 0; | ||
cfg.offset_rotation = 0; | ||
cfg.dummy_read_pixel = 8; | ||
cfg.dummy_read_bits = 1; | ||
cfg.readable = true; | ||
cfg.invert = false; | ||
cfg.rgb_order = false; | ||
cfg.dlen_16bit = false; | ||
cfg.bus_shared = true; | ||
|
||
_panel_instance.config(cfg); | ||
} | ||
|
||
{ | ||
auto cfg = _light_instance.config(); | ||
cfg.pin_bl = 23; | ||
cfg.invert = false; | ||
cfg.freq = 44100; | ||
cfg.pwm_channel = 7; | ||
|
||
_light_instance.config(cfg); | ||
_panel_instance.setLight(&_light_instance); | ||
} | ||
|
||
{ | ||
auto cfg = _touch_instance.config(); | ||
|
||
cfg.i2c_port = 1; | ||
cfg.i2c_addr = 0x38; | ||
cfg.pin_sda = 18; | ||
cfg.pin_scl = 19; | ||
cfg.freq = 400000; | ||
cfg.x_min = 0; | ||
cfg.x_max = 320; | ||
cfg.y_min = 0; | ||
cfg.y_max = 480; | ||
|
||
_touch_instance.config(cfg); | ||
_panel_instance.setTouch(&_touch_instance); | ||
} | ||
|
||
setPanel(&_panel_instance); | ||
} | ||
}; | ||
|
||
class VNCDriver : public VNCdisplay { | ||
public: | ||
|
||
VNCDriver(LGFX* lgfx); | ||
~VNCDriver(); | ||
|
||
bool hasCopyRect(void); | ||
uint32_t getHeight(void); | ||
uint32_t getWidth(void); | ||
void draw_area(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t* data); | ||
void draw_rect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint16_t color); | ||
void copy_rect(uint32_t src_x, uint32_t src_y, uint32_t dest_x, uint32_t dest_y, uint32_t w, uint32_t h); | ||
void area_update_start(uint32_t x, uint32_t y, uint32_t w, uint32_t h); | ||
void area_update_data(char* data, uint32_t pixel); | ||
void area_update_end(void); | ||
|
||
void vnc_options_override(dfb_vnc_options* opt); | ||
void print_screen(String title, String msg, int color); | ||
void print(String text); | ||
|
||
private: | ||
LGFX* _lcd; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* VNC_ST7796_LovyanGFX.ino | ||
* | ||
* Created on: 10.15.2022 | ||
* Created by Eric Nam(https://github.com/0015) | ||
* | ||
* required librarys: | ||
* - SPI (arduino core) | ||
* - WiFi (arduino core) | ||
* - arduinoVNC (https://github.com/Links2004/arduinoVNC) | ||
* - LovyanGFX (https://github.com/lovyan03/LovyanGFX) | ||
*/ | ||
|
||
#include <Arduino.h> | ||
#include <WiFi.h> | ||
#include <VNC.h> | ||
#include "LovyanGFX_VNCDriver.h" | ||
|
||
const char* vnc_ip = "192.168.1.12"; | ||
const uint16_t vnc_port = 5900; | ||
const char* vnc_pass = "12345678"; | ||
|
||
const char* ssid = "your-ssid"; | ||
const char* password = "your-password"; | ||
|
||
|
||
int touch_x = 0; | ||
int touch_y = 0; | ||
bool hadTouchEvent = false; | ||
|
||
LGFX _lgfx; | ||
VNCDriver* lcd = new VNCDriver(&_lgfx); | ||
arduinoVNC vnc = arduinoVNC(lcd); | ||
|
||
void setup(void) { | ||
|
||
Serial.begin(115200); | ||
_lgfx.init(); | ||
|
||
Serial.print("Connecting to "); | ||
Serial.println(ssid); | ||
|
||
lcd->print_screen("Connecting to ", ssid, TFT_YELLOW); | ||
|
||
WiFi.begin(ssid, password); | ||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
Serial.print("."); | ||
lcd->print("."); | ||
} | ||
Serial.println(""); | ||
Serial.println("WiFi connected"); | ||
Serial.println("IP address: "); | ||
Serial.println(WiFi.localIP()); | ||
|
||
lcd->print_screen("WiFi connected!", WiFi.localIP().toString(), TFT_GREEN); | ||
Serial.println(F("[SETUP] VNC...")); | ||
|
||
vnc.begin(vnc_ip, vnc_port); | ||
vnc.setPassword(vnc_pass); // check for vnc server settings | ||
|
||
xTaskCreatePinnedToCore(vnc_task, | ||
"vnc_task", | ||
10000, | ||
NULL, | ||
1, | ||
NULL, | ||
0); | ||
} | ||
|
||
void loop() {} | ||
|
||
void vnc_task(void* pvParameters) { | ||
while (1) { | ||
if (WiFi.status() != WL_CONNECTED) { | ||
lcd->print_screen("WiFi Disconnected!", "Check your WiFi", TFT_RED); | ||
vnc.reconnect(); | ||
vTaskDelay(100); | ||
} else { | ||
vnc.loop(); | ||
if (!vnc.connected()) { | ||
lcd->print_screen("Connecting VNC", getVNCAddr(), TFT_GREEN); | ||
vTaskDelay(5000); | ||
} else { | ||
touchEvent(); | ||
} | ||
} | ||
vTaskDelay(1); | ||
} | ||
} | ||
|
||
void touchEvent() { | ||
uint16_t x, y; | ||
if (_lgfx.getTouch(&x, &y)) { | ||
hadTouchEvent = true; | ||
touch_x = x; | ||
touch_y = y; | ||
vnc.mouseEvent(touch_x, touch_y, 0b001); | ||
|
||
} else if (hadTouchEvent) { | ||
hadTouchEvent = false; | ||
vnc.mouseEvent(touch_x, touch_y, 0b000); | ||
} | ||
} | ||
|
||
String getVNCAddr() { | ||
return String(vnc_ip) + String(":") + String(vnc_port); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,6 @@ | |
"tests" | ||
] | ||
}, | ||
"version": "1.4", | ||
"version": "1.5", | ||
"license": "GPL-2.0-or-later" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters