-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor for multi-device support (#29)
* WIP refactor, mostly working * Fixed issues with calibration state * Solved issue with duplicate free() calls * Hide all device-specific functionality behind generic interfaces * Reduce default look-ahead multiplier for XREAL
- Loading branch information
Showing
21 changed files
with
1,026 additions
and
706 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#pragma once | ||
|
||
#include <stdbool.h> | ||
|
||
struct buffer_t { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <stdbool.h> | ||
|
||
struct driver_config_t { | ||
bool disabled; | ||
bool use_roll_axis; | ||
int mouse_sensitivity; | ||
char *output_mode; | ||
float look_ahead_override; | ||
float external_zoom; | ||
|
||
bool debug_threads; | ||
bool debug_joystick; | ||
bool debug_multi_tap; | ||
bool debug_ipc; | ||
}; | ||
|
||
typedef struct driver_config_t driver_config_type; | ||
|
||
extern const char *joystick_output_mode; | ||
extern const char *mouse_output_mode; | ||
extern const char *external_only_output_mode; | ||
|
||
driver_config_type *default_config(); | ||
void update_config(driver_config_type **config, driver_config_type *new_config); | ||
|
||
bool is_joystick_mode(driver_config_type *config); | ||
bool is_mouse_mode(driver_config_type *config); | ||
bool is_external_mode(driver_config_type *config); | ||
bool is_evdev_output_mode(driver_config_type *config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include "imu.h" | ||
|
||
#include <stdbool.h> | ||
#include <stdint.h> | ||
|
||
typedef void (*imu_event_handler)(uint32_t timestamp_ms, imu_quat_type quat, imu_vector_type euler); | ||
typedef bool (*should_disconnect_callback)(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
#include <stdio.h> | ||
#include <stdbool.h> | ||
|
||
// creates a file, if it doesn't already exist, in the user home directory with home directory permissions and ownership. | ||
// this is helpful since the driver may be run with sudo, so we don't create files owned by root:root | ||
FILE* get_or_create_home_file(char *filename, char *mode, char *full_path, bool *created); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
struct imu_vector_t { | ||
float x; | ||
float y; | ||
float z; | ||
}; | ||
|
||
struct imu_quat_t { | ||
float x; | ||
float y; | ||
float z; | ||
float w; | ||
}; | ||
|
||
typedef struct imu_vector_t imu_vector_type; | ||
typedef struct imu_quat_t imu_quat_type; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
#include "device3.h" | ||
#pragma once | ||
|
||
#include "imu.h" | ||
|
||
#include <stdbool.h> | ||
#include <stdint.h> | ||
|
||
void init_multi_tap(int init_imu_cycles_per_s); | ||
|
||
int detect_multi_tap(device3_vec3_type velocities, uint64_t timestamp, const int cycles_per_second, bool debug_multi_tap); | ||
int detect_multi_tap(imu_vector_type velocities, uint32_t timestamp, bool debug); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include "config.h" | ||
#include "device.h" | ||
#include "imu.h" | ||
#include "ipc.h" | ||
|
||
#include <stdbool.h> | ||
|
||
void init_outputs(device_properties_type *device, driver_config_type *config); | ||
|
||
void deinit_outputs(driver_config_type *config); | ||
|
||
imu_vector_type get_euler_deltas(imu_vector_type euler); | ||
|
||
imu_vector_type get_euler_velocities(device_properties_type *device, imu_vector_type euler_deltas); | ||
|
||
void handle_imu_update(imu_quat_type quat, imu_vector_type euler_deltas, imu_quat_type screen_center, | ||
bool ipc_enabled, bool imu_calibrated, ipc_values_type *ipc_values, device_properties_type *device, | ||
driver_config_type *config); | ||
|
||
void reset_imu_data(ipc_values_type *ipc_values); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
#include <stdlib.h> | ||
|
||
void copy_string(const char *source, char **destination, size_t size); | ||
|
||
void free_and_clear(char **str_ptr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
static const device_properties_type xreal_air_properties = { | ||
.resolution_w = 1920, | ||
.resolution_h = 1080, | ||
.fov = 46.0, | ||
.lens_distance_ratio = 0.035, | ||
.calibration_wait_s = 15 | ||
}; | ||
#pragma once | ||
|
||
extern const device_properties_type xreal_air_properties; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "config.h" | ||
#include "device.h" | ||
#include "string.h" | ||
|
||
#include <stdbool.h> | ||
#include <stdio.h> | ||
|
||
const char *joystick_output_mode = "joystick"; | ||
const char *mouse_output_mode = "mouse"; | ||
const char *external_only_output_mode = "external_only"; | ||
|
||
|
||
driver_config_type *default_config() { | ||
driver_config_type *config = malloc(sizeof(driver_config_type)); | ||
if (config == NULL) { | ||
fprintf(stderr, "Error allocating config"); | ||
exit(1); | ||
} | ||
|
||
config->disabled = false; | ||
config->use_roll_axis = false; | ||
config->mouse_sensitivity = 30; | ||
config->output_mode = NULL; | ||
config->look_ahead_override = 0.0; | ||
config->external_zoom = 1.0; | ||
config->debug_threads = false; | ||
config->debug_joystick = false; | ||
config->debug_multi_tap = false; | ||
config->debug_ipc = false; | ||
|
||
copy_string(mouse_output_mode, &config->output_mode, strlen(mouse_output_mode) + 1); | ||
|
||
return config; | ||
} | ||
|
||
void update_config(driver_config_type **config, driver_config_type *new_config) { | ||
free((*config)->output_mode); | ||
free(*config); | ||
*config = new_config; | ||
} | ||
|
||
bool is_joystick_mode(driver_config_type *config) { | ||
return strcmp(config->output_mode, joystick_output_mode) == 0; | ||
} | ||
|
||
bool is_mouse_mode(driver_config_type *config) { | ||
return strcmp(config->output_mode, mouse_output_mode) == 0; | ||
} | ||
|
||
bool is_external_mode(driver_config_type *config) { | ||
return strcmp(config->output_mode, external_only_output_mode) == 0; | ||
} | ||
|
||
bool is_evdev_output_mode(driver_config_type *config) { | ||
return is_mouse_mode(config) || is_joystick_mode(config); | ||
} |
Oops, something went wrong.