led_strip_v2_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

Controls up to 2048 RGB(W) LEDs.

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

Index

Constants

View Source
const DeviceDisplayName = "LED Strip Bricklet 2.0"
View Source
const DeviceIdentifier = 2103

Variables

This section is empty.

Functions

This section is empty.

Types

type BootloaderMode

type BootloaderMode = uint8
const (
	BootloaderModeBootloader                    BootloaderMode = 0
	BootloaderModeFirmware                      BootloaderMode = 1
	BootloaderModeBootloaderWaitForReboot       BootloaderMode = 2
	BootloaderModeFirmwareWaitForReboot         BootloaderMode = 3
	BootloaderModeFirmwareWaitForEraseAndReboot BootloaderMode = 4
)

type BootloaderStatus

type BootloaderStatus = uint8
const (
	BootloaderStatusOK                        BootloaderStatus = 0
	BootloaderStatusInvalidMode               BootloaderStatus = 1
	BootloaderStatusNoChange                  BootloaderStatus = 2
	BootloaderStatusEntryFunctionNotPresent   BootloaderStatus = 3
	BootloaderStatusDeviceIdentifierIncorrect BootloaderStatus = 4
	BootloaderStatusCRCMismatch               BootloaderStatus = 5
)

type ChannelMapping

type ChannelMapping = uint8
const (
	ChannelMappingRGB  ChannelMapping = 6
	ChannelMappingRBG  ChannelMapping = 9
	ChannelMappingBRG  ChannelMapping = 33
	ChannelMappingBGR  ChannelMapping = 36
	ChannelMappingGRB  ChannelMapping = 18
	ChannelMappingGBR  ChannelMapping = 24
	ChannelMappingRGBW ChannelMapping = 27
	ChannelMappingRGWB ChannelMapping = 30
	ChannelMappingRBGW ChannelMapping = 39
	ChannelMappingRBWG ChannelMapping = 45
	ChannelMappingRWGB ChannelMapping = 54
	ChannelMappingRWBG ChannelMapping = 57
	ChannelMappingGRWB ChannelMapping = 78
	ChannelMappingGRBW ChannelMapping = 75
	ChannelMappingGBWR ChannelMapping = 108
	ChannelMappingGBRW ChannelMapping = 99
	ChannelMappingGWBR ChannelMapping = 120
	ChannelMappingGWRB ChannelMapping = 114
	ChannelMappingBRGW ChannelMapping = 135
	ChannelMappingBRWG ChannelMapping = 141
	ChannelMappingBGRW ChannelMapping = 147
	ChannelMappingBGWR ChannelMapping = 156
	ChannelMappingBWRG ChannelMapping = 177
	ChannelMappingBWGR ChannelMapping = 180
	ChannelMappingWRBG ChannelMapping = 201
	ChannelMappingWRGB ChannelMapping = 198
	ChannelMappingWGBR ChannelMapping = 216
	ChannelMappingWGRB ChannelMapping = 210
	ChannelMappingWBGR ChannelMapping = 228
	ChannelMappingWBRG ChannelMapping = 225
)

type ChipType

type ChipType = uint16
const (
	ChipTypeWS2801  ChipType = 2801
	ChipTypeWS2811  ChipType = 2811
	ChipTypeWS2812  ChipType = 2812
	ChipTypeLPD8806 ChipType = 8806
	ChipTypeAPA102  ChipType = 102
)

type Function

type Function = uint8
const (
	FunctionSetLEDValuesLowLevel                 Function = 1
	FunctionGetLEDValuesLowLevel                 Function = 2
	FunctionSetFrameDuration                     Function = 3
	FunctionGetFrameDuration                     Function = 4
	FunctionGetSupplyVoltage                     Function = 5
	FunctionSetClockFrequency                    Function = 7
	FunctionGetClockFrequency                    Function = 8
	FunctionSetChipType                          Function = 9
	FunctionGetChipType                          Function = 10
	FunctionSetChannelMapping                    Function = 11
	FunctionGetChannelMapping                    Function = 12
	FunctionSetFrameStartedCallbackConfiguration Function = 13
	FunctionGetFrameStartedCallbackConfiguration Function = 14
	FunctionGetSPITFPErrorCount                  Function = 234
	FunctionSetBootloaderMode                    Function = 235
	FunctionGetBootloaderMode                    Function = 236
	FunctionSetWriteFirmwarePointer              Function = 237
	FunctionWriteFirmware                        Function = 238
	FunctionSetStatusLEDConfig                   Function = 239
	FunctionGetStatusLEDConfig                   Function = 240
	FunctionGetChipTemperature                   Function = 242
	FunctionReset                                Function = 243
	FunctionWriteUID                             Function = 248
	FunctionReadUID                              Function = 249
	FunctionGetIdentity                          Function = 255
	FunctionCallbackFrameStarted                 Function = 6
)

type LEDStripV2Bricklet

type LEDStripV2Bricklet 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 (*LEDStripV2Bricklet) DeregisterFrameStartedCallback

func (device *LEDStripV2Bricklet) DeregisterFrameStartedCallback(registrationId uint64)

Remove a registered Frame Started callback.

func (*LEDStripV2Bricklet) GetAPIVersion

func (device *LEDStripV2Bricklet) 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 (*LEDStripV2Bricklet) GetBootloaderMode

func (device *LEDStripV2Bricklet) GetBootloaderMode() (mode BootloaderMode, err error)

Returns the current bootloader mode, see SetBootloaderMode.

Associated constants:

  • BootloaderModeBootloader
  • BootloaderModeFirmware
  • BootloaderModeBootloaderWaitForReboot
  • BootloaderModeFirmwareWaitForReboot
  • BootloaderModeFirmwareWaitForEraseAndReboot

func (*LEDStripV2Bricklet) GetChannelMapping

func (device *LEDStripV2Bricklet) GetChannelMapping() (mapping ChannelMapping, err error)

Returns the currently used channel mapping as set by SetChannelMapping.

Associated constants:

  • ChannelMappingRGB
  • ChannelMappingRBG
  • ChannelMappingBRG
  • ChannelMappingBGR
  • ChannelMappingGRB
  • ChannelMappingGBR
  • ChannelMappingRGBW
  • ChannelMappingRGWB
  • ChannelMappingRBGW
  • ChannelMappingRBWG
  • ChannelMappingRWGB
  • ChannelMappingRWBG
  • ChannelMappingGRWB
  • ChannelMappingGRBW
  • ChannelMappingGBWR
  • ChannelMappingGBRW
  • ChannelMappingGWBR
  • ChannelMappingGWRB
  • ChannelMappingBRGW
  • ChannelMappingBRWG
  • ChannelMappingBGRW
  • ChannelMappingBGWR
  • ChannelMappingBWRG
  • ChannelMappingBWGR
  • ChannelMappingWRBG
  • ChannelMappingWRGB
  • ChannelMappingWGBR
  • ChannelMappingWGRB
  • ChannelMappingWBGR
  • ChannelMappingWBRG

func (*LEDStripV2Bricklet) GetChipTemperature

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

Returns the temperature as measured inside the microcontroller. The value returned is not the ambient temperature!

The temperature is only proportional to the real temperature and it has bad accuracy. Practically it is only useful as an indicator for temperature changes.

func (*LEDStripV2Bricklet) GetChipType

func (device *LEDStripV2Bricklet) GetChipType() (chip ChipType, err error)

Returns the currently used chip type as set by SetChipType.

Associated constants:

  • ChipTypeWS2801
  • ChipTypeWS2811
  • ChipTypeWS2812
  • ChipTypeLPD8806
  • ChipTypeAPA102

func (*LEDStripV2Bricklet) GetClockFrequency

func (device *LEDStripV2Bricklet) GetClockFrequency() (frequency uint32, err error)

Returns the currently used clock frequency as set by SetClockFrequency.

func (*LEDStripV2Bricklet) GetFrameDuration

func (device *LEDStripV2Bricklet) GetFrameDuration() (duration uint16, err error)

Returns the frame duration as set by SetFrameDuration.

func (*LEDStripV2Bricklet) GetFrameStartedCallbackConfiguration

func (device *LEDStripV2Bricklet) GetFrameStartedCallbackConfiguration() (enable bool, err error)

Returns the configuration as set by SetFrameStartedCallbackConfiguration.

