Skip to content

Commit 485b780

Browse files
committed
refactor: made package more generic
1 parent ce6ca36 commit 485b780

File tree

2 files changed

+2
-70
lines changed

2 files changed

+2
-70
lines changed

interfaces.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,5 @@ type (
1616
SafeSetAngleToRight(angle uint16) tinygoerrors.ErrorCode
1717
SetAngleToLeft(angle uint16) tinygoerrors.ErrorCode
1818
SafeSetAngleToLeft(angle uint16) tinygoerrors.ErrorCode
19-
SetDirectionToCenter() tinygoerrors.ErrorCode
20-
SetDirectionToRight(angle uint16) tinygoerrors.ErrorCode
21-
SafeSetDirectionToRight(angle uint16) tinygoerrors.ErrorCode
22-
SetDirectionToLeft(angle uint16) tinygoerrors.ErrorCode
23-
SafeSetDirectionToLeft(angle uint16) tinygoerrors.ErrorCode
2419
}
2520
)

types.go

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func (h *DefaultHandler) SetAngleRelativeToCenter(relativeAngle int16) tinygoerr
218218
//
219219
// An error if the angle is not within the right limit
220220
func (h *DefaultHandler) SetAngleToRight(angle uint16) tinygoerrors.ErrorCode {
221-
return h.SetAngleRelativeToCenter(-int16(angle))
221+
return h.SetAngleRelativeToCenter(int16(angle))
222222
}
223223

224224
// SafeSetAngleToRight sets the servo motor to the right by a specified angle without exceeding limits
@@ -247,7 +247,7 @@ func (h *DefaultHandler) SafeSetAngleToRight(angle uint16) tinygoerrors.ErrorCod
247247
//
248248
// An error if the angle is not within the left limit
249249
func (h *DefaultHandler) SetAngleToLeft(angle uint16) tinygoerrors.ErrorCode {
250-
return h.SetAngleRelativeToCenter(int16(angle))
250+
return h.SetAngleRelativeToCenter(-int16(angle))
251251
}
252252

253253
// SafeSetAngleToLeft sets the servo motor to the left by a specified angle without exceeding limits
@@ -264,67 +264,4 @@ func (h *DefaultHandler) SafeSetAngleToLeft(angle uint16) tinygoerrors.ErrorCode
264264
angle = h.maxAngle
265265
}
266266
return h.SetAngleToLeft(angle)
267-
}
268-
269-
// SetDirectionToCenter sets the direction to center
270-
func (h *DefaultHandler) SetDirectionToCenter() tinygoerrors.ErrorCode {
271-
return h.SetAngleToCenter()
272-
}
273-
274-
// SetDirectionToRight sets the direction to right
275-
//
276-
// Parameters:
277-
//
278-
// angle: The angle value to move the servo to the left, must be between 0 and the left limit
279-
//
280-
// Returns:
281-
//
282-
// An error if the angle is not within the left limit
283-
func (h *DefaultHandler) SetDirectionToRight(angle uint16) tinygoerrors.ErrorCode {
284-
return h.SetAngleToLeft(angle)
285-
}
286-
287-
// SafeSetDirectionToRight sets the direction to right without exceeding limits
288-
//
289-
// Parameters:
290-
//
291-
// angle: The angle value to move the servo to the left, must be between 0 and the left limit
292-
//
293-
// Returns:
294-
//
295-
// An error if the angle is not within the left limit
296-
func (h *DefaultHandler) SafeSetDirectionToRight(angle uint16) tinygoerrors.ErrorCode {
297-
if angle > h.maxAngle {
298-
angle = h.maxAngle
299-
}
300-
return h.SetDirectionToRight(angle)
301-
}
302-
303-
// SetDirectionToLeft sets the direction to left
304-
//
305-
// Parameters:
306-
//
307-
// angle: The angle value to move the servo to the right, must be between 0 and the right limit
308-
//
309-
// Returns:
310-
//
311-
// An error if the angle is not within the right limit
312-
func (h *DefaultHandler) SetDirectionToLeft(angle uint16) tinygoerrors.ErrorCode {
313-
return h.SetAngleToRight(angle)
314-
}
315-
316-
// SafeSetDirectionToLeft sets the direction to left without exceeding limits
317-
//
318-
// Parameters:
319-
//
320-
// angle: The angle value to move the servo to the right, must be between 0 and the right limit
321-
//
322-
// Returns:
323-
//
324-
// An error if the angle is not within the right limit
325-
func (h *DefaultHandler) SafeSetDirectionToLeft(angle uint16) tinygoerrors.ErrorCode {
326-
if angle > h.maxAngle {
327-
angle = h.maxAngle
328-
}
329-
return h.SetDirectionToLeft(angle)
330267
}

0 commit comments

Comments
 (0)