Re: [magnetometer] Add RawMagnetometer, for uncalibrated readings.

@kenchris strictly speaking, magnetometer is an environmental sensor, as it is not measuring units of motion :-)

Promised to @anssiko to add technical / API design details for interface split:

Interfaces should clearly define model, operations and data that is provided by the implementation of the interface. If model, behavior or type of the data defined by the interface can be changed by construction parameter, it is a good design practice to split interface in favor of runtime variation.

**Pros**
 - Improves encapsulation. No need to dig into internals of the interface instance to understand what it is.
```
if (m1 instanceof Magnetometer && m2 instanceof Magnetometer
    && m1.isCalibrated && m2.isCalibrated) {
        console.log(“Ahoy! We have two calibrated magnetometers”); 
}
```

- Easier to manage different types of sensors in the future, e.g.,
```
SensorManager.onSensorConnected = sensor => { 
    if (sensor instanceof UncalibratedManetometer) { 
       enableCoolFeature(); 
    } 
}

```
 - Improves error handling and in our case, feature detection.
```
Magnetometer.start(); // fails with NotSupported => sensor not supported
UncalibratedMagnetometer.start(); // fails with NotSupported => sensor not supported

// confusing and error prone need to handle multiple error conditions,
// deviates from other sensor specs.
Magnetometer({avoidHardIronCalibration: true}).start(); => ?

```
- There could be cases when only [uncalibrated magnetometer](http://www.mouser.com/ds/2/196/Infineon-TLV493D-A1B6-DS-v01_00-EN-890494.pdf) is present in the system  therefore `Magnetometer.start()` should fail and `Magnetometer({avoidHardIronCalibration: true}).start()` should succeed, again, better to separate interfaces.

**Cons**
 - Increase of API surface area.
 - Might require more permission tokens / grouping by data type.

On a side note, we should also rethink (improve) 1:1 mapping and low-level sensors concept. There are sensors that fall under ‘fusion sensor’ category, yet they are hw sensors that provide, e.g., [simple orientation](http://www.mouser.com/ds/2/389/CD00199092-251158.pdf) or complex [6DoF](http://www.mouser.com/ds/2/149/FIS1100-611030.pdf) sensors that fuse data internally and provide quaternions.

-- 
GitHub Notification of comment by alexshalamov
Please view or discuss this issue at https://github.com/w3c/magnetometer/pull/21#issuecomment-300767961 using your GitHub account

Received on Thursday, 11 May 2017 12:04:05 UTC