From 1e4a2250d9f07d129db6e1a91fdf17379d9aa386 Mon Sep 17 00:00:00 2001 From: jusax23 Date: Sun, 24 Sep 2023 21:28:11 +0200 Subject: [PATCH] fs fix --- fs_helper.h | 2 +- system_sensors/compass.h | 11 +++++++---- system_sensors/mpu.h | 19 +++++++++++-------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/fs_helper.h b/fs_helper.h index 597861e..e38a8f2 100644 --- a/fs_helper.h +++ b/fs_helper.h @@ -33,7 +33,7 @@ bool fs_read(String path, void *buffer, size_t len) { bool fs_write(String path, void *buffer, size_t len) { mutex_enter_blocking(&littelfs_mut); - File f = LittleFS.open(path, "w"); + File f = LittleFS.open(path, "w+"); bool succ = false; if (f) { if (f.write((const unsigned char *)buffer, len) == len) { diff --git a/system_sensors/compass.h b/system_sensors/compass.h index ead6eca..079fcd8 100644 --- a/system_sensors/compass.h +++ b/system_sensors/compass.h @@ -23,6 +23,9 @@ typedef struct { float z; } compassPrefData; +#define compOff "/compOff" +#define compScale "/compScale" + #include QMC5883LCompass compass; @@ -33,13 +36,13 @@ void initCOMP() { compassPrefData buffer; - if (!fs_read("compOff", &buffer, sizeof(buffer))) { + if (!fs_read(compOff, &buffer, sizeof(buffer))) { buffer.x = 0; buffer.y = 0; buffer.z = 0; } compass.setCalibrationOffsets(buffer.x, buffer.y, buffer.z); - if (!fs_read("compScale", &buffer, sizeof(buffer))) { + if (!fs_read(compScale, &buffer, sizeof(buffer))) { buffer.x = 1; buffer.y = 1; buffer.z = 1; @@ -77,11 +80,11 @@ void COMPradioTask() { buffer.x = compass.getCalibrationOffset(0); buffer.y = compass.getCalibrationOffset(1); buffer.z = compass.getCalibrationOffset(2); - fs_write("compOff", &buffer, sizeof(buffer)); + fs_write(compOff, &buffer, sizeof(buffer)); buffer.x = compass.getCalibrationScale(0); buffer.y = compass.getCalibrationScale(1); buffer.z = compass.getCalibrationScale(2); - fs_write("compScale", &buffer, sizeof(buffer)); + fs_write(compScale, &buffer, sizeof(buffer)); compass_is_calibrating = false; } break; } diff --git a/system_sensors/mpu.h b/system_sensors/mpu.h index 4b07e18..fe2f345 100644 --- a/system_sensors/mpu.h +++ b/system_sensors/mpu.h @@ -38,6 +38,9 @@ typedef struct { float z; } mpuPrefData; +#define mpuOffGyr "/mpuOffGyr" +#define mpuOffAcc "/mpuOffAcc" + #include MPU6050 mpu6050(Wire, 0.001f, 0.999f); @@ -50,14 +53,14 @@ void initMPU() { mpuPrefData buffer; - if (!fs_read("mpuOffGyr", &buffer, sizeof(buffer))) { + if (!fs_read(mpuOffGyr, &buffer, sizeof(buffer))) { buffer.x = -7.8; buffer.y = 2.32; buffer.z = -0.22; } mpu6050.setGyroOffsets(buffer.x, buffer.y, buffer.z); - if (!fs_read("mpuOffAcc", &buffer, sizeof(buffer))) { + if (!fs_read(mpuOffAcc, &buffer, sizeof(buffer))) { buffer.x = 0.03; buffer.y = 0.0; buffer.z = 0.3; @@ -145,7 +148,7 @@ void MPUradioTask() { float offY = mpu6050.calcAccYoffset(); float offZ = mpu6050.calcAccZoffset(); mpuPrefData buffer{.x = offX, .y = offY, .z = offZ}; - fs_write("mpuOffAcc", &buffer, sizeof(buffer)); + fs_write(mpuOffAcc, &buffer, sizeof(buffer)); mpu6050.setAccXoffset(offX, offY, offZ); } break; case jCommand_MPU_set_calc_offsets_gyro: { @@ -153,7 +156,7 @@ void MPUradioTask() { float offY = mpu6050.getGyroYoffsetGlide(); float offZ = mpu6050.getGyroZoffsetGlide(); mpuPrefData buffer{.x = offX, .y = offY, .z = offZ}; - fs_write("mpuOffGyr", &buffer, sizeof(buffer)); + fs_write(mpuOffGyr, &buffer, sizeof(buffer)); mpu6050.setGyroOffsets(offX, offY, offZ); } break; case jCommand_MPU_get_calc_offsets_acc: { @@ -176,14 +179,14 @@ void MPUradioTask() { mpuSendData data; memmove(&data, &jRCbuff, sizeof(data)); mpuPrefData buffer{.x = data.X, .y = data.Y, .z = data.Z}; - fs_write("mpuOffAcc", &buffer, sizeof(buffer)); + fs_write(mpuOffAcc, &buffer, sizeof(buffer)); mpu6050.setGyroOffsets(data.X, data.Y, data.Z); } break; case jCommand_MPU_set_offsets_gyro: { mpuSendData data; memmove(&data, &jRCbuff, sizeof(data)); mpuPrefData buffer{.x = data.X, .y = data.Y, .z = data.Z}; - fs_write("mpuOffGyr", &buffer, sizeof(buffer)); + fs_write(mpuOffGyr, &buffer, sizeof(buffer)); mpu6050.setAccXoffset(data.X, data.Y, data.Z); } break; @@ -192,7 +195,7 @@ void MPUradioTask() { data.command = jCommand_MPU_get_offsets_acc; mpuPrefData buffer; - if (!fs_read("mpuOffAcc", &buffer, sizeof(buffer))) { + if (!fs_read(mpuOffAcc, &buffer, sizeof(buffer))) { buffer.x = 0.03; buffer.y = 0.0; buffer.z = 0.3; @@ -207,7 +210,7 @@ void MPUradioTask() { data.command = jCommand_MPU_get_offsets_gyro; mpuPrefData buffer; - if (!fs_read("mpuOffGyr", &buffer, sizeof(buffer))) { + if (!fs_read(mpuOffGyr, &buffer, sizeof(buffer))) { buffer.x = -7.8; buffer.y = 2.32; buffer.z = -0.22;