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

package real_time_clock_v2_bricklet

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

Battery-backed real-time clock.

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

Index

Package Files

real_time_clock_v2_bricklet.go

Constants

const DeviceDisplayName = "Real-Time Clock Bricklet 2.0"
const DeviceIdentifier = 2106

type AlarmInterval Uses

type AlarmInterval = int32
const (
    AlarmIntervalDisabled AlarmInterval = -1
)

type AlarmMatch Uses

type AlarmMatch = int8
const (
    AlarmMatchDisabled AlarmMatch = -1
)

type BootloaderMode Uses

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

type BootloaderStatus Uses

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

type Function Uses

type Function = uint8
const (
    FunctionSetDateTime                      Function = 1
    FunctionGetDateTime                      Function = 2
    FunctionGetTimestamp                     Function = 3
    FunctionSetOffset                        Function = 4
    FunctionGetOffset                        Function = 5
    FunctionSetDateTimeCallbackConfiguration Function = 6
    FunctionGetDateTimeCallbackConfiguration Function = 7
    FunctionSetAlarm                         Function = 8
    FunctionGetAlarm                         Function = 9
    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
    FunctionCallbackDateTime                 Function = 10
    FunctionCallbackAlarm                    Function = 11
)

type RealTimeClockV2Bricklet Uses

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

func New Uses

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

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

func (*RealTimeClockV2Bricklet) DeregisterAlarmCallback Uses

func (device *RealTimeClockV2Bricklet) DeregisterAlarmCallback(registrationId uint64)

Remove a registered Alarm callback.

func (*RealTimeClockV2Bricklet) DeregisterDateTimeCallback Uses

func (device *RealTimeClockV2Bricklet) DeregisterDateTimeCallback(registrationId uint64)

Remove a registered Date Time callback.

func (*RealTimeClockV2Bricklet) GetAPIVersion Uses

func (device *RealTimeClockV2Bricklet) 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 (*RealTimeClockV2Bricklet) GetAlarm Uses

func (device *RealTimeClockV2Bricklet) GetAlarm() (month AlarmMatch, day AlarmMatch, hour AlarmMatch, minute AlarmMatch, second AlarmMatch, weekday AlarmMatch, interval AlarmInterval, err error)

Returns the alarm configuration as set by SetAlarm.

Associated constants:

* AlarmMatchDisabled
* AlarmIntervalDisabled

func (*RealTimeClockV2Bricklet) GetBootloaderMode Uses

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

Returns the current bootloader mode, see SetBootloaderMode.

Associated constants:

* BootloaderModeBootloader
* BootloaderModeFirmware
* BootloaderModeBootloaderWaitForReboot
* BootloaderModeFirmwareWaitForReboot
* BootloaderModeFirmwareWaitForEraseAndReboot

func (*RealTimeClockV2Bricklet) GetChipTemperature Uses

func (device *RealTimeClockV2Bricklet) 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 (*RealTimeClockV2Bricklet) GetDateTime Uses

func (device *RealTimeClockV2Bricklet) GetDateTime() (year uint16, month uint8, day uint8, hour uint8, minute uint8, second uint8, centisecond uint8, weekday Weekday, timestamp int64, err error)

Returns the current date (including weekday) and the current time of the real-time.

The timestamp represents the current date and the the current time of the real-time clock converted to milliseconds and is an offset to 2000-01-01 00:00:00.0000.

Associated constants:

* WeekdayMonday
* WeekdayTuesday
* WeekdayWednesday
* WeekdayThursday
* WeekdayFriday
* WeekdaySaturday
* WeekdaySunday

func (*RealTimeClockV2Bricklet) GetDateTimeCallbackConfiguration Uses

func (device *RealTimeClockV2Bricklet) GetDateTimeCallbackConfiguration() (period uint32, err error)

Returns the period as set by SetDateTimeCallbackConfiguration.

func (*RealTimeClockV2Bricklet) GetIdentity Uses

func (device *RealTimeClockV2Bricklet) 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 (*RealTimeClockV2Bricklet) GetOffset Uses

func (device *RealTimeClockV2Bricklet) GetOffset() (offset int8, err error)

Returns the offset as set by SetOffset.

func (*RealTimeClockV2Bricklet) GetResponseExpected Uses

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

func (device *RealTimeClockV2Bricklet) 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 (*RealTimeClockV2Bricklet) GetStatusLEDConfig Uses

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

Returns the configuration as set by SetStatusLEDConfig

Associated constants:

* StatusLEDConfigOff
* StatusLEDConfigOn
* StatusLEDConfigShowHeartbeat
* StatusLEDConfigShowStatus

func (*RealTimeClockV2Bricklet) GetTimestamp Uses

func (device *RealTimeClockV2Bricklet) GetTimestamp() (timestamp int64, err error)

Returns the current date and the time of the real-time clock converted to milliseconds. The timestamp has an effective resolution of hundredths of a second and is an offset to 2000-01-01 00:00:00.0000.

func (*RealTimeClockV2Bricklet) ReadUID Uses

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

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

func (*RealTimeClockV2Bricklet) RegisterAlarmCallback Uses

func (device *RealTimeClockV2Bricklet) RegisterAlarmCallback(fn func(uint16, uint8, uint8, uint8, uint8, uint8, uint8, Weekday, int64)) uint64

This callback is triggered every time the current date and time matches the configured alarm (see SetAlarm). The parameters are the same as for GetDateTime.

func (*RealTimeClockV2Bricklet) RegisterDateTimeCallback Uses

