Skip to content
VisualPinballPublic
forked from vpinball/libdof

About

A cross platform library for performing Direct Output Framework tasks.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

libdof

Important

This is a temporary fork for the Visual Pinball Engine. The vpe branch is upstream vpinball/libdof master plus fixes VPE needs that are open as pull requests upstream, and it is what VisualPinball.Engine.DOF builds against. Once those pull requests are merged, VPE goes back to upstream libdof and this fork will be removed. Please report issues and send changes to vpinball/libdof.

Included pull requests: open PRs by freezy on vpinball/libdof.

A cross platform library for performing Direct Output Framework tasks.

This library is currently used by Visual Pinball Standalone to support Direct Output Framework.

About:

Direct Output Framework (DOF) is a system originally developed in C# for controlling feedback devices (like LEDs, solenoids, and motors) on virtual pinball machines. It is widely used in the virtual pinball community, especially in combination with Pinscape controllers and B2S-based backglasses.

libdof is a cross-platform C++ library aiming to be a faithful 1:1 port of the original DirectOutput C# codebase maintained by @mjrgh. This work began on March 23, 2024, and builds on previous porting efforts like B2S and FlexDMD, where accuracy to the original code has always been a priority.

Warning

Given the scope of Direct Output Framework - over 250 C# files - this C++ port leveraged a large amount of AI assistance (ChatGPT and Claude). I know for sure it is NOT fully accurate and DOES contain bugs. Now that most of the files are in place, I will continue refining it until we achieve a true faithful 1:1 port.

Supported Output Controllers

libdof supports a wide range of output controllers for driving LEDs, solenoids, and other feedback devices:

Tested & Working

Implemented & Ready To Test

  • DudesCab - RP2040-based controller with 128 PWM outputs
  • UMXController - Unified MX protocol for addressable LED strips (via DudesCab MX)
  • ArtNet/DMX - Professional lighting control via Ethernet (all platforms)
  • PinControl - Arduino-based controller with 10 outputs
  • WS2811/WS2812 LED Strips - Addressable LED strip support
  • PAC Controllers (PacDrive, PacUIO) - Cross-platform libusb implementation

Not Implemented

  • SSF Controllers - Audio-based feedback systems
  • Philips Hue - Smart lighting integration

libdof is actively used by Visual Pinball Standalone and continues expanding controller support.

PinOne Ultra (USB HID)

The PinOne Ultra, and PinOne boards on current firmware, receive output updates over a USB HID vendor channel instead of a serial port:

Vendor ID 0x39F5
Product ID Any ID in 0x9200–0x92FF, currently 0x9208 (standard mode) or 0x9209 (XInput controller mode)
HID usage page / usage 0xFF00 / 0x01 (vendor-defined collection)
Output report 64 bytes: report ID 6, followed by the 9-byte PinOne packet [0, 200 + bank, v1..v7], zero padded
  • Product IDs: The board reports a different product ID for each USB mode, and the vendor channel works the same in all of them. Product IDs 0x9200–0x92FF under vendor ID 0x39F5 are reserved for PinOne boards, and libdof accepts all of them, so firmware that adds a product ID in that range needs no libdof update.
  • Auto-detection: When the HID vendor channel is found, auto-configuration adds the board with ComPort set to HID and never opens a serial port. A legacy-firmware board (0x0E8F / 0x9207) is detected by looking up the COM port that belongs to that VID/PID. libdof no longer probes every serial port on the system.
  • Manual configuration: Use <ComPort>HID</ComPort> in Cabinet.xml (see the example below).
  • Do not point ComPort at the Ultra's serial port. The Ultra also exposes a USB serial port (e.g. COM9 or /dev/ttyACM0) used for firmware and configuration. libdof does not need it, and opening it at certain baud rates puts the board into firmware update mode. If an existing config names that port, change it to HID.
  • Shared access: On Windows and Linux the HID channel can be opened by several programs at once, so the PinOne configuration tool can stay connected while libdof is running. On macOS hidapi opens HID devices exclusively, so close the configuration tool before starting libdof.
  • Linux: Opening /dev/hidraw* requires permission. Add a udev rule, for example /etc/udev/rules.d/99-pinone.rules:
    SUBSYSTEM=="hidraw", ATTRS{idVendor}=="39f5", MODE="0666"
    
    The rule matches on the vendor ID only, so it covers every PinOne product ID. Then run sudo udevadm control --reload-rules && sudo udevadm trigger and reconnect the board.

Note

