Skip to content

Commit

Permalink
version 0.9.18a
Browse files Browse the repository at this point in the history
Updating for ESP32-S3.  Added USB HID support. Some refactoring. Added Keydefines.h for when USB is used.
  • Loading branch information
DustinWatts committed May 15, 2022
1 parent 395454d commit 83708a6
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 66 deletions.
4 changes: 4 additions & 0 deletions Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ void bleKeyboardAction(int action, int value, char *symbol)
}
break;
case 3: // Send Media Key
#if defined(USEUSBHID)

#else
switch (value)
{
case 1:
Expand Down Expand Up @@ -106,6 +109,7 @@ void bleKeyboardAction(int action, int value, char *symbol)
break;
}
break;
#endif //if defined(USEUSBHID)
case 4: // Send Character
bleKeyboard.print(symbol);
break;
Expand Down
5 changes: 5 additions & 0 deletions DrawHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -1584,8 +1584,13 @@ void printinfo()
float freemem = SPIFFS.totalBytes() - SPIFFS.usedBytes();
tft.print(freemem / 1000);
tft.println(" kB");
#if defined(USEUSBHID)
tft.println("Using USB Keyboard");
#else
tft.print("BLE Keyboard version: ");
tft.println(BLE_KEYBOARD_VERSION);
#endif //if defined(USEUSBHID)

tft.print("ArduinoJson version: ");
tft.println(ARDUINOJSON_VERSION);
tft.print("TFT_eSPI version: ");
Expand Down
129 changes: 73 additions & 56 deletions FreeTouchDeck.ino
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
// (THE ESP32 TOUCHDOWN USES THIS!)
//#define USECAPTOUCH

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

//#define USEUSBHID

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

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

const char *versionnumber = "0.9.17";
const char *versionnumber = "0.9.18a";

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

/* TODO NEXT VERSION
*
* - get image height/width and use it in bmp drawing.
*/

#include <pgmspace.h> // PROGMEM support header
#include <FS.h> // Filesystem support header
#include <SPIFFS.h> // Filesystem support header
#include <Preferences.h> // Used to store states before sleep/reboot

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

#include <BleKeyboard.h> // BleKeyboard is used to communicate over BLE
#if defined(USEUSBHID)

#include "USB.h"
#include "USBHIDKeyboard.h"
#include "Keydefines.h"
USBHIDKeyboard bleKeyboard;

#else

#include <BleKeyboard.h> // BleKeyboard is used to communicate over BLE
BleKeyboard bleKeyboard("FreeTouchDeck", "Made by me");

// Checking for BLE Keyboard version
#ifndef BLE_KEYBOARD_VERSION
#warning Old BLE Keyboard version detected. Please update.
#define BLE_KEYBOARD_VERSION "Outdated"
#endif // !defined(BLE_KEYBOARD_VERSION)

#endif // if

#if defined(USE_NIMBLE)

#include "NimBLEDevice.h" // Additional BLE functionaity using NimBLE
#include "NimBLEUtils.h" // Additional BLE functionaity using NimBLE
#include "NimBLEBeacon.h" // Additional BLE functionaity using NimBLE
#include "NimBLEDevice.h" // Additional BLE functionaity using NimBLE
#include "NimBLEUtils.h" // Additional BLE functionaity using NimBLE
#include "NimBLEBeacon.h" // Additional BLE functionaity using NimBLE

#else

#include "BLEDevice.h" // Additional BLE functionaity
#include "BLEUtils.h" // Additional BLE functionaity
#include "BLEBeacon.h" // Additional BLE functionaity
#include "BLEDevice.h" // Additional BLE functionaity
#include "BLEUtils.h" // Additional BLE functionaity
#include "BLEBeacon.h" // Additional BLE functionaity

#endif // USE_NIMBLE
#endif // defined(USE_NIMBLE)

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

#ifdef USECAPTOUCH
#include <Wire.h>
#include <FT6236.h>
FT6236 ts = FT6236();
#endif

BleKeyboard bleKeyboard("FreeTouchDeck", "Made by me");
#include <Wire.h>
#include <FT6236.h>
FT6236 ts = FT6236();
#endif // defined(USECAPTOUCH)

AsyncWebServer webserver(80);

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

// Checking for BLE Keyboard version
#ifndef BLE_KEYBOARD_VERSION
#warning Old BLE Keyboard version detected. Please update.
#define BLE_KEYBOARD_VERSION "Outdated"
#endif

//--------- Internal references ------------
// (this needs to be below all structs etc..)
#include "ScreenHelper.h"
Expand Down Expand Up @@ -332,27 +333,27 @@ void setup()
Serial.println("");

#ifdef USECAPTOUCH
#ifdef CUSTOM_TOUCH_SDA
if (!ts.begin(40, CUSTOM_TOUCH_SDA, CUSTOM_TOUCH_SCL))
#else
if (!ts.begin(40))
#endif
#ifdef CUSTOM_TOUCH_SDA
if (!ts.begin(40, CUSTOM_TOUCH_SDA, CUSTOM_TOUCH_SCL))
#else
if (!ts.begin(40))
#endif // defined(CUSTOM_TOUCH_SDA)
{
Serial.println("[WARNING]: Unable to start the capacitive touchscreen.");
}
else
{
Serial.println("[INFO]: Capacitive touch started!");
}
#endif
#endif // defined(USECAPTOUCH)

// Setup PWM channel and attach pin 32
// Setup PWM channel and attach pin bl_pin
ledcSetup(0, 5000, 8);
#ifdef TFT_BL
ledcAttachPin(TFT_BL, 0);
#else
ledcAttachPin(32, 0);
#endif
ledcAttachPin(backlightPin, 0);
#endif // defined(TFT_BL)
ledcWrite(0, ledBrightness); // Start @ initial Brightness

