Skip to content

Commit 70cf308

Browse files
committed
feat: added Direction enum
1 parent 485b780 commit 70cf308

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

enums.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package tinygo_servo
2+
3+
type (
4+
// Direction is an enum to represent the different servo directions for the vehicle.
5+
Direction uint8
6+
)
7+
8+
const (
9+
DirectionNil Direction = iota
10+
DirectionLeft
11+
DirectionRight
12+
DirectionStraight
13+
)
14+
15+
// InvertedDirection returns the inverted direction.
16+
func (d Direction) InvertedDirection() Direction {
17+
switch d {
18+
case DirectionLeft:
19+
return DirectionRight
20+
case DirectionRight:
21+
return DirectionLeft
22+
case DirectionStraight:
23+
return DirectionStraight
24+
default:
25+
return DirectionNil
26+
}
27+
}

errors.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ const (
1717
ErrorCodeServoAngleAboveMaxPulseWidth
1818
ErrorCodeServoFailedToSetServoAngle
1919
ErrorCodeServoNilHandler
20-
)
20+
ErrorCodeServoUnknownDirection
21+
)

0 commit comments

Comments
 (0)