Skip to content

Commit

Permalink
Updated docs and code.
Browse files Browse the repository at this point in the history
  • Loading branch information
slav-at-attachix committed Apr 13, 2022
1 parent 3bed927 commit feb72c3
Show file tree
Hide file tree
Showing 20 changed files with 222 additions and 99 deletions.
2 changes: 0 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -403,5 +403,3 @@
# END OF .gitmodules
#
#################################################################################################


Empty file.
4 changes: 4 additions & 0 deletions Sming/Arch/Esp32/Components/bt/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Esp32 Bluetooth
===============

All related libraries for Bluetooth support.
5 changes: 5 additions & 0 deletions Sming/Arch/Esp32/Components/bt/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
COMPONENT_LIBNAME :=

COMPONENT_DEPENDS := esp32

EXTRA_LIBS += btdm_app
65 changes: 65 additions & 0 deletions Sming/Libraries/BLEGamepad/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
ESP32 BLE Gamepad library
==========================

.. highlight:: c++

Introduction
------------
This library allows you to make the ESP32 act as a Bluetooth gamepad and control what it does.
The library uses :library:`NimBLE` for faster and lighter communication.

Features
--------

Using this library you can do the following:

- Button press (128 buttons)
- Button release (128 buttons)
- Axes movement (6 axes (16 bit) (x, y, z, rZ, rX, rY) --> (Left Thumb X, Left Thumb Y, Right Thumb X, Right Thumb Y, Left Trigger, Right Trigger))
- 2 Sliders (16 bit) (Slider 1 and Slider 2)
- 4 point of view hats (ie. d-pad plus 3 other hat switches)
- Simulation controls (rudder, throttle, accelerator, brake, steering)
- Configurable HID descriptor
- Report optional battery level to host (basically works, but it doesn't show up in Android's status bar)
- Customize Bluetooth device name/manufacturer
- Uses efficient NimBLE bluetooth library
- Compatible with Windows
- Compatible with Android (Android OS maps default buttons / axes / hats slightly differently than Windows)
- Compatible with Linux (limited testing)
- Compatible with MacOS X (limited testing)

Using
-----

1. Add ``COMPONENT_DEPENDS += BLEGamepad`` to your application componenent.mk file.
2. Add these lines to your application::

#include <BleGamepad.h>
namespace
{
BleGamepad bleGamepad;
// ...
} // namespace
void init()
{
// ...
bleGamepad.begin();
}


Notes
-----
By default, reports are sent on every button press/release or axis/slider/hat/simulation movement, however this can be disabled,
and then you manually call sendReport on the gamepad instance as shown in the IndividualAxes.ino example.

There is also Bluetooth specific information that you can use (optional):

Instead of `BleGamepad bleGamepad;` you can do `BleGamepad bleGamepad("Bluetooth Device Name", "Bluetooth Device Manufacturer", 100);`.
The third parameter is the initial battery level of your device.
Adjusting the battery level later on doesn't work.
By default the battery level will be set to 100%, the device name will be `ESP32 BLE Gamepad` and the manufacturer will be `Espressif`.
4 changes: 2 additions & 2 deletions Sming/Libraries/BLEGamepad/component.mk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
COMPONENT_SUBMODULES := ESP32-BLE-Gamepad
COMPONENT_SOC := esp32
COMPONENT_SOC := esp32*
COMPONENT_DEPENDS := NimBLE

COMPONENT_SRCDIRS := ESP32-BLE-Gamepad
COMPONENT_INCDIRS := $(COMPONENT_SRCDIRS)

COMPONENT_CPPFLAGS:= -DUSE_NIMBLE=1
APP_CFLAGS += -DUSE_NIMBLE=1
APP_CFLAGS += -DUSE_NIMBLE=1
25 changes: 12 additions & 13 deletions Sming/Libraries/BLEGamepad/samples/Bluetooth_Gamepad/README.rst
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
Basic Blink
===========
Bluetooth Gamepad
=================

Simple blink example to confirm that the basic build system is working with your system.
This sample turns the ESP32 into a Bluetooth LE gamepad that presses buttons and moves axis

We use Timer instead of a loop because we want to allow WiFi communications to work in the background.
See :doc:`/information/multitasking`.
Possible buttons are: BUTTON_1 through to BUTTON_16
(16 buttons supported by default. Library can be configured to support up to 128)

The LED on many development boards is connected to GPIO2, so this is the default.
Possible DPAD/HAT switch position values are:
DPAD_CENTERED, DPAD_UP, DPAD_UP_RIGHT, DPAD_RIGHT, DPAD_DOWN_RIGHT, DPAD_DOWN, DPAD_DOWN_LEFT, DPAD_LEFT, DPAD_UP_LEFT
(or HAT_CENTERED, HAT_UP etc)

