move constants nvs load to firehazard module
This commit is contained in:
+2
-18
@@ -101,6 +101,7 @@ void __attribute__((noreturn)) app_main()
|
||||
tcpip_adapter_init();
|
||||
initialise_wifi();
|
||||
|
||||
#if 0
|
||||
// TODO add proper join procedure
|
||||
const char *ssid = "Chlivek_2.4G";
|
||||
const char *pass = "slepice123";
|
||||
@@ -113,6 +114,7 @@ void __attribute__((noreturn)) app_main()
|
||||
ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
|
||||
ESP_ERROR_CHECK( esp_wifi_disconnect() );
|
||||
ESP_ERROR_CHECK( esp_wifi_connect() );
|
||||
#endif
|
||||
|
||||
gui_init();
|
||||
knob_init();
|
||||
@@ -122,24 +124,6 @@ void __attribute__((noreturn)) app_main()
|
||||
websrv_init();
|
||||
fire_init();
|
||||
|
||||
nvs_handle nvs;
|
||||
|
||||
ESP_ERROR_CHECK(nvs_open("config", NVS_READWRITE, &nvs)); // must use RW to allow opening nonexistent
|
||||
|
||||
union uf32 kp, ki, kd;
|
||||
|
||||
// TODO set good defaults
|
||||
kp.f = 0.3f;
|
||||
ki.f = 0.5f;
|
||||
kd.f = 0.0f;
|
||||
|
||||
nvs_get_u32(nvs, "kp", &kp.u);
|
||||
nvs_get_u32(nvs, "ki", &ki.u);
|
||||
nvs_get_u32(nvs, "kd", &kd.u);
|
||||
|
||||
fire_set_tuning(kp.f, ki.f, kd.f);
|
||||
nvs_close(nvs);
|
||||
|
||||
bool level = 0;
|
||||
while (1) {
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
|
||||
+13
-1
@@ -8,6 +8,7 @@
|
||||
#include <nvs.h>
|
||||
#include "driver/ledc.h"
|
||||
#include "esp_err.h"
|
||||
#include "utils.h"
|
||||
|
||||
static const char *TAG = "fire";
|
||||
|
||||
@@ -29,7 +30,18 @@ void fire_init() {
|
||||
PID_SetOutputLimits(&pid, 0, 1);
|
||||
PID_SetCtlMode(&pid, PID_MANUAL);
|
||||
|
||||
PID_SetTunings(&pid, 0.3, 0.01, 0.1); // TODO load from nvs
|
||||
nvs_handle nvs;
|
||||
ESP_ERROR_CHECK(nvs_open("config", NVS_READWRITE, &nvs)); // must use RW to allow opening nonexistent
|
||||
union uf32 kp, ki, kd;
|
||||
kp.f = 0.4f;
|
||||
ki.f = 0.5f;
|
||||
kd.f = 0.0f;
|
||||
nvs_get_u32(nvs, "kp", &kp.u);
|
||||
nvs_get_u32(nvs, "ki", &ki.u);
|
||||
nvs_get_u32(nvs, "kd", &kd.u);
|
||||
PID_SetTunings(&pid, kp.f, ki.f, kd.f);
|
||||
nvs_close(nvs);
|
||||
|
||||
pwm_init();
|
||||
|
||||
fire_setlevel(20);
|
||||
|
||||
Reference in New Issue
Block a user