hx711: implement pin.PinFunc

The interface pin.PinFunc will be merged into pin.Pin in v4.

Increase coverage to 84%.
pull/1/head
Marc-Antoine Ruel 7 years ago
parent 7c15fb5d1a
commit 71fdeecc9a

@ -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.

@ -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 {

Loading…
Cancel
Save