aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libsurvive/survive.h44
-rw-r--r--src/poser_charlesrefine.c6
-rw-r--r--src/survive.c24
-rw-r--r--src/survive_config.c135
-rw-r--r--src/survive_config.h9
-rw-r--r--src/survive_driver_dummy.c6
-rw-r--r--src/survive_playback.c10
7 files changed, 192 insertions, 42 deletions
diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h
index 28c96c3..831113d 100644
--- a/include/libsurvive/survive.h
+++ b/include/libsurvive/survive.h
@@ -10,6 +10,14 @@
extern "C" {
#endif
+
+#ifdef _MSC_VER
+ #define SURVIVE_EXPORT_CONSTRUCTOR SURVIVE_EXPORT
+#else
+ #define SURVIVE_EXPORT_CONSTRUCTOR __attribute__((constructor))
+#endif
+
+
/**
* This struct encodes what the last effective angles seen on a sensor were, and when they occured.
*/
@@ -144,6 +152,7 @@ struct BaseStationData {
struct config_group;
#define BUTTON_QUEUE_MAX_LEN 32
+#define MAX_SHORTHAND_CONFIGS 32
// note: buttonId and axisId are 1-indexed values.
// a value of 0 for an id means that no data is present in that value
@@ -199,12 +208,6 @@ struct SurviveContext {
lighthouse_pose_func lighthouseposeproc;
htc_config_func configfunction;
handle_lightcap_func lightcapfunction;
-
- struct config_group *global_config_values;
- struct config_group *lh_config; // lighthouse configs
- struct config_group
- *temporary_config_values; // Set per-session, from command-line. Not saved but override global_config_values
-
// Calibration data:
int activeLighthouses;
BaseStationData bsd[NUM_LIGHTHOUSES];
@@ -226,6 +229,15 @@ struct SurviveContext {
void *user_ptr;
struct survive_calibration_config calibration_config;
+
+
+ struct config_group *global_config_values;
+ struct config_group *lh_config; // lighthouse configs
+ struct config_group *temporary_config_values; // Set per-session, from command-line. Not saved but override global_config_values
+
+ //shorthand configs for the non-function-call syntax config variables.
+ //It helps with self-documentation, too. Indexes into this are determined by `static_configs`
+ union { int i; FLT f; const char * s; } shorthand_configs[MAX_SHORTHAND_CONFIGS];
};
SURVIVE_EXPORT void survive_verify_FLT_size(
@@ -279,6 +291,19 @@ SURVIVE_EXPORT FLT survive_configf(SurviveContext *ctx, const char *tag, char fl
SURVIVE_EXPORT uint32_t survive_configi(SurviveContext *ctx, const char *tag, char flags, uint32_t def);
SURVIVE_EXPORT const char *survive_configs(SurviveContext *ctx, const char *tag, char flags, const char *def);
+#define STATIC_CONFIG_ITEM_I( variable, name, description, default_value ) static int variable; \
+ SURVIVE_EXPORT_CONSTRUCTOR void REGISTER##variable() { survive_config_bind_variable( 'i', &variable, name, description, default_value ); }
+#define GCONFIGI( variable ) (ctx->shorthand_configs[variable].i)
+
+#define STATIC_CONFIG_ITEM_F( variable, name, description, default_value ) static int variable; \
+ SURVIVE_EXPORT_CONSTRUCTOR void REGISTER##variable() { survive_config_bind_variable( 'f', &variable, name, description, default_value ); }
+#define GCONFIGF( variable ) (ctx->shorthand_configs[variable].f)
+
+#define STATIC_CONFIG_ITEM_S( variable, name, description, default_value ) static int variable; \
+ SURVIVE_EXPORT_CONSTRUCTOR void REGISTER##variable() { survive_config_bind_variable( 's', &variable, name, description, default_value ); }
+#define GCONFIGS( variable ) (ctx->shorthand_configs[variable].s)
+
+
// Install the calibrator.
SURVIVE_EXPORT void survive_cal_install(SurviveContext *ctx); // XXX This will be removed if not already done so.
@@ -308,13 +333,8 @@ SURVIVE_EXPORT int survive_default_htc_config_process(SurviveObject *so, char *c
void RegisterDriver(const char *name, void *data);
-#ifdef _MSC_VER
#define REGISTER_LINKTIME(func) \
- SURVIVE_EXPORT void REGISTER##func() { RegisterDriver(#func, &func); }
-#else
-#define REGISTER_LINKTIME(func) \
- void __attribute__((constructor)) REGISTER##func() { RegisterDriver(#func, &func); }
-#endif
+ SURVIVE_EXPORT_CONSTRUCTOR void REGISTER##func() { RegisterDriver(#func, &func); }
///////////////////////// General stuff for writing drivers ///////
diff --git a/src/poser_charlesrefine.c b/src/poser_charlesrefine.c
index b35a878..b14d882 100644
--- a/src/poser_charlesrefine.c
+++ b/src/poser_charlesrefine.c
@@ -55,9 +55,9 @@ int PoserCharlesRefine(SurviveObject *so, PoserData *pd) {
//TODO: Actually do Madgwick's algorithm
LinmathQuat applymotion;
const SurvivePose * object_pose = &so->OutPose;
- imuData->gyro[0] *= 1./240.;
- imuData->gyro[1] *= 1./240.;
- imuData->gyro[2] *= 1./240.;
+ imuData->gyro[0] *= 1./1000.;
+ imuData->gyro[1] *= 1./1000.;
+ imuData->gyro[2] *= 1./1000.;
quatfromeuler( applymotion, imuData->gyro );
//printf( "%f %f %f\n", imuData->gyro [0], imuData->gyro [1], imuData->gyro [2] );
diff --git a/src/survive.c b/src/survive.c
index 13aeee9..20a2a1b 100644
--- a/src/survive.c
+++ b/src/survive.c
@@ -94,6 +94,8 @@ void survive_verify_FLT_size(uint32_t user_size) {
}
SurviveContext *survive_init_internal(int argc, char *const *argv) {
+ int i;
+
#ifdef RUNTIME_SYMNUM
if (!did_runtime_symnum) {
EnumerateSymbols(SymnumCheck);
@@ -131,15 +133,17 @@ SurviveContext *survive_init_internal(int argc, char *const *argv) {
ctx->state = SURVIVE_STOPPED;
+ survive_config_populate_ctx( ctx );
+
ctx->global_config_values = malloc(sizeof(config_group));
ctx->temporary_config_values = malloc(sizeof(config_group));
ctx->lh_config = malloc(sizeof(config_group) * NUM_LIGHTHOUSES);
// initdata
- init_config_group(ctx->global_config_values, 10);
- init_config_group(ctx->temporary_config_values, 20);
- init_config_group(&ctx->lh_config[0], 10);
- init_config_group(&ctx->lh_config[1], 10);
+ init_config_group(ctx->global_config_values, 10, ctx);
+ init_config_group(ctx->temporary_config_values, 20, ctx);
+ for( i = 0; i < NUM_LIGHTHOUSES; i++ )
+ init_config_group(&ctx->lh_config[i], 10, ctx);
// Process command-line parameters.
char *const *av = argv + 1;
@@ -176,7 +180,9 @@ SurviveContext *survive_init_internal(int argc, char *const *argv) {
const char *name = *av + 2; // Skip the '--';
bool flagArgument = (av + 1 == argvend) || av[1][0] == '-';
- if (flagArgument) {
+ if ( strcmp( name, "help" ) == 0 )
+ showhelp = 1;
+ else if (flagArgument) {
bool value = strncmp("no-", name, 3) != 0;
if (value == 0) {
name += 3; // Skip "no-"
@@ -202,15 +208,19 @@ SurviveContext *survive_init_internal(int argc, char *const *argv) {
fprintf(stderr, " --playback [log file] - Read events from the given file instead of USB devices.\n");
fprintf(stderr, " --playback-factor [f] - Time factor of playback -- 1 is run at the same timing as "
"original, 0 is run as fast as possible.\n");
- return 0;
}
config_read(ctx, survive_configs(ctx, "configfile", SC_GET, "config.json"));
ctx->activeLighthouses = survive_configi(ctx, "lighthousecount", SC_SETCONFIG, 2);
-
config_read_lighthouse(ctx->lh_config, &(ctx->bsd[0]), 0);
config_read_lighthouse(ctx->lh_config, &(ctx->bsd[1]), 1);
+ if( showhelp )
+ {
+ survive_print_known_configs( ctx );
+ return 0;
+ }
+
ctx->faultfunction = survivefault;
ctx->notefunction = survivenote;
ctx->lightproc = survive_default_light_process;
diff --git a/src/survive_config.c b/src/survive_config.c
index d67cd8e..92c0125 100644
--- a/src/survive_config.c
+++ b/src/survive_config.c
@@ -10,16 +10,102 @@
#endif
#include "math.h"
#include <errno.h>
+#include <stdarg.h>
+
+//Static-time registration system.
+
+struct static_conf_t
+{
+ union
+ {
+ FLT f;
+ int i;
+ char * s;
+ } data_default;
+ const char * name;
+ const char * description;
+ char type;
+};
+
+static struct static_conf_t static_configs[MAX_SHORTHAND_CONFIGS];
+
+void survive_config_bind_variable( char vt, int * variable, const char * name, const char * description, ... )
+{
+ va_list ap;
+ va_start(ap, description);
+ int i;
+ struct static_conf_t * config;
+ for( i = 0; i < MAX_SHORTHAND_CONFIGS; i++ )
+ {
+ config = &static_configs[i];
+ if( !config->name || strcmp( config->name, name ) == 0 ) break;
+ }
+ if( i == MAX_SHORTHAND_CONFIGS )
+ {
+ fprintf( stderr, "Fatal: Too many static configuration items. Please recompile with a higher MAX_STATIC_CONFIGS\n" );
+ exit( -1 );
+ }
+ if( !config->description ) config->description = description;
+ if( !config->name ) config->name = name;
+ if( config->type && config->type != vt )
+ {
+ fprintf( stderr, "Fatal: Internal error on variable %s. Types disagree.\n", name );
+ exit( -2 );
+ }
+ config->type = vt;
+ switch( vt )
+ {
+ case 'i': config->data_default.i = va_arg(ap, int); break;
+ case 'f': config->data_default.f = va_arg(ap, FLT); break;
+ case 's': config->data_default.s = va_arg(ap, char *); break;
+ default:
+ fprintf( stderr, "Fatal: Internal error on variable %s. Unknown type %c\n", name, vt );
+ }
+ *variable = i;
+}
+
+void survive_config_populate_ctx( SurviveContext * ctx )
+{
+ int i;
+ struct static_conf_t * config;
+ for( i = 0; i < MAX_SHORTHAND_CONFIGS; i++ )
+ {
+ config = &static_configs[i];
+ switch( config->type )
+ {
+ case 'i': ctx->shorthand_configs[i].i = config->data_default.i;
+ case 'f': ctx->shorthand_configs[i].f = config->data_default.f;
+ case 's': ctx->shorthand_configs[i].s = config->data_default.s;
+ }
+ }
+}
+
+void survive_print_known_configs( SurviveContext * ctx )
+{
+ int i;
+ struct static_conf_t * config;
+ for( i = 0; i < MAX_SHORTHAND_CONFIGS; i++ )
+ {
+ config = &static_configs[i];
+ if( !config->name ) break;
+ switch( config->type )
+ {
+ case 'i': printf( "%10d %20s %s\n", config->data_default.i, config->name, config->description ); break;
+ case 'f': printf( "%10f %20s %s\n", config->data_default.f, config->name, config->description ); break;
+ case 's': printf( "%10s %20s %s\n", config->data_default.s, config->name, config->description ); break;
+ }
+ }
+
+ //XXX TODO: Maybe this should print out the actual config values after being updated from the rest of the config system?
+ //struct config_group *global_config_values;
+ //struct config_group *temporary_config_values; // Set per-session, from command-line. Not saved but override global_config_values
+}
+
+
-//#define MAX_CONFIG_ENTRIES 100
-//#define MAX_LIGHTHOUSES 2
-// config_group global_config_values;
-// config_group lh_config[MAX_LIGHTHOUSES]; //lighthouse configs
-// static uint16_t used_entries = 0;
-// static FILE *config_file = NULL;
const FLT *config_set_float_a(config_group *cg, const char *tag, const FLT *values, uint8_t count);
void init_config_entry(config_entry *ce) {
@@ -27,6 +113,7 @@ void init_config_entry(config_entry *ce) {
ce->tag = NULL;
ce->type = CONFIG_UNKNOWN;
ce->elements = 0;
+ ce->shorthand_place = -1;
}
void destroy_config_entry(config_entry *ce) {
@@ -40,11 +127,12 @@ void destroy_config_entry(config_entry *ce) {
}
}
-void init_config_group(config_group *cg, uint8_t count) {
+void init_config_group(config_group *cg, uint8_t count, SurviveContext * ctx) {
uint16_t i = 0;
cg->used_entries = 0;
cg->max_entries = count;
cg->config_entries = NULL;
+ cg->ctx = ctx;
if (count == 0)
return;
@@ -214,7 +302,7 @@ uint16_t config_read_float_array(config_group *cg, const char *tag, FLT *values,
return count;
}
-config_entry *next_unused_entry(config_group *cg) {
+config_entry *next_unused_entry(config_group *cg, const char * tag) {
config_entry *cv = NULL;
// assert(cg->used_entries < cg->max_entries);
@@ -224,13 +312,28 @@ config_entry *next_unused_entry(config_group *cg) {
cv = cg->config_entries + cg->used_entries;
cg->used_entries++;
+
+
+ int i;
+ struct static_conf_t * config;
+ for( i = 0; i < MAX_SHORTHAND_CONFIGS; i++ )
+ {
+ config = &static_configs[i];
+ if( !config->name ) break;
+ if( strcmp( config->name, tag ) == 0 )
+ {
+ cv->shorthand_place = i;
+ break;
+ }
+ }
+
return cv;
}
const char *config_set_str(config_group *cg, const char *tag, const char *value) {
config_entry *cv = find_config_entry(cg, tag);
if (cv == NULL)
- cv = next_unused_entry(cg);
+ cv = next_unused_entry(cg,tag);
sstrcpy(&(cv->tag), tag);
@@ -241,37 +344,43 @@ const char *config_set_str(config_group *cg, const char *tag, const char *value)
}
cv->type = CONFIG_STRING;
+ if( cv->shorthand_place >= 0 ) cg->ctx->shorthand_configs[cv->shorthand_place].s = value;
+
return value;
}
const uint32_t config_set_uint32(config_group *cg, const char *tag, const uint32_t value) {
config_entry *cv = find_config_entry(cg, tag);
if (cv == NULL)
- cv = next_unused_entry(cg);
+ cv = next_unused_entry(cg,tag);
sstrcpy(&(cv->tag), tag);
cv->numeric.i = value;
cv->type = CONFIG_UINT32;
+ if( cv->shorthand_place >= 0 ) cg->ctx->shorthand_configs[cv->shorthand_place].i = value;
+
return value;
}
const FLT config_set_float(config_group *cg, const char *tag, const FLT value) {
config_entry *cv = find_config_entry(cg, tag);
if (cv == NULL)
- cv = next_unused_entry(cg);
+ cv = next_unused_entry(cg,tag);
sstrcpy(&(cv->tag), tag);
cv->numeric.f = value;
cv->type = CONFIG_FLOAT;
+ if( cv->shorthand_place >= 0 ) cg->ctx->shorthand_configs[cv->shorthand_place].f = value;
+
return value;
}
const FLT *config_set_float_a(config_group *cg, const char *tag, const FLT *values, uint8_t count) {
config_entry *cv = find_config_entry(cg, tag);
if (cv == NULL)
- cv = next_unused_entry(cg);
+ cv = next_unused_entry(cg,tag);
sstrcpy(&(cv->tag), tag);
@@ -548,3 +657,5 @@ const char *survive_configs(SurviveContext *ctx, const char *tag, char flags, co
return def;
}
+
+
diff --git a/src/survive_config.h b/src/survive_config.h
index 23d80c8..37e904c 100644
--- a/src/survive_config.h
+++ b/src/survive_config.h
@@ -26,18 +26,20 @@ typedef struct {
} numeric;
char *data;
uint32_t elements;
+ int shorthand_place;
} config_entry;
typedef struct config_group {
config_entry *config_entries;
uint16_t used_entries;
uint16_t max_entries;
+ SurviveContext * ctx;
} config_group;
//extern config_group global_config_values;
//extern config_group lh_config[2]; //lighthouse configs
-void init_config_group(config_group *cg, uint8_t count);
+void init_config_group(config_group *cg, uint8_t count, SurviveContext * ctx);
void destroy_config_group(config_group* cg);
//void config_init();
@@ -60,4 +62,9 @@ uint16_t config_read_float_array(config_group *cg, const char *tag, FLT* values,
uint32_t config_read_uint32(config_group *cg, const char *tag, const uint32_t def);
const char* config_read_str(config_group *cg, const char *tag, const char *def);
+//These are for the internal non-function configuration system.
+void survive_config_bind_variable( char vt, int * variable, const char * name, const char * description, ... );
+void survive_print_known_configs();
+void survive_config_populate_ctx( SurviveContext * ctx );
+
#endif
diff --git a/src/survive_driver_dummy.c b/src/survive_driver_dummy.c
index e2e01a4..01d0482 100644
--- a/src/survive_driver_dummy.c
+++ b/src/survive_driver_dummy.c
@@ -8,6 +8,8 @@
#include "survive_config.h"
#include "os_generic.h"
+STATIC_CONFIG_ITEM_I( DUMMY_DRIVER_ENABLE, "dummy-driver-enable", "Load a dummy driver for testing.", 0 );
+
struct SurviveDriverDummy {
SurviveContext * ctx;
SurviveObject * so;
@@ -53,9 +55,7 @@ int dummy_haptic( SurviveObject * so, uint8_t reserved, uint16_t pulseHigh, uint
int DriverRegDummy(SurviveContext *ctx)
{
- int enable_dummy_driver = survive_configi( ctx, "dummy_driver_enable", SC_GET, 0 );
-
- if( !enable_dummy_driver ) return 0;
+ if( !GCONFIGI(DUMMY_DRIVER_ENABLE) ) return 0;
SurviveDriverDummy *sp = calloc(1, sizeof(SurviveDriverDummy));
sp->ctx = ctx;
diff --git a/src/survive_playback.c b/src/survive_playback.c
index 7e22b47..a5c4519 100644
--- a/src/survive_playback.c
+++ b/src/survive_playback.c
@@ -21,6 +21,10 @@ ssize_t getdelim(char **lineptr, size_t *n, int delimiter, FILE *stream);
ssize_t getline(char **lineptr, size_t *n, FILE *stream);
#endif
+
+STATIC_CONFIG_ITEM_F( PLAYBACK_FACTOR, "playback-factor", "Time factor of playback -- 1 is run at the same timing as original, 0 is run as fast as possible.", 1.0f );
+
+
typedef struct SurviveRecordingData {
bool alwaysWriteStdOut;
bool writeRawLight;
@@ -172,7 +176,6 @@ struct SurvivePlaybackData {
FILE *playback_file;
int lineno;
- FLT time_factor;
double next_time_us;
bool hasRawLight;
};
@@ -292,7 +295,7 @@ static int playback_poll(struct SurviveContext *ctx, void *_driver) {
line = 0;
}
- if (driver->next_time_us * driver->time_factor > timestamp_in_us())
+ if (driver->next_time_us * GCONFIGF( PLAYBACK_FACTOR ) > timestamp_in_us())
return 0;
driver->next_time_us = 0;
@@ -384,7 +387,6 @@ int DriverRegPlayback(SurviveContext *ctx) {
SurvivePlaybackData *sp = calloc(1, sizeof(SurvivePlaybackData));
sp->ctx = ctx;
sp->playback_dir = playback_file;
- sp->time_factor = survive_configf(ctx, "playback-factor", SC_GET, 1.f);
sp->playback_file = fopen(playback_file, "r");
if (sp->playback_file == 0) {
@@ -392,7 +394,7 @@ int DriverRegPlayback(SurviveContext *ctx) {
return -1;
}
- SV_INFO("Using playback file '%s' with timefactor of %f", playback_file, sp->time_factor);
+ SV_INFO("Using playback file '%s' with timefactor of %f", playback_file, GCONFIGF( PLAYBACK_FACTOR ) );
SurviveObject *hmd = survive_create_hmd(ctx, "Playback", sp);
SurviveObject *wm0 = survive_create_wm0(ctx, "Playback", sp, 0);
SurviveObject *wm1 = survive_create_wm1(ctx, "Playback", sp, 0);