package i2c

import (
	"git.openpdu.org/OpenPDU/openpdu/syslog"
	I2C "periph.io/x/periph/conn/i2c"
	I2CREG "periph.io/x/periph/conn/i2c/i2creg"
	"periph.io/x/periph/host"
)

var I2Cbus I2C.Bus

func init() {
	var err error

	syslog.Info("i2c setup")

	// Make sure periph is initialized.
	if _, err = host.Init(); err != nil {
		syslog.Err(err.Error())
	}

	// Use i2creg I²C bus registry to find the first available I²C bus.
	//	i2cbus, err = i2creg.Open("/dev/i2c-1")
	I2Cbus, err = I2CREG.Open("")
	if err != nil {
		syslog.Err(err.Error())
	}

	syslog.Info("i2c setup completed")
}
