- 14 Oct 2024
- 1 Minute to read
- Print
Implementing an Adapter
- Updated on 14 Oct 2024
- 1 Minute to read
- Print
Implementing Nexmosphere Sensors on a Device
Supporting a new sensor requires a new “adapter“:
Decide on a prefix, e.g. “xprecipitation_“.
Add a new adapter class, e.g. “PrecipitationAdapter“ which subclasses “BaseAdapter“.
Add a new Options-interface, with the same naming-convention.
Use the same constructor-signature as the other adapters, but change the type of Options to your new one.
In the constructor, set this.filterExp to a RegEx which filters out the messages you want from the serial-interface.
Implement dataHandler as a listener, this should call this.onData() with the supplied text-fragment and loop on the array returned from this.popNewMessages(). After the call, the buffer is clamped, so you will never receive the same data more than once.
Add your adapter to the SENSOR_ORDER array in “Nexmosphere.ts“ with the new prefix and class/interface naming.
Call this.setAttribute() to update the Player.
If you need input-attributes for customization, implement onAttribute(attr: Dise.Attribute) => void in your class. Keep in mind that only attributes of the “nexmosphere“ type are filtered to you, and that you will receive all of these, so additional filtering on the name will need to be done.
Hosting More Than One Sensor of the Same Type on a Player
The “prefix” of options and input-attributes (e.g. the LED-commands to the Buttons-adapter) will be expected to be suffixed by an ordinal for all but the first one. For example, with two controllers, connected to different USB-ports:
Content.json:
[
{
"port": "COM3",
"xtB4N6_sensorAddress": 1,
"xtB4N6_btn1attributeName": "oneshot.Btn1",
"xtB4N6_btn4attributeName": "oneshot.Btn2",
"xtB4N6_2_sensorAddress": 2,
"xtB4N6_2_btn1attributeName": "oneshot.Btn3",
"xtB4N6_3_port": "COM4",
"xtB4N6_3_sensorAddress": 1,
"xtB4N6_3_btn1attributeName": "oneshot.Btn4",
"xtB4N6_4_port": "COM4",
"xtB4N6_4_sensorAddress": 2,
"xtB4N6_4_btn2attributeName": "oneshot.Btn5",
}
]
“port” is mandatory.
The handling of input-attributes expect the name to be prefixed by the same ordinal, so “button 1“ in this case, will listen to the “nexmosphere.BtnLEDs“ while “button 4“ will listen for “nexmosphere.4_BtnLEDs“.
“template.json“ will have to match this setup.