Giter Club home page Giter Club logo

Comments (6)

junction2412 avatar junction2412 commented on July 29, 2024

Well it worked fine for me in the underneath code.

import org.hid4java.*
import java.nio.ByteBuffer
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardOpenOption

fun main(args: Array<String>) {
    val path = Paths.get(System.getenv("USERPROFILE"), "Desktop", "hid", "test.txt")
    if (!Files.exists(path))
        Files.createFile(path)

    val arr: Array<HidDevice?> = Array(1) { null }

    for (device: HidDevice in HidManager.getHidServices().attachedHidDevices) {
        println("manufacturer: ${device.manufacturer}, product: ${device.product}, usage_page: ${device.usagePage}, usage: ${device.usage}")

        if (device.usagePage == 0x01 && device.usage == 0x05)
            arr[0] = device
    }

    if (arr[0] != null) {
        println("gamepad found\n")
        val gamepad: HidDevice = arr[0]!!
        gamepad.open()

        val start: Long = System.currentTimeMillis()

        do {
            val read: Array<Byte> = gamepad.read()!!
            val array = ByteArray(read.size)

            for (index in read.indices)
                array[index] = read[index]

            for (i in 0..(array.size / 8))
                print(String.format("%x ", ByteBuffer.wrap(array.copyOfRange(i, i + 8)).long))
            println()

            Files.write(
                path,
                array,
                StandardOpenOption.APPEND
            )
        } while (System.currentTimeMillis() - start <= 5_000)

        gamepad.close()
    }
}

Gotta admit I'm very impressed by this api, yet I still have to figure out how the input-reports work to be able to do something useful with it. 😅

from hid4java.

RKaixuan avatar RKaixuan commented on July 29, 2024

I have new problem, HipApi.open is returning null when I send information to the device for the second time

from hid4java.

junction2412 avatar junction2412 commented on July 29, 2024

Did you close the former connection properly before opening it the 2nd time?

from hid4java.

RKaixuan avatar RKaixuan commented on July 29, 2024

Thinks, I got it

from hid4java.

RKaixuan avatar RKaixuan commented on July 29, 2024

Why 32-bit windows7 can't send data to the device, but can receive data

from hid4java.

gary-rowe avatar gary-rowe commented on July 29, 2024

Since this is an old question/answer support issue I'll close it for now.

from hid4java.

Related Issues (20)

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.