diff --git a/experimental/devices/hx711/hx711.go b/experimental/devices/hx711/hx711.go index a89a114..fca1300 100644 --- a/experimental/devices/hx711/hx711.go +++ b/experimental/devices/hx711/hx711.go @@ -16,6 +16,7 @@ import ( "time" "periph.io/x/periph/conn/gpio" + "periph.io/x/periph/conn/pin" "periph.io/x/periph/experimental/conn/analog" ) @@ -87,7 +88,25 @@ func (d *Dev) Number() int { // Function implements analog.PinADC. func (d *Dev) Function() string { - return "ADC" + return string(d.Func()) +} + +// Func implements analog.PinADC. +func (d *Dev) Func() pin.Func { + return analog.ADC +} + +// SupportedFuncs implements analog.PinADC. +func (d *Dev) SupportedFuncs() []pin.Func { + return []pin.Func{analog.ADC} +} + +// SetFunc implements analog.PinADC. +func (d *Dev) SetFunc(f pin.Func) error { + if f == analog.ADC { + return nil + } + return errors.New("pin function cannot be changed") } // SetInputMode changes the voltage gain and channel multiplexer mode. diff --git a/experimental/devices/hx711/hx711_test.go b/experimental/devices/hx711/hx711_test.go index 26643bf..ff6266f 100644 --- a/experimental/devices/hx711/hx711_test.go +++ b/experimental/devices/hx711/hx711_test.go @@ -6,11 +6,14 @@ package hx711 import ( "errors" + "reflect" "testing" "time" "periph.io/x/periph/conn/gpio" "periph.io/x/periph/conn/gpio/gpiotest" + "periph.io/x/periph/conn/pin" + "periph.io/x/periph/experimental/conn/analog" ) func TestNew(t *testing.T) { @@ -32,6 +35,18 @@ func TestNew(t *testing.T) { if f := d.Function(); f != "ADC" { t.Fatal(f) } + if f := d.Func(); f != analog.ADC { + t.Fatal(f) + } + if v := d.SupportedFuncs(); !reflect.DeepEqual(v, []pin.Func{analog.ADC}) { + t.Fatal(v) + } + if err := d.SetFunc(analog.ADC); err != nil { + t.Fatal(err) + } + if err := d.SetFunc(pin.FuncNone); err == nil { + t.Fatal("expected failure") + } min, max := d.Range() // TODO(davidsansome): Is that the right values? if min.Raw != -8388608 {