Skip to content

Commit 83708a6

Browse files
committed
version 0.9.18a
Updating for ESP32-S3. Added USB HID support. Some refactoring. Added Keydefines.h for when USB is used.
1 parent 395454d commit 83708a6

8 files changed

+121
-66
lines changed

Action.h

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ void bleKeyboardAction(int action, int value, char *symbol)
7878
}
7979
break;
8080
case 3: // Send Media Key
81+
#if defined(USEUSBHID)
82+
83+
#else
8184
switch (value)
8285
{
8386
case 1:
@@ -106,6 +109,7 @@ void bleKeyboardAction(int action, int value, char *symbol)
106109
break;
107110
}
108111
break;
112+
#endif //if defined(USEUSBHID)
109113
case 4: // Send Character
110114
bleKeyboard.print(symbol);
111115
break;

DrawHelper.h

+5
Original file line numberDiff line numberDiff line change
@@ -1584,8 +1584,13 @@ void printinfo()
15841584
float freemem = SPIFFS.totalBytes() - SPIFFS.usedBytes();
15851585
tft.print(freemem / 1000);
15861586
tft.println(" kB");
1587+
#if defined(USEUSBHID)
1588+
tft.println("Using USB Keyboard");
1589+
#else
15871590
tft.print("BLE Keyboard version: ");
15881591
tft.println(BLE_KEYBOARD_VERSION);
1592+
#endif //if defined(USEUSBHID)
1593+
15891594
tft.print("ArduinoJson version: ");
15901595
tft.println(ARDUINOJSON_VERSION);
15911596
tft.print("TFT_eSPI version: ");

FreeTouchDeck.ino

+73-56
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@
4242
// (THE ESP32 TOUCHDOWN USES THIS!)
4343
//#define USECAPTOUCH
4444

45-
// ------- Uncomment and populate the following if your cap touch uses custom i2c pins -------
46-
//#define CUSTOM_TOUCH_SDA 26
47-
//#define CUSTOM_TOUCH_SCL 27
45+
// ------- If your board is capapble of USB HID you can undefine this -
46+
47+
//#define USEUSBHID
4848

49-
// PAY ATTENTION! Even if resistive touch is not used, the TOUCH pin has to be defined!
50-
// It can be a random unused pin.
51-
// TODO: Find a way around this!
49+
// ------- Uncomment and populate the following if your cap touch uses custom i2c pins -------
50+
//#define CUSTOM_TOUCH_SDA 17
51+
//#define CUSTOM_TOUCH_SCL 18
5252

5353
// ------- Uncomment the define below if you want to use SLEEP and wake up on touch -------
5454
// The pin where the IRQ from the touch screen is connected uses ESP-style GPIO_NUM_* instead of just pinnumber
@@ -61,44 +61,53 @@
6161
// and if you are using the original ESP32-BLE-Keyboard library by T-VK -------
6262
//#define USE_NIMBLE
6363

64-
const char *versionnumber = "0.9.17";
64+
const char *versionnumber = "0.9.18a";
6565

66-
/* Version 0.9.16.
66+
/* Version 0.9.18a.
6767
*
68-
* Added UserActions. In the UserAction.h file there are a few functions you can define and
69-
* select through the configurator. The functions have to written before compiling. These functions
70-
* are then hardcoded. Look at UserActions.h for some examples.
71-
*
72-
* Added some missing characters.
68+
* Adding ESP32-S3 support
7369
*/
7470

75-
/* TODO NEXT VERSION
76-
*
77-
* - get image height/width and use it in bmp drawing.
78-
*/
79-
8071
#include <pgmspace.h> // PROGMEM support header
8172
#include <FS.h> // Filesystem support header
8273
#include <SPIFFS.h> // Filesystem support header
8374
#include <Preferences.h> // Used to store states before sleep/reboot
8475

8576
#include <TFT_eSPI.h> // The TFT_eSPI library
8677

