From 783571ccdd1e9a0b256a172bb6ebaa3aacdb687d Mon Sep 17 00:00:00 2001 From: Denis Date: Sun, 19 Nov 2023 02:42:29 +0100 Subject: [PATCH] test for accel --- dev_iio.c | 13 ++++++++++--- output_dev.c | 4 ++-- rogue_enemy.h | 5 ++++- virt_ds4.c | 6 +++--- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/dev_iio.c b/dev_iio.c index f7903ea..f5e6f2d 100644 --- a/dev_iio.c +++ b/dev_iio.c @@ -188,10 +188,17 @@ dev_iio_t* dev_iio_create(const char* path) { // =========================================== in_accel_scale =============================================== { + const char* preferred_scale = LSB_PER_16G_STR; char* const accel_scale = read_file(iio->path, "/in_accel_scale"); if (accel_scale != NULL) { iio->accel_scale_x = iio->accel_scale_y = iio->accel_scale_z = strtod(accel_scale, NULL); free((void*)accel_scale); + + if (write_file(iio->path, "/in_anglvel_scale", preferred_scale, strlen(preferred_scale)) >= 0) { + iio->accel_scale_x = iio->accel_scale_y = iio->accel_scale_z = LSB_PER_16G; + } else { + fprintf(stderr, "Unable to set preferred in_accel_scale for device %s.\n", iio->name); + } } else { // TODO: what about if those are plit in in_accel_{x,y,z}_scale? fprintf(stderr, "Unable to read in_accel_scale file from path %s%s.\n", iio->path, "/in_accel_scale"); @@ -471,7 +478,7 @@ int dev_iio_read_imu(const dev_iio_t *const iio, imu_message_t *const out) { const int tmp_read = fread((void*)&tmp[0], 1, sizeof(tmp), iio->accel_x_fd); if (tmp_read >= 0) { out->accel_x_raw = strtol(&tmp[0], NULL, 10); - accel_out[0] = (double)out->accel_x_raw * iio->accel_scale_x; + accel_in[0] = (double)out->accel_x_raw * iio->accel_scale_x; } else { fprintf(stderr, "While reading accel(x): %d\n", tmp_read); return tmp_read; @@ -484,7 +491,7 @@ int dev_iio_read_imu(const dev_iio_t *const iio, imu_message_t *const out) { const int tmp_read = fread((void*)&tmp[0], 1, sizeof(tmp), iio->accel_y_fd); if (tmp_read >= 0) { out->accel_y_raw = strtol(&tmp[0], NULL, 10); - accel_out[1] = (double)out->accel_y_raw * iio->accel_scale_y; + accel_in[1] = (double)out->accel_y_raw * iio->accel_scale_y; } else { fprintf(stderr, "While reading accel(y): %d\n", tmp_read); return tmp_read; @@ -497,7 +504,7 @@ int dev_iio_read_imu(const dev_iio_t *const iio, imu_message_t *const out) { const int tmp_read = fread((void*)&tmp[0], 1, sizeof(tmp), iio->accel_z_fd); if (tmp_read >= 0) { out->accel_z_raw = strtol(&tmp[0], NULL, 10); - accel_out[2] = (double)out->accel_z_raw * iio->accel_scale_z; + accel_in[2] = (double)out->accel_z_raw * iio->accel_scale_z; } else { fprintf(stderr, "While reading accel(z): %d\n", tmp_read); return tmp_read; diff --git a/output_dev.c b/output_dev.c index caef27d..1a31f5a 100644 --- a/output_dev.c +++ b/output_dev.c @@ -740,8 +740,8 @@ static void handle_msg(output_dev_t *const out_dev, message_t *const msg) { const int upd_beg_res = logic_begin_status_update(out_dev->logic); if (upd_beg_res == 0) { out_dev->logic->gamepad.last_motion_time = msg->data.imu.read_time; - memcpy(out_dev->logic->gamepad.gyro, msg->data.imu.gyro_rad_s, sizeof(double) * 3); - memcpy(out_dev->logic->gamepad.accel, msg->data.imu.accel_m2s, sizeof(double) * 3); + memcpy(out_dev->logic->gamepad.gyro, msg->data.imu.gyro_rad_s, sizeof(double[3])); + memcpy(out_dev->logic->gamepad.accel, msg->data.imu.accel_m2s, sizeof(double[3])); logic_end_status_update(out_dev->logic); diff --git a/rogue_enemy.h b/rogue_enemy.h index f417f5a..65cc229 100644 --- a/rogue_enemy.h +++ b/rogue_enemy.h @@ -27,4 +27,7 @@ #include #define LSB_PER_RAD_S_2000_DEG_S ((double)0.001064724) -#define LSB_PER_RAD_S_2000_DEG_S_STR "0.001064724" \ No newline at end of file +#define LSB_PER_RAD_S_2000_DEG_S_STR "0.001064724" + +#define LSB_PER_16G ((double)0.004785) +#define LSB_PER_16G_STR "0.004785" \ No newline at end of file diff --git a/virt_ds4.c b/virt_ds4.c index 80e2523..547015b 100644 --- a/virt_ds4.c +++ b/virt_ds4.c @@ -564,9 +564,9 @@ static int send_data(int fd, logic_t *const logic, uint8_t counter) { const int16_t g_x = (gs.gyro[0]) / LSB_PER_RAD_S_2000_DEG_S; const int16_t g_y = (gs.gyro[1]) / LSB_PER_RAD_S_2000_DEG_S; const int16_t g_z = (gs.gyro[2]) / LSB_PER_RAD_S_2000_DEG_S; - const int16_t a_x = gs.accel[0] / (double)2.0; // TODO: IDK how to test... - const int16_t a_y = gs.accel[1] / (double)2.0; // TODO: IDK how to test... - const int16_t a_z = gs.accel[2] / (double)2.0; // TODO: IDK how to test... + const int16_t a_x = (gs.accel[0]) / LSB_PER_16G; // TODO: IDK how to test... + const int16_t a_y = (gs.accel[1]) / LSB_PER_16G; // TODO: IDK how to test... + const int16_t a_z = (gs.accel[2]) / LSB_PER_16G; // TODO: IDK how to test... buf[0] = 0x01; // [00] report ID (0x01) buf[1] = ((uint64_t)((int64_t)gs.joystick_positions[0][0] + (int64_t)32768) >> (uint64_t)8); // L stick, X axis