From 0cf4562d1e3da9befb9b14db97d2668137f432ba Mon Sep 17 00:00:00 2001 From: George Sexton Date: Mon, 25 Nov 2024 10:57:38 -0700 Subject: [PATCH] Initial create --- hdc302x/example_test.go | 0 hdc302x/hdc302x.go | 69 +++++++++++++++++++++++++++++++++++++++++ hdc302x/hdc302x_test.go | 0 3 files changed, 69 insertions(+) create mode 100644 hdc302x/example_test.go create mode 100644 hdc302x/hdc302x.go create mode 100644 hdc302x/hdc302x_test.go diff --git a/hdc302x/example_test.go b/hdc302x/example_test.go new file mode 100644 index 0000000..e69de29 diff --git a/hdc302x/hdc302x.go b/hdc302x/hdc302x.go new file mode 100644 index 0000000..e4206f8 --- /dev/null +++ b/hdc302x/hdc302x.go @@ -0,0 +1,69 @@ +// Copyright 2024 The Periph Authors. All rights reserved. +// Use of this source code is governed under the Apache License, Version 2.0 +// that can be found in the LICENSE file. +// +// This package provides a driver for the Texas Instruments HDC3021/3022 +// I2C Temperature/Humidity Sensors +// +// The datasheet is available at: +// +// https://www.ti.com/lit/ds/symlink/hdc3022.pdf +package hdc302x + +import ( + "errors" + "fmt" + "sync" + "time" + + "periph.io/x/conn/v3" + "periph.io/x/conn/v3/i2c" + "periph.io/x/conn/v3/physic" +) + +// NewI2C returns a new HDC302x sensor using the specified bus and address. +// If opts is not supplied, the configuration of the sensor is set to the +// default on startup. +func NewI2C(b i2c.Bus, addr uint16, opts *Opts) (*Dev, error) { + if opts == nil { + opts = &Opts{SampleRate: RateFourHertz, AlertSetting: ModeComparator} + } + d := &Dev{d: &i2c.Dev{Bus: b, Addr: addr}, opts: opts, shutdown: nil} + return d, d.start() +} + +// Halt shuts down the device. If a SenseContinuous operation is in progress, +// its aborted. Implements conn.Resource +func (dev *Dev) Halt() error { +} + +// Sense reads temperature from the device and writes the value to the specified +// env variable. Implements physic.SenseEnv. +func (dev *Dev) Sense(env *physic.Env) error { +} + +// SenseContinuous continuously reads from the device and writes the value to +// the returned channel. Implements physic.SenseEnv. To terminate the +// continuous read, call Halt(). +func (dev *Dev) SenseContinuous(interval time.Duration) (<-chan physic.Env, error) { +} + +// Precision returns the sensor's precision, or minimum value between steps the +// device can make. The specified precision is 0.0625 degrees Celsius. Note +// that the accuracy of the device is +/- 0.5 degrees Celsius. +func (dev *Dev) Precision(env *physic.Env) { + env.Temperature = _DEGREES_RESOLUTION + env.Pressure = 0 + env.Humidity = 0 +} + +func (dev *Dev) String() string { + return fmt.Sprintf("hdc302x: %s", dev.d.String()) +} + + + + + +var _ conn.Resource = &Dev{} +var _ physic.SenseEnv = &Dev{} diff --git a/hdc302x/hdc302x_test.go b/hdc302x/hdc302x_test.go new file mode 100644 index 0000000..e69de29