87-
#include <BleKeyboard.h> // BleKeyboard is used to communicate over BLE
78+
#if defined(USEUSBHID)
79+
80+
#include "USB.h"
81+
#include "USBHIDKeyboard.h"
82+
#include "Keydefines.h"
83+
USBHIDKeyboard bleKeyboard;
84+
85+
#else
86+
87+
#include <BleKeyboard.h> // BleKeyboard is used to communicate over BLE
88+
BleKeyboard bleKeyboard("FreeTouchDeck", "Made by me");
89+
90+
// Checking for BLE Keyboard version
91+
#ifndef BLE_KEYBOARD_VERSION
92+
#warning Old BLE Keyboard version detected. Please update.
93+
#define BLE_KEYBOARD_VERSION "Outdated"
94+
#endif // !defined(BLE_KEYBOARD_VERSION)
95+
96+
#endif // if
8897

8998
#if defined(USE_NIMBLE)
9099

91-
#include "NimBLEDevice.h" // Additional BLE functionaity using NimBLE
92-
#include "NimBLEUtils.h" // Additional BLE functionaity using NimBLE
93-
#include "NimBLEBeacon.h" // Additional BLE functionaity using NimBLE
100+
#include "NimBLEDevice.h" // Additional BLE functionaity using NimBLE
101+
#include "NimBLEUtils.h" // Additional BLE functionaity using NimBLE
102+
#include "NimBLEBeacon.h" // Additional BLE functionaity using NimBLE
94103

95104
#else
96105

97-
#include "BLEDevice.h" // Additional BLE functionaity
98-
#include "BLEUtils.h" // Additional BLE functionaity
99-
#include "BLEBeacon.h" // Additional BLE functionaity
106+
#include "BLEDevice.h" // Additional BLE functionaity
107+
#include "BLEUtils.h" // Additional BLE functionaity
108+
#include "BLEBeacon.h" // Additional BLE functionaity
100109

101-
#endif // USE_NIMBLE
110+
#endif // defined(USE_NIMBLE)
102111

103112
#include "esp_sleep.h" // Additional BLE functionaity
104113
#include "esp_bt_main.h" // Additional BLE functionaity
@@ -114,12 +123,10 @@ const char *versionnumber = "0.9.17";
114123
#include <ESPmDNS.h> // DNS functionality
115124

116125
#ifdef USECAPTOUCH
117-
#include <Wire.h>
118-
#include <FT6236.h>
119-
FT6236 ts = FT6236();
120-
#endif
121-
122-
BleKeyboard bleKeyboard("FreeTouchDeck", "Made by me");
126+
#include <Wire.h>
127+
#include <FT6236.h>
128+
FT6236 ts = FT6236();
129+
#endif // defined(USECAPTOUCH)
123130

124131
AsyncWebServer webserver(80);
125132

@@ -289,12 +296,6 @@ char* jsonfilefail = "";
289296
// Invoke the TFT_eSPI button class and create all the button objects
290297
TFT_eSPI_Button key[6];
291298

292-
// Checking for BLE Keyboard version
293-
#ifndef BLE_KEYBOARD_VERSION
294-
#warning Old BLE Keyboard version detected. Please update.
295-
#define BLE_KEYBOARD_VERSION "Outdated"
296-
#endif
297-
298299
//--------- Internal references ------------
299300
// (this needs to be below all structs etc..)
300301
#include "ScreenHelper.h"
@@ -332,27 +333,27 @@ void setup()
332333
Serial.println("");
333334

334335
#ifdef USECAPTOUCH
335-
#ifdef CUSTOM_TOUCH_SDA
336-
if (!ts.begin(40, CUSTOM_TOUCH_SDA, CUSTOM_TOUCH_SCL))
337-
#else
338-
if (!ts.begin(40))
339-
#endif
336+
#ifdef CUSTOM_TOUCH_SDA
337+
if (!ts.begin(40, CUSTOM_TOUCH_SDA, CUSTOM_TOUCH_SCL))
338+
#else
339+
if (!ts.begin(40))
340+
#endif // defined(CUSTOM_TOUCH_SDA)
340341
{
341342
Serial.println("[WARNING]: Unable to start the capacitive touchscreen.");
342343
}
343344
else
344345
{
345346
Serial.println("[INFO]: Capacitive touch started!");
346347
}
347-
#endif
348+
#endif // defined(USECAPTOUCH)
348349

