barometer_bricklet

package
v0.0.0-...-368b749 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2024 License: CC0-1.0 Imports: 5 Imported by: 1

Documentation

Overview

Measures air pressure and altitude changes.

See also the documentation here: https://www.tinkerforge.com/en/doc/Software/Bricklets/Barometer_Bricklet_Go.html.

Index

Constants

View Source
const DeviceDisplayName = "Barometer Bricklet"
View Source
const DeviceIdentifier = 221

Variables

This section is empty.

Functions

This section is empty.

Types

type BarometerBricklet

type BarometerBricklet struct {
	// contains filtered or unexported fields
}

func New

Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ipcon` is connected.

func (*BarometerBricklet) DeregisterAirPressureCallback

func (device *BarometerBricklet) DeregisterAirPressureCallback(registrationId uint64)

Remove a registered Air Pressure callback.

func (*BarometerBricklet) DeregisterAirPressureReachedCallback

func (device *BarometerBricklet) DeregisterAirPressureReachedCallback(registrationId uint64)

Remove a registered Air Pressure Reached callback.

func (*BarometerBricklet) DeregisterAltitudeCallback

func (device *BarometerBricklet) DeregisterAltitudeCallback(registrationId uint64)

Remove a registered Altitude callback.

func (*BarometerBricklet) DeregisterAltitudeReachedCallback

func (device *BarometerBricklet) DeregisterAltitudeReachedCallback(registrationId uint64)

Remove a registered Altitude Reached callback.

func (*BarometerBricklet) GetAPIVersion

func (device *BarometerBricklet) GetAPIVersion() [3]uint8

Returns the version of the API definition (major, minor, revision) implemented by this API bindings. This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.

func (*BarometerBricklet) GetAirPressure

func (device *BarometerBricklet) GetAirPressure() (airPressure int32, err error)

Returns the air pressure of the air pressure sensor.

If you want to get the air pressure periodically, it is recommended to use the RegisterAirPressureCallback callback and set the period with SetAirPressureCallbackPeriod.

func (*BarometerBricklet) GetAirPressureCallbackPeriod

func (device *BarometerBricklet) GetAirPressureCallbackPeriod() (period uint32, err error)

Returns the period as set by SetAirPressureCallbackPeriod.

func (*BarometerBricklet) GetAirPressureCallbackThreshold

func (device *BarometerBricklet) GetAirPressureCallbackThreshold() (option ThresholdOption, min int32, max int32, err error)

Returns the threshold as set by SetAirPressureCallbackThreshold.

Associated constants:

  • ThresholdOptionOff
  • ThresholdOptionOutside
  • ThresholdOptionInside
  • ThresholdOptionSmaller
  • ThresholdOptionGreater

func (*BarometerBricklet) GetAltitude

func (device *BarometerBricklet) GetAltitude() (altitude int32, err error)

Returns the relative altitude of the air pressure sensor. The value is calculated based on the difference between the current air pressure and the reference air pressure that can be set with SetReferenceAirPressure.

If you want to get the altitude periodically, it is recommended to use the RegisterAltitudeCallback callback and set the period with SetAltitudeCallbackPeriod.

func (*BarometerBricklet) GetAltitudeCallbackPeriod

func (device *BarometerBricklet) GetAltitudeCallbackPeriod() (period uint32, err error)

Returns the period as set by SetAltitudeCallbackPeriod.

func (*BarometerBricklet) GetAltitudeCallbackThreshold

func (device *BarometerBricklet) GetAltitudeCallbackThreshold() (option ThresholdOption, min int32, max int32, err error)

Returns the threshold as set by SetAltitudeCallbackThreshold.

Associated constants:

  • ThresholdOptionOff
  • ThresholdOptionOutside
  • ThresholdOptionInside
  • ThresholdOptionSmaller
  • ThresholdOptionGreater

func (*BarometerBricklet) GetAveraging

func (device *BarometerBricklet) GetAveraging() (movingAveragePressure uint8, averagePressure uint8, averageTemperature uint8, err error)

Returns the averaging configuration as set by SetAveraging.

.. versionadded:: 2.0.1$nbsp;(Plugin)

func (*BarometerBricklet) GetChipTemperature

func (device *BarometerBricklet) GetChipTemperature() (temperature int16, err error)

Returns the temperature of the air pressure sensor.

This temperature is used internally for temperature compensation of the air pressure measurement. It is not as accurate as the temperature measured by the `temperature_bricklet` or the `temperature_ir_bricklet`.

func (*BarometerBricklet) GetDebouncePeriod

func (device *BarometerBricklet) GetDebouncePeriod() (debounce uint32, err error)

Returns the debounce period as set by SetDebouncePeriod.

func (*BarometerBricklet) GetI2CMode

func (device *BarometerBricklet) GetI2CMode() (mode I2CMode, err error)

Returns the I2C mode as set by SetI2CMode.

.. versionadded:: 2.0.3$nbsp;(Plugin)

Associated constants:

  • I2CModeFast
  • I2CModeSlow

func (*BarometerBricklet) GetIdentity

func (device *BarometerBricklet) GetIdentity() (uid string, connectedUid string, position rune, hardwareVersion [3]uint8, firmwareVersion [3]uint8, deviceIdentifier uint16, err error)

Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an `Isolator Bricklet <isolator_bricklet>` is always at position 'z'.

The device identifier numbers can be found `here <device_identifier>`. |device_identifier_constant|

func (*BarometerBricklet) GetReferenceAirPressure

func (device *BarometerBricklet) GetReferenceAirPressure() (airPressure int32, err error)

Returns the reference air pressure as set by SetReferenceAirPressure.

func (*BarometerBricklet) GetResponseExpected

func (device *BarometerBricklet) GetResponseExpected(functionID Function) (bool, error)

Returns the response expected flag for the function specified by the function ID parameter. It is true if the function is expected to send a response, false otherwise.

For getter functions this is enabled by default and cannot be disabled, because those functions will always send a response. For callback configuration functions it is enabled by default too, but can be disabled by SetResponseExpected. For setter functions it is disabled by default and can be enabled.

Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is sent and errors are silently ignored, because they cannot be detected.

See SetResponseExpected for the list of function ID constants available for this function.

func (*BarometerBricklet) RegisterAirPressureCallback

func (device *BarometerBricklet) RegisterAirPressureCallback(fn func(int32)) uint64

This callback is triggered periodically with the period that is set by SetAirPressureCallbackPeriod. The parameter is the air pressure of the air pressure sensor.

The RegisterAirPressureCallback callback is only triggered if the air pressure has changed since the last triggering.

func (*BarometerBricklet) RegisterAirPressureReachedCallback

func (device *BarometerBricklet) RegisterAirPressureReachedCallback(fn func(int32)) uint64

This callback is triggered when the threshold as set by SetAirPressureCallbackThreshold is reached. The parameter is the air pressure of the air pressure sensor.

If the threshold keeps being reached, the callback is triggered periodically with the period as set by SetDebouncePeriod.

func (*BarometerBricklet) RegisterAltitudeCallback

func (device *BarometerBricklet) RegisterAltitudeCallback(fn func(int32)) uint64

This callback is triggered periodically with the period that is set by SetAltitudeCallbackPeriod. The parameter is the altitude of the air pressure sensor.

The RegisterAltitudeCallback callback is only triggered if the altitude has changed since the last triggering.

func (*BarometerBricklet) RegisterAltitudeReachedCallback

func (device *BarometerBricklet) RegisterAltitudeReachedCallback(fn func(int32)) uint64

This callback is triggered when the threshold as set by SetAltitudeCallbackThreshold is reached. The parameter is the altitude of the air pressure sensor.

If the threshold keeps being reached, the callback is triggered periodically with the period as set by SetDebouncePeriod.

func (*BarometerBricklet) SetAirPressureCallbackPeriod

func (device *BarometerBricklet) SetAirPressureCallbackPeriod(period uint32) (err error)

Sets the period with which the RegisterAirPressureCallback callback is triggered periodically. A value of 0 turns the callback off.

The RegisterAirPressureCallback callback is only triggered if the air pressure has changed since the last triggering.

func (*BarometerBricklet) SetAirPressureCallbackThreshold

func (device *BarometerBricklet) SetAirPressureCallbackThreshold(option ThresholdOption, min int32, max int32) (err error)

Sets the thresholds for the RegisterAirPressureReachedCallback callback.

The following options are possible:

Option| Description
--- | ---
'x'|    Callback is turned off
'o'|    Callback is triggered when the air pressure is *outside* the min and max values
'i'|    Callback is triggered when the air pressure is *inside* the min and max values
'<'|    Callback is triggered when the air pressure is smaller than the min value (max is ignored)
'>'|    Callback is triggered when the air pressure is greater than the min value (max is ignored)

Associated constants:

  • ThresholdOptionOff
  • ThresholdOptionOutside
  • ThresholdOptionInside
  • ThresholdOptionSmaller
  • ThresholdOptionGreater

func (*BarometerBricklet) SetAltitudeCallbackPeriod

func (device *BarometerBricklet) SetAltitudeCallbackPeriod(period uint32) (err error)

Sets the period with which the RegisterAltitudeCallback callback is triggered periodically. A value of 0 turns the callback off.

The RegisterAltitudeCallback callback is only triggered if the altitude has changed since the last triggering.

func (*BarometerBricklet) SetAltitudeCallbackThreshold

func (device *BarometerBricklet) SetAltitudeCallbackThreshold(option ThresholdOption, min int32, max int32) (err error)

Sets the thresholds for the RegisterAltitudeReachedCallback callback.

The following options are possible:

Option| Description
--- | ---
'x'|    Callback is turned off
'o'|    Callback is triggered when the altitude is *outside* the min and max values
'i'|    Callback is triggered when the altitude is *inside* the min and max values
'<'|    Callback is triggered when the altitude is smaller than the min value (max is ignored)
'>'|    Callback is triggered when the altitude is greater than the min value (max is ignored)

Associated constants:

  • ThresholdOptionOff
  • ThresholdOptionOutside
  • ThresholdOptionInside
  • ThresholdOptionSmaller
  • ThresholdOptionGreater

func (*BarometerBricklet) SetAveraging

func (device *BarometerBricklet) SetAveraging(movingAveragePressure uint8, averagePressure uint8, averageTemperature uint8) (err error)

Sets the different averaging parameters. It is possible to set the length of a normal averaging for the temperature and pressure, as well as an additional length of a https://en.wikipedia.org/wiki/Moving_average for the pressure. The moving average is calculated from the normal averages. There is no moving average for the temperature.

Setting the all three parameters to 0 will turn the averaging completely off. If the averaging is off, there is lots of noise on the data, but the data is without delay. Thus we recommend to turn the averaging off if the Barometer Bricklet data is to be used for sensor fusion with other sensors.

.. versionadded:: 2.0.1$nbsp;(Plugin)

func (*BarometerBricklet) SetDebouncePeriod

func (device *BarometerBricklet) SetDebouncePeriod(debounce uint32) (err error)

Sets the period with which the threshold callbacks

* RegisterAirPressureReachedCallback, * RegisterAltitudeReachedCallback

are triggered, if the thresholds

* SetAirPressureCallbackThreshold, * SetAltitudeCallbackThreshold

keep being reached.

func (*BarometerBricklet) SetI2CMode

func (device *BarometerBricklet) SetI2CMode(mode I2CMode) (err error)

Sets the I2C mode. Possible modes are:

* 0: Fast (400kHz) * 1: Slow (100kHz)

If you have problems with obvious outliers in the Barometer Bricklet measurements, they may be caused by EMI issues. In this case it may be helpful to lower the I2C speed.

It is however not recommended to lower the I2C speed in applications where a high throughput needs to be achieved.

.. versionadded:: 2.0.3$nbsp;(Plugin)

Associated constants:

  • I2CModeFast
  • I2CModeSlow

func (*BarometerBricklet) SetReferenceAirPressure

func (device *BarometerBricklet) SetReferenceAirPressure(airPressure int32) (err error)

Sets the reference air pressure for the altitude calculation. Setting the reference to the current air pressure results in a calculated altitude of 0cm. Passing 0 is a shortcut for passing the current air pressure as reference.

Well known reference values are the Q codes https://en.wikipedia.org/wiki/QNH and https://en.wikipedia.org/wiki/Mean_sea_level_pressure#Mean_sea_level_pressure used in aviation.

func (*BarometerBricklet) SetResponseExpected

func (device *BarometerBricklet) SetResponseExpected(functionID Function, responseExpected bool) error

Changes the response expected flag of the function specified by the function ID parameter. This flag can only be changed for setter (default value: false) and callback configuration functions (default value: true). For getter functions it is always enabled.

Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is sent and errors are silently ignored, because they cannot be detected.

func (*BarometerBricklet) SetResponseExpectedAll

func (device *BarometerBricklet) SetResponseExpectedAll(responseExpected bool)

Changes the response expected flag for all setter and callback configuration functions of this device at once.

type Function

type Function = uint8
const (
	FunctionGetAirPressure                  Function = 1
	FunctionGetAltitude                     Function = 2
	FunctionSetAirPressureCallbackPeriod    Function = 3
	FunctionGetAirPressureCallbackPeriod    Function = 4
	FunctionSetAltitudeCallbackPeriod       Function = 5
	FunctionGetAltitudeCallbackPeriod       Function = 6
	FunctionSetAirPressureCallbackThreshold Function = 7
	FunctionGetAirPressureCallbackThreshold Function = 8
	FunctionSetAltitudeCallbackThreshold    Function = 9
	FunctionGetAltitudeCallbackThreshold    Function = 10
	FunctionSetDebouncePeriod               Function = 11
	FunctionGetDebouncePeriod               Function = 12
	FunctionSetReferenceAirPressure         Function = 13
	FunctionGetChipTemperature              Function = 14
	FunctionGetReferenceAirPressure         Function = 19
	FunctionSetAveraging                    Function = 20
	FunctionGetAveraging                    Function = 21
	FunctionSetI2CMode                      Function = 22
	FunctionGetI2CMode                      Function = 23
	FunctionGetIdentity                     Function = 255
	FunctionCallbackAirPressure             Function = 15
	FunctionCallbackAltitude                Function = 16
	FunctionCallbackAirPressureReached      Function = 17
	FunctionCallbackAltitudeReached         Function = 18
)

type I2CMode

type I2CMode = uint8
const (
	I2CModeFast I2CMode = 0
	I2CModeSlow I2CMode = 1
)

type ThresholdOption

type ThresholdOption = rune
const (
	ThresholdOptionOff     ThresholdOption = 'x'
	ThresholdOptionOutside ThresholdOption = 'o'
	ThresholdOptionInside  ThresholdOption = 'i'
	ThresholdOptionSmaller ThresholdOption = '<'
	ThresholdOptionGreater ThresholdOption = '>'
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL