go-api-bindings: github.com/Tinkerforge/go-api-bindings/color_bricklet Index | Files

package color_bricklet

import "github.com/Tinkerforge/go-api-bindings/color_bricklet"

Measures color (RGB value), illuminance and color temperature.

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

Index

Package Files

color_bricklet.go

Constants

const DeviceDisplayName = "Color Bricklet"
const DeviceIdentifier = 243

type ColorBricklet Uses

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

func New Uses

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

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

func (*ColorBricklet) DeregisterColorCallback Uses

func (device *ColorBricklet) DeregisterColorCallback(registrationId uint64)

Remove a registered Color callback.

func (*ColorBricklet) DeregisterColorReachedCallback Uses

func (device *ColorBricklet) DeregisterColorReachedCallback(registrationId uint64)

Remove a registered Color Reached callback.

func (*ColorBricklet) DeregisterColorTemperatureCallback Uses

func (device *ColorBricklet) DeregisterColorTemperatureCallback(registrationId uint64)

Remove a registered Color Temperature callback.

func (*ColorBricklet) DeregisterIlluminanceCallback Uses

func (device *ColorBricklet) DeregisterIlluminanceCallback(registrationId uint64)

Remove a registered Illuminance callback.

func (*ColorBricklet) GetAPIVersion Uses

func (device *ColorBricklet) 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 (*ColorBricklet) GetColor Uses

func (device *ColorBricklet) GetColor() (r uint16, g uint16, b uint16, c uint16, err error)

Returns the measured color of the sensor.

The red (r), green (g), blue (b) and clear (c) colors are measured with four different photodiodes that are responsive at different wavelengths:

.. image:: /Images/Bricklets/bricklet_color_wavelength_chart_600.jpg

:scale: 100 %
:alt: Chart Responsivity / Wavelength
:align: center
:target: ../../_images/Bricklets/bricklet_color_wavelength_chart_600.jpg

If you want to get the color periodically, it is recommended to use the RegisterColorCallback callback and set the period with SetColorCallbackPeriod.

func (*ColorBricklet) GetColorCallbackPeriod Uses

func (device *ColorBricklet) GetColorCallbackPeriod() (period uint32, err error)

Returns the period as set by SetColorCallbackPeriod.

func (*ColorBricklet) GetColorCallbackThreshold Uses

func (device *ColorBricklet) GetColorCallbackThreshold() (option ThresholdOption, minR uint16, maxR uint16, minG uint16, maxG uint16, minB uint16, maxB uint16, minC uint16, maxC uint16, err error)

Returns the threshold as set by SetColorCallbackThreshold.

Associated constants:

* ThresholdOptionOff
* ThresholdOptionOutside
* ThresholdOptionInside
* ThresholdOptionSmaller
* ThresholdOptionGreater

func (*ColorBricklet) GetColorTemperature Uses

func (device *ColorBricklet) GetColorTemperature() (colorTemperature uint16, err error)

Returns the color temperature.

To get a correct color temperature measurement make sure that the color values themselves are not saturated. The color value (R, G or B) is saturated if it is equal to the maximum value of 65535. In that case you have to reduce the gain, see SetConfig.

func (*ColorBricklet) GetColorTemperatureCallbackPeriod Uses

func (device *ColorBricklet) GetColorTemperatureCallbackPeriod() (period uint32, err error)

Returns the period as set by SetColorTemperatureCallbackPeriod.

func (*ColorBricklet) GetConfig Uses

func (device *ColorBricklet) GetConfig() (gain Gain, integrationTime IntegrationTime, err error)

Returns the configuration as set by SetConfig.

Associated constants:

* Gain1x
* Gain4x
* Gain16x
* Gain60x
* IntegrationTime2ms
* IntegrationTime24ms
* IntegrationTime101ms
* IntegrationTime154ms
* IntegrationTime700ms

func (*ColorBricklet) GetDebouncePeriod Uses

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

Returns the debounce period as set by SetDebouncePeriod.

func (*ColorBricklet) GetIdentity Uses

func (device *ColorBricklet) 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). The Raspberry Pi HAT (Zero) Brick is always at position 'i' and the Bricklet connected to an `Isolator Bricklet <isolator_bricklet>` is always as position 'z'.

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

func (*ColorBricklet) GetIlluminance Uses

func (device *ColorBricklet) GetIlluminance() (illuminance uint32, err error)

Returns the illuminance affected by the gain and integration time as set by SetConfig. To get the illuminance in Lux apply this formula::

lux = illuminance * 700 / gain / integration_time

To get a correct illuminance measurement make sure that the color values themselves are not saturated. The color value (R, G or B) is saturated if it is equal to the maximum value of 65535. In that case you have to reduce the gain, see SetConfig.

func (*ColorBricklet) GetIlluminanceCallbackPeriod Uses

func (device *ColorBricklet) GetIlluminanceCallbackPeriod() (period uint32, err error)

Returns the period as set by SetIlluminanceCallbackPeriod.

func (*ColorBricklet) GetResponseExpected Uses

func (device *ColorBricklet) 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 (*ColorBricklet) IsLightOn Uses

func (device *ColorBricklet) IsLightOn() (light Light, err error)

Returns the state of the LED. Possible values are:

* 0: On * 1: Off

Associated constants:

* LightOn
* LightOff

func (*ColorBricklet) LightOff Uses

func (device *ColorBricklet) LightOff() (err error)

Turns the LED off.

func (*ColorBricklet) LightOn Uses

func (device *ColorBricklet) LightOn() (err error)

Turns the LED on.

func (*ColorBricklet) RegisterColorCallback Uses

func (device *ColorBricklet) RegisterColorCallback(fn func(uint16, uint16, uint16, uint16)) uint64

This callback is triggered periodically with the period that is set by SetColorCallbackPeriod. The parameter is the color of the sensor as RGBC.

The RegisterColorCallback callback is only triggered if the color has changed since the last triggering.

func (*ColorBricklet) RegisterColorReachedCallback Uses

func (device *ColorBricklet) RegisterColorReachedCallback(fn func(uint16, uint16, uint16, uint16)) uint64

This callback is triggered when the threshold as set by SetColorCallbackThreshold is reached. The parameter is the color of the sensor as RGBC.

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

func (*ColorBricklet) RegisterColorTemperatureCallback Uses

func (device *ColorBricklet) RegisterColorTemperatureCallback(fn func(uint16)) uint64

This callback is triggered periodically with the period that is set by SetColorTemperatureCallbackPeriod. The parameter is the color temperature.

The RegisterColorTemperatureCallback callback is only triggered if the color temperature has changed since the last triggering.

func (*ColorBricklet) RegisterIlluminanceCallback Uses

func (device *ColorBricklet) RegisterIlluminanceCallback(fn func(uint32)) uint64

This callback is triggered periodically with the period that is set by SetIlluminanceCallbackPeriod. The parameter is the illuminance. See GetIlluminance for how to interpret this value.

The RegisterIlluminanceCallback callback is only triggered if the illuminance has changed since the last triggering.

func (*ColorBricklet) SetColorCallbackPeriod Uses

func (device *ColorBricklet) SetColorCallbackPeriod(period uint32) (err error)

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

The RegisterColorCallback callback is only triggered if the color has changed since the last triggering.

func (*ColorBricklet) SetColorCallbackThreshold Uses

func (device *ColorBricklet) SetColorCallbackThreshold(option ThresholdOption, minR uint16, maxR uint16, minG uint16, maxG uint16, minB uint16, maxB uint16, minC uint16, maxC uint16) (err error)

Sets the thresholds for the RegisterColorReachedCallback callback.

The following options are possible:

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

Associated constants:

* ThresholdOptionOff
* ThresholdOptionOutside
* ThresholdOptionInside
* ThresholdOptionSmaller
* ThresholdOptionGreater

