diff options
author | Ennio Barbaro <enniobarbaro@gmail.com> | 2015-07-02 22:12:55 +0200 |
---|---|---|
committer | Ennio Barbaro <enniobarbaro@gmail.com> | 2015-07-02 22:57:21 +0200 |
commit | 1e1e4d6bf51805c30feee39083a1ee79f09f8641 (patch) | |
tree | 7d6b5f75914066c6687430c193a4a2f052934995 /x-plane-plugin | |
parent | 59144a96bf9e3391a32b9ad8f5240f02acb3f44a (diff) |
Added enable/disable plugin command.
Diffstat (limited to 'x-plane-plugin')
-rw-r--r-- | x-plane-plugin/plugin.c | 58 |
1 files changed, 54 insertions, 4 deletions
diff --git a/x-plane-plugin/plugin.c b/x-plane-plugin/plugin.c index eed3c774..1643fc9c 100644 --- a/x-plane-plugin/plugin.c +++ b/x-plane-plugin/plugin.c @@ -10,6 +10,7 @@ #include <XPLMPlugin.h> #include <XPLMDataAccess.h> #include <XPLMProcessing.h> +#include <XPLMUtilities.h> #ifndef PLUGIN_API #define PLUGIN_API @@ -39,6 +40,9 @@ static PortableLockedShm* lck_posix = NULL; static WineSHM* shm_posix = NULL; static void *view_x, *view_y, *view_z, *view_heading, *view_pitch; static float offset_x, offset_y, offset_z; +static XPLMCommandRef track_toggle = NULL, translation_disable_toggle = NULL; +static int track_disabled = 1; +static int translation_disabled; static void reinit_offset() { offset_x = XPLMGetDataf(view_x); @@ -93,9 +97,12 @@ float write_head_position( { if (lck_posix != NULL && shm_posix != NULL) { PortableLockedShm_lock(lck_posix); - XPLMSetDataf(view_x, shm_posix->data[TX] * 1e-3 + offset_x); - XPLMSetDataf(view_y, shm_posix->data[TY] * 1e-3 + offset_y); - XPLMSetDataf(view_z, shm_posix->data[TZ] * 1e-3 + offset_z); + if (!translation_disabled) + { + XPLMSetDataf(view_x, shm_posix->data[TX] * 1e-3 + offset_x); + XPLMSetDataf(view_y, shm_posix->data[TY] * 1e-3 + offset_y); + XPLMSetDataf(view_z, shm_posix->data[TZ] * 1e-3 + offset_z); + } XPLMSetDataf(view_heading, shm_posix->data[Yaw] * 180 / 3.141592654); XPLMSetDataf(view_pitch, shm_posix->data[Pitch] * 180 / 3.141592654); PortableLockedShm_unlock(lck_posix); @@ -103,13 +110,54 @@ float write_head_position( return -1.0; } +static int TrackToggleHandler( XPLMCommandRef inCommand, + XPLMCommandPhase inPhase, + void * inRefCon ) +{ + if ( track_disabled ) + { + //Enable + XPLMRegisterFlightLoopCallback(write_head_position, -1.0, NULL); + } + else + { + //Disable + XPLMUnregisterFlightLoopCallback(write_head_position, NULL); + } + track_disabled = !track_disabled; + return 0; +} + +static int TranslationToggleHandler( XPLMCommandRef inCommand, + XPLMCommandPhase inPhase, + void * inRefCon ) +{ + translation_disabled = !translation_disabled; + return 0; +} + PLUGIN_API int XPluginStart ( char * outName, char * outSignature, char * outDescription ) { view_x = XPLMFindDataRef("sim/aircraft/view/acf_peX"); view_y = XPLMFindDataRef("sim/aircraft/view/acf_peY"); view_z = XPLMFindDataRef("sim/aircraft/view/acf_peZ"); view_heading = XPLMFindDataRef("sim/graphics/view/pilots_head_psi"); view_pitch = XPLMFindDataRef("sim/graphics/view/pilots_head_the"); - if (view_x && view_y && view_z && view_heading && view_pitch) { + + track_toggle = XPLMCreateCommand("opentrack/toggle", "Disable/Enable head tracking"); + translation_disable_toggle = XPLMCreateCommand("opentrack/toggle_translation", "Disable/Enable input translation from opentrack"); + + XPLMRegisterCommandHandler( track_toggle, + TrackToggleHandler, + 1, + (void*)0); + + XPLMRegisterCommandHandler( translation_disable_toggle, + TranslationToggleHandler, + 1, + (void*)0); + + + if (view_x && view_y && view_z && view_heading && view_pitch && track_toggle && translation_disable_toggle) { lck_posix = PortableLockedShm_init(WINE_SHM_NAME, WINE_MTX_NAME, sizeof(WineSHM)); if (lck_posix->mem == (void*)-1) { fprintf(stderr, "opentrack failed to init SHM!\n"); @@ -137,10 +185,12 @@ PLUGIN_API void XPluginStop ( void ) { PLUGIN_API void XPluginEnable ( void ) { XPLMRegisterFlightLoopCallback(write_head_position, -1.0, NULL); + track_disabled = 0; } PLUGIN_API void XPluginDisable ( void ) { XPLMUnregisterFlightLoopCallback(write_head_position, NULL); + track_disabled = 1; } PLUGIN_API void XPluginReceiveMessage( |