-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor fixes and add NO-OP motor for testing purposes
- Loading branch information
Showing
5 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package noop | ||
|
||
import ( | ||
"github.com/fallais/gocoop/pkg/motor" | ||
) | ||
|
||
//------------------------------------------------------------------------------ | ||
// Structure | ||
//------------------------------------------------------------------------------ | ||
|
||
// Motor driver for BTS7960. | ||
type noop struct { | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
// Factory | ||
//------------------------------------------------------------------------------ | ||
|
||
// New returns a new NO-OP motor driver. | ||
func New() motor.Motor { | ||
return &noop{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//go:build linux | ||
// +build linux | ||
|
||
package noop | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// Forward turns the motor forward. | ||
func (d *noop) Forward(ctx context.Context) error { | ||
logrus.Infoln("Turn motor forward") | ||
|
||
// Enable the motor | ||
logrus.Infoln("Start the motor") | ||
|
||
// Wait | ||
until, _ := ctx.Deadline() | ||
logrus.Infoln("Wait until", until) | ||
<-ctx.Done() | ||
|
||
// Disable the motor | ||
logrus.Infoln("Stop the motor") | ||
logrus.Infoln("Motor has been stopped") | ||
|
||
return nil | ||
} | ||
|
||
// Backward turns the motor backward. | ||
func (d *noop) Backward(ctx context.Context) error { | ||
logrus.Infoln("Turn motor backward") | ||
|
||
// Enable the motor | ||
logrus.Infoln("Start the motor") | ||
|
||
// Wait | ||
until, _ := ctx.Deadline() | ||
logrus.Infoln("Wait until", until) | ||
<-ctx.Done() | ||
|
||
// Disable the motor | ||
logrus.Infoln("Stop the motor") | ||
logrus.Infoln("Motor has been stopped") | ||
|
||
return nil | ||
} | ||
|
||
// Stop the motor. | ||
func (d *noop) Stop() error { | ||
logrus.Infoln("Stopping the motor") | ||
|
||
// Set to LOW | ||
logrus.Infoln("Stop the motor") | ||
logrus.Infoln("Motor has been stopped") | ||
|
||
return nil | ||
} |