This commit is contained in:
jusax23 2023-09-24 21:28:11 +02:00
parent cd2102cbd4
commit 1e4a2250d9
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41
3 changed files with 19 additions and 13 deletions

View file

@ -33,7 +33,7 @@ bool fs_read(String path, void *buffer, size_t len) {
bool fs_write(String path, void *buffer, size_t len) { bool fs_write(String path, void *buffer, size_t len) {
mutex_enter_blocking(&littelfs_mut); mutex_enter_blocking(&littelfs_mut);
File f = LittleFS.open(path, "w"); File f = LittleFS.open(path, "w+");
bool succ = false; bool succ = false;
if (f) { if (f) {
if (f.write((const unsigned char *)buffer, len) == len) { if (f.write((const unsigned char *)buffer, len) == len) {

View file

@ -23,6 +23,9 @@ typedef struct {
float z; float z;
} compassPrefData; } compassPrefData;
#define compOff "/compOff"
#define compScale "/compScale"
#include <QMC5883LCompass.h> #include <QMC5883LCompass.h>
QMC5883LCompass compass; QMC5883LCompass compass;
@ -33,13 +36,13 @@ void initCOMP() {
compassPrefData buffer; compassPrefData buffer;
if (!fs_read("compOff", &buffer, sizeof(buffer))) { if (!fs_read(compOff, &buffer, sizeof(buffer))) {
buffer.x = 0; buffer.x = 0;
buffer.y = 0; buffer.y = 0;
buffer.z = 0; buffer.z = 0;
} }
compass.setCalibrationOffsets(buffer.x, buffer.y, buffer.z); 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.x = 1;
buffer.y = 1; buffer.y = 1;
buffer.z = 1; buffer.z = 1;
@ -77,11 +80,11 @@ void COMPradioTask() {
buffer.x = compass.getCalibrationOffset(0); buffer.x = compass.getCalibrationOffset(0);
buffer.y = compass.getCalibrationOffset(1); buffer.y = compass.getCalibrationOffset(1);
buffer.z = compass.getCalibrationOffset(2); buffer.z = compass.getCalibrationOffset(2);
fs_write("compOff", &buffer, sizeof(buffer)); fs_write(compOff, &buffer, sizeof(buffer));
buffer.x = compass.getCalibrationScale(0); buffer.x = compass.getCalibrationScale(0);
buffer.y = compass.getCalibrationScale(1); buffer.y = compass.getCalibrationScale(1);
buffer.z = compass.getCalibrationScale(2); buffer.z = compass.getCalibrationScale(2);
fs_write("compScale", &buffer, sizeof(buffer)); fs_write(compScale, &buffer, sizeof(buffer));
compass_is_calibrating = false; compass_is_calibrating = false;
} break; } break;
} }

View file

@ -38,6 +38,9 @@ typedef struct {
float z; float z;
} mpuPrefData; } mpuPrefData;
#define mpuOffGyr "/mpuOffGyr"
#define mpuOffAcc "/mpuOffAcc"
#include <MPU6050_jusax23.h> #include <MPU6050_jusax23.h>
MPU6050 mpu6050(Wire, 0.001f, 0.999f); MPU6050 mpu6050(Wire, 0.001f, 0.999f);
@ -50,14 +53,14 @@ void initMPU() {
mpuPrefData buffer; mpuPrefData buffer;
if (!fs_read("mpuOffGyr", &buffer, sizeof(buffer))) { if (!fs_read(mpuOffGyr, &buffer, sizeof(buffer))) {
buffer.x = -7.8; buffer.x = -7.8;
buffer.y = 2.32; buffer.y = 2.32;
buffer.z = -0.22; buffer.z = -0.22;
} }
mpu6050.setGyroOffsets(buffer.x, buffer.y, buffer.z); 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.x = 0.03;
buffer.y = 0.0; buffer.y = 0.0;
buffer.z = 0.3; buffer.z = 0.3;
@ -145,7 +148,7 @@ void MPUradioTask() {
float offY = mpu6050.calcAccYoffset(); float offY = mpu6050.calcAccYoffset();
float offZ = mpu6050.calcAccZoffset(); float offZ = mpu6050.calcAccZoffset();
mpuPrefData buffer{.x = offX, .y = offY, .z = offZ}; 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); mpu6050.setAccXoffset(offX, offY, offZ);
} break; } break;
case jCommand_MPU_set_calc_offsets_gyro: { case jCommand_MPU_set_calc_offsets_gyro: {
@ -153,7 +156,7 @@ void MPUradioTask() {
float offY = mpu6050.getGyroYoffsetGlide(); float offY = mpu6050.getGyroYoffsetGlide();
float offZ = mpu6050.getGyroZoffsetGlide(); float offZ = mpu6050.getGyroZoffsetGlide();
mpuPrefData buffer{.x = offX, .y = offY, .z = offZ}; 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); mpu6050.setGyroOffsets(offX, offY, offZ);
} break; } break;
case jCommand_MPU_get_calc_offsets_acc: { case jCommand_MPU_get_calc_offsets_acc: {
@ -176,14 +179,14 @@ void MPUradioTask() {
mpuSendData data; mpuSendData data;
memmove(&data, &jRCbuff, sizeof(data)); memmove(&data, &jRCbuff, sizeof(data));
mpuPrefData buffer{.x = data.X, .y = data.Y, .z = data.Z}; 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); mpu6050.setGyroOffsets(data.X, data.Y, data.Z);
} break; } break;
case jCommand_MPU_set_offsets_gyro: { case jCommand_MPU_set_offsets_gyro: {
mpuSendData data; mpuSendData data;
memmove(&data, &jRCbuff, sizeof(data)); memmove(&data, &jRCbuff, sizeof(data));
mpuPrefData buffer{.x = data.X, .y = data.Y, .z = data.Z}; 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); mpu6050.setAccXoffset(data.X, data.Y, data.Z);
} break; } break;
@ -192,7 +195,7 @@ void MPUradioTask() {
data.command = jCommand_MPU_get_offsets_acc; data.command = jCommand_MPU_get_offsets_acc;
mpuPrefData buffer; mpuPrefData buffer;
if (!fs_read("mpuOffAcc", &buffer, sizeof(buffer))) { if (!fs_read(mpuOffAcc, &buffer, sizeof(buffer))) {
buffer.x = 0.03; buffer.x = 0.03;
buffer.y = 0.0; buffer.y = 0.0;
buffer.z = 0.3; buffer.z = 0.3;
@ -207,7 +210,7 @@ void MPUradioTask() {
data.command = jCommand_MPU_get_offsets_gyro; data.command = jCommand_MPU_get_offsets_gyro;
mpuPrefData buffer; mpuPrefData buffer;
if (!fs_read("mpuOffGyr", &buffer, sizeof(buffer))) { if (!fs_read(mpuOffGyr, &buffer, sizeof(buffer))) {
buffer.x = -7.8; buffer.x = -7.8;
buffer.y = 2.32; buffer.y = 2.32;
buffer.z = -0.22; buffer.z = -0.22;