Skip to content

Driver design API

Ayke edited this page Jan 28, 2019 · 7 revisions

Proposal for driver design

Drivers vary greatly in their complexity. Here is a WIP proposal for an API.

Simple sensors

type TemperatureSensor interface {
    // ReadTemperature returns the current temperature in milli-degrees
    // Celsius. For example, 25°C is returned as 25000.
    ReadTemperature() (int32, error)
}

type RelativeHumiditySensor interface {
    // ReadRelativeHumidity returns the current humidity (0%-100%) in
    // promilles.
    // Rationale: even very precise humidity sensors rarely go below 1%
    // accuracy so providing more accuracy isn't very useful.
    ReadRelativeHumidity() (int16, error)
}

More complex sensors

type AccelerationSensor interface {
    // ReadAcceleration returns the current acceleration in µm/s².
    // Note: this is more precise than returning gravity, because gravity
    // varies by location.
    // The unit µm/s² is used because it captures the precision of most
    // sensors, unlike mm/s².
    ReadAcceleration() (x int32, y int32, z int32, err error)
}

type RotationSensor interface {
    // TODO
    ReadRotation() (x int32, y int32, z int32, err error)
}

Displays

Sensor fusion

type SensorFusionAlgorithm interface {
    UpdateAcceleration(x, y, z int32)
    UpdateRotation(x, y, z int32)

    // Orientation returns the current rotation quaternion.
    Orientation() (x, y, z, w int32)
}
Clone this wiki locally