func (*ColorBricklet) SetColorTemperatureCallbackPeriod Uses

func (device *ColorBricklet) SetColorTemperatureCallbackPeriod(period uint32) (err error)

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

The RegisterColorTemperatureCallback callback is only triggered if the color temperature has changed since the last triggering.

func (*ColorBricklet) SetConfig Uses

func (device *ColorBricklet) SetConfig(gain Gain, integrationTime IntegrationTime) (err error)

Sets the configuration of the sensor. Gain and integration time can be configured in this way.

For configuring the gain:

* 0: 1x Gain * 1: 4x Gain * 2: 16x Gain * 3: 60x Gain

For configuring the integration time:

* 0: 2.4ms * 1: 24ms * 2: 101ms * 3: 154ms * 4: 700ms

Increasing the gain enables the sensor to detect a color from a higher distance.

The integration time provides a trade-off between conversion time and accuracy. With a longer integration time the values read will be more accurate but it will take longer time to get the conversion results.

Associated constants:

* Gain1x
* Gain4x
* Gain16x
* Gain60x
* IntegrationTime2ms
* IntegrationTime24ms
* IntegrationTime101ms
* IntegrationTime154ms
* IntegrationTime700ms

func (*ColorBricklet) SetDebouncePeriod Uses

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

Sets the period with which the threshold callback

* RegisterColorReachedCallback

is triggered, if the threshold

* SetColorCallbackThreshold

keeps being reached.

func (*ColorBricklet) SetIlluminanceCallbackPeriod Uses

func (device *ColorBricklet) SetIlluminanceCallbackPeriod(period uint32) (err error)

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

The RegisterIlluminanceCallback callback is only triggered if the illuminance has changed since the last triggering.

func (*ColorBricklet) SetResponseExpected Uses

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

func (device *ColorBricklet) SetResponseExpectedAll(responseExpected bool)

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

type Function Uses

type Function = uint8
const (
    FunctionGetColor                          Function = 1
    FunctionSetColorCallbackPeriod            Function = 2
    FunctionGetColorCallbackPeriod            Function = 3
    FunctionSetColorCallbackThreshold         Function = 4
    FunctionGetColorCallbackThreshold         Function = 5
    FunctionSetDebouncePeriod                 Function = 6
    FunctionGetDebouncePeriod                 Function = 7
    FunctionLightOn                           Function = 10
    FunctionLightOff                          Function = 11
    FunctionIsLightOn                         Function = 12
    FunctionSetConfig                         Function = 13
    FunctionGetConfig                         Function = 14
    FunctionGetIlluminance                    Function = 15
    FunctionGetColorTemperature               Function = 16
    FunctionSetIlluminanceCallbackPeriod      Function = 17
    FunctionGetIlluminanceCallbackPeriod      Function = 18
    FunctionSetColorTemperatureCallbackPeriod Function = 19
    FunctionGetColorTemperatureCallbackPeriod Function = 20
    FunctionGetIdentity                       Function = 255
    FunctionCallbackColor                     Function = 8
    FunctionCallbackColorReached              Function = 9
    FunctionCallbackIlluminance               Function = 21
    FunctionCallbackColorTemperature          Function = 22
)

type Gain Uses

type Gain = uint8
const (
    Gain1x  Gain = 0
    Gain4x  Gain = 1
    Gain16x Gain = 2
    Gain60x Gain = 3
)

type IntegrationTime Uses

type IntegrationTime = uint8
const (
    IntegrationTime2ms   IntegrationTime = 0
    IntegrationTime24ms  IntegrationTime = 1
    IntegrationTime101ms IntegrationTime = 2
    IntegrationTime154ms IntegrationTime = 3
    IntegrationTime700ms IntegrationTime = 4
)

type Light Uses

type Light = uint8
const (
    LightOn  Light = 0
    LightOff Light = 1
)

type ThresholdOption Uses

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

Package color_bricklet imports 5 packages (graph). Updated 2020-05-23. Refresh now. Tools for package owners.