Skip to content

Commit

Permalink
Merge branch 'release-v1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
robsdedude committed Oct 1, 2017
2 parents 9579532 + 349883a commit e59243b
Show file tree
Hide file tree
Showing 19 changed files with 471 additions and 294 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
1.3.0
=====
* Introduced Changelog
* Improved documentation (e.g. explaining `config.json`)
* D-Pad supports analog stick behaviour by default
* Improved logging
* Using module `forever-monitor` to restart the server if it crashes
for some reason.
* Bug fixes
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,29 @@ Installation
git clone https://github.com/miroof/node-virtual-gamepads
cd node-virtual-gamepads
npm install
sudo node main.js

If you encounter problems while installing or running node-virtual-gamepads have
a look at the [troubleshooting](TROUBLESHOOTING.md) page.

You can now configure the server to your needs. Just open `config.json`
with the editor of you choice and adjust the values.

* `port`: sets the port the web-server is listening on.
* `useGamepadByDefault`: if set to `false`, the `/` will redirect to a
page where one of gamepad, keyboard, or touchpad can be chosen.
If set to `true`, `/` redirects to the gamepad. The input-selection
page can still be accessed via `/index.html`.
* `analog`: if set to `true` the the above mentioned redirection will
append `?analog` to the address. This flag will cause the gamepad's
d-pad to act like an analog stick instead of d-pad.
* `logLevel`: set it to `"debug"` to get a lot more logging output,
to `"warning"` to only get critical output, or even to `"error"` if
you want to only get errors logged (not recommended).

To start the server run

sudo node main.js

Usage
-----
Once the nodejs application is launched, you just have to plug your gamepad controller
Expand Down Expand Up @@ -61,6 +79,15 @@ to let as much space as possible for the joystick and avoid touch mistakes.
To know if we pressed a button with success, the web application provides an haptic feedback
which can be easily deactivated by turning off the vibrations of the phone.