On macOS, accessing HID devices with usage page 0x06 and usage 0x00 (like Pinscape Pico) requires elevated permissions. You must run as sudo to communicate with the device. See here for more details.

Usage:

#include "DOF/DOF.h"
.
.

void LIBDOFCALLBACK LogCallback(DOF_LogLevel logLevel, const char* format, va_list args)
{
   va_list args_copy;
   va_copy(args_copy, args);
   int size = vsnprintf(nullptr, 0, format, args_copy);
   va_end(args_copy);

   if (size > 0)
   {
      char* const buffer = static_cast<char*>(malloc(size + 1));
      vsnprintf(buffer, size + 1, format, args);
      printf("%s\n", buffer);
      free(buffer);
   }
}

void test()
{
   DOF::Config* pConfig = DOF::Config::GetInstance();
   pConfig->SetLogCallback(LogCallback);
   pConfig->SetLogLevel(DOF_LogLevel_DEBUG);
   pConfig->SetBasePath("/Users/jmillard/Library/Application Support/VPinballX/10.8/");

   DOF::DOF* pDof = new DOF::DOF();

   std::vector<std::string> romNames = pDof->GetLedControlRomNames("");
   if (std::find(romNames.begin(), romNames.end(), "ij_l7") == romNames.end())
      printf("No ledcontrol config for ij_l7\n");

   pDof->Init("", "ij_l7");
   .
   .
   pDof->DataReceive('L', 88, 1);
   .
   .
   pDof->DataReceive('L', 88, 0);
   .
   .
   pDof->Finish();
   delete pDof;
}

Building:

Windows (x64)

Requires MSYS2 for building external dependencies:

pacman -S --noconfirm make diffutils \
  mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-libwinpthread \
  mingw-w64-ucrt-x86_64-cmake
platforms/win/x64/external.sh
cmake -G "Visual Studio 18 2026" -DPLATFORM=win -DARCH=x64 -B build
cmake --build build --config Release

Windows (x86)

Requires MSYS2 for building external dependencies:

pacman -S --noconfirm make diffutils \
  mingw-w64-i686-gcc mingw-w64-i686-libwinpthread \
  mingw-w64-i686-cmake
platforms/win/x86/external.sh
cmake -G "Visual Studio 18 2026" -A Win32 -DPLATFORM=win -DARCH=x86 -B build
cmake --build build --config Release

Windows MinGW / MSYS2 UCRT64 (x64)

Requires MSYS2 with UCRT64 environment. Install dependencies:

pacman -S --noconfirm make diffutils autoconf automake libtool \
  mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-libwinpthread \
  mingw-w64-ucrt-x86_64-cmake

Build (entire build runs inside the MSYS2 UCRT64 shell):

MSYSTEM=UCRT64 /c/msys64/usr/bin/bash.exe -l -c "
  cd \"$(pwd)\" &&
  ./platforms/win-mingw/x64/external.sh &&
  cmake -DCMAKE_BUILD_TYPE=Release -DPLATFORM=win-mingw -DARCH=x64 -B build &&
  cmake --build build -- -j\$(nproc)
"

Linux (x64)

platforms/linux/x64/external.sh
cmake -DPLATFORM=linux -DARCH=x64 -DCMAKE_BUILD_TYPE=Release -B build
cmake --build build

Linux (aarch64)

platforms/linux/aarch64/external.sh
cmake -DPLATFORM=linux -DARCH=aarch64 -DCMAKE_BUILD_TYPE=Release -B build
cmake --build build

MacOS (arm64)

platforms/macos/arm64/external.sh
cmake -DPLATFORM=macos -DARCH=arm64 -DCMAKE_BUILD_TYPE=Release -B build
cmake --build build

MacOS (x64)

platforms/macos/x64/external.sh
cmake -DPLATFORM=macos -DARCH=x64 -DCMAKE_BUILD_TYPE=Release -B build
cmake --build build

iOS (arm64)

platforms/ios/arm64/external.sh
cmake -DPLATFORM=ios -DARCH=arm64 -DCMAKE_BUILD_TYPE=Release -B build
cmake --build build

tvOS (arm64)

platforms/tvos/arm64/external.sh
cmake -DPLATFORM=tvos -DARCH=arm64 -DCMAKE_BUILD_TYPE=Release -B build
cmake --build build

Android (arm64-v8a)

platforms/android/arm64-v8a/external.sh
cmake -DPLATFORM=android -DARCH=arm64-v8a -DCMAKE_BUILD_TYPE=Release -B build
cmake --build build

