That Powermate code did the trick!
I had to use a different reference for rotation direction, because Index 19 was throwing positives and negatives. It probably will need a little refinement, but for now, this code is doing what I need, with a coarse step scroll, a fine step scroll, and a double-touch trigger. I still want to add something for the super-fine control nudge-movement, but I'll try this for a while.
Touch
TouchRelease
DoubleTouch
Press
PressHoldStatic
PressRelease
StepCW
StepCCW
PressStepCW
PressStepCCW
FineCW
FineCCW
PressFineCW
PressFineCCW
// Enter your input analyzer script here.
// Do not change the function signatures
function analyzeDeviceInput(targetDevice, reportID, reportDataHex) {
let reportBuffer = buffer.Buffer.from(reportDataHex, 'hex');
// the values you see above are in hex format. To read such a byte
// use readUInt8(index).
// Index 0 is crown press state. 1 = press, 0 = release.
crownpress = reportBuffer.readUInt8(10),
// Index 1 is amount of movement since last report.
// Signed value, positive for right, negative for left.
// Spinning really fast I have observed a value up to +/- 7,
// lets assume it will never be larger than 9.
movement = reportBuffer.readInt8(19),
direction = reportBuffer.readInt8(5)
ratchetstep = reportBuffer.readInt8(6),
touch = reportBuffer.readInt8(8),
doubletouch = reportBuffer.readInt8(9);
if ( direction < 0 ) {
if ( crownpress == 04 ) {
log('fineccw ' + movement + ' pressed');
// We should probably repeat the trigger "movement" times ...
// but that would be too many triggers :)
bttTriggerDeviceTrigger(targetDevice, 'PressFineCCW');
} else if ( crownpress == 00 && touch == 02) {
log('fineccw ' + movement);
bttTriggerDeviceTrigger(targetDevice, 'FineCCW');
}
// If we are spinning we want the next report even if it's the same
bttGetNextEvenWithoutChange(targetDevice, reportID);
}
else if( direction > 0 ) {
if ( crownpress == 04 ) {
log('finecw ' + movement + ' pressed');
bttTriggerDeviceTrigger(targetDevice, 'PressFineCW');
} else if ( crownpress == 00 && touch == 02){
log('finecw ' + movement);
bttTriggerDeviceTrigger(targetDevice, 'FineCW');
}
bttGetNextEvenWithoutChange(targetDevice, reportID);
}
//Touch events
if ( touch == 03 && doubletouch == 01 ) {
log('doubletouch');
// Tap the crown twice without pushing it.
bttTriggerDeviceTrigger(targetDevice, 'DoubleTouch');
}
if(reportBuffer.readUInt8(8) === 0x01) {
log('touch');
bttTriggerDeviceTrigger(targetDevice, 'Touch');
}else if(reportBuffer.readUInt8(8) === 0x03) {
log('touchrelease');
bttTriggerDeviceTrigger(targetDevice, 'TouchRelease');
}
//Press events
if(reportBuffer.readUInt8(10) === 0x01) {
log('press');
bttTriggerDeviceTrigger(targetDevice, 'Press');
}else if(reportBuffer.readUInt8(10) === 0x03) {
log('pressholdstatic');
bttTriggerDeviceTrigger(targetDevice, 'PressHoldStatic');
}else if(reportBuffer.readUInt8(10) === 0x05) {
log('pressrelease');
bttTriggerDeviceTrigger(targetDevice, 'PressRelease');
}
//StepEvents
if(reportBuffer.readUInt8(8) === 2 && reportBuffer.readUInt8(6) === 0x01 && reportBuffer.readUInt8(10) === 0x00) {
log('stepcw');
bttTriggerDeviceTrigger(targetDevice, 'StepCW');
}else if(reportBuffer.readUInt8(8) === 2 && reportBuffer.readUInt8(6) === 0xff && reportBuffer.readUInt8(10) === 0x00) {
log('stepccw');
bttTriggerDeviceTrigger(targetDevice, 'StepCCW');
}
if(reportBuffer.readUInt8(8) === 2 && reportBuffer.readUInt8(6) === 0x01 && reportBuffer.readUInt8(10) === 0x04) {
log('pressstepcw');
bttTriggerDeviceTrigger(targetDevice, 'PressStepCW');
}else if(reportBuffer.readUInt8(8) === 2 && reportBuffer.readUInt8(6) === 0xff && reportBuffer.readUInt8(10) === 0x04) {
log('pressstepccw');
bttTriggerDeviceTrigger(targetDevice, 'PressStepCCW');
}