Giter Site home page Giter Site logo

yaha's Introduction

Yaha

Yaha is a Windows C++ API for interacting with USB Human Interface Devices. It allows to generate notifications when a device is added or removed and when an IO operation is complete.

Usage

Devices can be found using an HidApi object which enumerates the connected HID devices. Device paths are mapped to device object pointers in a std::map container. After creating an HidApi object, devices can be iterated through or a specific device object matching certain product and vendor IDs can be requested from the API.

HidApi m_hid;
for(auto &x : m_hid.m_devices)
	std::wcout << (x.second)->getProduct();

HidDevice *m_device;
m_device = m_hid.getHidDevice(0x1000, 0x2000);

HidApi generates a notification when a device is added or removed. Callbacks must be set for the application to catch these notifications. Callbacks are stored in std::function wrappers and can be set using lambda functions.

#include "hidapi.h"

void init() {
	HidApi m_hid;
    m_hid.setCallbackArrival([this](HidDevice* d){return arrivalCallback(d);});
    m_hid.setCallbackRemoval([this](HidDevice* d){return removalCallback(d);});
}

void arrivalCallback(HidDevice *d) {}
void removalCallback(HidDevice *d) {}

Devices can be written to and read from either asynchronously (non-blocking) or isosynchronously (default). Also asynchronous read can be performed continuously.

void arrivalCallback(HidDevice *d)
{
	d->setCallbackReadComplete([this](HidDevice* d){return readCallback(d);});
	d->setWriteBlocking(true);
	d->setReadBlocking(false);
	d->setReadContinuous(true);
	d->write(buf);
}

void readCallback(HidDevice *d)
{
	std::cout << d->m_readBuf << std::endl;
}

Building

Qt

Include yaha.pri in your projects .pro file as is done in the example.

Visual Studio

XXX

yaha's People

Contributors

karel avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.