hidapi_dart 0.0.7

  • Readme
  • Changelog
  • Example
  • Installing
  • 65

hidapi_dart #

Use ffi to bridge apis of hidapi.

[0.0.7] - 2020/05/28 #

  • Minor changes

[0.0.6] - 2020/05/28 #

  • More useful example
  • Fix potential memory oob access and memory leak.
  • Remove HID#flush, since not needed.

[0.0.5] - 2020/05/25 #

  • Fix the dependency from copied allocation.dart to package:ffi one

[0.0.4] - 2020/05/23 #

  • Fix a multiple free caused by missing colon

[0.0.3] - 2020/05/23 #

  • Add example

[0.0.2] - 2020/05/23 #

  • Removed debug output inside HID.flush

[0.0.1] - 2020/05/23 #

  • Added hid_open, hid_write, hid_read, hid_timeout, hid_close

example/main.dart

import 'dart:io';
import 'package:hidapi_dart/hidapi_dart.dart';

void main(List<String> args) async {
  if(args.length < 3) {
    String exe = Platform.executable;
    String script = Platform.script.toFilePath();
    stdout.writeln("Usage: ${exe} ${script} <vid> <pid> <payload>");
    return;
  }

  int vid = int.tryParse(args[0]), pid = int.tryParse(args[1]);

  if(vid == null || pid == null) {
    stdout.write("Invalid ");
    if(vid == null) { stdout.write('idVendor'); }
    if(vid == null && pid == null) { stdout.write(' and'); }
    if(pid == null) { stdout.write(' idProduct'); }
    return;
  }

  var hexpat = RegExp(r"^([a-z0-9]{2})+$", caseSensitive: false);
  if(!hexpat.hasMatch(args[2])) {
    stdout.writeln("Invalid payload, only accept hexstring");
  }

  String payload = '';

  for (var i = 0; i < args[2].length; i+=2) {
    payload += String.fromCharCode(int.parse(args[2].substring(i,i+2), radix: 16));
  }

  var hid = HID(idVendor: int.parse(args[0]), idProduct: int.parse(args[1]));

  if(hid.open() < 0) {
    stdout.writeln('HID Device open failed!');
    return;
  }

  await hid.write(payload);
  String str = await hid.read();
  stdout.writeln(str);
  hid.close();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  hidapi_dart: ^0.0.7

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:hidapi_dart/hidapi_dart.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
34
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
65
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Analysis suggestions

Package not compatible with runtime flutter-web on web

Because:

  • package:hidapi_dart/hidapi_dart.dart that imports:
  • package:hidapi_dart/hid.dart that imports:
  • package:ffi/src/allocation.dart that imports:
  • dart:io

Package not compatible with runtime js

Because:

  • package:hidapi_dart/hidapi_dart.dart that imports:
  • package:hidapi_dart/hid.dart that imports:
  • package:ffi/src/allocation.dart that imports:
  • dart:io

Health suggestions

Format lib/hid.dart.

Run dartfmt to format lib/hid.dart.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
ffi ^0.1.3 0.1.3