Skip to content

dumbowumbo/buttplugCpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Buttplug C++ Client Library

A C++ client implementation for the Buttplug intimate hardware control protocol.

Overview

This library provides a C++ client for the Buttplug Server, allowing developers to connect to and control various intimate hardware devices. The implementation supports C++11 and higher with minimal external dependencies.

Key features:

  • WebSocket-based communication with Buttplug servers
  • Thread-safe device control
  • Support for various device commands (vibration, linear, rotation)
  • Support for sensor reading and subscription
  • Built-in logging capabilities

Dependencies

The library has the following dependencies:

Building

Linux (Ubuntu)

  1. Install the required dependencies:
# Install build tools
sudo apt-get update
sudo apt-get install build-essential cmake git

# Install nlohmann/json (via package manager if available)
sudo apt-get install nlohmann-json3-dev

# Or manually (if not available in package manager)
git clone https://github.com/nlohmann/json.git
cd json
mkdir build && cd build
cmake ..
make
sudo make install
cd ../..
  1. Build IXWebSocket:
git clone https://github.com/machinezone/IXWebSocket.git
cd IXWebSocket
mkdir build && cd build
cmake ..
make
sudo make install
cd ../..
  1. Clone and build this repository:
git clone https://github.com/dumbowumbo/buttplugCpp
cd buttplugCpp
mkdir build && cd build
cmake ..
make
  1. Install the library system-wide (optional):
sudo make install

This will install:

  • Library files to /usr/local/lib (or as configured)
  • Headers to /usr/local/include/buttplug
  • CMake configuration files for dependent projects
  1. To uninstall the library (if needed):
sudo make uninstall

Windows

Using Visual Studio and vcpkg

  1. Install Visual Studio with C++ development tools

  2. Install vcpkg:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
bootstrap-vcpkg.bat
  1. Install dependencies via vcpkg:
vcpkg install nlohmann-json:x64-windows
vcpkg install ixwebsocket:x64-windows
vcpkg integrate install
  1. Clone this repository and open it in Visual Studio:
git clone https://github.com/dumbowumbo/buttplugCpp
cd buttplugCpp
  1. Create a new CMake project in Visual Studio, or run the following from Developer Command Prompt:
mkdir build
cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=[path\to\vcpkg]\scripts\buildsystems\vcpkg.cmake
  1. Build the project:
cmake --build . --config Release
  1. Install the library (optional, run as Administrator):
cmake --install . --config Release

This will install:

  • Library files to the system library directory
  • Headers to the system include directory
  • CMake configuration files for dependent projects
  1. To uninstall the library (if needed, run as Administrator):
cmake -P cmake_uninstall.cmake

Usage

Basic Example

#include <buttplug/buttplugclient.h>
#include <iostream>
#include <thread>
#include <chrono>

// Callback for handling device messages
void messageHandler(const mhl::Messages& msg) {
    if (msg.messageType == mhl::MessageTypes::DeviceAdded) {
        std::cout << "New device added: " << msg.deviceAdded.device.DeviceName << std::endl;
    }
}

int main() {
    // Create client connection to a buttplug server at localhost:12345
    Client client("ws://localhost", 12345);
    
    // Connect to the server
    client.connect(messageHandler);
    
    // Start scanning for devices
    client.startScan();
    
    // Wait for devices to connect
    std::this_thread::sleep_for(std::chrono::seconds(5));
    
    // Get list of connected devices
    auto devices = client.getDevices();
    
    if (!devices.empty()) {
        // Control the first device (simple vibration at 50% power)
        client.sendScalar(devices[0], 0.5);
        
        std::this_thread::sleep_for(std::chrono::seconds(3));
        
        // Stop the device
        client.stopDevice(devices[0]);
    }
    
    return 0;
}

Using as a Dependency in CMake Projects

After installing the library, you can easily use it in your CMake projects:

find_package(ButtplugClient REQUIRED)

add_executable(my_app main.cpp)
target_link_libraries(my_app PRIVATE ButtplugClient::buttplugclient)

Documentation

The Buttplug protocol documentation is available at:

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

C++ API for Buttplug IO

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •