co2_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: 0

Documentation

Overview

Measures CO2 concentration in ppm.

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

Index

Constants

View Source
const DeviceDisplayName = "CO2 Bricklet"
View Source
const DeviceIdentifier = 262

Variables

This section is empty.

Functions

This section is empty.

Types

type CO2Bricklet

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

func New

func New(uid string, ipcon *ipconnection.IPConnection) (CO2Bricklet, error)

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

func (*CO2Bricklet) DeregisterCO2ConcentrationCallback

func (device *CO2Bricklet) DeregisterCO2ConcentrationCallback(registrationId uint64)

Remove a registered CO2 Concentration callback.

func (*CO2Bricklet) DeregisterCO2ConcentrationReachedCallback

func (device *CO2Bricklet) DeregisterCO2ConcentrationReachedCallback(registrationId uint64)

Remove a registered CO2 Concentration Reached callback.

func (*CO2Bricklet) GetAPIVersion

func (device *CO2Bricklet) 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 (*CO2Bricklet) GetCO2Concentration

func (device *CO2Bricklet) GetCO2Concentration() (co2Concentration uint16, err error)

Returns the measured CO2 concentration.

If you want to get the CO2 concentration periodically, it is recommended to use the RegisterCO2ConcentrationCallback callback and set the period with SetCO2ConcentrationCallbackPeriod.

func (*CO2Bricklet) GetCO2ConcentrationCallbackPeriod

func (device *CO2Bricklet) GetCO2ConcentrationCallbackPeriod() (period uint32, err error)

Returns the period as set by SetCO2ConcentrationCallbackPeriod.

func (*CO2Bricklet) GetCO2ConcentrationCallbackThreshold

func (device *CO2Bricklet) GetCO2ConcentrationCallbackThreshold() (option ThresholdOption, min uint16, max uint16, err error)

Returns the threshold as set by SetCO2ConcentrationCallbackThreshold.

Associated constants:

  • ThresholdOptionOff
  • ThresholdOptionOutside
  • ThresholdOptionInside
  • ThresholdOptionSmaller
  • ThresholdOptionGreater

func (*CO2Bricklet) GetDebouncePeriod

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

Returns the debounce period as set by SetDebouncePeriod.

func (*CO2Bricklet) GetIdentity

func (device *CO2Bricklet) 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 (*CO2Bricklet) GetResponseExpected

func (device *CO2Bricklet) 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 (*CO2Bricklet) RegisterCO2ConcentrationCallback

func (device *CO2Bricklet) RegisterCO2ConcentrationCallback(fn func(uint16)) uint64

This callback is triggered periodically with the period that is set by SetCO2ConcentrationCallbackPeriod. The parameter is the CO2 concentration of the sensor.

The RegisterCO2ConcentrationCallback callback is only triggered if the CO2 concentration has changed since the last triggering.

func (*CO2Bricklet) RegisterCO2ConcentrationReachedCallback

func (device *CO2Bricklet) RegisterCO2ConcentrationReachedCallback(fn func(uint16)) uint64

This callback is triggered when the threshold as set by SetCO2ConcentrationCallbackThreshold is reached. The parameter is the CO2 concentration.

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

func (*CO2Bricklet) SetCO2ConcentrationCallbackPeriod

func (device *CO2Bricklet) SetCO2ConcentrationCallbackPeriod(period uint32) (err error)

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

The RegisterCO2ConcentrationCallback callback is only triggered if the CO2 concentration has changed since the last triggering.

func (*CO2Bricklet) SetCO2ConcentrationCallbackThreshold

func (device *CO2Bricklet) SetCO2ConcentrationCallbackThreshold(option ThresholdOption, min uint16, max uint16) (err error)

Sets the thresholds for the RegisterCO2ConcentrationReachedCallback callback.

The following options are possible:

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

Associated constants:

  • ThresholdOptionOff
  • ThresholdOptionOutside
  • ThresholdOptionInside
  • ThresholdOptionSmaller
  • ThresholdOptionGreater

func (*CO2Bricklet) SetDebouncePeriod

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

Sets the period with which the threshold callbacks

* RegisterCO2ConcentrationReachedCallback,

are triggered, if the thresholds

* SetCO2ConcentrationCallbackThreshold,

keep being reached.

func (*CO2Bricklet) SetResponseExpected

func (device *CO2Bricklet) 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 (*CO2Bricklet) SetResponseExpectedAll

func (device *CO2Bricklet) 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 (
	FunctionGetCO2Concentration                  Function = 1
	FunctionSetCO2ConcentrationCallbackPeriod    Function = 2
	FunctionGetCO2ConcentrationCallbackPeriod    Function = 3
	FunctionSetCO2ConcentrationCallbackThreshold Function = 4
	FunctionGetCO2ConcentrationCallbackThreshold Function = 5
	FunctionSetDebouncePeriod                    Function = 6
	FunctionGetDebouncePeriod                    Function = 7
	FunctionGetIdentity                          Function = 255
	FunctionCallbackCO2Concentration             Function = 8
	FunctionCallbackCO2ConcentrationReached      Function = 9
)

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