2014-04-28 10:34:16 +08:00
|
|
|
package gpio
|
2014-04-26 18:11:51 +08:00
|
|
|
|
2014-12-17 05:42:48 +08:00
|
|
|
type gpioTestBareAdaptor struct{}
|
|
|
|
|
2016-11-07 21:55:21 +08:00
|
|
|
func (t *gpioTestBareAdaptor) Connect() (err error) { return }
|
|
|
|
func (t *gpioTestBareAdaptor) Finalize() (err error) { return }
|
|
|
|
func (t *gpioTestBareAdaptor) Name() string { return "" }
|
|
|
|
func (t *gpioTestBareAdaptor) SetName(n string) {}
|
2014-12-17 05:42:48 +08:00
|
|
|
|
|
|
|
type gpioTestDigitalWriter struct {
|
|
|
|
gpioTestBareAdaptor
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *gpioTestDigitalWriter) DigitalWrite(string, byte) (err error) { return }
|
|
|
|
|
2014-06-16 08:22:50 +08:00
|
|
|
type gpioTestAdaptor struct {
|
2014-11-23 04:21:28 +08:00
|
|
|
name string
|
|
|
|
port string
|
2014-06-16 08:22:50 +08:00
|
|
|
}
|
|
|
|
|
2014-12-17 05:42:48 +08:00
|
|
|
var testAdaptorDigitalWrite = func() (err error) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var testAdaptorServoWrite = func() (err error) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var testAdaptorPwmWrite = func() (err error) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var testAdaptorAnalogRead = func() (val int, err error) {
|
2014-11-17 05:45:18 +08:00
|
|
|
return 99, nil
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
2014-12-17 05:42:48 +08:00
|
|
|
var testAdaptorDigitalRead = func() (val int, err error) {
|
2014-11-17 05:45:18 +08:00
|
|
|
return 1, nil
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
2014-12-17 05:42:48 +08:00
|
|
|
|
|
|
|
func (t *gpioTestAdaptor) DigitalWrite(string, byte) (err error) {
|
|
|
|
return testAdaptorDigitalWrite()
|
|
|
|
}
|
|
|
|
func (t *gpioTestAdaptor) ServoWrite(string, byte) (err error) {
|
|
|
|
return testAdaptorServoWrite()
|
|
|
|
}
|
|
|
|
func (t *gpioTestAdaptor) PwmWrite(string, byte) (err error) {
|
|
|
|
return testAdaptorPwmWrite()
|
|
|
|
}
|
|
|
|
func (t *gpioTestAdaptor) AnalogRead(string) (val int, err error) {
|
|
|
|
return testAdaptorAnalogRead()
|
|
|
|
}
|
|
|
|
func (t *gpioTestAdaptor) DigitalRead(string) (val int, err error) {
|
|
|
|
return testAdaptorDigitalRead()
|
|
|
|
}
|
2016-11-07 21:55:21 +08:00
|
|
|
func (t *gpioTestAdaptor) Connect() (err error) { return }
|
|
|
|
func (t *gpioTestAdaptor) Finalize() (err error) { return }
|
|
|
|
func (t *gpioTestAdaptor) Name() string { return t.name }
|
|
|
|
func (t *gpioTestAdaptor) SetName(n string) { t.name = n }
|
|
|
|
func (t *gpioTestAdaptor) Port() string { return t.port }
|
2014-06-16 08:22:50 +08:00
|
|
|
|
2016-09-25 19:36:18 +08:00
|
|
|
func newGpioTestAdaptor() *gpioTestAdaptor {
|
2014-06-16 08:22:50 +08:00
|
|
|
return &gpioTestAdaptor{
|
2014-11-23 04:21:28 +08:00
|
|
|
port: "/dev/null",
|
2014-06-16 08:22:50 +08:00
|
|
|
}
|
|
|
|
}
|