diff --git a/app/src/lib/models.ts b/app/src/lib/models.ts index 0a22098..dae1c8e 100644 --- a/app/src/lib/models.ts +++ b/app/src/lib/models.ts @@ -170,20 +170,23 @@ export type CameraSettings = { hmirror: boolean; }; -export type servo = { - channel: number; - name: string; - inverted: boolean; - angle: number; - center_angle: number; - // min_pwm: number; - // max_pwm: number; - // min_angle: number; - // max_angle: number; -}; - export type File = number; export interface Directory { [key: string]: File | Directory; -} \ No newline at end of file +} + +export type Servo = { + name: string; + channel: number; + inverted: boolean; + angle: number; + center_angle: number; +}; + +export type ServoConfiguration = { + is_active: boolean; + servo_pwm_frequency: number; + servo_oscillator_frequency: number; + servos: Servo[]; +}; \ No newline at end of file diff --git a/app/src/routes/peripherals/servo/servo.svelte b/app/src/routes/peripherals/servo/servo.svelte index 122cbb4..2956472 100644 --- a/app/src/routes/peripherals/servo/servo.svelte +++ b/app/src/routes/peripherals/servo/servo.svelte @@ -1,6 +1,6 @@
diff --git a/app/src/routes/peripherals/servo/servos.svelte b/app/src/routes/peripherals/servo/servos.svelte index db5f7e5..350072b 100644 --- a/app/src/routes/peripherals/servo/servos.svelte +++ b/app/src/routes/peripherals/servo/servos.svelte @@ -1,39 +1,51 @@ Servo - {#each servos as servo} - + {#await getServoConfig() } + + {:then _} +
+

General servo configuration

+ + Servo Oscillator Frequency + + + Servo PWM Frequency + + + Is active + +
- {/each} + {#each servo_config.servos as servo} + +
+ {/each} + {/await}
\ No newline at end of file diff --git a/app/src/routes/system/filesystem/FileSystem.svelte b/app/src/routes/system/filesystem/FileSystem.svelte index 20ace7f..4d0e577 100644 --- a/app/src/routes/system/filesystem/FileSystem.svelte +++ b/app/src/routes/system/filesystem/FileSystem.svelte @@ -9,7 +9,7 @@ let filename = ''; const getFiles = async () => { - const result = await api.get('/api/files/list') + const result = await api.get('/api/files') if (result.isOk()) { return result.inner; } diff --git a/esp32/factory_settings.ini b/esp32/factory_settings.ini index fc66fed..ddef7f5 100644 --- a/esp32/factory_settings.ini +++ b/esp32/factory_settings.ini @@ -54,4 +54,10 @@ build_flags = -D FACTORY_MQTT_MAX_TOPIC_LENGTH=128 ; JWT Secret - -D FACTORY_JWT_SECRET=\"#{random}-#{random}\" ; supports placeholders \ No newline at end of file + -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 \ No newline at end of file diff --git a/esp32/lib/ESP32-sveltekit/FileExplorerService.h b/esp32/lib/ESP32-sveltekit/FileExplorerService.h index 3194a9f..9987331 100644 --- a/esp32/lib/ESP32-sveltekit/FileExplorerService.h +++ b/esp32/lib/ESP32-sveltekit/FileExplorerService.h @@ -5,7 +5,8 @@ #include #include -#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()) + { + 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); diff --git a/esp32/lib/ESP32-sveltekit/ServoController.h b/esp32/lib/ESP32-sveltekit/ServoController.h index 728e567..5b86db4 100644 --- a/esp32/lib/ESP32-sveltekit/ServoController.h +++ b/esp32/lib/ESP32-sveltekit/ServoController.h @@ -6,11 +6,25 @@ #include -#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 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; }; diff --git a/esp32/lib/ESP32-sveltekit/WiFiSettingsService.cpp b/esp32/lib/ESP32-sveltekit/WiFiSettingsService.cpp index 1fc67f6..1638774 100644 --- a/esp32/lib/ESP32-sveltekit/WiFiSettingsService.cpp +++ b/esp32/lib/ESP32-sveltekit/WiFiSettingsService.cpp @@ -118,7 +118,7 @@ void WiFiSettingsService::connectToWiFi() } else if (scanResult == 0) { - ESP_LOGW("WiFiSettingsService", "No networks found."); + ESP_LOGI("WiFiSettingsService", "No networks found."); } else {