Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 52 additions & 8 deletions AnalogSense.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,27 +340,26 @@ class AsProvider
}
}

class AsProviderWooting extends AsProvider
//wooting analog interface v1
class AsProviderWootingV1 extends AsProvider
{
static populateFilters(filters)
{
filters.push({ usagePage: 0xFF54, vendorId: 0x31E3 });
filters.push({ usagePage: 0xFF54, vendorId: 0x03EB, productId: 0xFF01 }); // Wooting One with old firmware
filters.push({ usagePage: 0xFF54, vendorId: 0x03EB, productId: 0xFF02 }); // Wooting Two with old firmware
filters.push({ usagePage: 0xFF54, vendorId: 0x03EB, productId: 0xFF01 }); // Wooting One old firmware
filters.push({ usagePage: 0xFF54, vendorId: 0x03EB, productId: 0xFF02 }); // Wooting Two old firmware
}

startListening(handler)
{
//v1 big eddie u16 scancodes , u8 value, up to 16 keys
this.dev.oninputreport = function(event)
{
const active_keys = [];
for (let i = 0; i < event.data.byteLength; )
{
const scancode = (event.data.getUint8(i++) << 8) | event.data.getUint8(i++);
if (scancode == 0)
{
break;
}
if (scancode == 0) break;
const value = event.data.getUint8(i++);
active_keys.push({ scancode, value: value / 255 });
}
Expand All @@ -374,6 +373,50 @@ class AsProviderWooting extends AsProvider
}
}

//wooting analog interface v2 (firmware 2.13.0 and up | wootility 5.3.0 and up)
class AsProviderWootingV2 extends AsProvider
{
static populateFilters(filters)
{
filters.push({ usagePage: 0xFF53, vendorId: 0x31E3 });
}

startListening(handler)
{
this.dev.oninputreport = function(event)
{
const active_keys = [];
const data = event.data;
//each entry is 4 bytes (pos, keycode, namespace + analog lo, analog depth
//namespace 0 are regular hid keys, non zero are media keys
//analog value is 10bit 0 to 1023
for (let i = 0; i + 4 <= data.byteLength; i += 4)
{
const keycode = data.getUint8(i + 1);
const packed = data.getUint8(i + 2);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the first bit of the packed section is the key's actuated state if that is of interest

const value_hi = data.getUint8(i + 3);

const keyNamespace = (packed >> 2) & 0xf;
const value_lo = (packed >> 6) & 0x3;

const scancode = (keyNamespace << 8) | keycode;
const value = (value_hi << 2) | value_lo;

if (scancode === 0) break;
if (value === 0) continue;

active_keys.push({ scancode, value: value / 1023 });
}
handler(active_keys);
};
}

stopListening()
{
this.dev.oninputreport = undefined;
}
}

class AsProviderRazerHuntsman extends AsProvider
{
static populateFilters(filters)
Expand Down Expand Up @@ -870,7 +913,8 @@ class AsProviderBytech extends AsProvider

window.analogsense = {
providers: [
AsProviderWooting,
AsProviderWootingV1,
AsProviderWootingV2,
AsProviderRazerHuntsman,
AsProviderRazerHuntsmanV3,
AsProviderNuphy,
Expand Down