// --------------- Init Display -------------------------
Expand Down Expand Up @@ -429,7 +430,7 @@ void setup()
Serial.println("[INFO]: Waiting for touch calibration...");
touch_calibrate();
Serial.println("[INFO]: Touch calibration completed!");
#endif
#endif // !defined(USECAPTOUCH)

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

#endif
#endif // defined(speakerPin)

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

//------------------BLE Initialization ------------------------------------------------------------------------

#if defined(USEUSBHID)

// initialize control over the keyboard:
bleKeyboard.begin();
USB.begin();

#else

Serial.println("[INFO]: Starting BLE");
bleKeyboard.begin();

#endif //if defined(USEUSBHID)

// ---------------- Printing version numbers -----------------------------------------------

#if defined(USEUSBHID)
Serial.println("[INFO]: Using USB Keyboard");
#else
Serial.print("[INFO]: BLE Keyboard version: ");
Serial.println(BLE_KEYBOARD_VERSION);
#endif //if defined(USEUSBHID)

Serial.print("[INFO]: ArduinoJson version: ");
Serial.println(ARDUINOJSON_VERSION);
Serial.print("[INFO]: TFT_eSPI version: ");
Expand All @@ -596,7 +613,7 @@ if(generalconfig.beep){
Serial.println(" minutes");
islatched[28] = 1;
}
#endif
#endif // defined(touchInterruptPin)

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

Expand Down Expand Up @@ -741,7 +758,7 @@ void loop(void)

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

#endif
#endif // defined(USECAPTOUCH)

if (pressed)
{
Expand Down Expand Up @@ -779,7 +796,7 @@ void loop(void)

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

#endif
#endif // defined(USECAPTOUCH)

if (pressed)
{
Expand Down Expand Up @@ -818,7 +835,7 @@ void loop(void)

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

#endif
#endif // defined(USECAPTOUCH)

if (pressed)
{
Expand Down Expand Up @@ -863,7 +880,7 @@ void loop(void)
ledcDetachPin(speakerPin);
ledcWrite(2, 0);
}
#endif
#endif // defined(speakerPin)
Serial.println("[INFO]: Saving latched states");

// You could uncomment this to see the latch stated before going to sleep
Expand All @@ -879,7 +896,7 @@ void loop(void)
esp_deep_sleep_start();
}
}
#endif
#endif // defined(touchInterruptPin)

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

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

#endif
#endif // defined(USECAPTOUCH)

// Check if the X and Y coordinates of the touch are within one of our buttons
for (uint8_t b = 0; b < 6; b++)
Expand Down
23 changes: 23 additions & 0 deletions Keydefines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Some extra KEY definitions the original USB Keyboard library does not have
to make it compatible with FreeTouchDeck. Only included when #define USEUSBHID
is defined.
*/
const uint8_t KEY_PRTSC = 0xCE;

const uint8_t KEY_NUM_0 = 0xEA;
const uint8_t KEY_NUM_1 = 0xE1;
const uint8_t KEY_NUM_2 = 0xE2;
const uint8_t KEY_NUM_3 = 0xE3;
const uint8_t KEY_NUM_4 = 0xE4;
const uint8_t KEY_NUM_5 = 0xE5;
const uint8_t KEY_NUM_6 = 0xE6;
const uint8_t KEY_NUM_7 = 0xE7;
const uint8_t KEY_NUM_8 = 0xE8;
const uint8_t KEY_NUM_9 = 0xE9;
const uint8_t KEY_NUM_SLASH = 0xDC;
const uint8_t KEY_NUM_ASTERISK = 0xDD;
const uint8_t KEY_NUM_MINUS = 0xDE;
const uint8_t KEY_NUM_PLUS = 0xDF;
const uint8_t KEY_NUM_ENTER = 0xE0;
const uint8_t KEY_NUM_PERIOD = 0xEB;
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@



For interfacing with Windows/macOS/Linux using an ESP32, a touchscreen and BLE.
For interfacing with Windows/macOS/Linux using an ESP32, a touchscreen and BLE.

***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.***

# Install Using The Web Installer (recommended!)

Expand Down
3 changes: 3 additions & 0 deletions Touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*
* @note If USECAPTOUCH is defined we do not need to calibrate touch
*/

#if !defined(USECAPTOUCH)
void touch_calibrate()
{
uint16_t calData[5];
Expand Down Expand Up @@ -72,3 +74,4 @@ void touch_calibrate()
}
}
}
#endif //!defined(USECAPTOUCH)
9 changes: 0 additions & 9 deletions UserActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ void userAction1(){
}

void userAction2(){

// (Windows Only) This functions opens the calculator and does some simple mathematics.

bleKeyboard.write(KEY_MEDIA_CALCULATOR);
delay(1000); // after opening an app, a longer delay is required for the app to completely launch.
bleKeyboard.print("22/7");
delay(USER_ACTION_DELAY);
bleKeyboard.write(KEY_RETURN);
delay(USER_ACTION_DELAY);

}

Expand Down
10 changes: 10 additions & 0 deletions Webserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,22 @@ String handleInfo()
output += String(freemem / 1000);
output += " kB\"},";

#if defined(USEUSBHID)

output += "{\"";
output += "Using USB Keyboard";
output += "\"},";

#else

output += "{\"";
output += "BLE Keyboard Version";
output += "\":\"";
output += String(BLE_KEYBOARD_VERSION);
output += "\"},";

#endif //if defined(USEUSBHID)

output += "{\"";
output += "ArduinoJson Version";
output += "\":\"";
Expand Down

0 comments on commit 83708a6

Please sign in to comment.