go_hdc1080

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2021 License: MIT Imports: 3 Imported by: 0

README

go-hdc1080

德州仪器HDC1080温度湿度传感器golang库
ti hdc1080 temperature and humidity sensor golang library


MIT License

这个库使用 golang 编写,用于操作hdc1080温湿度传感器。

This library written in Go programming language intended to operation hdc1080 sensor chip.


Usage

func main(){
hdc1080, err := NewHdc1080(0x40, 0)
if err != nil {
// ....
}
defer hdc1080.Close()
temp, err := hdc1080.GetTemperature()
hum, err := hdc1080.GetHumidity()
}

详细使用方法参考 hdc1080_test.go

Documentation

Index

Constants

View Source
const (
	Hdc1080RegTemperature     = 0x0
	Hdc1080RegHumidity        = 0x1
	Hdc1080RegConfigAndStatus = 0x2
	Hdc1080RegSerialPart1     = 0xfb
	Hdc1080RegSerialPart2     = 0xfc
	Hdc1080RegSerialPart3     = 0xfd
	Hdc1080RegManufacturerId  = 0xfe
	Hdc1080RegDeviceId        = 0xff

	Hdc1080CommandDelay = 20 * time.Millisecond

	Hdc1080ModeNormal = 0b0
	Hdc1080ModeReset  = 0b1

	Hdc1080HeaterEnable  = 0b1
	Hdc1080HeaterDisable = 0b0

	Hdc1080AcquisitionSingle = 0b0
	Hdc1080AcquisitionBoth   = 0b1

	Hdc1080BatteryStatusHigh = 0b0
	Hdc1080BatteryStatusLow  = 0b1

	Hdc1080TemperatureResolution14Bit = 0b0
	Hdc1080TemperatureResolution11Bit = 0b1

	Hdc1080HumidityResolution14Bit = 0b0
	Hdc1080HumidityResolution11Bit = 0b1
	Hdc1080HumidityResolution8Bit  = 0b10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type HDC1080

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

func NewHdc1080

func NewHdc1080(addr uint8, bus int) (*HDC1080, error)

NewHdc1080 新建一个hdc1080的连接句柄 NewHdc1080 open a new connection of hdc1080

func (*HDC1080) Close

func (h *HDC1080) Close() error

Close 关闭hdc1080连接 Close hdc1080 connection.

func (*HDC1080) GetConfig

func (h *HDC1080) GetConfig() (*HDC1080Config, error)

GetConfig 获取配置 GetConfig get chip config

func (*HDC1080) GetDeviceId

func (h *HDC1080) GetDeviceId() (uint16, error)

GetDeviceId 获取器件id,固定为0x1050 GetDeviceId get device id, result is 0x1050

func (*HDC1080) GetHumidity

func (h *HDC1080) GetHumidity() (float64, error)

GetHumidity 获取相对湿度 GetHumidity get relative humidity

func (*HDC1080) GetManufacturerId

func (h *HDC1080) GetManufacturerId() (uint16, error)

GetManufacturerId 获取制造商id,固定为0x5449 GetManufacturerId get manufacturer id, result is 0x5449

func (*HDC1080) GetSerialId

func (h *HDC1080) GetSerialId() (string, error)

GetSerialId 获取器件唯一id GetSerialId get device serial id

func (*HDC1080) GetTemperature

func (h *HDC1080) GetTemperature() (float64, error)

GetTemperature 获取摄氏温度 GetTemperature get celsius temperature

func (*HDC1080) Reset

func (h *HDC1080) Reset() error

Reset 重置芯片配置 Reset reset chip config

func (*HDC1080) SetConfig

func (h *HDC1080) SetConfig(conf *HDC1080Config) error

SetConfig 写入配置 SetConfig write config to chip

type HDC1080Config

type HDC1080Config struct {
	Reset                 uint8 `json:"reset"`
	Heater                uint8 `json:"heater"`
	AcquisitionMode       uint8 `json:"acquisition_mode"`
	BatteryStatus         uint8 `json:"battery_status"`
	TemperatureResolution uint8 `json:"temperature_resolution"`
	HumidityResolution    uint8 `json:"humidity_resolution"`
}

HDC1080Config hdc1080配置结构体 HDC1080Config config struct

func (*HDC1080Config) Marshal

func (conf *HDC1080Config) Marshal() uint16

Marshal 根据配置结构体生成配置 Marshal convert struct to code

Jump to

Keyboard shortcuts

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