mirror of https://github.com/kidoman/embd
initialize configuration so we aren't unintentionally overwriting something on the first configuration change
This commit is contained in:
parent
95e4b68b74
commit
24db7580a4
|
@ -15,7 +15,7 @@ func main() {
|
|||
bus := embd.NewI2CBus(1)
|
||||
defer embd.CloseI2C()
|
||||
|
||||
therm := mcp9808.New(bus)
|
||||
therm, _ := mcp9808.New(bus)
|
||||
// set sensor to low power mode when we're done
|
||||
defer therm.SetShutdownMode(true)
|
||||
|
||||
|
@ -38,11 +38,16 @@ func main() {
|
|||
config, _ := therm.Config()
|
||||
fmt.Printf("New Config: %b\n", config)
|
||||
|
||||
if err := therm.SetCriticalTemp(TempFToC(90)); err != nil {
|
||||
if err := therm.SetCriticalTemp(TempFToC(95)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
critTemp, err := therm.CriticalTemp()
|
||||
if err != nil {
|
||||
fmt.Printf("Error reading critical temp limit: %s\n", err.Error())
|
||||
}
|
||||
fmt.Printf("Critical Temp set to: %fC\n", critTemp)
|
||||
|
||||
if err := therm.SetWindowTempLower(TempFToC(32)); err != nil {
|
||||
if err := therm.SetWindowTempLower(TempFToC(50)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
lowerTemp, err := therm.WindowTempLower()
|
||||
|
@ -51,7 +56,7 @@ func main() {
|
|||
}
|
||||
fmt.Printf("Lower Temp Limit set to: %fC\n", lowerTemp)
|
||||
|
||||
if err := therm.SetWindowTempUpper(TempFToC(75)); err != nil {
|
||||
if err := therm.SetWindowTempUpper(TempFToC(80)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
upperTemp, _ := therm.WindowTempUpper()
|
||||
|
|
|
@ -39,8 +39,12 @@ type MCP9808 struct {
|
|||
}
|
||||
|
||||
// New returns a handle to a MCP9808 sensor.
|
||||
func New(bus embd.I2CBus) *MCP9808 {
|
||||
return &MCP9808{Bus: bus}
|
||||
func New(bus embd.I2CBus) (*MCP9808, error) {
|
||||
d := &MCP9808{Bus: bus}
|
||||
|
||||
// initialize the configuration
|
||||
_, err := d.Config()
|
||||
return d, err
|
||||
}
|
||||
|
||||
// ManufacturerID reads the device manufacturer ID
|
||||
|
|
Loading…
Reference in New Issue