00001 /********************************************************************* 00002 * 00003 * This is free and unencumbered software released into the public domain. 00004 * 00005 * Anyone is free to copy, modify, publish, use, compile, sell, or 00006 * distribute this software, either in source code form or as a compiled 00007 * binary, for any purpose, commercial or non-commercial, and by any 00008 * means. 00009 * 00010 * In jurisdictions that recognize copyright laws, the author or authors 00011 * of this software dedicate any and all copyright interest in the 00012 * software to the public domain. We make this dedication for the benefit 00013 * of the public at large and to the detriment of our heirs and 00014 * successors. We intend this dedication to be an overt act of 00015 * relinquishment in perpetuity of all present and future rights to this 00016 * software under copyright law. 00017 * 00018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00019 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00020 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00021 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00022 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00023 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00024 * OTHER DEALINGS IN THE SOFTWARE. 00025 * 00026 * For more information, please refer to <http://unlicense.org/> 00027 * 00028 **********************************************************************/ 00029 #include <cstdio> 00030 #include <signal.h> 00031 #include "razer_hydra/hydra.h" 00032 using namespace razer_hydra; 00033 00034 static bool g_done = false; 00035 void sigint_handler(int signal) 00036 { 00037 g_done = true; 00038 } 00039 00040 int main(int argc, char **argv) 00041 { 00042 if (argc != 3) 00043 { 00044 printf("usage: print DEVICE FILENAME\n"); 00045 return 1; 00046 } 00047 signal(SIGINT, sigint_handler); 00048 RazerHydra h; 00049 if (!h.init(argv[1])) 00050 return 1; 00051 FILE *f = fopen(argv[2], "w"); 00052 static int print_count = 0; 00053 while (!g_done) 00054 { 00055 if (h.poll(10, 100)) 00056 { 00057 char buf[1000]; 00058 snprintf(buf, sizeof(buf), 00059 "%.3f %.3f %.3f %.3f %.3f %.3f %.3f", 00060 h.pos[1].x(), h.pos[1].y(), h.pos[1].z(), 00061 h.quat[1].x(), h.quat[1].y(), 00062 h.quat[1].z(), h.quat[1].w()); 00063 fprintf(f, "%s\n", buf); 00064 if (print_count++ % 100 == 0) 00065 printf("%s\n", buf); 00066 } 00067 } 00068 fclose(f); 00069 return 0; 00070 } 00071