Testing:

The dof_test tool requires --base-path to specify the VPinballX data directory.

Available ROMs: ij_l7, tna, gw, goldcue, bourne, twenty4, afm, pinupmenu

macOS

./build/dof_test --base-path "$HOME/Library/Application Support/VPinballX/10.8" gw

Linux

./build/dof_test --base-path ~/.local/share/VPinballX/10.8 gw

Windows

build\Release\dof_test.exe --base-path %APPDATA%\VPinballX\10.8 gw

Acknowledgments:

PAC controller USB communication protocols were figured out with significant help from the Ultimarc-linux repository by @katie-snow. This project provided essential insights into the libusb control transfer implementation for PacLed64, PacDrive, and PacUIO devices.

Configuration:

For custom setups, create a CabinetConfig.xml file in your DOF config directory:

<?xml version="1.0" encoding="utf-8"?>
<Cabinet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Name>Test Cabinet with Multiple Controllers</Name>
  <OutputControllers>
    <!-- Teensy LED Strip Controller -->
    <TeensyStripController>
      <Name>Cabinet Teensy</Name>
      <ComPortName>/dev/cu.usbmodem104409301</ComPortName>
      <ComPortBaudRate>9600</ComPortBaudRate>
      <ComPortParity>None</ComPortParity>
      <ComPortDataBits>8</ComPortDataBits>
      <ComPortStopBits>One</ComPortStopBits>
      <ComPortTimeOutMs>200</ComPortTimeOutMs>
      <ComPortOpenWaitMs>50</ComPortOpenWaitMs>
      <ComPortHandshakeStartWaitMs>20</ComPortHandshakeStartWaitMs>
      <ComPortHandshakeEndWaitMs>50</ComPortHandshakeEndWaitMs>
      <ComPortDtrEnable>false</ComPortDtrEnable>
      <NumberOfLedsStrip1>36</NumberOfLedsStrip1>
      <NumberOfLedsStrip2>36</NumberOfLedsStrip2>
      <NumberOfLedsStrip3>0</NumberOfLedsStrip3>
      <NumberOfLedsStrip4>0</NumberOfLedsStrip4>
      <NumberOfLedsStrip5>0</NumberOfLedsStrip5>
      <NumberOfLedsStrip6>0</NumberOfLedsStrip6>
      <NumberOfLedsStrip7>0</NumberOfLedsStrip7>
      <NumberOfLedsStrip8>0</NumberOfLedsStrip8>
      <NumberOfLedsStrip9>0</NumberOfLedsStrip9>
      <NumberOfLedsStrip10>0</NumberOfLedsStrip10>
    </TeensyStripController>

    <!-- Wemos LED Strip Controller -->
    <WemosD1MPStripController>
      <Name>Main Wemos</Name>
      <ComPortName>/dev/cu.usbserial-02G5PBVF</ComPortName>
      <ComPortBaudRate>2000000</ComPortBaudRate>
      <ComPortParity>None</ComPortParity>
      <ComPortDataBits>8</ComPortDataBits>
      <ComPortStopBits>One</ComPortStopBits>
      <ComPortTimeOutMs>500</ComPortTimeOutMs>
      <ComPortOpenWaitMs>50</ComPortOpenWaitMs>
      <ComPortHandshakeStartWaitMs>20</ComPortHandshakeStartWaitMs>
      <ComPortHandshakeEndWaitMs>50</ComPortHandshakeEndWaitMs>
      <ComPortDtrEnable>true</ComPortDtrEnable>
      <SendPerLedstripLength>true</SendPerLedstripLength>
      <UseCompression>false</UseCompression>
      <TestOnConnect>false</TestOnConnect>
      <NumberOfLedsStrip1>20</NumberOfLedsStrip1>
      <NumberOfLedsStrip2>0</NumberOfLedsStrip2>
      <NumberOfLedsStrip3>0</NumberOfLedsStrip3>
      <NumberOfLedsStrip4>0</NumberOfLedsStrip4>
      <NumberOfLedsStrip5>0</NumberOfLedsStrip5>
      <NumberOfLedsStrip6>0</NumberOfLedsStrip6>
      <NumberOfLedsStrip7>0</NumberOfLedsStrip7>
      <NumberOfLedsStrip8>0</NumberOfLedsStrip8>
      <NumberOfLedsStrip9>0</NumberOfLedsStrip9>
      <NumberOfLedsStrip10>0</NumberOfLedsStrip10>
    </WemosD1MPStripController>
    
    <!-- Pinscape Controller -->
    <Pinscape>
      <Name>Main Pinscape</Name>
      <Number>1</Number>
    </Pinscape>
    
    <!-- Pinscape Pico Controller -->
    <PinscapePico>
      <Name>Backbox Pico</Name>
      <Number>1</Number>
    </PinscapePico>
    
    <!-- PinOne Controller -->
    <PinOne>
      <Name>Main PinOne</Name>
      <Number>1</Number>
      <ComPort>HID</ComPort> <!-- USB HID (current firmware / PinOne Ultra), or a serial port such as /dev/ttyACM0 for legacy firmware -->
    </PinOne>
  </OutputControllers>
  
  <Toys>    
    <!-- LED Strip Toys for Teensy Controller -->
    <LedStrip>
      <Name>PF Left</Name>
      <Width>36</Width>
      <Height>1</Height>
      <Brightness>100</Brightness>
      <LedStripArrangement>TopDownLeftRight</LedStripArrangement>
      <ColorOrder>GRB</ColorOrder>
      <FirstLedNumber>36</FirstLedNumber> 
      <FadingCurveName>SwissLizardsLedCurve</FadingCurveName>
      <OutputControllerName>Cabinet Teensy</OutputControllerName>
    </LedStrip>

    <!-- LED Strip Toys for Wemos Controller -->
    <LedStrip>
      <Name>PF Right</Name> 
      <Width>20</Width> 
      <Brightness>100</Brightness>
      <Height>1</Height>
      <LedStripArrangement>TopDownLeftRight</LedStripArrangement>
      <ColorOrder>RGB</ColorOrder> 
      <FirstLedNumber>0</FirstLedNumber> 
      <FadingCurveName>SwissLizardsLedCurve</FadingCurveName>
      <OutputControllerName>Main Wemos</OutputControllerName>
    </LedStrip>
    
    <!-- LedWizEquivalent for LED Strips (LedWiz #30) -->
    <LedWizEquivalent>
      <Name>LED Strip Equivalent</Name> 
      <LedWizNumber>30</LedWizNumber>
      <Outputs>
        <LedWizEquivalentOutput>
          <OutputName>PF Left</OutputName>
          <LedWizEquivalentOutputNumber>4</LedWizEquivalentOutputNumber> 
        </LedWizEquivalentOutput>
        <LedWizEquivalentOutput>
          <OutputName>PF Right</OutputName> 
          <LedWizEquivalentOutputNumber>1</LedWizEquivalentOutputNumber>
        </LedWizEquivalentOutput> 
      </Outputs>
    </LedWizEquivalent> 
    
    <!-- LedWizEquivalent for Pinscape (Unit 1 = LedWiz #51) -->
    <LedWizEquivalent>
      <Name>Main Pinscape Equivalent</Name>
      <LedWizNumber>51</LedWizNumber>
      <Outputs>
        <LedWizEquivalentOutput>
          <OutputName>Main Pinscape.08</OutputName>
          <LedWizEquivalentOutputNumber>8</LedWizEquivalentOutputNumber>
        </LedWizEquivalentOutput>
      </Outputs>
    </LedWizEquivalent>
    
    <!-- LedWizEquivalent for PinscapePico (Unit 1 = LedWiz #120) -->
    <LedWizEquivalent>
      <Name>Backbox Pico Equivalent</Name>
      <LedWizNumber>120</LedWizNumber>
      <Outputs>
        <LedWizEquivalentOutput>
          <OutputName>Backbox Pico.01</OutputName>
          <LedWizEquivalentOutputNumber>1</LedWizEquivalentOutputNumber>
        </LedWizEquivalentOutput>
      </Outputs>
    </LedWizEquivalent>

    <!-- LedWizEquivalent for PinOne (Unit 1 = LedWiz #11) -->
    <LedWizEquivalent>
      <Name>PinOne Equivalent</Name>
      <LedWizNumber>11</LedWizNumber>
      <Outputs>
        <LedWizEquivalentOutput>
          <OutputName>PinOne\PinOne.01</OutputName>
          <LedWizEquivalentOutputNumber>1</LedWizEquivalentOutputNumber>
        </LedWizEquivalentOutput>
      </Outputs>
    </LedWizEquivalent>
  </Toys>
  
  <!-- Disable auto-configuration to use manual config -->
  <AutoConfigEnabled>false</AutoConfigEnabled> 
</Cabinet>

About

A cross platform library for performing Direct Output Framework tasks.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages