|
/* |
|
* Sample program for ESP32 acting as a Bluetooth keyboard |
|
* |
|
* Copyright (c) 2019 Manuel Bl |
|
* |
|
* Licensed under MIT License |
|
* https://opensource.org/licenses/MIT |
|
*/ |
|
|
|
// |
|
// This program lets an ESP32 act as a keyboard connected via Bluetooth. |
|
// When a button attached to the ESP32 is pressed, it will generate the key strokes for a message. |
|
// |
|
// For the setup, a momentary button should be connected to pin 2 and to ground. |
|
// Pin 2 will be configured as an input with pull-up. |
|
// |
|
// In order to receive the message, add the ESP32 as a Bluetooth keyboard of your computer |
|
// or mobile phone: |
|
// |
|
// 1. Go to your computers/phones settings |
|
// 2. Ensure Bluetooth is turned on |
|
// 3. Scan for Bluetooth devices |
|
// 4. Connect to the device called "ESP32 Keyboard" |
|
// 5. Open an empty document in a text editor |
|
// 6. Press the button attached to the ESP32 |
|
|
|
#define US_KEYBOARD 1 |
|
|
|
#include <Arduino.h> |
|
#include "BLEDevice.h" |
|
#include "BLEHIDDevice.h" |
|
#include "HIDTypes.h" |
|
#include "HIDKeyboardTypes.h" |
|
|
|
|
|
// Change the below values if desired |
|
#define BUTTON_PIN 2 |
|
#define MESSAGE "Hello from ESP32\n" |
|
#define DEVICE_NAME "ESP32 Keyboard" |
|
|
|
|
|
// Forward declarations |
|
void bluetoothTask(void*); |
|
void typeText(const char* text); |
|
|
|
|
|
bool isBleConnected = false; |
|
|
|
|
|
void setup() { |
|
Serial.begin(115200); |
|
|
|
// configure pin for button |
|
pinMode(BUTTON_PIN, INPUT_PULLUP); |
|
|
|
// start Bluetooth task |
|
xTaskCreate(bluetoothTask, "bluetooth", 20000, NULL, 5, NULL); |
|
} |
|
|
|
|
|
void loop() { |
|
if (isBleConnected && digitalRead(BUTTON_PIN) == LOW) { |
|
// button has been pressed: type message |
|
Serial.println(MESSAGE); |
|
typeText(MESSAGE); |
|
} |
|
|
|
delay(100); |
|
} |
|
|
|
|
|
// Message (report) sent when a key is pressed or released |
|
struct InputReport { |
|
uint8_t modifiers; // bitmask: CTRL = 1, SHIFT = 2, ALT = 4 |
|
uint8_t reserved; // must be 0 |
|
uint8_t pressedKeys[6]; // up to six concurrenlty pressed keys |
|
}; |
|
|
|
// Message (report) received when an LED's state changed |
|
struct OutputReport { |
|
uint8_t leds; // bitmask: num lock = 1, caps lock = 2, scroll lock = 4, compose = 8, kana = 16 |
|
}; |
|
|
|
|
|
// The report map describes the HID device (a keyboard in this case) and |
|
// the messages (reports in HID terms) sent and received. |
|
static const uint8_t REPORT_MAP[] = { |
|
USAGE_PAGE(1), 0x01, // Generic Desktop Controls |
|
USAGE(1), 0x06, // Keyboard |
|
COLLECTION(1), 0x01, // Application |
|
REPORT_ID(1), 0x01, // Report ID (1) |
|
USAGE_PAGE(1), 0x07, // Keyboard/Keypad |
|
USAGE_MINIMUM(1), 0xE0, // Keyboard Left Control |
|
USAGE_MAXIMUM(1), 0xE7, // Keyboard Right Control |
|
LOGICAL_MINIMUM(1), 0x00, // Each bit is either 0 or 1 |
|
LOGICAL_MAXIMUM(1), 0x01, |
|
REPORT_COUNT(1), 0x08, // 8 bits for the modifier keys |
|
REPORT_SIZE(1), 0x01, |
|
HIDINPUT(1), 0x02, // Data, Var, Abs |
|
REPORT_COUNT(1), 0x01, // 1 byte (unused) |
|
REPORT_SIZE(1), 0x08, |
|
HIDINPUT(1), 0x01, // Const, Array, Abs |
|
REPORT_COUNT(1), 0x06, // 6 bytes (for up to 6 concurrently pressed keys) |
|
REPORT_SIZE(1), 0x08, |
|
LOGICAL_MINIMUM(1), 0x00, |
|
LOGICAL_MAXIMUM(1), 0x65, // 101 keys |
|
USAGE_MINIMUM(1), 0x00, |
|
USAGE_MAXIMUM(1), 0x65, |
|
HIDINPUT(1), 0x00, // Data, Array, Abs |
|
REPORT_COUNT(1), 0x05, // 5 bits (Num lock, Caps lock, Scroll lock, Compose, Kana) |
|
REPORT_SIZE(1), 0x01, |
|
USAGE_PAGE(1), 0x08, // LEDs |
|
USAGE_MINIMUM(1), 0x01, // Num Lock |
|
USAGE_MAXIMUM(1), 0x05, // Kana |
|
LOGICAL_MINIMUM(1), 0x00, |
|
LOGICAL_MAXIMUM(1), 0x01, |
|
HIDOUTPUT(1), 0x02, // Data, Var, Abs |
|
REPORT_COUNT(1), 0x01, // 3 bits (Padding) |
|
REPORT_SIZE(1), 0x03, |
|
HIDOUTPUT(1), 0x01, // Const, Array, Abs |
|
END_COLLECTION(0) // End application collection |
|
}; |
|
|
|
|
|
BLEHIDDevice* hid; |
|
BLECharacteristic* input; |
|
BLECharacteristic* output; |
|
|
|
const InputReport NO_KEY_PRESSED = { }; |
|
|
|
|
|
/* |
|
* Callbacks related to BLE connection |
|
*/ |
|
class BleKeyboardCallbacks : public BLEServerCallbacks { |
|
|
|
void onConnect(BLEServer* server) { |
|
isBleConnected = true; |
|
|
|
// Allow notifications for characteristics |
|
BLE2902* cccDesc = (BLE2902*)input->getDescriptorByUUID(BLEUUID((uint16_t)0x2902)); |
|
cccDesc->setNotifications(true); |
|
|
|
Serial.println("Client has connected"); |
|
} |
|
|
|
void onDisconnect(BLEServer* server) { |
|
isBleConnected = false; |
|
|
|
// Disallow notifications for characteristics |
|
BLE2902* cccDesc = (BLE2902*)input->getDescriptorByUUID(BLEUUID((uint16_t)0x2902)); |
|
cccDesc->setNotifications(false); |
|
|
|
Serial.println("Client has disconnected"); |
|
} |
|
}; |
|
|
|
|
|
/* |
|
* Called when the client (computer, smart phone) wants to turn on or off |
|
* the LEDs in the keyboard. |
|
* |
|
* bit 0 - NUM LOCK |
|
* bit 1 - CAPS LOCK |
|
* bit 2 - SCROLL LOCK |
|
*/ |
|
class OutputCallbacks : public BLECharacteristicCallbacks { |
|
void onWrite(BLECharacteristic* characteristic) { |
|
OutputReport* report = (OutputReport*) characteristic->getData(); |
|
Serial.print("LED state: "); |
|
Serial.print((int) report->leds); |
|
Serial.println(); |
|
} |
|
}; |
|
|
|
|
|
void bluetoothTask(void*) { |
|
|
|
// initialize the device |
|
BLEDevice::init(DEVICE_NAME); |
|
BLEServer* server = BLEDevice::createServer(); |
|
server->setCallbacks(new BleKeyboardCallbacks()); |
|
|
|
// create an HID device |
|
hid = new BLEHIDDevice(server); |
|
input = hid->inputReport(1); // report ID |
|
output = hid->outputReport(1); // report ID |
|
output->setCallbacks(new OutputCallbacks()); |
|
|
|
// set manufacturer name |
|
hid->manufacturer()->setValue("Maker Community"); |
|
// set USB vendor and product ID |
|
hid->pnp(0x02, 0xe502, 0xa111, 0x0210); |
|
// information about HID device: device is not localized, device can be connected |
|
hid->hidInfo(0x00, 0x02); |
|
|
|
// Security: device requires bonding |
|
BLESecurity* security = new BLESecurity(); |
|
security->setAuthenticationMode(ESP_LE_AUTH_BOND); |
|
|
|
// set report map |
|
hid->reportMap((uint8_t*)REPORT_MAP, sizeof(REPORT_MAP)); |
|
hid->startServices(); |
|
|
|
// set battery level to 100% |
|
hid->setBatteryLevel(100); |
|
|
|
// advertise the services |
|
BLEAdvertising* advertising = server->getAdvertising(); |
|
advertising->setAppearance(HID_KEYBOARD); |
|
advertising->addServiceUUID(hid->hidService()->getUUID()); |
|
advertising->addServiceUUID(hid->deviceInfo()->getUUID()); |
|
advertising->addServiceUUID(hid->batteryService()->getUUID()); |
|
advertising->start(); |
|
|
|
Serial.println("BLE ready"); |
|
delay(portMAX_DELAY); |
|
}; |
|
|
|
|
|
void typeText(const char* text) { |
|
int len = strlen(text); |
|
for (int i = 0; i < len; i++) { |
|
|
|
// translate character to key combination |
|
uint8_t val = (uint8_t)text[i]; |
|
if (val > KEYMAP_SIZE) |
|
continue; // character not available on keyboard - skip |
|
KEYMAP map = keymap[val]; |
|
|
|
// create input report |
|
InputReport report = { |
|
.modifiers = map.modifier, |
|
.reserved = 0, |
|
.pressedKeys = { |
|
map.usage, |
|
0, 0, 0, 0, 0 |
|
} |
|
}; |
|
|
|
// send the input report |
|
input->setValue((uint8_t*)&report, sizeof(report)); |
|
input->notify(); |
|
|
|
delay(5); |
|
|
|
// release all keys between two characters; otherwise two identical |
|
// consecutive characters are treated as just one key press |
|
input->setValue((uint8_t*)&NO_KEY_PRESSED, sizeof(NO_KEY_PRESSED)); |
|
input->notify(); |
|
|
|
delay(5); |
|
} |
|
} |
I think that it is easier to understand and modify a ready-made structure than to do unfortunately there are example of a structure made of keyboards for gaming devices but there is no structure made from which one can guide to modify and adapt an HD braille device would be It is very helpful that someone will provide a h & d braile structure that serves as an example for one to adapt it to the particular project or adapt the project to that structure
I basically need a structure for a 40-cell braille display
With a braille keyboard which contains eight brsille keys a space bar day chif keys
Basically its keyboard structure is similar to that of Freedom Scientific Focus 40 braille displays with an additional navigation key up arrow down arrow left arrow right arrow and center button and on either side a tab key and on the other side tab chip these keys are for move within a document or within the menus from a cell phone in a simple way here I leave more or less a manual of how the screen would be arranged shine
A general HID tuning document with this data would be very helpful.
Introduction
.a line Braille brailletouch is open source in both hardware and software.
The Braille brailletouch line consists of:
40, touch cells 1, Braille cells A sensor button (cursor scroll button) above the Braille cell. 8-key Braille keyboard, Perkins style Two scroll buttons two rocker keys two selectors two Shift keys one multiple scroll keyboard right left up down select and from the sides tab and chif tab One navigation rocker One mode button at either end of the line, for quick navigation through files, lists and menus. USB connection to computer Compatibility with select phones and other mobile devices via screen readers Physical description
On the left side of the line there are, starting from the position closest to you, a power button and a micro USB port. standard. The USB port allows you to connect the line to a computer using the USB cable or the power adapter.
Braille cells are located on the front of the right side of the unit. There is a sensor above the Braille cell. At both ends of the Braille display surface there is a navigation rocker whose purpose is to facilitate navigation. Above each of the navigation rockers is a mode button to toggle between the different navigation modes.
the braille display has 40 touch cells that are located on the center front of the unit
On the left is the multi-scroll keyboard, it has Jockey-style diction and selection keys and stubborn left and right corresponding to tab and chif + tab
Above the touch cells is an eight-key Braille (Perkins-style) keyboard. These keys are used to type text and execute commands. On the front edge, located in the center and below the Braille cells, is the SPACEBAR. This is used in combination with the Braille keys to enter commands. The commands that are executed with the SPACEBAR are called Cor. For example, COR L or COR 1-2-3. on the side and side of the SPACEBAR are the left SHIFT key, right SHIFT key
The following controls are located on the front of the equipment, from left to right:
brailletouch 40: left selector, left scroll button, left rocker key, right rocker key, right scroll button and right selector.
The following sections describe the use of these controls when working with Braille Touch and NVDA. If you are working with the brailletouch line and another screen reviewer, both on a computer and with a mobile device, consult the documentation for that software, as the functions of these controls may be different from those of NVDA.
Navigation Rockers and Mode Buttons
The Navigation Rockers on the brailletouch allow you to quickly scroll through files, dialogs, lists and menus. In files, the wheels allow you to scroll through lines, sentences, paragraphs or scroll left and right. To switch between the four available navigation modes, press the Mode Button located above the Navigation Rocker. In the dialogs, you can scroll through the available controls. In menus, by menu items. It is also possible to completely deactivate the Navigation Rockers by pressing the Left or Right Mode Button and the SPACEBAR at the same time. To activate them, run the same command again.
Scroll buttons
The scroll buttons allow you to scroll a display to the left or right. Press the Left Scroll button, which displays a raised double left arrow, to scroll left; press the Right Scroll button, which displays a raised right double arrow, to scroll right.
Rocker keys
The rocker keys allow you to move to the next or previous line. Press the upper part of the rocker key to go to the previous line, and the lower part to go to the next line. In combination with the scroll buttons, the rocker keys allow you to move the cursor to the beginning or end of the current line. To move the cursor to the beginning of the line, press a scroll button plus the top of a rocker key; To move the cursor to the end of the line, press a scroll button plus the bottom of a rocker key;
Selectors
If used individually, the selectors (concave in shape) allow you to configure Auto Advance. Pressing both Selector buttons at the same time will turn auto advance on or off. Press the Left selector to decrease the speed of the automatic advance, and press the Right selector to increase it.
When pressed in combination with other keys, they perform various functions. For example, if you press a Selector in conjunction with the top or bottom of a rocker key, you will page up or down. You can also press a Selector together with the Scroll left or right button to go to the beginning or end of a file.
Multi-scroll keyboard
it behaves like a Jockey with the keys arrow up arrow down arrow right arrow left and in the center select, from the left side a key corresponding to tabulator and from the right side a key corresponding to Shift + tabulator
Shift buttons
The Shift buttons are used in combination with the SPACEBAR, Braille keys, and other controls on the line to execute commands.
the Sensor button
There is a sensor button above the braille cell. The sensor button allows you to move the cursor to the corresponding character currently displayed in the cell, or to open links on web pages and email messages. In Line mode, the sensor allows you to open menus or select a menu item.
If you hold down the LEFT or RIGHT SCROLL BUTTON and press the sensor, you will execute a Right Mouse Click on the position corresponding to the character displayed on the braille display below the sensor.
The sensor button also allows you to select text in a document. To select using the Braille display sensor button, press and hold the LEFT SHIFT button and press the sensor on the character you want to initiate selection. Release both keys. Move to the position where you want to end the selection and do the same operation again. You can use any navigation command, including the Navigation Rockers, to move between the beginning and the end of the text you want to select.
touch sensors
The braille braille touch screen has 40 tactile sensors and a horizontal mine that represents virtually 40 braille bristles, when a finger moves through the touch sensors the character that is represented by each position is shown in the brille brille and the router above the braille bristle it becomes the router for that character at that time.
The power button
The Power button turns the brailletouch screen on and off when it is not connected. I think it is easier to understand and modify a ready-made structure than to do unfortunately there are examples of a structure made of keyboards for gaming devices but there is no structure made of Which one can be guided to modify and adapt a HD braille device would be very helpful if someone will contribute a h & d braille structure that serves as an example for one to adapt it to the particular project or adapt the project to that structure
I basically need a structure for a 40-cell braille display
With a braille keyboard which contains eight brsille keys a space bar day chif keys
Basically its keyboard structure is similar to that of Freedom Scientific Focus 40 braille displays with an additional navigation key up arrow down arrow left arrow right arrow and center button and on either side a tab key and on the other side tab chip these keys are for move within a document or within the menus from a cell phone in a simple way here I leave more or less a manual of how the screen would be arranged shine
A general HID tuning document with this data would be very helpful.
Introduction
.a line Braille brailletouch is open source in both hardware and software.
The Braille brailletouch line consists of:
40, touch cells 1, Braille cells A sensor button (cursor scroll button) above the Braille cell. 8-key Braille keyboard, Perkins style Two scroll buttons two rocker keys two selectors two Shift keys one multiple scroll keyboard right left up down select and from the sides tab and chif tab One navigation rocker One mode button at either end of the line, for quick navigation through files, lists and menus. USB connection to computer Compatibility with select phones and other mobile devices via screen readers Physical description
On the left side of the line there are, starting from the position closest to you, a power button and a micro USB port. standard. The USB port allows you to connect the line to a computer using the USB cable or the power adapter.
Braille cells are located on the front of the right side of the unit. There is a sensor above the Braille cell. At both ends of the Braille display surface there is a navigation rocker whose purpose is to facilitate navigation. Above each of the navigation rockers is a mode button to toggle between the different navigation modes.
the braille display has 40 touch cells that are located on the center front of the unit
On the left is the multi-scroll keyboard, it has Jockey-style diction and selection keys and stubborn left and right corresponding to tab and chif + tab
Above the touch cells is an eight-key Braille (Perkins-style) keyboard. These keys are used to type text and execute commands. On the front edge, located in the center and below the Braille cells, is the SPACEBAR. This is used in combination with the Braille keys to enter commands. The commands that are executed with the SPACEBAR are called Cor. For example, COR L or COR 1-2-3. on the side and side of the SPACEBAR are the left SHIFT key, right SHIFT key
The following controls are located on the front of the equipment, from left to right:
brailletouch 40: left selector, left scroll button, left rocker key, right rocker key, right scroll button and right selector.
The following sections describe the use of these controls when working with Braille Touch and NVDA. If you are working with the brailletouch line and another screen reviewer, both on a computer and with a mobile device, consult the documentation for that software, as the functions of these controls may be different from those of NVDA.
Navigation Rockers and Mode Buttons
The Navigation Rockers on the brailletouch allow you to quickly scroll through files, dialogs, lists and menus. In files, the wheels allow you to scroll through lines, sentences, paragraphs or scroll left and right. To switch between the four available navigation modes, press the Mode Button located above the Navigation Rocker. In the dialogs, you can scroll through the available controls. In menus, by menu items. It is also possible to completely deactivate the Navigation Rockers by pressing the Left or Right Mode Button and the SPACEBAR at the same time. To activate them, run the same command again.
Scroll buttons
The scroll buttons allow you to scroll a display to the left or right. Press the Left Scroll button, which displays a raised double left arrow, to scroll left; press the Right Scroll button, which displays a raised right double arrow, to scroll right.
Rocker keys
The rocker keys allow you to move to the next or previous line. Press the upper part of the rocker key to go to the previous line, and the lower part to go to the next line. In combination with the scroll buttons, the rocker keys allow you to move the cursor to the beginning or end of the current line. To move the cursor to the beginning of the line, press a scroll button plus the top of a rocker key; To move the cursor to the end of the line, press a scroll button plus the bottom of a rocker key;
Selectors
If used individually, the selectors (concave in shape) allow you to configure Auto Advance. Pressing both Selector buttons at the same time will turn auto advance on or off. Press the Left selector to decrease the speed of the automatic advance, and press the Right selector to increase it.
When pressed in combination with other keys, they perform various functions. For example, if you press a Selector in conjunction with the top or bottom of a rocker key, you will page up or down. You can also press a Selector together with the Scroll left or right button to go to the beginning or end of a file.
Multi-scroll keyboard
it behaves like a Jockey with the keys arrow up arrow down arrow right arrow left and in the center select, from the left side a key corresponding to tabulator and from the right side a key corresponding to Shift + tabulator
Shift buttons
The Shift buttons are used in combination with the SPACEBAR, Braille keys, and other controls on the line to execute commands.
the Sensor button
There is a sensor button above the braille cell. The sensor button allows you to move the cursor to the corresponding character currently displayed in the cell, or to open links on web pages and email messages. In Line mode, the sensor allows you to open menus or select a menu item.
If you hold down the LEFT or RIGHT SCROLL BUTTON and press the sensor, you will execute a Right Mouse Click on the position corresponding to the character displayed on the braille display below the sensor.
The sensor button also allows you to select text in a document. To select using the Braille display sensor button, press and hold the LEFT SHIFT button and press the sensor on the character you want to initiate selection. Release both keys. Move to the position where you want to end the selection and do the same operation again. You can use any navigation command, including the Navigation Rockers, to move between the beginning and the end of the text you want to select.
touch sensors
The braille braille touch screen has 40 tactile sensors and a horizontal mine that represents virtually 40 braille bristles, when a finger moves through the touch sensors the character that is represented by each position is shown in the brille brille and the router above the braille bristle it becomes the router for that character at that time.
The power button
The Power button turns the brailletouch display on and off