If you get no response then check the documentation or schematic as your system
may differ and change the LED_PIN definition accordingly.
bleGamepad.setAxes takes the following int16_t parameters for the Left/Right Thumb X/Y, Left/Right Triggers plus slider1 and slider2, and hat switch position as above:
(Left Thumb X, Left Thumb Y, Right Thumb X, Right Thumb Y, Left Trigger, Right Trigger, Hat switch position ^ (1 hat switch (dpad) supported by default. Library can be configured to support up to 4)

For example, the NodeMCU ESP-C3 kits have an RGB LED connected to GPIO 3, 4 & 5.


.. image:: blink.jpg
:height: 192px
Library can also be configured to support up to 5 simulation controls (can be set with setSimulationControls)
(rudder, throttle, accelerator, brake, steering), but they are not enabled by default.
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
/*
* This example turns the ESP32 into a Bluetooth LE gamepad that presses buttons and moves axis
*
* Possible buttons are:
* BUTTON_1 through to BUTTON_16
* (16 buttons supported by default. Library can be configured to support up to 128)
*
* Possible DPAD/HAT switch position values are:
* DPAD_CENTERED, DPAD_UP, DPAD_UP_RIGHT, DPAD_RIGHT, DPAD_DOWN_RIGHT, DPAD_DOWN, DPAD_DOWN_LEFT, DPAD_LEFT, DPAD_UP_LEFT
* (or HAT_CENTERED, HAT_UP etc)
*
* bleGamepad.setAxes takes the following int16_t parameters for the Left/Right Thumb X/Y, Left/Right Triggers plus slider1 and slider2, and hat switch position as above:
* (Left Thumb X, Left Thumb Y, Right Thumb X, Right Thumb Y, Left Trigger, Right Trigger, Hat switch position
^ (1 hat switch (dpad) supported by default. Library can be configured to support up to 4)
*
* Library can also be configured to support up to 5 simulation controls (can be set with setSimulationControls)
* (rudder, throttle, accelerator, brake, steering), but they are not enabled by default.
*/

#include <SmingCore.h>
#include <BleGamepad.h>

namespace
{
BleGamepad bleGamepad;

Timer procTimer;
Expand All @@ -43,6 +26,8 @@ void loop()
delay(500);
}

} // namespace

