The Indiemark lens encoder communicated through USB HID, we've made this protocol open for third party developers to assist with integration into their systems.
We've put together a developer guide, which can be downloaded here.
This example gets data from an Indiemark 1/2/3 encoder via USB HID. HID is super low latency and fast (1000hz) but can be difficult to implement.
This uses the NODE-HID packages, and is intended to be run in NodeJS. It takes one command line argument, which is the serial number of the encoder you want to connect to.
const path = require('path');
const HID = require('node-hid');
//var device = new HID.HID(1204,32849); Indiemark 1 early models
//var device = new HID.HID(11914,61450);//Indiemark 2
var device = new HID.HID(9114,51966);//Indiemark 3
var status = 0;
var camera = "0";
var number = 0;
var position = 0;
var USBData = [];
var bISBlackedOut = false;
function Blackout(data){
console.log("Blackout");
var rList = [0x00, 0xff, 0x00, 0xff, 0xff];
if (data == 1){
rList[2] = (1 << 5) | rList[2];
}
else {
rList[2] = rList[2] & ~(1 << 5);
}
if(data == 1){
bISBlackedOut = 1;
} else {
bISBlackedOut = 0;
}
console.log(rList);
device.write(rList);
});
function FlashLED(data) {
console.log("flash")
rList = [0x00, 0xff, 0x00, 0xff, 0xff]
if (data == 1){
rList[2] = (1 << 7) | 0x00
}
else {
rList[2] = 0x00 & ~(1 << 7)
}
if (bISBlackedOut == 1){
rList[2] = (1 << 5) | rList[2];
}
else if(bISBlackedOut == 0) {
rList[2] = rList[2] & ~(1 << 5);
}
device.write(rList)
});
device.on("data", function(data) {
var oldCam = camera;
var oldNum = number;
var oldPos = position;
USBData = data;
UnpackCamLetter(data[0]);
status = data[1];
position = UnpackRotation(data[2], data[3])
if(position != oldPos){
console.log(camera, number, position);
}
});
function UnpackCamLetter(byte){
camera = (byte & 0xf0) >> 4;
if (camera != 0){
camera = String.fromCharCode(camera + 64);
}
number = byte & 0x0f;
}
function UnpackRotation(byte1, byte2){
var newPositon = 0;
newPositon = byte1 << 8 | byte2;
return newPositon;
}
The Indiemark 3 also sends data via USB Serial. This is an easier way to develop, but is slower. Connect to the encoder via it's serial port at 115200 baud. The data is simply the current position as an integer followed by a newline.