-
Notifications
You must be signed in to change notification settings - Fork 11
Description
I wanted to bring @rwaldron into this discussion because I know it is something he has dealt with in the past and he may have some insight that will be valuable.
Rick, since ECMA-419 is now a real live spec the committee is moving on to some new things to complement it. One of those things is a collection of hardware component class specifications. Obviously, you've got some experience there and a question that came up that seems very similar to some discussions we've had in the past so I thought it would be smart to bring you in.
I've pasted the relevant bits from our August meeting below.
Excerpt from August Meeting Notes
PH: Looking at the LSM303DLHC Accelerometer & Magnetometer sensor. This is actually a compound sensor. It incorporates 2+ sensors in one package. This one has an accelerometer and a magnetometer.
PH: We went around on how to handle this in the past. This one takes a physical package for two components and integrates them into one package. It’s weird but not uncommon.
PH: In this draft, we decided not to have a new module for the part number because we can address each sensor class directly. We did draft a document explaining how to use the part number and how to instantiate, configure, and sample each sensor type. In this case, for example, the I2C address is different in the combined package vs the constituent packages, so we did make a note of that.
PH: Thoughts on if this is the right way to handle this?
PH: Now there’s another compound sensor, the MPU9250, which is implemented in a different way. Here, it looks like one sensor with multiple different parameters - an accelerometer, a gyroscope, and a magnetometer accessible via pass-through communication.
PH: Both the accelerometer and gyroscope are returned in one sample object.
PH: What I don’t like about this is that X, Y, Z is repeated twice with X, gyroX, etc. It’s messy. We could do sample.accelerometer.x, sample.gyroscope.x, and so on to avoid naming conflicts.
AC: In the Moddable SDK, we configure whether you want the accelerometer or gyroscope coming back. We don’t support getting both at the same time. But if you want to get both, making them into sub-objects seems correct.
DB: Agreed.
PH: In other cases, sensors like the AHT10 can get into messy naming. We need to access humidity.humidity and temperature.temperature, for example, to avoid naming conflicts.
DB: A sensor actually reports an ADC value; would we instead have humidity.value?
PH: Yes, we could, though the current property name is humidity because conversion is done within the class itself.
AC: And value versus raw may not extend to other sensor types, e.g. x_raw vs. x_value.
Questions for Rick
When a compound sensor wraps two components that are addressed directly is there value in wrapping them in a single class for the device?
When reading a sample from a compound sensor should the data be flat or should each component be its own property of the sample?
Property | Description |
---|---|
x |
A number representing the acceleration along the X-axis in m/s² |
y |
A number representing the acceleration along the Y-axis in m/s² |
z |
A number representing the acceleration along the Z-axis in m/s² |
gyroX |
A number representing the rotation along the X-axis in º/s |
gyroY |
A number representing the rotation along the Y-axis in º/s |
gyroZ |
A number representing the rotation along the Z-axis in º/s |
vs.
Property | Description |
---|---|
`accelerometer | An object containing the accelerometer's sample data |
accelerometer.x |
A number representing the acceleration along the X-axis in m/s² |
accelerometer.y |
A number representing the acceleration along the Y-axis in m/s² |
accelerometer.z |
A number representing the acceleration along the Z-axis in m/s² |
`gyroscope | An object containing the gyroscope's sample data |
gyroscope.x |
A number representing the rotation along the X-axis in º/s |
gyroscope.y |
A number representing the rotation along the Y-axis in º/s |
gyroscope.z |
A number representing the rotation along the Z-axis in º/s |
Johnny-Five does the latter.
And what about the humidity.humidity
situation? @phoddie can you remind me why humidity
needs to be an object. It's not clear to me how there might be a naming conflict. A quick note, a humidity sensor is a hygrometer so it should probably be hygrometer.humidity
or hygrometer.relativeHumidity