You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
4.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. // SDL_HAD.cpp : Defines the entry point for the application.
  2. //
  3. #include "framework.h"
  4. #include "SDL_HAD.h"
  5. #include "../../lib/sdl/gui_sdl.h"
  6. #include "../../lib/sdl/widgets/logWidget.h"
  7. #include "../../lib/sdl/widgets/OSDWidget.h"
  8. #include "../../lib/sdl/widgets/buttonWidget.h"
  9. #include "../../lib/components/base/basicLogCollection.h"
  10. #include "../../lib/components/object/objectFlyHunter.h"
  11. #include "../../lib/components/object/objectFileLoggingService.h"
  12. #include "../../lib/sdl/elements/animatedSprite.h"
  13. #include "../../lib/sdl/joystickWrapper.h"
  14. #include "../../lib/sdl/widgets/flyHunterWidget.h"
  15. #define LOG( X ) mLGP->Log( "Main", NULL, X )
  16. #define LOG_ERROR( X ) mLGP->Log( "Main", NULL, _LOG_ERROR, X )
  17. sdlOsdVideoWidget * mVID;
  18. sdlFlyHunterWidget * mFHW;
  19. objectFlyHunter * mHNT;
  20. void test(void) {
  21. exit(1212);
  22. };
  23. void setVizor1(int16_t a) {
  24. mVID->setJoystickRoll(a);
  25. //mHNT->setJoystickRoll(a);
  26. };
  27. void setVizor2(int16_t a) {
  28. mVID->setJoystickPitch(a);
  29. };
  30. void setVizor3(int16_t a) {
  31. mVID->setJoystickYaw(a);
  32. };
  33. void setVizor4(int16_t a) {
  34. mVID->setJoistickThrottle(a);
  35. };
  36. void updateOrien(float a, float b, float c) {
  37. mVID->setRoll(a * 57.295779513082320876798154814105f);
  38. //void setPitch(float Angle);
  39. //void setYaw(float Angle);
  40. //void setAlt(float Angle);
  41. };
  42. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  43. _In_opt_ HINSTANCE hPrevInstance,
  44. _In_ LPWSTR lpCmdLine,
  45. _In_ int nCmdShow)
  46. {
  47. UNREFERENCED_PARAMETER(hPrevInstance);
  48. UNREFERENCED_PARAMETER(lpCmdLine);
  49. classGUI_SDL * SDL;
  50. sdlLog * mLOG;
  51. sdlButtonWidget * mBTN;
  52. basicSettingsProvider * mMSP;
  53. config_setting_t * mSET = NULL;
  54. basicLogCollection * mLGP;
  55. objectFileLoggingService * mFLO;
  56. sdlJoystickWrapper * mJOY;
  57. bool mVIW = false;
  58. char mVSRC[256];
  59. mLGP = basicLogCollection::getInstance();
  60. mFLO = new objectFileLoggingService("SDL_HAD.log");
  61. mLGP->addHandler(mFLO);
  62. mMSP = basicSettingsProvider::getInstance((CSTR)"SDL_HAD.conf");
  63. SDL = classGUI_SDL::getInstance();
  64. SLEEP(1000);
  65. mLOG = new sdlLog(10, 520, 400, 190);
  66. mLGP->addHandler(mLOG);
  67. LOG("Start Application");
  68. if (mMSP != NULL) {
  69. mSET = mMSP->getSubNode(NULL, (CSTR)"APPLICATION");
  70. if (mSET == NULL) {
  71. LOG_ERROR("Cannot get Settings!");
  72. } else {
  73. config_setting_t * pSetting;
  74. LOG("Reading Settings");
  75. pSetting = config_setting_get_member(mSET, "VIDEO_SOURCE");
  76. if (pSetting == NULL) {
  77. pSetting = config_setting_add(mSET, "VIDEO_SOURCE", CONFIG_TYPE_STRING);
  78. sprintf(mVSRC, "video=USB2.0 PC CAMERA");
  79. if (pSetting != NULL) {
  80. config_setting_set_string(pSetting, mVSRC );
  81. mMSP->compromise();
  82. };
  83. } else {
  84. sprintf(mVSRC, "%s", config_setting_get_string(pSetting));
  85. };
  86. pSetting = config_setting_get_member(mSET, "VIDEO_WIDE");
  87. if (pSetting == NULL) {
  88. pSetting = config_setting_add(mSET, "VIDEO_WIDE", CONFIG_TYPE_BOOL);
  89. if (pSetting != NULL) {
  90. config_setting_set_bool(pSetting, mVIW);
  91. mMSP->compromise();
  92. };
  93. } else {
  94. mVIW = (bool)config_setting_get_bool(pSetting);
  95. };
  96. };
  97. mMSP->validate();
  98. } else {
  99. LOG_ERROR("Error create Settings File!");
  100. };
  101. mHNT = new objectFlyHunter(mSET);
  102. if (mHNT == NULL) {
  103. LOG_ERROR("Error create FlyHunter Object!");
  104. } else {
  105. if( mHNT->cerate()){
  106. LOG("FlyHunter Created Sucessfully");
  107. } else {
  108. LOG_ERROR("Error Init of FlyHunter!");
  109. };
  110. };
  111. if (mVIW) {
  112. mFHW = new sdlFlyHunterWidget(550, 10, 405, 400);
  113. if (mFHW) {
  114. mFHW->attachFlyHunter(mHNT);
  115. };
  116. mJOY = new sdlJoystickWrapper(10, 320);
  117. if (mJOY) {
  118. SDL->registerJoystickWraper(mJOY);
  119. };
  120. mVID = new sdlOsdVideoWidget((CSTR)mVSRC, 10, 10, 528, 300);
  121. mJOY->Roll = setVizor1;
  122. mJOY->Pitch = setVizor2;
  123. mJOY->Yaw = setVizor3;
  124. mJOY->Throttle = setVizor4;
  125. if (mFHW) {
  126. mFHW->attachOSD(mVID);
  127. };
  128. mHNT->updateOrientation = updateOrien;
  129. mBTN = new sdlButtonWidget((CSTR)"EXIT", 10, 720, 200, 40);
  130. mBTN->Pushed = &test;
  131. } else {
  132. mFHW = new sdlFlyHunterWidget(420, 10, 594, 400);
  133. if (mFHW) {
  134. mFHW->attachFlyHunter(mHNT);
  135. };
  136. mJOY = new sdlJoystickWrapper(10, 320);
  137. if (mJOY) {
  138. SDL->registerJoystickWraper(mJOY);
  139. };
  140. mVID = new sdlOsdVideoWidget((CSTR)mVSRC, 10, 10, 400, 300);
  141. mJOY->Roll = setVizor1;
  142. mJOY->Pitch = setVizor2;
  143. mJOY->Yaw = setVizor3;
  144. mJOY->Throttle = setVizor4;
  145. if (mFHW) {
  146. mFHW->attachOSD(mVID);
  147. };
  148. mBTN = new sdlButtonWidget((CSTR)"EXIT", 10, 720, 200, 40);
  149. mBTN->Pushed = &test;
  150. };
  151. SDL->waitThreadEnd();
  152. LOG("End Application");
  153. return (int) 1234;
  154. }
  155. #undef LOG
  156. #undef LOG_ERROR