dual_button_bricklet

package
Version: v0.0.0-...-1640943 Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: CC0-1.0 Imports: 5 Imported by: 0

Documentation

Overview

Two tactile buttons with built-in blue LEDs.

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

Index

Constants

View Source
const DeviceDisplayName = "Dual Button Bricklet"
View Source
const DeviceIdentifier = 230

Variables

This section is empty.

Functions

This section is empty.

Types

type ButtonState

type ButtonState = uint8
const (
	ButtonStatePressed  ButtonState = 0
	ButtonStateReleased ButtonState = 1
)

type DualButtonBricklet

type DualButtonBricklet 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 (*DualButtonBricklet) DeregisterStateChangedCallback

func (device *DualButtonBricklet) DeregisterStateChangedCallback(registrationId uint64)

Remove a registered State Changed callback.

func (*DualButtonBricklet) GetAPIVersion

func (device *DualButtonBricklet) 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 (*DualButtonBricklet) GetButtonState

func (device *DualButtonBricklet) GetButtonState() (buttonL ButtonState, buttonR ButtonState, err error)

Returns the current state for both buttons. Possible states are:

* 0 = pressed * 1 = released

Associated constants:

* ButtonStatePressed
* ButtonStateReleased

func (*DualButtonBricklet) GetIdentity

func (device *DualButtonBricklet) 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 (*DualButtonBricklet) GetLEDState

func (device *DualButtonBricklet) GetLEDState() (ledL LEDState, ledR LEDState, err error)

Returns the current state of the LEDs, as set by SetLEDState.

Associated constants:

* LEDStateAutoToggleOn
* LEDStateAutoToggleOff
* LEDStateOn
* LEDStateOff

func (*DualButtonBricklet) GetResponseExpected

func (device *DualButtonBricklet) 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 (*DualButtonBricklet) RegisterStateChangedCallback

func (device *DualButtonBricklet) RegisterStateChangedCallback(fn func(ButtonState, ButtonState, LEDState, LEDState)) uint64

This callback is called whenever a button is pressed.

Possible states for buttons are:

* 0 = pressed * 1 = released

Possible states for LEDs are:

* 0 = AutoToggleOn: Auto toggle enabled and LED on. * 1 = AutoToggleOff: Auto toggle enabled and LED off. * 2 = On: LED on (auto toggle is disabled). * 3 = Off: LED off (auto toggle is disabled).

func (*DualButtonBricklet) SetLEDState

func (device *DualButtonBricklet) SetLEDState(ledL LEDState, ledR LEDState) (err error)

Sets the state of the LEDs. Possible states are:

* 0 = AutoToggleOn: Enables auto toggle with initially enabled LED. * 1 = AutoToggleOff: Activates auto toggle with initially disabled LED. * 2 = On: Enables LED (auto toggle is disabled). * 3 = Off: Disables LED (auto toggle is disabled).

In auto toggle mode the LED is toggled automatically at each press of a button.

If you just want to set one of the LEDs and don't know the current state of the other LED, you can get the state with GetLEDState or you can use SetSelectedLEDState.

Associated constants:

* LEDStateAutoToggleOn
* LEDStateAutoToggleOff
* LEDStateOn
* LEDStateOff

func (*DualButtonBricklet) SetResponseExpected

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

func (device *DualButtonBricklet) SetResponseExpectedAll(responseExpected bool)

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

func (*DualButtonBricklet) SetSelectedLEDState

func (device *DualButtonBricklet) SetSelectedLEDState(led LED, state LEDState) (err error)

Sets the state of the selected LED (0 or 1).

The other LED remains untouched.

Associated constants:

* LEDLeft
* LEDRight
* LEDStateAutoToggleOn
* LEDStateAutoToggleOff
* LEDStateOn
* LEDStateOff

type Function

type Function = uint8
const (
	FunctionSetLEDState          Function = 1
	FunctionGetLEDState          Function = 2
	FunctionGetButtonState       Function = 3
	FunctionSetSelectedLEDState  Function = 5
	FunctionGetIdentity          Function = 255
	FunctionCallbackStateChanged Function = 4
)

type LED

type LED = uint8
const (
	LEDLeft  LED = 0
	LEDRight LED = 1
)

type LEDState

type LEDState = uint8
const (
	LEDStateAutoToggleOn  LEDState = 0
	LEDStateAutoToggleOff LEDState = 1
	LEDStateOn            LEDState = 2
	LEDStateOff           LEDState = 3
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL