IO defining/extending a device target? #927
-
|
Wrote a Question: While writing this I was making an example, but couldn't find any guidance of how to define the device. Is this meant to extend the https://github.com/Templarian/moddable/blob/joycon/examples/drivers/sensors/joycon/main.js#L51 Off topic:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Apologies for being a little slow to get to this. The driver looks great! (For completeness on close it should close the two analog instances to free up the memory and release the pins.)
What you've done here is reasonable. Building the device is often a bit ad-hoc when adding peripherals to an existing device. We did something similar for our recent network protocol work (HTTP, WebSocket, etc). A host provider for an actual device with a built-in joystick would do this directly. For sensors, the way we like to set-up the device is a bit different. More or less, the goal is to allow instantiation with something like: js = new device.sensor.Joycon;A good example of that style is the temperature and humidity sensor built into the M5Paper. In your case, that might look something like this: device.sensor ?? = {};
device.sensor.Joycon = class {
constructor(options) {
new Joycon({
...options,
x: {
io: device.io.Analog,
pin: device.pin.joystickX
},
y: {
io: device.io.Analog,
pin: device.pin.joystickY
}
});
}
};You might not even define
That's the plan. We're moving to phase out pins (which is how the old Button is implemented) is favor of the ECMA-419 IO.
Yes! It would be great to have a PR for this so anyone who needs a basic analog joystick controller doesn't need to start over. |
Beta Was this translation helpful? Give feedback.
Apologies for being a little slow to get to this.
The driver looks great! (For completeness on close it should close the two analog instances to free up the memory and release the pins.)
What you've done here is reasonable. Building the device is often a bit ad-hoc when adding peripherals to an existing device. We did something similar for our recent network protocol work (HTTP, WebSocket, etc). A host provider for an actual device with a built-in joystick would do this …