349-
// Setup PWM channel and attach pin 32
350+
// Setup PWM channel and attach pin bl_pin
350351
ledcSetup(0, 5000, 8);
351352
#ifdef TFT_BL
352353
ledcAttachPin(TFT_BL, 0);
353354
#else
354-
ledcAttachPin(32, 0);
355-
#endif
355+
ledcAttachPin(backlightPin, 0);
356+
#endif // defined(TFT_BL)
356357
ledcWrite(0, ledBrightness); // Start @ initial Brightness
357358

358359
// --------------- Init Display -------------------------
@@ -429,7 +430,7 @@ void setup()
429430
Serial.println("[INFO]: Waiting for touch calibration...");
430431
touch_calibrate();
431432
Serial.println("[INFO]: Touch calibration completed!");
432-
#endif
433+
#endif // !defined(USECAPTOUCH)
433434

434435
// Let's first check if all the files we need exist
435436
if (!checkfile("/config/general.json"))
@@ -514,7 +515,7 @@ if(generalconfig.beep){
514515
ledcWrite(2, 0);
515516
}
516517

517-
#endif
518+
#endif // defined(speakerPin)
518519

519520
if(!loadConfig("homescreen")){
520521
Serial.println("[WARNING]: homescreen.json seems to be corrupted!");
@@ -565,12 +566,28 @@ if(generalconfig.beep){
565566

566567
//------------------BLE Initialization ------------------------------------------------------------------------
567568

569+
#if defined(USEUSBHID)
570+
571+
// initialize control over the keyboard:
572+
bleKeyboard.begin();
573+
USB.begin();
574+
575+
#else
576+
568577
Serial.println("[INFO]: Starting BLE");
569578
bleKeyboard.begin();
570579

580+
#endif //if defined(USEUSBHID)
581+
571582
// ---------------- Printing version numbers -----------------------------------------------
583+
584+
#if defined(USEUSBHID)
585+
Serial.println("[INFO]: Using USB Keyboard");
586+
#else
572587
Serial.print("[INFO]: BLE Keyboard version: ");
573588
Serial.println(BLE_KEYBOARD_VERSION);
589+
#endif //if defined(USEUSBHID)
590+
574591
Serial.print("[INFO]: ArduinoJson version: ");
575592
Serial.println(ARDUINOJSON_VERSION);
576593
Serial.print("[INFO]: TFT_eSPI version: ");
@@ -596,7 +613,7 @@ if(generalconfig.beep){
596613
Serial.println(" minutes");
597614
islatched[28] = 1;
598615
}
599-
#endif
616+
#endif // defined(touchInterruptPin)
600617

601618
Serial.println("[INFO]: Boot completed and successful!");
602619

@@ -741,7 +758,7 @@ void loop(void)
741758

742759
pressed = tft.getTouch(&t_x, &t_y);
743760

744-
#endif
761+
#endif // defined(USECAPTOUCH)
745762

746763
if (pressed)
747764
{
@@ -779,7 +796,7 @@ void loop(void)
779796

780797
pressed = tft.getTouch(&t_x, &t_y);
781798

782-
#endif
799+
#endif // defined(USECAPTOUCH)
783800

784801
if (pressed)
785802
{
@@ -818,7 +835,7 @@ void loop(void)
818835

819836
pressed = tft.getTouch(&t_x, &t_y);
820837

821-
#endif
838+
#endif // defined(USECAPTOUCH)
822839

823840
if (pressed)
824841
{
@@ -863,7 +880,7 @@ void loop(void)
863880
ledcDetachPin(speakerPin);
864881
ledcWrite(2, 0);
865882
}
866-
#endif
883+
#endif // defined(speakerPin)
867884
Serial.println("[INFO]: Saving latched states");
868885

869886
// You could uncomment this to see the latch stated before going to sleep
@@ -879,7 +896,7 @@ void loop(void)
879896
esp_deep_sleep_start();
880897
}
881898
}
882-
#endif
899+
#endif // defined(touchInterruptPin)
883900

884901
// Touch coordinates are stored here
885902
uint16_t t_x = 0, t_y = 0;
@@ -906,7 +923,7 @@ void loop(void)
906923

907924
pressed = tft.getTouch(&t_x, &t_y);
908925

909-
#endif
926+
#endif // defined(USECAPTOUCH)
910927

911928
// Check if the X and Y coordinates of the touch are within one of our buttons
912929
for (uint8_t b = 0; b < 6; b++)

Keydefines.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Some extra KEY definitions the original USB Keyboard library does not have
3+
to make it compatible with FreeTouchDeck. Only included when #define USEUSBHID
4+
is defined.
5+
*/
6+
const uint8_t KEY_PRTSC = 0xCE;
7+
8+
const uint8_t KEY_NUM_0 = 0xEA;
9+
const uint8_t KEY_NUM_1 = 0xE1;
10+
const uint8_t KEY_NUM_2 = 0xE2;
11+
const uint8_t KEY_NUM_3 = 0xE3;
12+
const uint8_t KEY_NUM_4 = 0xE4;
13+
const uint8_t KEY_NUM_5 = 0xE5;
14+
const uint8_t KEY_NUM_6 = 0xE6;
15+
const uint8_t KEY_NUM_7 = 0xE7;
16+
const uint8_t KEY_NUM_8 = 0xE8;
17+
const uint8_t KEY_NUM_9 = 0xE9;
18+
const uint8_t KEY_NUM_SLASH = 0xDC;
19+
const uint8_t KEY_NUM_ASTERISK = 0xDD;
20+
const uint8_t KEY_NUM_MINUS = 0xDE;
21+
const uint8_t KEY_NUM_PLUS = 0xDF;
22+
const uint8_t KEY_NUM_ENTER = 0xE0;
23+
const uint8_t KEY_NUM_PERIOD = 0xEB;

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99

1010

11-
For interfacing with Windows/macOS/Linux using an ESP32, a touchscreen and BLE.
11+
For interfacing with Windows/macOS/Linux using an ESP32, a touchscreen and BLE.
12+
13+
***Version 0.9.18a remark: This version might be unstable due to current work on adding support for the ESP32-S3. Last stable is 0.9.17 which you can find in the Releases section.***
1214

1315
# Install Using The Web Installer (recommended!)
1416

Touch.h

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*
99
* @note If USECAPTOUCH is defined we do not need to calibrate touch
1010
*/
11+
12+
#if !defined(USECAPTOUCH)
1113
void touch_calibrate()
1214
{
1315
uint16_t calData[5];
@@ -72,3 +74,4 @@ void touch_calibrate()
7274
}
7375
}
7476
}
77+
#endif //!defined(USECAPTOUCH)

