Converted servocontroller to protobufs + persistance defaults
This commit is contained in:
@@ -63,6 +63,19 @@ inline uint32_t parseIPv4(const char *str) {
|
||||
|
||||
using APSettings = api_APSettings;
|
||||
|
||||
inline APSettings APSettings_defaults() {
|
||||
APSettings settings = {};
|
||||
settings.provision_mode = FACTORY_AP_PROVISION_MODE;
|
||||
strncpy(settings.ssid, FACTORY_AP_SSID, sizeof(settings.ssid) - 1);
|
||||
strncpy(settings.password, FACTORY_AP_PASSWORD, sizeof(settings.password) - 1);
|
||||
settings.channel = FACTORY_AP_CHANNEL;
|
||||
settings.ssid_hidden = FACTORY_AP_SSID_HIDDEN;
|
||||
settings.max_clients = FACTORY_AP_MAX_CLIENTS;
|
||||
settings.local_ip = parseIPv4(FACTORY_AP_LOCAL_IP);
|
||||
settings.gateway_ip = parseIPv4(FACTORY_AP_GATEWAY_IP);
|
||||
settings.subnet_mask = parseIPv4(FACTORY_AP_SUBNET_MASK);
|
||||
return settings;
|
||||
}
|
||||
|
||||
inline void APSettings_read(const APSettings &settings, APSettings &proto) {
|
||||
proto = settings;
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <template/state_result.h>
|
||||
|
||||
typedef struct {
|
||||
float centerPwm;
|
||||
float direction;
|
||||
float centerAngle;
|
||||
float conversion;
|
||||
const char *name;
|
||||
// bool enable;
|
||||
} servo_settings_t;
|
||||
|
||||
class ServoSettings {
|
||||
public:
|
||||
servo_settings_t servos[12] = {
|
||||
{306, -1, 0, 2.2, "Servo1"}, {306, 1, -45, 2.1055555, "Servo2"}, {306, 1, 90, 1.96923, "Servo3"},
|
||||
{306, -1, 0, 2.2, "Servo4"}, {306, -1, 45, 2.1055555, "Servo5"}, {306, -1, -90, 1.96923, "Servo6"},
|
||||
{306, 1, 0, 2.2, "Servo7"}, {306, 1, -45, 2.1055555, "Servo8"}, {306, 1, 90, 1.96923, "Servo9"},
|
||||
{306, 1, 0, 2.2, "Servo10"}, {306, -1, 45, 2.1055555, "Servo11"}, {306, -1, -90, 1.96923, "Servo12"}};
|
||||
static void read(ServoSettings &settings, JsonVariant &root) {
|
||||
JsonArray servos = root["servos"].to<JsonArray>();
|
||||
for (auto &servo : settings.servos) {
|
||||
JsonVariant newServo = servos.add<JsonVariant>();
|
||||
newServo["center_pwm"] = servo.centerPwm;
|
||||
newServo["direction"] = servo.direction;
|
||||
newServo["center_angle"] = servo.centerAngle;
|
||||
newServo["conversion"] = servo.conversion;
|
||||
}
|
||||
}
|
||||
static StateUpdateResult update(JsonVariant &root, ServoSettings &settings) {
|
||||
if (root["servos"].is<JsonArray>()) {
|
||||
JsonArray servosJson = root["servos"];
|
||||
int i = 0;
|
||||
for (auto servo : servosJson) {
|
||||
JsonVariant servoObject = servo.as<JsonVariant>();
|
||||
uint8_t servoId = i; // servoObject["id"].as<uint8_t>();
|
||||
settings.servos[servoId].centerPwm = servoObject["center_pwm"].as<float>();
|
||||
settings.servos[servoId].centerAngle = servoObject["center_angle"].as<float>();
|
||||
settings.servos[servoId].direction = servoObject["direction"].as<float>();
|
||||
settings.servos[servoId].conversion = servoObject["conversion"].as<float>();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
ESP_LOGI("ServoController", "Updating servo data");
|
||||
return StateUpdateResult::CHANGED;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user