🦼 Updates servoController
This commit is contained in:
@@ -1,16 +1,45 @@
|
|||||||
#include <Adafruit_PWMServoDriver.h>
|
#include <EventEndpoint.h>
|
||||||
#include <DeviceConfigurationService.h>
|
#include <FSPersistence.h>
|
||||||
|
#include <HttpEndpoint.h>
|
||||||
|
#include <SecurityManager.h>
|
||||||
|
#include <StatefulService.h>
|
||||||
|
|
||||||
class ServoController : public Adafruit_PWMServoDriver {
|
#include <Adafruit_PWMServoDriver.h>
|
||||||
|
|
||||||
|
#define SERVO_OSCILLATOR_FREQUENCY 27000000
|
||||||
|
#define SERVO_FREQ 50
|
||||||
|
#define SERVO_CONFIG_FILE "/config/deviceConfig.json"
|
||||||
|
#define SERVO_CONFIGURATION_SETTINGS_PATH "/api/servo/configuration"
|
||||||
|
|
||||||
|
|
||||||
|
class ServoConfiguration {
|
||||||
public:
|
public:
|
||||||
ServoController(DeviceConfigurationService deviceConfigurationService)
|
int32_t servo_oscillator_frequency {SERVO_OSCILLATOR_FREQUENCY};
|
||||||
: Adafruit_PWMServoDriver(), _config(deviceConfigurationService) {
|
int32_t servo_pwm_frequency {SERVO_FREQ};
|
||||||
begin();
|
static void read(ServoConfiguration &settings, JsonObject &root) {}
|
||||||
|
|
||||||
|
static StateUpdateResult update(JsonObject &root, ServoConfiguration &settings) {
|
||||||
|
return StateUpdateResult::CHANGED;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
class ServoController : public Adafruit_PWMServoDriver, public StatefulService<ServoConfiguration> {
|
||||||
|
public:
|
||||||
|
ServoController(PsychicHttpServer *server, FS *fs, SecurityManager *securityManager, EventSocket *socket)
|
||||||
|
: Adafruit_PWMServoDriver(), _server(server),
|
||||||
|
_securityManager(securityManager),
|
||||||
|
_httpEndpoint(ServoConfiguration::read, ServoConfiguration::update,
|
||||||
|
this, server, SERVO_CONFIGURATION_SETTINGS_PATH,
|
||||||
|
securityManager, AuthenticationPredicates::IS_ADMIN),
|
||||||
|
// _eventEndpoint(ServoConfiguration::read, ServoConfiguration::update,
|
||||||
|
// this, socket, EVENT_CONFIGURATION_SETTINGS),
|
||||||
|
_fsPersistence(ServoConfiguration::read, ServoConfiguration::update, this, fs, SERVO_CONFIG_FILE) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void configure() {
|
void configure() {
|
||||||
setOscillatorFrequency(_config.servo_oscillator_frequency());
|
setOscillatorFrequency(_state.servo_oscillator_frequency);
|
||||||
setPWMFreq(_config.servo_pwm_frequency());
|
setPWMFreq(_state.servo_pwm_frequency);
|
||||||
|
ESP_LOGI("ServoController", "Configured with oscillator frequency %d and PWM frequency %d", _state.servo_oscillator_frequency, _state.servo_pwm_frequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
void deactivate() {
|
void deactivate() {
|
||||||
@@ -26,5 +55,9 @@ class ServoController : public Adafruit_PWMServoDriver {
|
|||||||
bool isActive{false};
|
bool isActive{false};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeviceConfigurationService _config;
|
PsychicHttpServer *_server;
|
||||||
|
SecurityManager *_securityManager;
|
||||||
|
HttpEndpoint<ServoConfiguration> _httpEndpoint;
|
||||||
|
// EventEndpoint<ServoConfiguration> _eventEndpoint;
|
||||||
|
FSPersistence<ServoConfiguration> _fsPersistence;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user