🎩 Adds lots of magic
This commit is contained in:
@@ -54,4 +54,10 @@ build_flags =
|
||||
-D FACTORY_MQTT_MAX_TOPIC_LENGTH=128
|
||||
|
||||
; JWT Secret
|
||||
-D FACTORY_JWT_SECRET=\"#{random}-#{random}\" ; supports placeholders
|
||||
-D FACTORY_JWT_SECRET=\"#{random}-#{random}\" ; supports placeholders
|
||||
|
||||
; Servo settings
|
||||
-D FACTORY_SERVO_NUM=12
|
||||
-D FACTORY_SERVO_OSCILLATOR_FREQUENCY=27000000
|
||||
-D FACTORY_SERVO_PWM_FREQUENCY=50
|
||||
-D FACTORY_SERVO_CENTER_ANGLE=90
|
||||
@@ -5,7 +5,8 @@
|
||||
#include <PsychicHttp.h>
|
||||
#include <SecurityManager.h>
|
||||
|
||||
#define FILE_EXPLORER_SERVICE_PATH "/api/files/list"
|
||||
#define FILE_EXPLORER_SERVICE_PATH "/api/files"
|
||||
#define FILE_EXPLORER_DELETE_SERVICE_PATH "/api/files/delete"
|
||||
|
||||
class FileExplorer
|
||||
{
|
||||
@@ -20,6 +21,9 @@ class FileExplorer
|
||||
_server->on(FILE_EXPLORER_SERVICE_PATH, HTTP_GET,
|
||||
_securityManager->wrapRequest(std::bind(&FileExplorer::explore, this, std::placeholders::_1),
|
||||
AuthenticationPredicates::IS_AUTHENTICATED));
|
||||
_server->on(FILE_EXPLORER_DELETE_SERVICE_PATH, HTTP_POST,
|
||||
_securityManager->wrapCallback(std::bind(&FileExplorer::deleteFile, this, std::placeholders::_1, std::placeholders::_2),
|
||||
AuthenticationPredicates::IS_AUTHENTICATED));
|
||||
|
||||
ESP_LOGV("APStatus", "Registered GET endpoint: %s", FILE_EXPLORER_SERVICE_PATH);
|
||||
}
|
||||
@@ -27,11 +31,23 @@ class FileExplorer
|
||||
private:
|
||||
PsychicHttpServer *_server;
|
||||
SecurityManager *_securityManager;
|
||||
|
||||
esp_err_t explore(PsychicRequest *request)
|
||||
{
|
||||
return request->reply(200, "application/json", listFiles("/").c_str());
|
||||
}
|
||||
|
||||
esp_err_t deleteFile(PsychicRequest *request, JsonVariant &json)
|
||||
{
|
||||
if (json.is<JsonObject>())
|
||||
{
|
||||
String filename = json["file"];
|
||||
ESP_LOGI("FileExplorer", "Deleting file: %s", filename.c_str());
|
||||
return ESPFS.remove(filename.c_str()) ? request->reply(200) : request->reply(500);
|
||||
}
|
||||
return request->reply(400);
|
||||
}
|
||||
|
||||
String listFiles(const String &directory, bool isRoot = true)
|
||||
{
|
||||
File root = ESPFS.open(directory.startsWith("/") ? directory : "/" + directory);
|
||||
|
||||
@@ -6,11 +6,25 @@
|
||||
|
||||
#include <Adafruit_PWMServoDriver.h>
|
||||
|
||||
#define SERVO_OSCILLATOR_FREQUENCY 27000000
|
||||
#define SERVO_FREQ 50
|
||||
#define SERVO_CONFIG_FILE "/config/servoConfig.json"
|
||||
#define SERVO_CONFIGURATION_SETTINGS_PATH "/api/servo/configuration"
|
||||
|
||||
#ifndef FACTORY_SERVO_NUM
|
||||
#define FACTORY_SERVO_NUM 12
|
||||
#endif
|
||||
|
||||
#ifndef FACTORY_SERVO_PWM_FREQUENCY
|
||||
#define FACTORY_SERVO_PWM_FREQUENCY 50
|
||||
#endif
|
||||
|
||||
#ifndef FACTORY_SERVO_OSCILLATOR_FREQUENCY
|
||||
#define FACTORY_SERVO_OSCILLATOR_FREQUENCY 27000000
|
||||
#endif
|
||||
|
||||
#ifndef FACTORY_SERVO_CENTER_ANGLE
|
||||
#define FACTORY_SERVO_CENTER_ANGLE 90
|
||||
#endif
|
||||
|
||||
struct servo_t
|
||||
{
|
||||
String name;
|
||||
@@ -22,8 +36,8 @@ struct servo_t
|
||||
|
||||
class ServoConfiguration {
|
||||
public:
|
||||
int32_t servo_oscillator_frequency {SERVO_OSCILLATOR_FREQUENCY};
|
||||
int32_t servo_pwm_frequency {SERVO_FREQ};
|
||||
int32_t servo_oscillator_frequency {FACTORY_SERVO_OSCILLATOR_FREQUENCY};
|
||||
int32_t servo_pwm_frequency {FACTORY_SERVO_PWM_FREQUENCY};
|
||||
std::vector<servo_t> servos_config;
|
||||
bool is_active {false};
|
||||
|
||||
@@ -47,9 +61,9 @@ class ServoConfiguration {
|
||||
}
|
||||
|
||||
static StateUpdateResult update(JsonObject &root, ServoConfiguration &settings) {
|
||||
settings.is_active = root["is_active"];
|
||||
settings.servo_pwm_frequency = root["servo_pwm_frequency"];
|
||||
settings.servo_oscillator_frequency = root["servo_oscillator_frequency"];
|
||||
settings.is_active = root["is_active"] | false;
|
||||
settings.servo_pwm_frequency = root["servo_pwm_frequency"] | FACTORY_SERVO_PWM_FREQUENCY;
|
||||
settings.servo_oscillator_frequency = root["servo_oscillator_frequency"] | FACTORY_SERVO_OSCILLATOR_FREQUENCY;
|
||||
settings.servos_config.clear();
|
||||
|
||||
JsonArray servos = root["servos"];
|
||||
@@ -70,6 +84,17 @@ class ServoConfiguration {
|
||||
settings.servos_config.push_back(new_servo);
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
for (int8_t i = 0; i < FACTORY_SERVO_NUM; i++) {
|
||||
ESP_LOGI("WiFiSettings", "Adding servo %d", i);
|
||||
settings.servos_config.push_back(servo_t {
|
||||
.name = "Servo " + String(i),
|
||||
.channel = i,
|
||||
.inverted = 1,
|
||||
.angle = 0,
|
||||
.center_angle = FACTORY_SERVO_CENTER_ANGLE
|
||||
});
|
||||
}
|
||||
}
|
||||
return StateUpdateResult::CHANGED;
|
||||
};
|
||||
|
||||
@@ -118,7 +118,7 @@ void WiFiSettingsService::connectToWiFi()
|
||||
}
|
||||
else if (scanResult == 0)
|
||||
{
|
||||
ESP_LOGW("WiFiSettingsService", "No networks found.");
|
||||
ESP_LOGI("WiFiSettingsService", "No networks found.");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user