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) {
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) {

View file

@ -23,6 +23,9 @@ typedef struct {
float z;
} compassPrefData;
#define compOff "/compOff"
#define compScale "/compScale"
#include <QMC5883LCompass.h>
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;
}

View file

@ -38,6 +38,9 @@ typedef struct {
float z;
} mpuPrefData;
#define mpuOffGyr "/mpuOffGyr"
#define mpuOffAcc "/mpuOffAcc"
#include <MPU6050_jusax23.h>
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;