void init()
{
Serial.begin(COM_SPEED_SERIAL);
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
COMPONENT_DEPENDS := BLEGamepad
COMPONENT_DEPENDS := BLEGamepad
81 changes: 81 additions & 0 deletions Sming/Libraries/BLEKeyboard/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
ESP32 BLE Keyboard library
==========================

.. highlight:: c++

Introduction
------------
This library allows you to make the ESP32 act as a Bluetooth keyboard and control what it does.
The library uses :library:`NimBLE` for faster and lighter communication.

Features
--------

Using this library you can do the following:

- Send key strokes
- Send text
- Press/release individual keys
- Media keys are supported
- Set battery level (basically works, but doesn't show up in Android's status bar)
- Compatible with Android
- Compatible with Windows
- Compatible with Linux
- Compatible with MacOS X (not stable, some people have issues, doesn't work with old devices)
- Compatible with iOS (not stable, some people have issues, doesn't work with old devices)

Using
-----

1. Add ``COMPONENT_DEPENDS += BLEKeyboard`` to your application componenent.mk file.
2. Add these lines to your application::

#include <BleKeyboard.h>

namespace
{
BleKeyboard bleKeyboard;
// ...
} // namespace
void init()
{
// ...
bleKeyboard.begin();
}


API documentation
-----------------
The BleKeyboard interface is almost identical to the Keyboard Interface, so you can use documentation right here:
https://www.arduino.cc/reference/en/language/functions/usb/keyboard/

In addition to that you can send media keys (which is not possible with the USB keyboard library). Supported are the following:

- KEY_MEDIA_NEXT_TRACK
- KEY_MEDIA_PREVIOUS_TRACK
- KEY_MEDIA_STOP
- KEY_MEDIA_PLAY_PAUSE
- KEY_MEDIA_MUTE
- KEY_MEDIA_VOLUME_UP
- KEY_MEDIA_VOLUME_DOWN
- KEY_MEDIA_WWW_HOME
- KEY_MEDIA_LOCAL_MACHINE_BROWSER // Opens "My Computer" on Windows
- KEY_MEDIA_CALCULATOR
- KEY_MEDIA_WWW_BOOKMARKS
- KEY_MEDIA_WWW_SEARCH
- KEY_MEDIA_WWW_STOP
- KEY_MEDIA_WWW_BACK
- KEY_MEDIA_CONSUMER_CONTROL_CONFIGURATION // Media Selection
- KEY_MEDIA_EMAIL_READER

There is also Bluetooth specific information that you can set (optional):
Instead of `BleKeyboard bleKeyboard;` you can do `BleKeyboard bleKeyboard("Bluetooth Device Name", "Bluetooth Device Manufacturer", 100);`. (Max length is 15 characters, anything beyond that will be truncated.)
The third parameter is the initial battery level of your device. To adjust the battery level later on you can simply call e.g. `bleKeyboard.setBatteryLevel(50)` (set battery level to 50%).
By default the battery level will be set to 100%, the device name will be `ESP32 Bluetooth Keyboard` and the manufacturer will be `Espressif`.
There is also a `setDelay` method to set a delay between each key event. E.g. `bleKeyboard.setDelay(10)` (10 milliseconds). The default is `8`.
This feature is meant to compensate for some applications and devices that can't handle fast input and will skip letters if too many keys are sent in a small time frame.
4 changes: 2 additions & 2 deletions Sming/Libraries/BLEKeyboard/component.mk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
COMPONENT_SUBMODULES := ESP32-BLE-Keyboard
COMPONENT_SOC := esp32
COMPONENT_SOC := esp32*
COMPONENT_DEPENDS := NimBLE

COMPONENT_SRCDIRS := ESP32-BLE-Keyboard
COMPONENT_INCDIRS := $(COMPONENT_SRCDIRS)

COMPONENT_CPPFLAGS:= -DUSE_NIMBLE=1
APP_CFLAGS += -DUSE_NIMBLE=1
APP_CFLAGS += -DUSE_NIMBLE=1
31 changes: 13 additions & 18 deletions Sming/Libraries/BLEKeyboard/samples/Bluetooth_Keyboard/README.rst
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
Basic Blink
===========

Simple blink example to confirm that the basic build system is working with your system.

We use Timer instead of a loop because we want to allow WiFi communications to work in the background.
See :doc:`/information/multitasking`.

The LED on many development boards is connected to GPIO2, so this is the default.

If you get no response then check the documentation or schematic as your system
may differ and change the LED_PIN definition accordingly.

For example, the NodeMCU ESP-C3 kits have an RGB LED connected to GPIO 3, 4 & 5.


.. image:: blink.jpg
:height: 192px
Bluetooth Keyboard
==================

This sample demonstrates how to turn an Esp32 device into external keyboard.
The "keyboard" and your PC will be communicating using Bluetooth Low Energy (BLE).
The "keyboard" will write words, press Enter, press a media key and, if enabled in the sample code, Ctrl+Alt+Delete.

Usage
-----
Once this sample is flashed and running on your ESP32 you can test it.
Open a new text editor on your PC. Then search from your PC for new bluetooth devices.
A device named "Sming BLE Keyboard" should show up. Connect to it and focus/open you text editor window.
Be fast. Soon enough a "Hello World" text will start to be "magically" typed inside your text editor.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/**
* This example turns the ESP32 into a Bluetooth LE keyboard that writes words, presses Enter, presses a media key and then Ctrl+Alt+Delete
*/

#include <SmingCore.h>
#include <BleKeyboard.h>

BleKeyboard bleKeyboard;
namespace
{
BleKeyboard bleKeyboard("Sming BLE Keyboard");
Timer procTimer;

void loop()
Expand Down Expand Up @@ -38,6 +36,8 @@ void loop()
*/
}

} // namespace

void init()
{
Serial.begin(COM_SPEED_SERIAL);
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
COMPONENT_DEPENDS := BLEKeyboard
COMPONENT_SOC := esp32*

COMPONENT_DEPENDS := BLEKeyboard
24 changes: 24 additions & 0 deletions Sming/Libraries/NimBLE/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ESP32 NimBLE
============

.. highlight:: c++

Introduction
------------
NimBLE is a completely open source Bluetooth Low Energy (BLE) stack produced by `Apache <https://github.com/apache/mynewt-nimble>`_.
It is more suited to resource constrained devices than bluedroid and has now been ported to the ESP32 by Espressif.

Using
-----

1. Add ``COMPONENT_DEPENDS += NimBLE`` to your application componenent.mk file.
2. Add these lines to your application::

#include <NimBLEDevice.h>
void init()
{
// ...
BLEDevice::init("");
}
2 changes: 1 addition & 1 deletion Sming/Libraries/NimBLE/component.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
COMPONENT_SUBMODULES := esp-nimble-cpp
COMPONENT_SOC := esp32
COMPONENT_SOC := esp32*

COMPONENT_SRCDIRS := esp-nimble-cpp/src
COMPONENT_INCDIRS := $(COMPONENT_SRCDIRS)
9 changes: 0 additions & 9 deletions Sming/Libraries/NimBLE/samples/Bluetooth_Client/Makefile

This file was deleted.

18 changes: 0 additions & 18 deletions Sming/Libraries/NimBLE/samples/Bluetooth_Client/README.rst

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit feb72c3

Please sign in to comment.