-
-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a37d476
commit edd76fa
Showing
13 changed files
with
813 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
Switch Joycon | ||
============= | ||
|
||
.. highlight:: c++ | ||
|
||
Introduction | ||
------------ | ||
This library allows you to make the ESP32 act as a Nintendo Switch Joycon and control what it does. | ||
The library uses :library:`NimBLE` for faster and lighter communication. | ||
|
||
Disclaimer | ||
---------- | ||
We are not affiliated, associated, authorized, endorsed by, or in any way officially connected with Nintendo, | ||
or any of its subsidiaries or its affiliates. | ||
The names Nintendo, Nintendo Switch and Joycon as well as related names, marks, emblems and images are | ||
registered trademarks of their respective owners. | ||
|
||
Features | ||
-------- | ||
|
||
Using this library you can do the following: | ||
|
||
- Button press and release (16 buttons) | ||
- Switch Hat (1 hat ) | ||
- Rotate 4 Axis | ||
|
||
Using | ||
----- | ||
|
||
1. Add ``COMPONENT_DEPENDS += SwitchJoycon`` to your application componenent.mk file. | ||
2. Add these lines to your application:: | ||
|
||
#include <SwitchJoycon.h> | ||
namespace | ||
{ | ||
SwitchJoycon joycon; | ||
// ... | ||
} // namespace | ||
void init() | ||
{ | ||
// ... | ||
joycon.begin(); | ||
} | ||
|
||
|
||
Notes | ||
----- | ||
By default, reports are sent on every button press/release or axis/hat movement, however this can be disabled:: | ||
|
||
joycon.setAutoReport(false); | ||
and then you should manually call sendReport on the joycon instance as shown below:: | ||
|
||
joycon.sendReport(); | ||
|
||
|
||
HID Debugging | ||
------------- | ||
|
||
On Linux you can install `hid-tools <https://gitlab.freedesktop.org/libevdev/hid-tools>`__ using the command below:: | ||
|
||
sudo pip3 install . | ||
|
||
Once installed hid-recorder can be used to check the device HID report description and sniff the different reports:: | ||
|
||
sudo hid-recorder | ||
|
||
Useful Links | ||
------------ | ||
- `Tutorial about USB HID Report Descriptors <https://eleccelerator.com/tutorial-about-usb-hid-report-descriptors/>`__ | ||
- `HID constants <https://github.com/katyo/hid_def/blob/master/include/hid_def.h>`__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
COMPONENT_SOC := esp32* | ||
COMPONENT_DEPENDS := NimBLE | ||
|
||
COMPONENT_SRCDIRS := src | ||
COMPONENT_INCDIRS := $(COMPONENT_SRCDIRS) |
Empty file.
9 changes: 9 additions & 0 deletions
9
Sming/Libraries/SwitchJoycon/samples/Bluetooth_Joycon/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
##################################################################### | ||
#### Please don't change this file. Use component.mk instead #### | ||
##################################################################### | ||
|
||
ifndef SMING_HOME | ||
$(error SMING_HOME is not set: please configure it as an environment variable) | ||
endif | ||
|
||
include $(SMING_HOME)/project.mk |
23 changes: 23 additions & 0 deletions
23
Sming/Libraries/SwitchJoycon/samples/Bluetooth_Joycon/README.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Switch Joycon | ||
============= | ||
|
||
Introduction | ||
------------ | ||
This sample turns the ESP32 into a Switch Joycon (Bluetooth LE gamepad) that presses buttons and moves axis | ||
|
||
Possible buttons are 0 through to 15. | ||
|
||
Possible HAT switch position values are: | ||
Centered, Up, UpRight, Right, DownRight, Down, DownLeft, Left, UpLeft. | ||
|
||
|
||
Testing | ||
------- | ||
|
||
You can use one of the following applications on your PC to test and see all buttons that were clicked. | ||
|
||
On Linux install ``jstest-gtk`` to test the ESP32 gamepad. Under Ubuntu this can be done by typing the following command:: | ||
|
||
sudo apt install jstest-gtk | ||
On Windows use this `Windows test application <http://www.planetpointy.co.uk/joystick-test-application/>`__. |
54 changes: 54 additions & 0 deletions
54
Sming/Libraries/SwitchJoycon/samples/Bluetooth_Joycon/app/application.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <SmingCore.h> | ||
#include <SwitchJoycon.h> | ||
|
||
namespace | ||
{ | ||
Timer procTimer; | ||
|
||
void onConnect(NimBLEServer& server); | ||
void onDisconnect(NimBLEServer& server); | ||
|
||
SwitchJoycon joycon(SwitchJoycon::Type::Left, 100, onConnect, onDisconnect); | ||
|
||
void loop() | ||
{ | ||
if(!joycon.isConnected()) { | ||
return; | ||
} | ||
|
||
uint8_t button = random(0, 15); | ||
|
||
joycon.press(button); | ||
joycon.setHat(SwitchJoycon::JoystickPosition::UpLeft); | ||
delay(5000); | ||
|
||
joycon.release(button); | ||
joycon.setHat(SwitchJoycon::JoystickPosition::Center); | ||
delay(5000); | ||
} | ||
|
||
void onConnect(NimBLEServer& server) | ||
{ | ||
Serial.println("Connected :) !"); | ||
|
||
procTimer.initializeMs(500, loop).start(); | ||
} | ||
|
||
void onDisconnect(NimBLEServer& server) | ||
{ | ||
procTimer.stop(); | ||
Serial.println("Disconnected :(!"); | ||
} | ||
|
||
} // namespace | ||
|
||
void init() | ||
{ | ||
Serial.begin(COM_SPEED_SERIAL); | ||
Serial.systemDebugOutput(true); | ||
|
||
Serial.println("Starting Joycon Gamepad sample!"); | ||
joycon.begin(); | ||
// Auto reporting is enabled by default. | ||
// Use joycon.setAutoReport(false); to disable auto reporting, and then use joycon.sendReport(); as needed | ||
} |
1 change: 1 addition & 0 deletions
1
Sming/Libraries/SwitchJoycon/samples/Bluetooth_Joycon/component.mk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
COMPONENT_DEPENDS := SwitchJoycon |
Empty file.
Oops, something went wrong.