func (*LEDStripV2Bricklet) GetIdentity

func (device *LEDStripV2Bricklet) 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 (*LEDStripV2Bricklet) GetLEDValues

func (device *LEDStripV2Bricklet) GetLEDValues(index uint16, length uint16) (value []uint8, err error)

Returns *length* RGB(W) values starting from the given *index*.

If the channel mapping has 3 colors, you will get the data in the sequence RGBRGBRGB... if the channel mapping has 4 colors you will get the data in the sequence RGBWRGBWRGBW... (assuming you start at an index divisible by 3 (RGB) or 4 (RGBW)).

func (*LEDStripV2Bricklet) GetLEDValuesLowLevel

func (device *LEDStripV2Bricklet) GetLEDValuesLowLevel(index uint16, length uint16) (valueLength uint16, valueChunkOffset uint16, valueChunkData [60]uint8, err error)

Returns *length* RGB(W) values starting from the given *index*.

If the channel mapping has 3 colors, you will get the data in the sequence RGBRGBRGB... if the channel mapping has 4 colors you will get the data in the sequence RGBWRGBWRGBW... (assuming you start at an index divisible by 3 (RGB) or 4 (RGBW)).

func (*LEDStripV2Bricklet) GetResponseExpected

func (device *LEDStripV2Bricklet) 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 (*LEDStripV2Bricklet) GetSPITFPErrorCount

func (device *LEDStripV2Bricklet) GetSPITFPErrorCount() (errorCountAckChecksum uint32, errorCountMessageChecksum uint32, errorCountFrame uint32, errorCountOverflow uint32, err error)

Returns the error count for the communication between Brick and Bricklet.

The errors are divided into

* ACK checksum errors, * message checksum errors, * framing errors and * overflow errors.

The errors counts are for errors that occur on the Bricklet side. All Bricks have a similar function that returns the errors on the Brick side.

func (*LEDStripV2Bricklet) GetStatusLEDConfig

func (device *LEDStripV2Bricklet) GetStatusLEDConfig() (config StatusLEDConfig, err error)

Returns the configuration as set by SetStatusLEDConfig

Associated constants:

  • StatusLEDConfigOff
  • StatusLEDConfigOn
  • StatusLEDConfigShowHeartbeat
  • StatusLEDConfigShowStatus

func (*LEDStripV2Bricklet) GetSupplyVoltage

func (device *LEDStripV2Bricklet) GetSupplyVoltage() (voltage uint16, err error)

Returns the current supply voltage of the LEDs.

func (*LEDStripV2Bricklet) ReadUID

func (device *LEDStripV2Bricklet) ReadUID() (uid uint32, err error)

Returns the current UID as an integer. Encode as Base58 to get the usual string version.

func (*LEDStripV2Bricklet) RegisterFrameStartedCallback

func (device *LEDStripV2Bricklet) RegisterFrameStartedCallback(fn func(uint16)) uint64

This callback is triggered directly after a new frame render is started. The parameter is the number of LEDs in that frame.

You should send the data for the next frame directly after this callback was triggered.

For an explanation of the general approach see SetLEDValues.

func (*LEDStripV2Bricklet) Reset

func (device *LEDStripV2Bricklet) Reset() (err error)

Calling this function will reset the Bricklet. All configurations will be lost.

After a reset you have to create new device objects, calling functions on the existing ones will result in undefined behavior!

func (*LEDStripV2Bricklet) SetBootloaderMode

func (device *LEDStripV2Bricklet) SetBootloaderMode(mode BootloaderMode) (status BootloaderStatus, err error)

Sets the bootloader mode and returns the status after the requested mode change was instigated.

You can change from bootloader mode to firmware mode and vice versa. A change from bootloader mode to firmware mode will only take place if the entry function, device identifier and CRC are present and correct.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

Associated constants:

  • BootloaderModeBootloader
  • BootloaderModeFirmware
  • BootloaderModeBootloaderWaitForReboot
  • BootloaderModeFirmwareWaitForReboot
  • BootloaderModeFirmwareWaitForEraseAndReboot
  • BootloaderStatusOK
  • BootloaderStatusInvalidMode
  • BootloaderStatusNoChange
  • BootloaderStatusEntryFunctionNotPresent
  • BootloaderStatusDeviceIdentifierIncorrect
  • BootloaderStatusCRCMismatch

