Skip to content

Latest commit

 

History

History

driver

Driver

This is Node.js application which reads data from serial port sent by arduino and performs actions mapped for the particular button on a remote control.

Install

To support keyboard and mouse actions by robotjs you have to install build tools first. However it is not required for the whole application — if you don't use keyboard/mouse actions then this step is not needed as well.

  • Windows

    • windows-build-tools. Run in PowerShell or CMD.exe:

      npm install --global --production windows-build-tools
  • Mac

    • Xcode Command Line Tools
  • Linux

    • Python (v2.7 recommended, v3.x.x is not supported)

    • make

    • A C/C++ compiler like GCC

    • libxtst-dev and libpng++-dev

      sudo apt-get install libxtst-dev libpng++-dev

Then install local dependencies:

npm i

Usage

  • Run in normal mode:

    npm start
  • Run in debug mode:

    npm run start:debug

Test mode

This will loop over leds and exit. Just for testing connectivity.

npm run start:test-mode

Configuration

Key mapping configuration is contained in settings.json. For example:

{
  "serialPort": "COM# or /dev/tty-xxx",
  "debounceDelay": 150,
  "noDebounce": ["volume_up", "volume_down"],
  "mappings": {
    "play": {
      "if": {"running": "mpc-hc.exe"},
      "then": {"key": "space"},
      "else": {"exec": ["c:\\Program Files (x86)\\foobar2000\\foobar2000.exe", "/play"]}
    },
    "rew": {
      "if": {"running": "mpc-hc.exe"},
      "then": {"key": ["shift", "left"]}
    },
    "ff": {
      "if": {"running": "mpc-hc.exe"},
      "then": {"key": ["shift", "right"]}
    }
  }
}

Serial port

Required. To be able to connect to your Arduino.

Debounce

While pressing a button on the remote control IR it sends a lot of repeating signals. Each of those signals are treated as separate button presses by the driver. In this case a single action would be run multiple times on a single actual button press.

To avoid such behavior there is debounceDelay value. By default — 150 (ms). This ensures to run your action only once on one button press.

However this behavior is not acceptable in all cases. For example for volume control it is useful opposite behavior to have possibility to change volume while button is pressed. This is controlled by noDebounce value.

Mappings

Each mapping is a key-value value where the key is a button on the remote control and the value is an action or a list of actions.

Supported actions

  • Condition if

    Operators:

    • running — check if running application (using ps-list)

      {
        "if": {"running": "mpc-hc.exe"},
        "then": ["list of actions described below"],
        "else": ["list of actions described below"]
      }
    • state — check current state controlled by action state (see below)

      {
        "if": {"state": "turned off"},
        "then": ["list of actions described below"],
        "else": ["list of actions described below"]
      }
  • Emulate key press. Key codes could be retrieved from robotjs syntax or robotjs.cc file

    {"key": "space"}
  • Run application

    {"exec": ["c:\\Program Files (x86)\\foobar2000\\foobar2000.exe", "/play"]}
  • Control mouse

    {"mouse": ["set of mouse actions described below"]}
    • click

      {"click": "left | right | middle"}
    • delay

      {"delay": 30}
    • doubleClick

      {"delay": "left | right | middle"}
    • move

      {"move": [1750, 100]}
    • moveSmooth

      {"moveSmooth": [1750, 100]}
    • moveRelative

      {"moveRelative": [100, 200]}
    • moveRelativeSmooth

      {"moveRelativeSmooth": [100, 200]}
    • scroll

      {"scroll": 42}
  • Switch state

    {"state": ["music", "video", "browser", "etc"]}

    Every time when this action is executed a global state will be updated with the next value listed in the array.

    This state can be retrieved by if to do different things depending on the current value.

  • Switch on/off LEDs on the device

    {"led": "red"},           // as string - "red" | "yellow"  | "green" | "blue"
    {"led": ["red", "blue"]}, // as array
    {"led": []},              // empty array - to switch off all LEDs