Example #1
0
    private void comm(Pointer<hid_device> device) {
      log.debug("starting comm loop");
      Pointer<Byte> data = Pointer.allocateBytes(1024);
      HidapiLibrary.hid_set_nonblocking(device, 1);
      while (loop && connected) {
        int result = HidapiLibrary.hid_read(device, data, 1024);
        if (result > 0) {
          byte bytes[] = data.getBytes(result);
          messageQueue.addAll(parse(result, bytes));
        }

        BpmMessage msg = writeQueue.poll();
        if (msg != null) {
          encode(msg, writeBuffer);
          try {
            HidapiLibrary.hid_write(device, Pointer.pointerToBytes(writeBuffer), 9);
          } finally {
            writeBuffer.rewind();
          }
        }
      }
    }
Example #2
0
 @Override
 public String toString(Pointer<?> value, int size) {
   return Hex.encodeHexString(value.getBytes(size));
 }
Example #3
0
 @Override
 public String toString(Pointer<?> value, int size) {
   return new String(value.getBytes(size));
 }
Example #4
0
 @Override
 public Object toObject(Pointer<?> value, int size) {
   return value.getBytes(size);
 }