Skip to content

Commit

Permalink
Fix sampling rate of iio and reduce reporting frequency from devices
Browse files Browse the repository at this point in the history
  • Loading branch information
NeroReflex committed Feb 13, 2024
1 parent 9da2278 commit 98e64bb
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
6 changes: 3 additions & 3 deletions dev_out.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,9 @@ void *dev_out_thread_func(void *ptr) {
printf("Keyboard initialized: fd=%d\n", current_keyboard_fd);
}

const int64_t kbd_report_timing_us = 1125;
const int64_t mouse_report_timing_us = 950;
const int64_t gamepad_report_timing_us = 1250;
const int64_t kbd_report_timing_us = 2025;
const int64_t mouse_report_timing_us = 1650;
const int64_t gamepad_report_timing_us = 2500;

if (current_gamepad == GAMEPAD_DUALSENSE) {
const int ds5_init_res = virt_dualsense_init(
Expand Down
49 changes: 43 additions & 6 deletions rog_ally.c
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,8 @@ typedef struct dev_iio {

double mount_matrix[3][3];

double sampling_rate_hz;
double anglvel_sampling_rate_hz;
double accel_sampling_rate_hz;
} dev_old_iio_t;


Expand Down Expand Up @@ -1785,14 +1786,50 @@ static dev_old_iio_t* dev_old_iio_create(const char* path) {
}
// ==========================================================================================================

// ============================================ sampling_rate ================================================
// ======================================= anglvel_sampling_rate_hz ==========================================
{
char* const accel_scale = read_file(iio->path, "/in_temp_scale");
const char* preferred_scale = PREFERRED_SAMPLING_FREQ_STR;
const char *scale_main_file = "/in_anglvel_sampling_frequency";

char* const accel_scale = read_file(iio->path, scale_main_file);
if (accel_scale != NULL) {
iio->temp_scale = strtod(accel_scale, NULL);
iio->anglvel_sampling_rate_hz = strtod(accel_scale, NULL);
free((void*)accel_scale);

if (inline_write_file(iio->path, scale_main_file, preferred_scale, strlen(preferred_scale)) >= 0) {
iio->anglvel_sampling_rate_hz = PREFERRED_SAMPLING_FREQ;
printf("anglvel sampling rate changed to %f for device %s\n", iio->accel_scale_x, iio->name);
} else {
fprintf(stderr, "Unable to set preferred in_anglvel_sampling_frequency for device %s.\n", iio->name);
}
} else {
fprintf(stderr, "Unable to read in_accel_scale file from path %s%s.\n", iio->path, "/in_accel_scale");
fprintf(stderr, "Unable to read in_anglvel_sampling_frequency file from path %s%s.\n", iio->path, scale_main_file);

free(iio);
iio = NULL;
goto dev_old_iio_create_err;
}
}
// ==========================================================================================================

// ======================================= accel_sampling_rate_hz ==========================================
{
const char* preferred_scale = PREFERRED_SAMPLING_FREQ_STR;
const char *scale_main_file = "/in_accel_sampling_frequency";

char* const accel_scale = read_file(iio->path, scale_main_file);
if (accel_scale != NULL) {
iio->accel_sampling_rate_hz = strtod(accel_scale, NULL);
free((void*)accel_scale);

if (inline_write_file(iio->path, scale_main_file, preferred_scale, strlen(preferred_scale)) >= 0) {
iio->accel_sampling_rate_hz = PREFERRED_SAMPLING_FREQ;
printf("accel sampling rate changed to %f for device %s\n", iio->accel_scale_x, iio->name);
} else {
fprintf(stderr, "Unable to set preferred in_accel_sampling_frequency for device %s.\n", iio->name);
}
} else {
fprintf(stderr, "Unable to read in_accel_sampling_frequency file from path %s%s.\n", iio->path, scale_main_file);

free(iio);
iio = NULL;
Expand Down Expand Up @@ -2038,7 +2075,7 @@ input_dev_t bmc150_timer_dev = {
.timer = {
.name = "RC71L_bmc150-accel_timer",
.ticktime_ms = 0,
.ticktime_ns = 625000
.ticktime_ns = 1250000
}
},
.user_data = &bmc15_timer_data,
Expand Down
3 changes: 3 additions & 0 deletions rogue_enemy.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
#define LSB_PER_16G ((double)0.004785)
#define LSB_PER_16G_STR "0.004785"

#define PREFERRED_SAMPLING_FREQ ((double)800.000000)
#define PREFERRED_SAMPLING_FREQ_STR "800.000000"

// courtesy of linux kernel
#ifndef __packed
#define __packed __attribute__((packed))
Expand Down

0 comments on commit 98e64bb

Please sign in to comment.