Skip to content

Commit

Permalink
Merge pull request #152 from MHeironimus/version-2.0
Browse files Browse the repository at this point in the history
Version 2.0.6 - Community Updates 1
  • Loading branch information
MHeironimus authored Jun 30, 2020
2 parents 6ce9a51 + 96fab9b commit 6884663
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 47 deletions.
109 changes: 73 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Arduino Joystick Library
#### Version 2.0.5

#### Version 2.0.6

This library can be used with Arduino IDE 1.6.6 (or above) to add one or more joysticks (or gamepads) to the list of HID devices an [Arduino Leonardo](https://www.arduino.cc/en/Main/ArduinoBoardLeonardo) or [Arduino Micro](https://www.arduino.cc/en/Main/ArduinoBoardMicro) (or any Arduino clone that is based on the ATmega32u4) can support. This library will also work with the [Arduino Due](https://www.arduino.cc/en/Main/ArduinoBoardDue), thanks to [@Palakis](https://github.com/Palakis). A complete list of supported boards can be found in the [Wiki](https://github.com/MHeironimus/ArduinoJoystickLibrary/wiki/Supported-Boards). This will not work with Arduino IDE 1.6.5 (or below) or with non-32u4 based Arduino devices (e.g. Arduino UNO, Arduino MEGA, etc.).

## Features

The joystick or gamepad can have the following features:
- Buttons (default: 32)
- Up to 2 Hat Switches
Expand All @@ -15,13 +18,14 @@ The joystick or gamepad can have the following features:
- Steering (up to 16-bit precision)

## Installation Instructions
Copy the `Joystick` folder to the Arduino libraries folder. Once the folder has been copied, the Joystick library should appear in the Arduino IDE list of libraries. The examples should also appear in the examples menu in the Arduino IDE.
### Microsoft Windows
On Microsoft Windows machines, this is typically `%userprofile%\Documents\Arduino\libraries`. The `deploy.bat` file can be executed to install the Joystick folder on Microsoft Windows machines (assuming a default Arduino installation).
### Linux
On Linux machines, this is typically `$HOME/Arduino/libraries`. The `deploy.sh` file can be executed to install the Joystick folder on Linux machines (assuming a default Arduino installation). [Thanks to @Nihlus (Jarl Gullberg) for his help with this.]

The following instructions can be used to install the latest version of the library in the Arduino IDE (thanks to [@per1234](https://github.com/per1234) for this update):

1. Download https://github.com/MHeironimus/ArduinoJoystickLibrary/archive/master.zip
2. In the Arduino IDE, select `Sketch` > `Include Library` > `Add .ZIP Library...`. Browse to where the downloaded ZIP file is located and click `Open`. The Joystick library's examples will now appear under `File` > `Examples` > `Joystick`.

## Examples

The following example Arduino sketch files are included in this library:

- `JoystickTest` - Simple test of the Joystick library. It exercises many of the Joystick library’s functions when pin A0 is grounded.
Expand All @@ -35,42 +39,46 @@ The following example Arduino sketch files are included in this library:

### Simple example

#include <Joystick.h>

// Create the Joystick
Joystick_ Joystick;

// Constant that maps the phyical pin to the joystick button.
const int pinToButtonMap = 9;

void setup() {
// Initialize Button Pins
pinMode(pinToButtonMap, INPUT_PULLUP);

// Initialize Joystick Library
Joystick.begin();
}

// Last state of the button
int lastButtonState = 0;

void loop() {

// Read pin values
int currentButtonState = !digitalRead(pinToButtonMap);
if (currentButtonState != lastButtonState)
{
Joystick.setButton(0, currentButtonState);
lastButtonState = currentButtonState;
}

delay(50);
```C++
#include <Joystick.h>

// Create the Joystick
Joystick_ Joystick;

// Constant that maps the physical pin to the joystick button.
const int pinToButtonMap = 9;

void setup() {
// Initialize Button Pins
pinMode(pinToButtonMap, INPUT_PULLUP);

// Initialize Joystick Library
Joystick.begin();
}

// Last state of the button
int lastButtonState = 0;

void loop() {

// Read pin values
int currentButtonState = !digitalRead(pinToButtonMap);
if (currentButtonState != lastButtonState)
{
Joystick.setButton(0, currentButtonState);
lastButtonState = currentButtonState;
}

delay(50);
}
```

## Joystick Library API

The following API is available if the Joystick library in included in a sketch file.

### Joystick\_(...)

Constructor used to initialize and setup the Joystick. The following optional parameters are available:

- `uint8_t hidReportId` - Default: `0x03` - Indicates the joystick's HID report ID. This value must be unique if you are creating multiple instances of Joystick. Do not use `0x01` or `0x02` as they are used by the built-in Arduino Keyboard and Mouse libraries.
Expand Down Expand Up @@ -99,90 +107,119 @@ The following constants define the default values for the constructor parameters
- `JOYSTICK_DEFAULT_HATSWITCH_COUNT` is set to `2`

### Joystick.begin(bool initAutoSendState)

Starts emulating a game controller connected to a computer. By default, all methods update the game controller state immediately. If `initAutoSendState` is set to `false`, the `Joystick.sendState` method must be called to update the game controller state.

### Joystick.end()

Stops the game controller emulation to a connected computer.

### Joystick.setXAxisRange(int16_t minimum, int16_t maximum)

Sets the range of values that will be used for the X axis. Default: `0` to `1023`

### Joystick.setXAxis(int16_t value)

Sets the X axis value. See `setXAxisRange` for the range.

### Joystick.setYAxisRange(int16_t minimum, int16_t maximum)

Sets the range of values that will be used for the Y axis. Default: `0` to `1023`

### Joystick.setYAxis(int16_t value)

Sets the Y axis value. See `setYAxisRange` for the range.

### Joystick.setZAxisRange(int16_t minimum, int16_t maximum)

Sets the range of values that will be used for the Z axis. Default: `0` to `1023`

### Joystick.setZAxis(int16_t value)

Sets the Z axis value. See `setZAxisRange` for the range.

### Joystick.setRxAxisRange(int16_t minimum, int16_t maximum)

Sets the range of values that will be used for the X axis rotation. Default: `0` to `1023`

### Joystick.setRxAxis(int16_t value)

Sets the X axis rotation value. See `setRxAxisRange` for the range.

### Joystick.setRyAxisRange(int16_t minimum, int16_t maximum)

Sets the range of values that will be used for the Y axis rotation. Default: `0` to `1023`

### Joystick.setRyAxis(int16_t value)

Sets the Y axis rotation value. See `setRyAxisRange` for the range.

### Joystick.setRzAxisRange(int16_t minimum, int16_t maximum)

Sets the range of values that will be used for the Z axis rotation. Default: `0` to `1023`

### Joystick.setRzAxis(int16_t value)

Sets the Z axis rotation value. See `setRzAxisRange` for the range.

### Joystick.setRudderRange(int16_t minimum, int16_t maximum)

Sets the range of values that will be used for the Rudder. Default: `0` to `1023`

### Joystick.setRudder(int16_t value)

Sets the Rudder value. See `setRudderRange` for the range.

### Joystick.setThrottleRange(int16_t minimum, int16_t maximum)

Sets the range of values that will be used for the Throttle. Default: `0` to `1023`

### Joystick.setThrottle(int16_t value)

Sets the Throttle value. See `setThrottleRange` for the range.

### Joystick.setAcceleratorRange(int16_t minimum, int16_t maximum)

Sets the range of values that will be used for the Accelerator. Default: `0` to `1023`

### Joystick.setAccelerator(int16_t value)

Sets the Accelerator value. See `setAcceleratorRange` for the range.

### Joystick.setBrakeRange(int16_t minimum, int16_t maximum)

Sets the range of values that will be used for the Brake. Default: `0` to `1023`

### Joystick.setBrake(int16_t value)

Sets the Brake value. See `setBrakeRange` for the range.

### Joystick.setSteeringRange(int16_t minimum, int16_t maximum)

Sets the range of values that will be used for the Steering. Default: `0` to `1023`

### Joystick.setSteering(int16_t value)

Sets the Steering value. See `setSteeringRange` for the range.

### Joystick.setButton(uint8_t button, uint8_t value)

Sets the state (`0` or `1`) of the specified button (range: `0` - (`buttonCount - 1`)). The button is the 0-based button number (i.e. button #1 is `0`, button #2 is `1`, etc.). The value is `1` if the button is pressed and `0` if the button is released.

### Joystick.pressButton(uint8_t button)

Press the indicated button (range: `0` - (`buttonCount - 1`)). The button is the 0-based button number (i.e. button #1 is `0`, button #2 is `1`, etc.).

### Joystick.releaseButton(uint8_t button)

Release the indicated button (range: `0` - (`buttonCount - 1`)). The button is the 0-based button number (i.e. button #1 is `0`, button #2 is `1`, etc.).

### Joystick.setHatSwitch(int8_t hatSwitch, int16_t value)

Sets the value of the specified hat switch. The hatSwitch is 0-based (i.e. hat switch #1 is `0` and hat switch #2 is `1`). The value is from 0° to 360°, but in 45° increments. Any value less than 45° will be rounded down (i.e. 44° is rounded down to 0°, 89° is rounded down to 45°, etc.). Set the value to `JOYSTICK_HATSWITCH_RELEASE` or `-1` to release the hat switch.

### Joystick.sendState()

Sends the updated joystick state to the host computer. Only needs to be called if `AutoSendState` is `false` (see `Joystick.begin` for more details).

See the [Wiki](https://github.com/MHeironimus/ArduinoJoystickLibrary/wiki) for more details on things like FAQ, supported boards, testing, etc.
3 changes: 0 additions & 3 deletions deploy.bat

This file was deleted.

5 changes: 0 additions & 5 deletions deploy.sh

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions Joystick/library.properties → library.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name=Joystick
version=2.0.5
version=2.0.6
author=Matthew Heironimus
maintainer=Matthew Heironimus <heironimus@live.com>
sentence=Arduino library that allows an Arduino Leonardo, Arduino Micro, or Arudino Due to appear as a Joystick or Gamepad.
sentence=Allows an Arduino board with USB capabilities (e.g. Leonardo, Arduino Micro, Arudino Due, etc.) to appear as a Joystick or Gamepad.
paragraph=This library is built on the PluggableUSB library. It can be used with or without other HID-based libraries (Mouse, Keyboard, etc.).
category=Device Control
url=https://github.com/MHeironimus/ArduinoJoystickLibrary
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion Joystick/src/Joystick.h → src/Joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#ifndef JOYSTICK_h
#define JOYSTICK_h

#include <DynamicHID/DynamicHID.h>
#include "DynamicHID/DynamicHID.h"

#if ARDUINO < 10606
#error The Joystick library requires Arduino IDE 1.6.6 or greater. Please update your IDE.
Expand Down

0 comments on commit 6884663

Please sign in to comment.