// deviceMap.js export default class DeviceMap { constructor() { // Map of deviceIndex => { name, funscript, index } this.devices = new Map(); } // addDevice(device) { // if (this.devices.has(device.index)) return; // this.devices.set(device.index, { // name: device.name, // funscript: null, // }); // console.log(`[DeviceMap] Added device "${device.name}", index=${device.index}`); // } addDevice(device) { const scalarCmds = device._deviceInfo?.DeviceMessages?.ScalarCmd || []; const actuators = scalarCmds.map((cmd, i) => { return { name: `${device.name} - ${cmd.ActuatorType} #${cmd.Index + 1}`, type: cmd.ActuatorType, index: cmd.Index, reportedValue: cmd.Default ?? 0, // example, could use other reported info assignedFunscript: null, // initially empty }; }); this.devices.push({ name: device._deviceInfo.DeviceName, index: this.devices.length, actuators }); } removeDevice(device) { this.devices.delete(device.index); console.log(`[DeviceMap] Removed device "${device.name}"`); } getDevices() { // Return array for easy menu mapping return Array.from(this.devices.entries()).map(([index, { name, funscript }]) => ({ index, name, funscript, })); } assignFunscript(deviceIndex, funscript) { const d = this.devices.get(deviceIndex); if (!d) return; d.funscript = funscript; console.log(`[DeviceMap] Assigned funscript to "${d.name}"`); } }