implement AFServoMotor

This commit is contained in:
Leonetienne
2025-12-14 15:02:55 +01:00
parent a1c1cf0c40
commit d339f5b297
5 changed files with 203 additions and 1 deletions
+50
View File
@@ -0,0 +1,50 @@
#include "AdafruitPWMBoard.hpp"
AdafruitPWMBoard::AdafruitPWMBoard(const uint8_t addr, const uint8_t pwmFreq):
hwif(addr)
{
if (!hwif.begin()) {
good = false;
return;
}
hwif.setPWMFreq(pwmFreq);
good = true;
}
bool AdafruitPWMBoard::isMotorSlotOccupied(const uint8_t motorIndex) const noexcept
{
if (motorIndex >= 16) {
return false;
}
return occupiedMotorSlots & (1 << motorIndex);
}
bool AdafruitPWMBoard::occupyMotorSlot(const uint8_t motorIndex) noexcept
{
if (motorIndex >= 16) {
return false;
}
if (isMotorSlotOccupied(motorIndex)) {
return false;
}
occupiedMotorSlots |= 1 << motorIndex;
return true;
}
bool AdafruitPWMBoard::releaseMotorSlot(const uint8_t motorIndex) noexcept
{
if (motorIndex >= 16) {
return false;
}
if (!isMotorSlotOccupied(motorIndex)) {
return false;
}
occupiedMotorSlots &= ~(1 << motorIndex);
return true;
}