hall_effect_bricklet

package
v0.0.0-...-8a98e63 Latest Latest
Warning

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

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

Documentation

Overview

Detects presence of magnetic field.

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

Index

Constants

View Source
const DeviceDisplayName = "Hall Effect Bricklet"
View Source
const DeviceIdentifier = 240

Variables

This section is empty.

Functions

This section is empty.

Types

type EdgeType

type EdgeType = uint8
const (
	EdgeTypeRising  EdgeType = 0
	EdgeTypeFalling EdgeType = 1
	EdgeTypeBoth    EdgeType = 2
)

type Function

type Function = uint8
const (
	FunctionGetValue                   Function = 1
	FunctionGetEdgeCount               Function = 2
	FunctionSetEdgeCountConfig         Function = 3
	FunctionGetEdgeCountConfig         Function = 4
	FunctionSetEdgeInterrupt           Function = 5
	FunctionGetEdgeInterrupt           Function = 6
	FunctionSetEdgeCountCallbackPeriod Function = 7
	FunctionGetEdgeCountCallbackPeriod Function = 8
	FunctionEdgeInterrupt              Function = 9
	FunctionGetIdentity                Function = 255
	FunctionCallbackEdgeCount          Function = 10
)

type HallEffectBricklet

type HallEffectBricklet 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 (*HallEffectBricklet) DeregisterEdgeCountCallback

func (device *HallEffectBricklet) DeregisterEdgeCountCallback(registrationId uint64)

Remove a registered Edge Count callback.

func (*HallEffectBricklet) EdgeInterrupt

func (device *HallEffectBricklet) EdgeInterrupt() (count uint32, value bool, err error)

This callback is triggered every n-th count, as configured with SetEdgeInterrupt. The parameters are the current count and the current value (see GetValue and GetEdgeCount).

func (*HallEffectBricklet) GetAPIVersion

func (device *HallEffectBricklet) 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 (*HallEffectBricklet) GetEdgeCount

func (device *HallEffectBricklet) GetEdgeCount(resetCounter bool) (count uint32, err error)

Returns the current value of the edge counter. You can configure edge type (rising, falling, both) that is counted with SetEdgeCountConfig.

If you set the reset counter to *true*, the count is set back to 0 directly after it is read.

func (*HallEffectBricklet) GetEdgeCountCallbackPeriod

func (device *HallEffectBricklet) GetEdgeCountCallbackPeriod() (period uint32, err error)

Returns the period as set by SetEdgeCountCallbackPeriod.

func (*HallEffectBricklet) GetEdgeCountConfig

func (device *HallEffectBricklet) GetEdgeCountConfig() (edgeType EdgeType, debounce uint8, err error)

Returns the edge type and debounce time as set by SetEdgeCountConfig.

Associated constants:

  • EdgeTypeRising
  • EdgeTypeFalling
  • EdgeTypeBoth

func (*HallEffectBricklet) GetEdgeInterrupt

func (device *HallEffectBricklet) GetEdgeInterrupt() (edges uint32, err error)

Returns the edges as set by SetEdgeInterrupt.

func (*HallEffectBricklet) GetIdentity

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

func (device *HallEffectBricklet) 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 (*HallEffectBricklet) GetValue

func (device *HallEffectBricklet) GetValue() (value bool, err error)

Returns *true* if a magnetic field of 3.5 millitesla or greater is detected.

func (*HallEffectBricklet) RegisterEdgeCountCallback

func (device *HallEffectBricklet) RegisterEdgeCountCallback(fn func(uint32, bool)) uint64

This callback is triggered periodically with the period that is set by SetEdgeCountCallbackPeriod. The parameters are the current count and the current value (see GetValue and GetEdgeCount).

The RegisterEdgeCountCallback callback is only triggered if the count or value changed since the last triggering.

func (*HallEffectBricklet) SetEdgeCountCallbackPeriod

func (device *HallEffectBricklet) SetEdgeCountCallbackPeriod(period uint32) (err error)

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

The RegisterEdgeCountCallback callback is only triggered if the edge count has changed since the last triggering.

func (*HallEffectBricklet) SetEdgeCountConfig

func (device *HallEffectBricklet) SetEdgeCountConfig(edgeType EdgeType, debounce uint8) (err error)

The edge type parameter configures if rising edges, falling edges or both are counted. Possible edge types are:

* 0 = rising * 1 = falling * 2 = both

A magnetic field of 3.5 millitesla or greater causes a falling edge and a magnetic field of 2.5 millitesla or smaller causes a rising edge.

If a magnet comes near the Bricklet the signal goes low (falling edge), if a magnet is removed from the vicinity the signal goes high (rising edge).

Configuring an edge counter resets its value to 0.

If you don't know what any of this means, just leave it at default. The default configuration is very likely OK for you.

Associated constants:

  • EdgeTypeRising
  • EdgeTypeFalling
  • EdgeTypeBoth

func (*HallEffectBricklet) SetEdgeInterrupt

func (device *HallEffectBricklet) SetEdgeInterrupt(edges uint32) (err error)

Sets the number of edges until an interrupt is invoked.

If *edges* is set to n, an interrupt is invoked for every n-th detected edge.

If *edges* is set to 0, the interrupt is disabled.

func (*HallEffectBricklet) SetResponseExpected

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

func (device *HallEffectBricklet) SetResponseExpectedAll(responseExpected bool)

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

Jump to

Keyboard shortcuts

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