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
+27
View File
@@ -0,0 +1,27 @@
#pragma once
#include <Arduino.h>
#include <Adafruit_PWMServoDriver.h>
// Wrapper class to prevent duplicate motor port assignments
// This board can drive up to 16 motors
class AdafruitPWMBoard
{
public:
AdafruitPWMBoard(const uint8_t addr, const uint8_t pwmFreq);
Adafruit_PWMServoDriver& get() noexcept { return hwif; };
const Adafruit_PWMServoDriver& get() const noexcept { return hwif; };
bool isGood() const noexcept { return good; }
bool isMotorSlotOccupied(const uint8_t motorIndex) const noexcept;
// Returns false if the slot is already occupied or index is out of range
bool occupyMotorSlot(const uint8_t motorIndex) noexcept;
// Returns false if the slot is already free or index is out of range
bool releaseMotorSlot(const uint8_t motorIndex) noexcept;
private:
// No release needed, hardware interface does not expose any method for release
Adafruit_PWMServoDriver hwif;
bool good;
uint16_t occupiedMotorSlots = 0;
};