func (*LEDStripV2Bricklet) SetChannelMapping

func (device *LEDStripV2Bricklet) SetChannelMapping(mapping ChannelMapping) (err error)

Sets the channel mapping for the connected LEDs.

If the mapping has 4 colors, the function SetLEDValues expects 4 values per pixel and if the mapping has 3 colors it expects 3 values per pixel.

The function always expects the order RGB(W). The connected LED driver chips might have their 3 or 4 channels in a different order. For example, the WS2801 chips typically use BGR order, then WS2812 chips typically use GRB order and the APA102 chips typically use WBGR order.

The APA102 chips are special. They have three 8-bit channels for RGB and an additional 5-bit channel for the overall brightness of the RGB LED making them 4-channel chips. Internally the brightness channel is the first channel, therefore one of the Wxyz channel mappings should be used. Then the W channel controls the brightness.

Associated constants:

  • ChannelMappingRGB
  • ChannelMappingRBG
  • ChannelMappingBRG
  • ChannelMappingBGR
  • ChannelMappingGRB
  • ChannelMappingGBR
  • ChannelMappingRGBW
  • ChannelMappingRGWB
  • ChannelMappingRBGW
  • ChannelMappingRBWG
  • ChannelMappingRWGB
  • ChannelMappingRWBG
  • ChannelMappingGRWB
  • ChannelMappingGRBW
  • ChannelMappingGBWR
  • ChannelMappingGBRW
  • ChannelMappingGWBR
  • ChannelMappingGWRB
  • ChannelMappingBRGW
  • ChannelMappingBRWG
  • ChannelMappingBGRW
  • ChannelMappingBGWR
  • ChannelMappingBWRG
  • ChannelMappingBWGR
  • ChannelMappingWRBG
  • ChannelMappingWRGB
  • ChannelMappingWGBR
  • ChannelMappingWGRB
  • ChannelMappingWBGR
  • ChannelMappingWBRG

func (*LEDStripV2Bricklet) SetChipType

func (device *LEDStripV2Bricklet) SetChipType(chip ChipType) (err error)

Sets the type of the LED driver chip. We currently support the chips

* WS2801, * WS2811, * WS2812 / SK6812 / NeoPixel RGB, * SK6812RGBW / NeoPixel RGBW (Chip Type = WS2812), * WS2813 / WS2815 (Chip Type = WS2812) * LPD8806 and * APA102 / DotStar.

Associated constants:

  • ChipTypeWS2801
  • ChipTypeWS2811
  • ChipTypeWS2812
  • ChipTypeLPD8806
  • ChipTypeAPA102

func (*LEDStripV2Bricklet) SetClockFrequency

func (device *LEDStripV2Bricklet) SetClockFrequency(frequency uint32) (err error)

Sets the frequency of the clock.

The Bricklet will choose the nearest achievable frequency, which may be off by a few Hz. You can get the exact frequency that is used by calling GetClockFrequency.

If you have problems with flickering LEDs, they may be bits flipping. You can fix this by either making the connection between the LEDs and the Bricklet shorter or by reducing the frequency.

With a decreasing frequency your maximum frames per second will decrease too.

func (*LEDStripV2Bricklet) SetFrameDuration

func (device *LEDStripV2Bricklet) SetFrameDuration(duration uint16) (err error)

Sets the frame duration.

Example: If you want to achieve 20 frames per second, you should set the frame duration to 50ms (50ms * 20 = 1 second).

For an explanation of the general approach see SetLEDValues.

Default value: 100ms (10 frames per second).

func (*LEDStripV2Bricklet) SetFrameStartedCallbackConfiguration

func (device *LEDStripV2Bricklet) SetFrameStartedCallbackConfiguration(enable bool) (err error)

Enables/disables the RegisterFrameStartedCallback callback.

func (*LEDStripV2Bricklet) SetLEDValues

func (device *LEDStripV2Bricklet) SetLEDValues(index uint16, value []uint8) (err error)

Sets the RGB(W) values for the LEDs starting from *index*. You can set at most 2048 RGB values or 1536 RGBW values (6144 byte each).