### Use the keyboard to enter text
![Virtual Keyboard](https://github.com/miroof/node-virtual-gamepads/blob/resources/screenshots/keyboard.png?raw=true)

### Use the touchpad for mouse inputs
![Virtual Touchpad](https://github.com/miroof/node-virtual-gamepads/blob/resources/screenshots/touchpad.png?raw=true)

### An index page lets you choose
![Index page](https://github.com/miroof/node-virtual-gamepads/blob/resources/screenshots/index.png?raw=true)

Developing
----------
For developing you will also have to install coffeescript
Expand All @@ -78,4 +105,3 @@ To compile all coffee files when ever they change run
coffee -cw .

If you want do add a new keyboard layout please refer to [this file](CREATE_KEYBOARD_LAYOUT.md).

14 changes: 8 additions & 6 deletions app/virtual_gamepad.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ ioctl = require 'ioctl'
uinput = require '../lib/uinput'
uinputStructs = require '../lib/uinput_structs'
config = require '../config.json'
winston = require('winston')
winston.level = config.logLevel


class virtual_gamepad
Expand Down Expand Up @@ -57,21 +59,21 @@ class virtual_gamepad

fs.write @fd, uidev_buffer, 0, uidev_buffer.length, null, (err) =>
if err
console.warn "Error on init gamepad write:\n", err
winston.log 'warn', "Error on init gamepad write:\n", err
error err
else
try
ioctl @fd, uinput.UI_DEV_CREATE
callback()
catch err
console.error "Error on gamepad create dev:\n", err
winston.log 'error', "Error on gamepad create dev:\n", err
fs.close @fd
@fd = undefined
if retry < 5
console.info "Retry to create gamepad"
winston.log 'info', "Retry to create gamepad"
@connect callback, error, retry+1
else
console.error "Gave up on creating device"
winston.log 'error', "Gave up on creating device"
error err

disconnect: (callback) ->
Expand Down Expand Up @@ -102,12 +104,12 @@ class virtual_gamepad
try
fs.writeSync @fd, ev_buffer, 0, ev_buffer.length, null
catch err
console.error "Error on writing ev_buffer"
winston.log 'error', "Error on writing ev_buffer"
throw err
try
fs.writeSync @fd, ev_end_buffer, 0, ev_end_buffer.length, null
catch err
console.error "Error on writing ev_end_buffer"
winston.log 'error', "Error on writing ev_end_buffer"
throw err


Expand Down
18 changes: 11 additions & 7 deletions app/virtual_gamepad.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions app/virtual_gamepad_hub.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Virtual gamepad hub class
###

gamepad = require './virtual_gamepad'
config = require '../config.json'
winston = require('winston')
winston.level = config.logLevel

class virtual_gamepad_hub

Expand All @@ -25,9 +28,11 @@ class virtual_gamepad_hub
padId++

if !freeSlot
winston.log('warning', "Couldn't add new Gamepad: no slot left.")
callback -1
else
# Create and connect the gamepad
winston.log('info', 'Gamepad number', padId)
@gamepads[padId] = new gamepad()
@gamepads[padId].connect () ->
callback padId
Expand Down
10 changes: 9 additions & 1 deletion app/virtual_gamepad_hub.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions app/virtual_keyboard.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ ioctl = require 'ioctl'
uinput = require '../lib/uinput'
uinputStructs = require '../lib/uinput_structs'
config = require '../config.json'
winston = require('winston')
winston.level = config.logLevel

class virtual_keyboard

Expand Down Expand Up @@ -36,14 +38,14 @@ class virtual_keyboard

fs.write @fd, uidev_buffer, 0, uidev_buffer.length, null, (err) =>
if err
console.error err
winston.log 'error', err
error err
else
try
ioctl @fd, uinput.UI_DEV_CREATE
callback()
catch error
console.error error
winston.log 'error', error
fs.close @fd
@fd = undefined
@connect callback, error
Expand All @@ -56,7 +58,7 @@ class virtual_keyboard
callback()

sendEvent: (event) ->
console.log(event)
winston.log 'debug', event
if @fd
ev = new uinputStructs.input_event
ev.type = event.type
Expand Down
12 changes: 8 additions & 4 deletions app/virtual_keyboard.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions app/virtual_touchpad.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ ioctl = require 'ioctl'
uinput = require '../lib/uinput'
uinputStructs = require '../lib/uinput_structs'
config = require '../config.json'
winston = require('winston')
winston.level = config.logLevel

class virtual_touchpad

Expand Down Expand Up @@ -63,21 +65,21 @@ class virtual_touchpad

fs.write @fd, uidev_buffer, 0, uidev_buffer.length, null, (err) =>
if err
console.warn "Error on init touchpad write:\n", err
winston.log 'warn', "Error on init touchpad write:\n", err
error err
else
try
ioctl @fd, uinput.UI_DEV_CREATE
callback()
catch err
console.error "Error on touchpad create dev:\n", err
winston.log 'error', "Error on touchpad create dev:\n", err
fs.close @fd
@fd = undefined
if retry < 5
console.info "Retry to create touchpad"
winston.log 'info', "Retry to create touchpad"
@connect callback, error, retry+1
else
console.error "Gave up on creating device"
winston.log 'error', "Gave up on creating device"
error err

disconnect: (callback) ->
Expand Down Expand Up @@ -108,12 +110,12 @@ class virtual_touchpad
try
fs.writeSync @fd, ev_buffer, 0, ev_buffer.length, null
catch err
console.error "Error on writing ev_buffer"
winston.log 'error', "Error on writing ev_buffer"
throw err
try
fs.writeSync @fd, ev_end_buffer, 0, ev_end_buffer.length, null
catch err
console.error "Error on writing ev_end_buffer"
winston.log 'error', "Error on writing ev_end_buffer"
throw err


Expand Down
Loading

0 comments on commit e59243b

Please sign in to comment.