Skip to content
Draft
Show file tree
Hide file tree
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
54 changes: 39 additions & 15 deletions AnalogSense.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class AsProvider
const active_keys = [];
for (const [scancode, value] of Object.entries(this.buffer))
{
active_keys.push({ scancode, value });
active_keys.push({ scancode, value, actuated: null });
}
return active_keys;
}
Expand All @@ -361,7 +361,7 @@ class AsProviderWootingV1 extends AsProvider
const scancode = (event.data.getUint8(i++) << 8) | event.data.getUint8(i++);
if (scancode == 0) break;
const value = event.data.getUint8(i++);
active_keys.push({ scancode, value: value / 255 });
active_keys.push({ scancode, value: value / 255, actuated: null });
}
handler(active_keys);
};
Expand All @@ -386,27 +386,48 @@ class AsProviderWootingV2 extends AsProvider
this.dev.oninputreport = function(event)
{
const active_keys = [];
const features_by_pos = {};
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
//
//namespace 6 are `advanced keys` (like socd dks etc etc)
//with which we can check if the user has configured eg socd on them or nah
for (let i = 0; i + 4 <= data.byteLength; i += 4)
{
const keycode = data.getUint8(i + 1);
const packed = data.getUint8(i + 2);
const value_hi = data.getUint8(i + 3);
const matrix_pos = data.getUint8(i + 0);
const keycode = data.getUint8(i + 1);
const packed = data.getUint8(i + 2);
const value_hi = data.getUint8(i + 3);

const keyNamespace = (packed >> 2) & 0xf;
const value_lo = (packed >> 6) & 0x3;
const actuated = (packed & 0x1) !== 0;
const key_namespace = (packed >> 2) & 0xf;
const value_lo = (packed >> 6) & 0x3;
const value = (value_hi << 2) | value_lo;

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

if (scancode === 0) break;
if (matrix_pos === 0 && keycode === 0) break;
if (value === 0) continue;

active_keys.push({ scancode, value: value / 1023 });
if (key_namespace === 6)
{
if (!features_by_pos[matrix_pos]) features_by_pos[matrix_pos] = {};
//if (keycode === 0x01) features_by_pos[matrix_pos].dks = true; //needs different handling
//if (keycode === 0x02) features_by_pos[matrix_pos].mod_tap = true; //needs different handling
//if (keycode === 0x03) features_by_pos[matrix_pos].toggle = true; //needs different handling
if (keycode === 0x04) features_by_pos[matrix_pos].rappy_snappy = true;
if (keycode === 0x05) features_by_pos[matrix_pos].socd = true;
}
else if (key_namespace === 0)
{
active_keys.push({
scancode: keycode,
value: value / 1023,
extra: { actuated, ...features_by_pos[matrix_pos] },
});
}
}

handler(active_keys);
};
}
Expand Down Expand Up @@ -442,7 +463,8 @@ class AsProviderRazerHuntsman extends AsProvider
const value = event.data.getUint8(i++);
active_keys.push({
scancode: analogsense.razerScancodeToHidScancode(scancode),
value: value / 255
value: value / 255,
actuated: null
});
}
handler(active_keys);
Expand Down Expand Up @@ -483,7 +505,8 @@ class AsProviderRazerHuntsmanV3 extends AsProvider
i++; // unclear, might be something like "priority."
active_keys.push({
scancode: analogsense.razerScancodeToHidScancode(scancode),
value: value / 255
value: value / 255,
actuated: null
});
}
handler(active_keys);
Expand Down Expand Up @@ -575,7 +598,8 @@ class AsProviderDrunkdeer extends AsProvider
{
this.active_keys.push({
scancode: analogsense.drunkdeerIndexToHidScancode((n * (64 - 5)) + (i - 4)),
value: value / 40
value: value / 40,
actuated: null
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Once loaded, the following global functions become available:
- `analogsense.scancodeToString(scancode: number): string`

A device instance has the following members:
- `startListening(handler: function<void({scancode: int, value: float}[])>)`
- `startListening(handler: function<void({scancode: int, value: float, extra: {actuated: bool, socd: bool, rappy_snappy: bool} | null}[])>)`
- `stopListening()`
- `getProductName(): string`
- `forget()`
Expand Down
3 changes: 3 additions & 0 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ <h2 id="devname"></h2>
const bar = document.createElement("div");
bar.className = "progress-bar";
bar.style.width = (key.value * 100) + "%";
bar.style.backgroundColor = key.extra?.actuated ? "#7e28bf" : "";
bar.textContent = analogsense.scancodeToString(key.scancode);
if (key.extra?.socd) bar.textContent += " (socd enabled)";
if (key.extra?.rappy_snappy) bar.textContent += " (rappy snappy enabled)";
div.appendChild(bar);
}
document.getElementById("active-keys").appendChild(div);
Expand Down