To make the colors show correctly you need to configure the chip type (see SetChipType) and a channel mapping (see SetChannelMapping) according to the connected LEDs.

If the channel mapping has 3 colors, you need to give the data in the sequence RGBRGBRGB... if the channel mapping has 4 colors you need to give data in the sequence RGBWRGBWRGBW...

The data is double buffered and the colors will be transfered to the LEDs when the next frame duration ends (see SetFrameDuration).

Generic approach:

  • Set the frame duration to a value that represents the number of frames per second you want to achieve.
  • Set all of the LED colors for one frame.
  • Wait for the RegisterFrameStartedCallback callback.
  • Set all of the LED colors for next frame.
  • Wait for the RegisterFrameStartedCallback callback.
  • And so on.

This approach ensures that you can change the LED colors with a fixed frame rate.

func (*LEDStripV2Bricklet) SetLEDValuesLowLevel

func (device *LEDStripV2Bricklet) SetLEDValuesLowLevel(index uint16, valueLength uint16, valueChunkOffset uint16, valueChunkData [58]uint8) (err error)

Sets the RGB(W) values for the LEDs starting from *index*. You can set at most 2048 RGB values or 1536 RGBW values (6144 byte each).

To make the colors show correctly you need to configure the chip type (see SetChipType) and a channel mapping (see SetChannelMapping) according to the connected LEDs.

If the channel mapping has 3 colors, you need to give the data in the sequence RGBRGBRGB... if the channel mapping has 4 colors you need to give data in the sequence RGBWRGBWRGBW...

The data is double buffered and the colors will be transfered to the LEDs when the next frame duration ends (see SetFrameDuration).

Generic approach:

  • Set the frame duration to a value that represents the number of frames per second you want to achieve.
  • Set all of the LED colors for one frame.
  • Wait for the RegisterFrameStartedCallback callback.
  • Set all of the LED colors for next frame.
  • Wait for the RegisterFrameStartedCallback callback.
  • And so on.

This approach ensures that you can change the LED colors with a fixed frame rate.

func (*LEDStripV2Bricklet) SetResponseExpected

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

func (device *LEDStripV2Bricklet) SetResponseExpectedAll(responseExpected bool)

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

func (*LEDStripV2Bricklet) SetStatusLEDConfig

func (device *LEDStripV2Bricklet) SetStatusLEDConfig(config StatusLEDConfig) (err error)

Sets the status LED configuration. By default the LED shows communication traffic between Brick and Bricklet, it flickers once for every 10 received data packets.

You can also turn the LED permanently on/off or show a heartbeat.

If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.

Associated constants:

  • StatusLEDConfigOff
  • StatusLEDConfigOn
  • StatusLEDConfigShowHeartbeat
  • StatusLEDConfigShowStatus

func (*LEDStripV2Bricklet) SetWriteFirmwarePointer

func (device *LEDStripV2Bricklet) SetWriteFirmwarePointer(pointer uint32) (err error)

Sets the firmware pointer for WriteFirmware. The pointer has to be increased by chunks of size 64. The data is written to flash every 4 chunks (which equals to one page of size 256).

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

func (*LEDStripV2Bricklet) WriteFirmware

func (device *LEDStripV2Bricklet) WriteFirmware(data [64]uint8) (status uint8, err error)

Writes 64 Bytes of firmware at the position as written by SetWriteFirmwarePointer before. The firmware is written to flash every 4 chunks.

You can only write firmware in bootloader mode.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

func (*LEDStripV2Bricklet) WriteUID

func (device *LEDStripV2Bricklet) WriteUID(uid uint32) (err error)

Writes a new UID into flash. If you want to set a new UID you have to decode the Base58 encoded UID string into an integer first.

We recommend that you use Brick Viewer to change the UID.

type StatusLEDConfig

type StatusLEDConfig = uint8
const (
	StatusLEDConfigOff           StatusLEDConfig = 0
	StatusLEDConfigOn            StatusLEDConfig = 1
	StatusLEDConfigShowHeartbeat StatusLEDConfig = 2
	StatusLEDConfigShowStatus    StatusLEDConfig = 3
)

Jump to

Keyboard shortcuts

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