Skip to content

Commit 2db3a41

Browse files
authored
Merge pull request #27 from 0015/0015
Make KeyEvent Public
2 parents 7432977 + c75cff9 commit 2db3a41

File tree

8 files changed

+289
-2
lines changed

8 files changed

+289
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Video:
3131
##### Supported Displays #####
3232
- ILI9341 [library](https://github.com/Links2004/Adafruit_ILI9341)
3333
- ST7789 [library](https://github.com/Bodmer/TFT_eSPI)
34+
- ST7796 [library](https://github.com/lovyan03/LovyanGFX)
3435

3536
more possible using ```VNCdisplay``` Interface
3637

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include "LovyanGFX_VNCDriver.h"
2+
3+
VNCDriver::VNCDriver(LGFX *lgfx) {
4+
_lcd = lgfx;
5+
_lcd->setRotation(1);
6+
_lcd->setBrightness(255);
7+
_lcd->fillScreen(TFT_BLACK);
8+
}
9+
10+
VNCDriver::~VNCDriver() {
11+
}
12+
13+
bool VNCDriver::hasCopyRect(void) {
14+
return false;
15+
}
16+
17+
uint32_t VNCDriver::getHeight(void) {
18+
return _lcd->height();
19+
}
20+
21+
uint32_t VNCDriver::getWidth(void) {
22+
return _lcd->width();
23+
}
24+
25+
void VNCDriver::draw_area(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t *data) {
26+
_lcd->pushImage(x, y, w, h, (uint16_t *)data);
27+
}
28+
29+
void VNCDriver::draw_rect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint16_t color) {
30+
_lcd->fillRect(x, y, w, h, ((((color)&0xff) << 8) | (((color) >> 8))));
31+
}
32+
33+
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) {
34+
}
35+
36+
void VNCDriver::area_update_start(uint32_t x, uint32_t y, uint32_t w, uint32_t h) {
37+
_lcd->setAddrWindow(x, y, w, h);
38+
}
39+
40+
void VNCDriver::area_update_data(char *data, uint32_t pixel) {
41+
_lcd->pushPixels((uint16_t *)data, pixel);
42+
}
43+
44+
void VNCDriver::area_update_end(void) {
45+
_lcd->endWrite();
46+
}
47+
48+
void VNCDriver::vnc_options_override(dfb_vnc_options *opt) {
49+
opt->client.bigendian = 1;
50+
}
51+
52+
void VNCDriver::print_screen(String title, String msg, int color) {
53+
_lcd->fillScreen(TFT_BLACK);
54+
_lcd->setCursor(0, _lcd->height() / 3);
55+
_lcd->setTextColor(color);
56+
_lcd->setTextSize(5);
57+
_lcd->println(title);
58+
_lcd->setTextSize(3);
59+
_lcd->println(msg);
60+
}
61+
62+
void VNCDriver::print(String text) {
63+
_lcd->print(text);
64+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#pragma once
2+
#include "VNC_config.h"
3+
#include "VNC.h"
4+
#define LGFX_USE_V1
5+
#include <LovyanGFX.hpp>
6+
7+
class LGFX : public lgfx::LGFX_Device {
8+
lgfx::Panel_ST7796 _panel_instance;
9+
lgfx::Bus_SPI _bus_instance;
10+
lgfx::Light_PWM _light_instance;
11+
lgfx::Touch_FT5x06 _touch_instance;
12+
13+
public:
14+
LGFX(void) {
15+
{
16+
auto cfg = _bus_instance.config();
17+
cfg.spi_host = HSPI_HOST;
18+
cfg.spi_mode = 0;
19+
cfg.freq_write = 80000000;
20+
cfg.freq_read = 16000000;
21+
cfg.spi_3wire = false;
22+
cfg.use_lock = true;
23+
cfg.dma_channel = 1;
24+
cfg.pin_sclk = 14;
25+
cfg.pin_mosi = 13;
26+
cfg.pin_miso = 12;
27+
cfg.pin_dc = 21;
28+
_bus_instance.config(cfg);
29+
_panel_instance.setBus(&_bus_instance);
30+
}
31+
32+
{
33+
auto cfg = _panel_instance.config();
34+
cfg.pin_cs = 15;
35+
cfg.pin_rst = 22;
36+
cfg.pin_busy = -1;
37+
cfg.memory_width = 320;
38+
cfg.memory_height = 480;
39+
cfg.panel_width = 320;
40+
cfg.panel_height = 480;
41+
cfg.offset_x = 0;
42+
cfg.offset_y = 0;
43+
cfg.offset_rotation = 0;
44+
cfg.dummy_read_pixel = 8;
45+
cfg.dummy_read_bits = 1;
46+
cfg.readable = true;
47+
cfg.invert = false;
48+
cfg.rgb_order = false;
49+
cfg.dlen_16bit = false;
50+
cfg.bus_shared = true;
51+
52+
_panel_instance.config(cfg);
53+
}
54+
55+
{
56+
auto cfg = _light_instance.config();
57+
cfg.pin_bl = 23;
58+
cfg.invert = false;
59+
cfg.freq = 44100;
60+
cfg.pwm_channel = 7;
61+
62+
_light_instance.config(cfg);
63+
_panel_instance.setLight(&_light_instance);
64+
}
65+
66+
{
67+
auto cfg = _touch_instance.config();
68+
69+
cfg.i2c_port = 1;
70+
cfg.i2c_addr = 0x38;
71+
cfg.pin_sda = 18;
72+
cfg.pin_scl = 19;
73+
cfg.freq = 400000;
74+
cfg.x_min = 0;
75+
cfg.x_max = 320;
76+
cfg.y_min = 0;
77+
cfg.y_max = 480;
78+
79+
_touch_instance.config(cfg);
80+
_panel_instance.setTouch(&_touch_instance);
81+
}
82+
83+
setPanel(&_panel_instance);
84+
}
85+
};
86+
87+
class VNCDriver : public VNCdisplay {
88+
public:
89+
90+
VNCDriver(LGFX* lgfx);
91+
~VNCDriver();
92+
93+
bool hasCopyRect(void);
94+
uint32_t getHeight(void);
95+
uint32_t getWidth(void);
96+
void draw_area(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t* data);
97+
void draw_rect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint16_t color);
98+
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);
99+
void area_update_start(uint32_t x, uint32_t y, uint32_t w, uint32_t h);
100+
void area_update_data(char* data, uint32_t pixel);
101+
void area_update_end(void);
102+
103+
void vnc_options_override(dfb_vnc_options* opt);
104+
void print_screen(String title, String msg, int color);
105+
void print(String text);
106+
107+
private:
108+
LGFX* _lcd;
109+
};
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* VNC_ST7796_LovyanGFX.ino
3+
*
4+
* Created on: 10.15.2022
5+
* Created by Eric Nam(https://github.com/0015)
6+
*
7+
* required librarys:
8+
* - SPI (arduino core)
9+
* - WiFi (arduino core)
10+
* - arduinoVNC (https://github.com/Links2004/arduinoVNC)
11+
* - LovyanGFX (https://github.com/lovyan03/LovyanGFX)
12+
*/
13+
14+
#include <Arduino.h>
15+
#include <WiFi.h>
16+
#include <VNC.h>
17+
#include "LovyanGFX_VNCDriver.h"
18+
19+
const char* vnc_ip = "192.168.1.12";
20+
const uint16_t vnc_port = 5900;
21+
const char* vnc_pass = "12345678";
22+
23+
const char* ssid = "your-ssid";
24+
const char* password = "your-password";
25+
26+
27+
int touch_x = 0;
28+
int touch_y = 0;
29+
bool hadTouchEvent = false;
30+
31+
LGFX _lgfx;
32+
VNCDriver* lcd = new VNCDriver(&_lgfx);
33+
arduinoVNC vnc = arduinoVNC(lcd);
34+
35+
void setup(void) {
36+
37+
Serial.begin(115200);
38+
_lgfx.init();
39+
40+
Serial.print("Connecting to ");
41+
Serial.println(ssid);
42+
43+
lcd->print_screen("Connecting to ", ssid, TFT_YELLOW);
44+
45+
WiFi.begin(ssid, password);
46+
while (WiFi.status() != WL_CONNECTED) {
47+
delay(500);
48+
Serial.print(".");
49+
lcd->print(".");
50+
}
51+
Serial.println("");
52+
Serial.println("WiFi connected");
53+
Serial.println("IP address: ");
54+
Serial.println(WiFi.localIP());
55+
56+
lcd->print_screen("WiFi connected!", WiFi.localIP().toString(), TFT_GREEN);
57+
Serial.println(F("[SETUP] VNC..."));
58+
59+
vnc.begin(vnc_ip, vnc_port);
60+
vnc.setPassword(vnc_pass); // check for vnc server settings
61+
62+
xTaskCreatePinnedToCore(vnc_task,
63+
"vnc_task",
64+
10000,
65+
NULL,
66+
1,
67+
NULL,
68+
0);
69+
}
70+
71+
void loop() {}
72+
73+
void vnc_task(void* pvParameters) {
74+
while (1) {
75+
if (WiFi.status() != WL_CONNECTED) {
76+
lcd->print_screen("WiFi Disconnected!", "Check your WiFi", TFT_RED);
77+
vnc.reconnect();
78+
vTaskDelay(100);
79+
} else {
80+
vnc.loop();
81+
if (!vnc.connected()) {
82+
lcd->print_screen("Connecting VNC", getVNCAddr(), TFT_GREEN);
83+
vTaskDelay(5000);
84+
} else {
85+
touchEvent();
86+
}
87+
}
88+
vTaskDelay(1);
89+
}
90+
}
91+
92+
void touchEvent() {
93+
uint16_t x, y;
94+
if (_lgfx.getTouch(&x, &y)) {
95+
hadTouchEvent = true;
96+
touch_x = x;
97+
touch_y = y;
98+
vnc.mouseEvent(touch_x, touch_y, 0b001);
99+
100+
} else if (hadTouchEvent) {
101+
hadTouchEvent = false;
102+
vnc.mouseEvent(touch_x, touch_y, 0b000);
103+
}
104+
}
105+
106+
String getVNCAddr() {
107+
return String(vnc_ip) + String(":") + String(vnc_port);
108+
}

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
"tests"
2121
]
2222
},
23-
"version": "1.4",
23+
"version": "1.5",
2424
"license": "GPL-2.0-or-later"
2525
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=arduinoVNC
2-
version=1.4
2+
version=1.5
33
author=Markus Sattler
44
maintainer=Markus Sattler
55
sentence=VNC Client for Arduino

src/VNC.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ void arduinoVNC::mouseEvent(uint16_t x, uint16_t y, uint8_t buttonMask) {
255255
rfb_update_mouse();
256256
}
257257

258+
void arduinoVNC::keyEvent(int key, int keyMask)
259+
{
260+
rfb_send_key_event(key, keyMask);
261+
}
258262

259263
void arduinoVNC::reconnect(void) {
260264
// auto reconnect on next loop

src/VNC.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class arduinoVNC {
185185

186186
void setMaxFPS(uint16_t fps);
187187
void mouseEvent(uint16_t x, uint16_t y, uint8_t buttonMask);
188+
void keyEvent(int key, int keyMask);
188189

189190
private:
190191
bool onlyFullUpdate;

0 commit comments

Comments
 (0)