functional yet ugly
This commit is contained in:
@@ -6,12 +6,7 @@ import (
|
||||
"github.com/google/gousb"
|
||||
)
|
||||
|
||||
type TEMPer struct {
|
||||
Device *gousb.Device
|
||||
}
|
||||
|
||||
// GetDevice will return the first temper device found.
|
||||
func GetDevice() (*TEMPer, error) {
|
||||
func GetTemperature() (float64, error) {
|
||||
ctx := gousb.NewContext()
|
||||
defer ctx.Close()
|
||||
|
||||
@@ -21,24 +16,20 @@ func GetDevice() (*TEMPer, error) {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return &TEMPer{}, err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if len(devs) == 0 {
|
||||
return &TEMPer{}, fmt.Errorf("no devices found matching VID %s and PID %s", vid, pid)
|
||||
return 0, fmt.Errorf("no devices found matching VID %s and PID %s", vid, pid)
|
||||
}
|
||||
|
||||
devs[0].SetAutoDetach(true)
|
||||
|
||||
for i := 1; i <= len(devs)-1; i++ {
|
||||
defer devs[i].Close()
|
||||
for _, d := range devs {
|
||||
defer d.Close()
|
||||
}
|
||||
|
||||
return &TEMPer{Device: devs[0]}, nil
|
||||
}
|
||||
|
||||
func (d *TEMPer) GetTemperature() (float64, error) {
|
||||
cfg, err := d.Device.Config(1)
|
||||
cfg, err := devs[0].Config(1)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -55,7 +46,7 @@ func (d *TEMPer) GetTemperature() (float64, error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
_, err = d.Device.Control(
|
||||
_, err = devs[0].Control(
|
||||
0x21, 0x09, 0x0200, 0x01, []byte{0x01, 0x80, 0x33, 0x01, 0x00, 0x00, 0x00, 0x00},
|
||||
)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user