Old fashion design for PC-104
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.

404 lines
9.8 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LgUISiteCamera.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgUISiteCamera.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "LgUISiteCamera.h"
  16. #include "LgUISiteSensor.h"
  17. #include "LgUISiteEngine.h"
  18. #include "..\UICamera\LgUICameraVideoWnd.h"
  19. CLgUISiteCamera::CLgUISiteCamera( HAL_OBJECT_ID nID ) :
  20. CLgHALCamera( nID )
  21. {
  22. m_Position.x = (rand() % 100) / 100.0;
  23. m_Position.y = (rand() % 100) / 100.0;
  24. m_ptzDelta.dPan = m_ptzDelta.dTilt = m_ptzDelta.dZoom = 0;
  25. m_ptzPosition.dPan = m_ptzPosition.dTilt = m_ptzPosition.dZoom = 0;
  26. m_dwDirection = CAMERA_PAN_STOP | CAMERA_TILT_STOP | CAMERA_ZOOM_STOP;
  27. m_nVideoSampleID = 0;
  28. }
  29. CLgUISiteCamera::~CLgUISiteCamera()
  30. {
  31. }
  32. BOOL CLgUISiteCamera::OnUIMapHitTest( CLgUIMapObjectWnd*, CLgDRect *pRect )
  33. {
  34. if( !pRect->PtInRect( m_Position ) )
  35. return FALSE;
  36. CLgUISiteEngine *pEngine = *this;
  37. if( !pEngine )
  38. {
  39. // critical error!
  40. ASSERT( NULL );
  41. return TRUE;
  42. }
  43. // try to activate camera
  44. pEngine->OnActivateVideoCamera( this );
  45. return TRUE;
  46. }
  47. void CLgUISiteCamera::OnUIMapDraw( CLgUIMapObjectWnd *pMap, CDC *pDC, BOOL bActive, BOOL bOddUpdate )
  48. {
  49. CLgDPoint dp( m_Position.x, m_Position.y );
  50. // draw sensor representation
  51. CPoint p = pMap->AreaToWindow( &dp );
  52. CRect rect;
  53. if( bActive && !bOddUpdate ) rect.SetRect( p.x - 2, p.y - 2, p.x + 2, p.y + 2 );
  54. else rect.SetRect( p.x - 1, p.y - 1, p.x + 1, p.y + 1 );
  55. pDC->FillSolidRect( &rect, RGB(255,255,255) );
  56. // test
  57. CLgDRect dr( dp.x - 0.2, dp.y - 0.2, dp.x + 0.2, dp.y + 0.2 );
  58. // paint video frame
  59. CRect cr = pMap->AreaToWindow( &dr );
  60. // calculate positions
  61. double d = 3.0 + (1.0 - m_ptzPosition.dZoom) * 21.0;
  62. INT w = cr.Width() / 2;
  63. INT h = cr.Height() / 2;
  64. double r = h * ( 0.2 + m_ptzPosition.dZoom * 0.8 );
  65. w = h = 1;
  66. INT x1 = (INT)( ( cos( ( m_ptzPosition.dPan + d ) / 360.0 * 6.2831 ) ) * r + w ) + p.x;
  67. INT y1 = (INT)( ( sin( ( m_ptzPosition.dPan + d ) / 360.0 * 6.2831 ) ) * r + h ) + p.y;
  68. INT x2 = (INT)( ( cos( ( m_ptzPosition.dPan - d ) / 360.0 * 6.2831 ) ) * r + w ) + p.x;
  69. INT y2 = (INT)( ( sin( ( m_ptzPosition.dPan - d ) / 360.0 * 6.2831 ) ) * r + h ) + p.y;
  70. // draw
  71. POINT pP[] = { { x1, y1 }, { x2, y2 }, { w + p.x, h + p.y } };
  72. COLORREF color = RGB(0,255,0);
  73. CBrush brush( color );
  74. CPen pen( PS_SOLID, 1, color );
  75. CBrush *pBrush = pDC->SelectObject( &brush );
  76. CPen *pPen = pDC->SelectObject( &pen );
  77. rect.SetRect( (INT)(w-r+p.x), (INT)(h-r+p.y), (INT)(w+r+p.x), (INT)(h+r+p.y) );
  78. pDC->Pie( &rect, pP[0], pP[1] );
  79. pDC->SelectObject( pBrush );
  80. pDC->SelectObject( pPen );
  81. }
  82. void CLgUISiteCamera::OnUIMapDrawBackground( CLgUIMapObjectWnd *pMap, CDC *pDC )
  83. {
  84. }
  85. // camera access events
  86. void CLgUISiteCamera::OnHalCameraVideo( HAL_CAMERA_RESULT eReason )
  87. {
  88. // call base class
  89. // CLgHALCamera::OnHalCameraVideo( eReason );
  90. switch( eReason )
  91. {
  92. case HAL_CAMERA_VIDEO_GRANTED:
  93. // askquare video sample
  94. HalCameraVideoGetSample( m_nVideoSampleID );
  95. // notify user interface
  96. OnUICameraVideo( TRUE );
  97. // try to access to control stream
  98. switch( HalCameraControlGet() )
  99. {
  100. case HAL_CAMERA_CONTROL_PENDING:
  101. break;
  102. case HAL_CAMERA_CONTROL_GRANTED:
  103. OnUICameraControl( TRUE );
  104. break;
  105. }
  106. break;
  107. case HAL_CAMERA_VIDEO_RELEASED:
  108. case HAL_CAMERA_VIDEO_RELEASED_BY_TIMEOUT:
  109. case HAL_CAMERA_VIDEO_RELEASED_BY_PRIORITY:
  110. OnUICameraVideo( FALSE );
  111. // try to release to control stream
  112. switch( HalCameraControlRelease() )
  113. {
  114. case HAL_CAMERA_CONTROL_PENDING:
  115. break;
  116. case HAL_CAMERA_CONTROL_RELEASED:
  117. OnUICameraControl( FALSE );
  118. break;
  119. }
  120. break;
  121. }
  122. }
  123. // video samples events
  124. void CLgUISiteCamera::OnHalCameraVideoSample( HAL_CAMERA_RESULT eReason, CLgImageDIB* pDIB, INT nVideoSampleID )
  125. {
  126. // call base class
  127. // CLgHALCamera::OnHalCameraVideoSample( eReason, pDIB );
  128. if( eReason == HAL_CAMERA_VIDEO_SAMPLE_RECEIVED )
  129. {
  130. // remeber sample id for next request
  131. m_nVideoSampleID = nVideoSampleID;
  132. OnUICameraVideoSample( pDIB );
  133. // get next sample
  134. // HalCameraVideoGetSample();
  135. }
  136. }
  137. // camera access events
  138. void CLgUISiteCamera::OnHalCameraControl( HAL_CAMERA_RESULT eReason )
  139. {
  140. // call base class
  141. // CLgHALCamera::OnHalCameraControl( eReason );
  142. switch( eReason )
  143. {
  144. case HAL_CAMERA_CONTROL_GRANTED:
  145. OnUICameraControl( TRUE );
  146. break;
  147. case HAL_CAMERA_CONTROL_RELEASED:
  148. case HAL_CAMERA_CONTROL_RELEASED_BY_TIMEOUT:
  149. case HAL_CAMERA_CONTROL_RELEASED_BY_PRIORITY:
  150. OnUICameraControl( FALSE );
  151. break;
  152. }
  153. }
  154. // camera movements events
  155. void CLgUISiteCamera::OnHalCameraControlPosition( HAL_CAMERA_RESULT eReason, double dPan, double dTilt, double dZoom )
  156. {
  157. // CLgHALCamera::OnHalCameraControlPosition( eReason, dPan, dTilt, dZoom );
  158. }
  159. // start stop camera operation
  160. BOOL CLgUISiteCamera::CameraActivate( BOOL bActivate )
  161. {
  162. if( bActivate )
  163. {
  164. // acquare access from camera
  165. HAL_CAMERA_RESULT eResult = HalCameraVideoGet();
  166. // depend on result
  167. switch( eResult )
  168. {
  169. // wait for access
  170. case HAL_CAMERA_VIDEO_PENDING:
  171. return TRUE;
  172. // access already granted
  173. case HAL_CAMERA_VIDEO_GRANTED:
  174. OnUICameraVideo( bActivate );
  175. // try to access to control stream
  176. eResult = HalCameraControlGet();
  177. switch( eResult )
  178. {
  179. case HAL_CAMERA_CONTROL_PENDING:
  180. return TRUE;
  181. // access already granted
  182. case HAL_CAMERA_CONTROL_GRANTED:
  183. OnUICameraControl( bActivate );
  184. return TRUE;
  185. }
  186. }
  187. }
  188. else
  189. {
  190. // acquare access from camera
  191. HAL_CAMERA_RESULT eResult = HalCameraVideoRelease();
  192. // depend on result
  193. switch( eResult )
  194. {
  195. // wait for access
  196. case HAL_CAMERA_VIDEO_PENDING:
  197. return TRUE;
  198. // access already granted
  199. case HAL_CAMERA_VIDEO_RELEASED:
  200. OnUICameraVideo( bActivate );
  201. OnUICameraControl( bActivate );
  202. return TRUE;
  203. }
  204. }
  205. return FALSE;
  206. }
  207. BOOL CLgUISiteCamera::UICameraMovePTZ( DWORD dwDirection )
  208. {
  209. if( dwDirection & CAMERA_PAN_MASK )
  210. {
  211. if( ( m_dwDirection & CAMERA_PAN_MASK ) != ( dwDirection & CAMERA_PAN_MASK ) )
  212. {
  213. m_ptzDelta.dPan = 0;
  214. m_dwDirection = ( m_dwDirection & ~CAMERA_PAN_MASK ) | ( dwDirection & CAMERA_PAN_MASK );
  215. }
  216. }
  217. if( dwDirection & CAMERA_TILT_MASK )
  218. {
  219. if( ( m_dwDirection & CAMERA_TILT_MASK ) != ( dwDirection & CAMERA_TILT_MASK ) )
  220. {
  221. m_ptzDelta.dTilt = 0;
  222. m_dwDirection = ( m_dwDirection & ~CAMERA_TILT_MASK ) | ( dwDirection & CAMERA_TILT_MASK );
  223. }
  224. }
  225. if( dwDirection & CAMERA_ZOOM_MASK )
  226. {
  227. if( ( m_dwDirection & CAMERA_ZOOM_MASK ) != ( dwDirection & CAMERA_ZOOM_MASK ) )
  228. {
  229. m_ptzDelta.dZoom = 0;
  230. m_dwDirection = ( m_dwDirection & ~CAMERA_ZOOM_MASK ) | ( dwDirection & CAMERA_ZOOM_MASK );
  231. }
  232. }
  233. return TRUE;
  234. }
  235. BOOL CLgUISiteCamera::UICameraSampleGet()
  236. {
  237. // ask for next sample
  238. return HalCameraVideoGetSample( m_nVideoSampleID );
  239. }
  240. // move PTZ camera
  241. BOOL CLgUISiteCamera::CameraMovePTZ( double dPan, double dTilt, double dZoom )
  242. {
  243. TRACE( "[%p]CLgUISiteCamera::CameraMovePTZ %0.2f %0.2f %0.2f\n", this, dPan, dTilt, dZoom );
  244. // repaint itself
  245. return CLgUIMapObject::RedrawUIMapObject();
  246. }
  247. BOOL CLgUISiteCamera::CameraGetPTZ( double *pPan, double *pTilt, double *pZoom )
  248. {
  249. return FALSE;
  250. }
  251. BOOL CLgUISiteCamera::OnUISiteClock()
  252. {
  253. BOOL bChange = FALSE;
  254. // apply pan
  255. switch( m_dwDirection & CAMERA_PAN_MASK )
  256. {
  257. case CAMERA_PAN_LEFT:
  258. // perform acceleration
  259. if( m_ptzDelta.dPan < 10 )
  260. m_ptzDelta.dPan += 1;
  261. // calculate new position
  262. m_ptzPosition.dPan -= m_ptzDelta.dPan;
  263. if( m_ptzPosition.dPan < 0.0 )
  264. m_ptzPosition.dPan += 360.0;
  265. // remember changes
  266. bChange = TRUE;
  267. break;
  268. case CAMERA_PAN_RIGHT:
  269. // perform acceleration
  270. if( m_ptzDelta.dPan < 10 )
  271. m_ptzDelta.dPan += 1;
  272. // calculate new position
  273. m_ptzPosition.dPan += m_ptzDelta.dPan;
  274. if( m_ptzPosition.dPan >= 360.0 )
  275. m_ptzPosition.dPan -= 360.0;
  276. bChange = TRUE;
  277. break;
  278. case CAMERA_PAN_STOP:
  279. default:
  280. break;
  281. }
  282. // apply tilt
  283. switch( m_dwDirection & CAMERA_TILT_MASK )
  284. {
  285. case CAMERA_TILT_UP:
  286. // perform acceleration
  287. if( m_ptzDelta.dTilt < 10 )
  288. m_ptzDelta.dTilt += 1;
  289. // calculate new position
  290. m_ptzPosition.dTilt -= m_ptzDelta.dTilt;
  291. if( m_ptzPosition.dTilt < -30.0 )
  292. m_ptzPosition.dTilt = -30.0;
  293. bChange = TRUE;
  294. break;
  295. case CAMERA_TILT_DOWN:
  296. // perform acceleration
  297. if( m_ptzDelta.dTilt < 10 )
  298. m_ptzDelta.dTilt += 1;
  299. // calculate new position
  300. m_ptzPosition.dTilt += m_ptzDelta.dTilt;
  301. if( m_ptzPosition.dTilt > 90.0 )
  302. m_ptzPosition.dTilt = 90.0;
  303. bChange = TRUE;
  304. break;
  305. case CAMERA_TILT_STOP:
  306. default:
  307. break;
  308. }
  309. // apply zoom
  310. switch( m_dwDirection & CAMERA_ZOOM_MASK )
  311. {
  312. case CAMERA_ZOOM_TELE:
  313. // perform acceleration
  314. if( m_ptzDelta.dZoom < 0.10 )
  315. m_ptzDelta.dZoom += 0.01;
  316. // calculate new position
  317. m_ptzPosition.dZoom += m_ptzDelta.dZoom;
  318. if( m_ptzPosition.dZoom > 1.0 )
  319. m_ptzPosition.dZoom = 1.0;
  320. bChange = TRUE;
  321. break;
  322. case CAMERA_ZOOM_WIDE:
  323. // perform acceleration
  324. if( m_ptzDelta.dZoom < 0.10 )
  325. m_ptzDelta.dZoom += 0.01;
  326. // calculate new position
  327. m_ptzPosition.dZoom -= m_ptzDelta.dZoom;
  328. if( m_ptzPosition.dZoom < 0.0 )
  329. m_ptzPosition.dZoom = 0.0;
  330. bChange = TRUE;
  331. break;
  332. case CAMERA_ZOOM_STOP:
  333. default:
  334. break;
  335. }
  336. // apply changes
  337. if( bChange )
  338. CameraMovePTZ( m_ptzPosition.dPan, m_ptzPosition.dTilt, m_ptzPosition.dZoom );
  339. return TRUE;
  340. }