41 lines
962 B
C++
41 lines
962 B
C++
// This is a personal academic project. Dear PVS-Studio, please check it.
|
|
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: https://pvs-studio.com
|
|
|
|
#include <cstdint>
|
|
#include "Arduino.h"
|
|
#include "string.h"
|
|
#include "driver/ledc.h"
|
|
|
|
|
|
class BrushedMotor {
|
|
// TODO: rewrite with MCPWM
|
|
public:
|
|
BrushedMotor(uint32_t pwmAGpioNum, uint32_t pwmBGpioNum, uint32_t frequency,
|
|
uint8_t channel, uint8_t resolution, const char *name = "Rotor1", bool forward_directional = true);
|
|
|
|
void setDuty(uint32_t duty) const;
|
|
|
|
void setExtendedDuty(int32_t duty);
|
|
|
|
[[nodiscard]] uint32_t maxDuty() const;
|
|
|
|
void forward();
|
|
|
|
void backward();
|
|
|
|
void reverse();
|
|
|
|
void coast();
|
|
|
|
private:
|
|
uint8_t _channel;
|
|
uint32_t _frequency;
|
|
uint32_t _resolution;
|
|
|
|
uint32_t _pwmAGpioNum;
|
|
uint32_t _pwmBGpioNum;
|
|
bool _forward_directional;
|
|
String _tag_name = "BrushedMotor";
|
|
|
|
void _apply_directional() const;
|
|
}; |