UserActions.h

-9
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ void userAction1(){
2222
}
2323

2424
void userAction2(){
25-
26-
// (Windows Only) This functions opens the calculator and does some simple mathematics.
27-
28-
bleKeyboard.write(KEY_MEDIA_CALCULATOR);
29-
delay(1000); // after opening an app, a longer delay is required for the app to completely launch.
30-
bleKeyboard.print("22/7");
31-
delay(USER_ACTION_DELAY);
32-
bleKeyboard.write(KEY_RETURN);
33-
delay(USER_ACTION_DELAY);
3425

3526
}
3627

Webserver.h

+10
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,22 @@ String handleInfo()
123123
output += String(freemem / 1000);
124124
output += " kB\"},";
125125

126+
#if defined(USEUSBHID)
127+
128+
output += "{\"";
129+
output += "Using USB Keyboard";
130+
output += "\"},";
131+
132+
#else
133+
126134
output += "{\"";
127135
output += "BLE Keyboard Version";
128136
output += "\":\"";
129137
output += String(BLE_KEYBOARD_VERSION);
130138
output += "\"},";
131139

140+
#endif //if defined(USEUSBHID)
141+
132142
output += "{\"";
133143
output += "ArduinoJson Version";
134144
output += "\":\"";

0 commit comments

Comments
 (0)