func (device *RealTimeClockV2Bricklet) RegisterDateTimeCallback(fn func(uint16, uint8, uint8, uint8, uint8, uint8, uint8, Weekday, int64)) uint64

This callback is triggered periodically with the period that is set by SetDateTimeCallbackConfiguration. The parameters are the same as for GetDateTime.

func (*RealTimeClockV2Bricklet) Reset Uses

func (device *RealTimeClockV2Bricklet) 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 (*RealTimeClockV2Bricklet) SetAlarm Uses

func (device *RealTimeClockV2Bricklet) SetAlarm(month AlarmMatch, day AlarmMatch, hour AlarmMatch, minute AlarmMatch, second AlarmMatch, weekday AlarmMatch, interval AlarmInterval) (err error)

Configures a repeatable alarm. The RegisterAlarmCallback callback is triggered if the current date and time matches the configured alarm.

Setting a parameter to -1 means that it should be disabled and doesn't take part in the match. Setting all parameters to -1 disables the alarm completely.

For example, to make the alarm trigger every day at 7:30 AM it can be configured as (-1, -1, 7, 30, -1, -1, -1). The hour is set to match 7 and the minute is set to match 30. The alarm is triggered if all enabled parameters match.

The interval has a special role. It allows to make the alarm reconfigure itself. This is useful if you need a repeated alarm that cannot be expressed by matching the current date and time. For example, to make the alarm trigger every 23 seconds it can be configured as (-1, -1, -1, -1, -1, -1, 23). Internally the Bricklet will take the current date and time, add 23 seconds to it and set the result as its alarm. The first alarm will be triggered 23 seconds after the call. Because the interval is not -1, the Bricklet will do the same again internally, take the current date and time, add 23 seconds to it and set that as its alarm. This results in a repeated alarm that triggers every 23 seconds.

The interval can also be used in combination with the other parameters. For example, configuring the alarm as (-1, -1, 7, 30, -1, -1, 300) results in an alarm that triggers every day at 7:30 AM and is then repeated every 5 minutes.

Associated constants:

* AlarmMatchDisabled
* AlarmIntervalDisabled

func (*RealTimeClockV2Bricklet) SetBootloaderMode Uses

func (device *RealTimeClockV2Bricklet) 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 (*RealTimeClockV2Bricklet) SetDateTime Uses

func (device *RealTimeClockV2Bricklet) SetDateTime(year uint16, month uint8, day uint8, hour uint8, minute uint8, second uint8, centisecond uint8, weekday Weekday) (err error)

Sets the current date (including weekday) and the current time.

If the backup battery is installed then the real-time clock keeps date and time even if the Bricklet is not powered by a Brick.

The real-time clock handles leap year and inserts the 29th of February accordingly. But leap seconds, time zones and daylight saving time are not handled.

Associated constants:

* WeekdayMonday
* WeekdayTuesday
* WeekdayWednesday
* WeekdayThursday
* WeekdayFriday
* WeekdaySaturday
* WeekdaySunday

func (*RealTimeClockV2Bricklet) SetDateTimeCallbackConfiguration Uses

func (device *RealTimeClockV2Bricklet) SetDateTimeCallbackConfiguration(period uint32) (err error)

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

func (*RealTimeClockV2Bricklet) SetOffset Uses

func (device *RealTimeClockV2Bricklet) SetOffset(offset int8) (err error)

Sets the offset the real-time clock should compensate for in 2.17 ppm steps between -277.76 ppm (-128) and +275.59 ppm (127).

The real-time clock time can deviate from the actual time due to the frequency deviation of its 32.768 kHz crystal. Even without compensation (factory default) the resulting time deviation should be at most ±20 ppm (±52.6 seconds per month).

This deviation can be calculated by comparing the same duration measured by the real-time clock (“rtc_duration“) an accurate reference clock (“ref_duration“).

For best results the configured offset should be set to 0 ppm first and then a duration of at least 6 hours should be measured.

The new offset (“new_offset“) can be calculated from the currently configured offset (“current_offset“) and the measured durations as follow::

new_offset = current_offset - round(1000000 * (rtc_duration - ref_duration) / rtc_duration / 2.17)

If you want to calculate the offset, then we recommend using the calibration dialog in Brick Viewer, instead of doing it manually.

The offset is saved in the EEPROM of the Bricklet and only needs to be configured once.

func (*RealTimeClockV2Bricklet) SetResponseExpected Uses

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

func (device *RealTimeClockV2Bricklet) SetResponseExpectedAll(responseExpected bool)

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

func (*RealTimeClockV2Bricklet) SetStatusLEDConfig Uses

func (device *RealTimeClockV2Bricklet) 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 (*RealTimeClockV2Bricklet) SetWriteFirmwarePointer Uses

func (device *RealTimeClockV2Bricklet) 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 (*RealTimeClockV2Bricklet) WriteFirmware Uses

func (device *RealTimeClockV2Bricklet) 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 (*RealTimeClockV2Bricklet) WriteUID Uses

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

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

type Weekday Uses

type Weekday = uint8
const (
    WeekdayMonday    Weekday = 1
    WeekdayTuesday   Weekday = 2
    WeekdayWednesday Weekday = 3
    WeekdayThursday  Weekday = 4
    WeekdayFriday    Weekday = 5
    WeekdaySaturday  Weekday = 6
    WeekdaySunday    Weekday = 7
)

Package real_time_clock_v2_bricklet imports 5 packages (graph). Updated 2021-01-20. Refresh now. Tools for package owners.