From a5ab35527062617c21fdcd31305d1e0b8ed1d267 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Tue, 24 Apr 2018 20:03:31 -0400 Subject: Pave the way for more, different, interesting devices. --- Makefile | 2 +- src/survive.c | 5 +++ src/survive_driver_dummy.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++ src/survive_driverman.c | 1 - src/survive_vive.c | 2 +- 5 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 src/survive_driver_dummy.c diff --git a/Makefile b/Makefile index 2c727df..2f9063e 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ endif SBA:=redist/sba/sba_chkjac.c redist/sba/sba_crsm.c redist/sba/sba_lapack.c redist/sba/sba_levmar.c redist/sba/sba_levmar_wrap.c redist/minimal_opencv.c src/poser_epnp.c src/poser_sba.c src/epnp/epnp.c src/poser_general_optimizer.c LIBSURVIVE_CORE+=src/survive.c src/survive_process.c src/ootx_decoder.c src/survive_driverman.c src/survive_default_devices.c src/survive_playback.c src/survive_config.c src/survive_cal.c src/poser.c src/survive_sensor_activations.c src/survive_disambiguator.c src/survive_imu.c src/survive_kalman.c MINIMAL_NEEDED+=src/survive_usb.c src/survive_charlesbiguator.c src/survive_vive.c src/survive_reproject.c -AUX_NEEDED+=src/survive_turveybiguator.c src/survive_statebased_disambiguator.c +AUX_NEEDED+=src/survive_turveybiguator.c src/survive_statebased_disambiguator.c src/survive_driver_dummy.c POSERS:=src/poser_dummy.c src/poser_imu.c src/poser_charlesrefine.c EXTRA_POSERS:=src/poser_daveortho.c src/poser_charlesslow.c src/poser_octavioradii.c src/poser_turveytori.c REDISTS:=redist/json_helpers.c redist/linmath.c redist/jsmn.c diff --git a/src/survive.c b/src/survive.c index ce17295..13aeee9 100644 --- a/src/survive.c +++ b/src/survive.c @@ -343,6 +343,11 @@ int survive_startup(SurviveContext *ctx) { } } + if( ctx->objs_ct == 0 ) + { + SV_ERROR( "Fatal error: No trackable objects found in any calibrators." ); + } + return 0; } diff --git a/src/survive_driver_dummy.c b/src/survive_driver_dummy.c new file mode 100644 index 0000000..d940d21 --- /dev/null +++ b/src/survive_driver_dummy.c @@ -0,0 +1,90 @@ +// All MIT/x11 Licensed Code in this file may be relicensed freely under the GPL +// or LGPL licenses. + +#include +#include +#include +#include +#include "survive_config.h" +#include "os_generic.h" + +struct SurviveDriverDummy { + SurviveContext * ctx; + SurviveObject * so; +}; +typedef struct SurviveDriverDummy SurviveDriverDummy; + +static int dummy_poll(struct SurviveContext *ctx, void *_driver) { + SurviveDriverDummy *driver = _driver; + +/* + To emit an IMU event, send this: + driver->ctx->imuproc(so, mask, accelgyro, timecode, id); + + To emit light data, send this: + LightcapElement le; + le.sensor_id = X //8 bits + le.length = Z //16 bits + le.timestamp = Y //32 bits + handle_lightcap(so, &le); +*/ + + return 0; +} + +static int dummy_close(struct SurviveContext *ctx, void *_driver) { + SurviveDriverDummy *driver = _driver; + +/* + If you need to handle any cleanup here, like closing handles, etc. + you can perform it here. +*/ + + return 0; +} + +int dummy_haptic( SurviveObject * so, uint8_t reserved, uint16_t pulseHigh, uint16_t pulseLow, uint16_t repeatCount ) +{ +/* + If your device has haptics, you can add the control for them here. +*/ + return 0; +} + +int DriverRegDummy(SurviveContext *ctx) +{ + int enable_dummy_driver = survive_configi( ctx, "dummy_driver_enable", SC_GET, 0 ); + + if( !enable_dummy_driver ) return 0; + + SurviveDriverDummy *sp = calloc(1, sizeof(SurviveDriverDummy)); + sp->ctx = ctx; + + SV_INFO("Setting up dummy driver."); + + //Create a new SurviveObject... + SurviveObject *device = calloc(1, sizeof(SurviveObject)); + device->ctx = ctx; + device->driver = sp; + memcpy(device->codename, "DM0", 4); + memcpy(device->drivername, "DUM", 4); + + device->timebase_hz = 48000000; + device->pulsedist_max_ticks = 500000; + device->pulselength_min_sync = 2200; + device->pulse_in_clear_time = 35000; + device->pulse_max_for_sweep = 1800; + device->pulse_synctime_offset = 20000; + device->pulse_synctime_slack = 5000; + device->timecenter_ticks = device->timebase_hz / 240; + device->imu_freq = 1000.0f; + device->haptic = dummy_haptic; + + sp->so = device; + survive_add_object( ctx, device ); + survive_add_driver( ctx, sp, dummy_poll, dummy_close, 0 ); + return 0; +} + +REGISTER_LINKTIME(DriverRegDummy); + diff --git a/src/survive_driverman.c b/src/survive_driverman.c index ac5d1f6..c43e8ec 100644 --- a/src/survive_driverman.c +++ b/src/survive_driverman.c @@ -31,7 +31,6 @@ const char *GetDriverNameMatching(const char *prefix, int place) { int prefixlen = (int)strlen(prefix); for (i = 0; i < NrDrivers; i++) { - fprintf(stderr, "%s %s\n", prefix, DriverNames[i]); if (strncmp(prefix, DriverNames[i], prefixlen) == 0) if (0 == (place--)) return DriverNames[i]; diff --git a/src/survive_vive.c b/src/survive_vive.c index d9cbc3e..493215a 100755 --- a/src/survive_vive.c +++ b/src/survive_vive.c @@ -1722,7 +1722,7 @@ int DriverRegHTCVive( SurviveContext * ctx ) sv->udev[USB_DEV_W_WATCHMAN1] ) { survive_add_driver( ctx, sv, survive_vive_usb_poll, survive_vive_close, survive_vive_send_magic ); } else { - SV_ERROR("No USB devices detected"); + SV_INFO("No USB devices detected"); } //Next, pull out the config stuff. -- cgit v1.2.3