diff --git a/platforms/digispark/digispark_adaptor.go b/platforms/digispark/digispark_adaptor.go index 6260dd64..c7b37dc4 100644 --- a/platforms/digispark/digispark_adaptor.go +++ b/platforms/digispark/digispark_adaptor.go @@ -14,8 +14,10 @@ var _ gpio.DigitalWriter = (*DigisparkAdaptor)(nil) var _ gpio.PwmWriter = (*DigisparkAdaptor)(nil) var _ gpio.ServoWriter = (*DigisparkAdaptor)(nil) +// ErrConnection is the error resulting of a connection error with the digispark var ErrConnection = errors.New("connection error") +// DigisparkAdaptor is the Gobot Adaptor for the Digispark type DigisparkAdaptor struct { name string littleWire lw @@ -24,7 +26,7 @@ type DigisparkAdaptor struct { connect func(*DigisparkAdaptor) (err error) } -// NewDigisparkAdaptor create a Digispark adaptor with specified name +// NewDigisparkAdaptor returns a new DigisparkAdaptor with specified name func NewDigisparkAdaptor(name string) *DigisparkAdaptor { return &DigisparkAdaptor{ name: name, @@ -38,9 +40,10 @@ func NewDigisparkAdaptor(name string) *DigisparkAdaptor { } } +// Name returns the DigisparkAdaptors name func (d *DigisparkAdaptor) Name() string { return d.name } -// Connect starts connection to digispark, returns true if successful +// Connect starts a connection to the digispark func (d *DigisparkAdaptor) Connect() (errs []error) { if err := d.connect(d); err != nil { return []error{err} @@ -48,10 +51,10 @@ func (d *DigisparkAdaptor) Connect() (errs []error) { return } -// Finalize returns true if finalization is successful +// Finalize implements the Adaptor interface func (d *DigisparkAdaptor) Finalize() (errs []error) { return } -// DigitalWrite writes level to specified pin using littlewire +// DigitalWrite writes a value to the pin. Acceptable values are 1 or 0. func (d *DigisparkAdaptor) DigitalWrite(pin string, level byte) (err error) { p, err := strconv.Atoi(pin) @@ -66,7 +69,7 @@ func (d *DigisparkAdaptor) DigitalWrite(pin string, level byte) (err error) { return d.littleWire.digitalWrite(uint8(p), level) } -// PwmWrite updates pwm pin with sent value +// PwmWrite writes the 0-254 value to the specified pin func (d *DigisparkAdaptor) PwmWrite(pin string, value byte) (err error) { if d.pwm == false { if err = d.littleWire.pwmInit(); err != nil { @@ -82,7 +85,7 @@ func (d *DigisparkAdaptor) PwmWrite(pin string, value byte) (err error) { return d.littleWire.pwmUpdateCompare(value, value) } -// ServoWrite updates servo location with specified angle +// ServoWrite writes the 0-180 degree val to the specified pin. func (d *DigisparkAdaptor) ServoWrite(pin string, angle uint8) (err error) { if d.servo == false { if err = d.littleWire.servoInit(); err != nil {