Web Interface For Lite Argus Control modules
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.

315 lines
9.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. function parseLibconfig_section( &$Array, &$LineID ){
  3. $RetVal = array();
  4. $TCount = count( $Array );
  5. while( $TCount > $LineID ){
  6. if( ( stripos( $Array[$LineID] , ':' ) !== false ) && ( stripos( $Array[$LineID] , '=' ) === false ) ){
  7. $TArr = explode( ' ', trim( $Array[$LineID] ) );
  8. $CS = $TArr[0];
  9. } elseif( stripos( $Array[$LineID] , '{' ) !== false ){
  10. $LineID++;
  11. $RetVal[$CS] = parseLibconfig_section( $Array, $LineID );
  12. } elseif( stripos( $Array[$LineID] , '}' ) !== false ){
  13. break;
  14. } else {
  15. $TVrr = parse_ini_string( trim( $Array[$LineID] ) );
  16. if( count( $TVrr ) ){
  17. foreach( $TVrr as $Key => $Val ) $RetVal[$Key] = $Val;
  18. };
  19. };
  20. $LineID++;
  21. };
  22. return $RetVal;
  23. };
  24. function parseLibconfig( $FName ){
  25. $RetVal = array();
  26. $Data = file( $FName );
  27. $TCount = count( $Data );
  28. $Index = 0;
  29. if( $TCount > 0 )$RetVal = parseLibconfig_section( $Data, $Index );
  30. return $RetVal;
  31. };
  32. function listVideoDevices(){
  33. $Data=`ls /dev/video* -1`;
  34. $RR = explode("\n", $Data );
  35. foreach( $RR as $R ){
  36. $CD = trim( $R );
  37. if( $CD != '' ){
  38. $CMD = "v4l2-ctl -d {$CD} -L";
  39. $Data = `$CMD`;
  40. echo"------------------------------------------------------------------------------------\n";
  41. echo $Data;
  42. };
  43. };
  44. };
  45. //$LibConfig = parseLibconfig( '/srv/mastbaum/SingleIPI.conf' );
  46. $LibConfig = parseLibconfig( '/home/samba/dev/MastBaum/Debug/SingleIPI.conf' );
  47. function getDeviceIdByBusID( $bid ){
  48. $CMD = "v4l2-ctl --list-devices";
  49. $Data = `$CMD`;
  50. $RR = explode("\n", $Data);
  51. for( $index = 0; $index < count($RR); $index++ ){
  52. if( stripos( $RR[$index], $bid )!== false ) {
  53. $TArr = substr( $RR[$index+1], stripos( $RR[$index+1], 'video')+5);
  54. return intval( trim( $TArr ));
  55. };
  56. };
  57. return -1;
  58. };
  59. function getVideoSourcesCount(){
  60. global $LibConfig;
  61. $RetVal = 0;
  62. if( count($LibConfig) ){
  63. foreach( $LibConfig['KERNEL']['VIDEO_INPUTS'] as $VI ) $RetVal ++;
  64. };
  65. return $RetVal;
  66. };
  67. function getVideoSourceID( $id ){
  68. global $LibConfig;
  69. $RetVal = -1;
  70. if( count( $LibConfig )){
  71. $index = 0;
  72. foreach( $LibConfig['KERNEL']['VIDEO_INPUTS'] as $VI ){
  73. if( $index == $id ){
  74. $RetVal = getDeviceIdByBusID($VI['VIDEO_INPUT_ID']);
  75. break;
  76. };
  77. $index ++;
  78. };
  79. };
  80. return $RetVal;
  81. };
  82. function getPictureWidth(){
  83. global $LibConfig;
  84. if( count($LibConfig) ){
  85. $RetVal = 0;
  86. foreach( $LibConfig['KERNEL']['VIDEO_INPUTS'] as $VI ){
  87. $RetVal += $VI['VIDEO_INPUT_WIDTH'];
  88. };
  89. return $RetVal;
  90. } else {
  91. return 320;
  92. };
  93. };
  94. function getPictureHeight(){
  95. global $LibConfig;
  96. if( count($LibConfig) ){
  97. $RetVal = 0;
  98. foreach( $LibConfig['KERNEL']['VIDEO_INPUTS'] as $VI ){
  99. if( $RetVal < $VI['VIDEO_INPUT_HEIGHT'] ) $RetVal = $VI['VIDEO_INPUT_HEIGHT'];
  100. };
  101. return $RetVal+18;
  102. } else {
  103. return 320;
  104. };
  105. };
  106. function getDeviceCtrl( $id ){
  107. $CMD = "v4l2-ctl -d /dev/video{$id} -L";
  108. $Data = `$CMD`;
  109. $RR = explode("\n", $Data);
  110. $C_SECT = '';
  111. $menu_flag = false;
  112. $SUB_CAT = array();
  113. $RetVal = array();
  114. $C_MIN = 0;
  115. $C_MAX = 0;
  116. $C_DEF = 0;
  117. $C_STEP = 0;
  118. $C_VALUE = 0;
  119. foreach( $RR as $R ){
  120. if( stripos( $R, ':' ) === false ){
  121. if( trim( $R ) != '' ){
  122. $C_SECT = trim( $R );
  123. $RetVal[] = array( 'type'=>'section', 'name'=>$C_SECT );
  124. };
  125. } elseif( stripos( $R, '(' ) !== false ){
  126. $C1 = stripos( $R, '(' );
  127. $C2 = stripos( $R, ')' );
  128. $C3 = stripos( $R, ':' );
  129. $SUB = $C3 < $C1;
  130. if( !$SUB ){
  131. if( $menu_flag ){
  132. $RetVal[] = array( 'type'=>$C_TYPE, 'name'=>$C_READ, 'tag'=>$C_NAME, 'value'=>$C_VALUE, 'min'=>$C_MIN, 'max'=>$C_MAX, 'def'=>$C_DEF, 'step'=>$C_STEP, 'items'=>$SUB_CAT );
  133. //Handle Prev Menu Items
  134. $C_MIN = 0;
  135. $C_MAX = 0;
  136. $C_DEF = 0;
  137. $C_STEP = 0;
  138. $C_VALUE = 0;
  139. $SUB_CAT = array();
  140. $menu_flag = false;
  141. };
  142. $C_NAME = trim( substr( $R, 0, $C1 ) );
  143. $C_READ = str_replace( '_', ' ', $C_NAME );
  144. $C_TYPE = strtolower( substr( $R, $C1+1, ($C2 - $C1)-1 ) );
  145. if( $C_TYPE == 'int' || $C_TYPE == 'menu' || $C_TYPE == 'intmenu' ){
  146. if( $C_TYPE == 'menu' || $C_TYPE == 'intmenu' ){
  147. $menu_flag = true;
  148. };
  149. $V = substr( $R, $C3 + 2 );
  150. $PRM = explode( ' ', $V );
  151. foreach( $PRM as $P ){
  152. $TT = explode( '=', $P );
  153. switch( $TT[0] ){
  154. case 'min': $C_MIN = intval($TT[1]); break;
  155. case 'max': $C_MAX = intval($TT[1]); break;
  156. case 'step': $C_STEP = intval($TT[1]); break;
  157. case 'default': $C_DEF = intval($TT[1]); break;
  158. case 'value': $C_VALUE = intval($TT[1]); break;
  159. };
  160. };
  161. };
  162. if( !$menu_flag ){
  163. // No new menu started - Adding plane value
  164. $RetVal[] = array( 'type'=>$C_TYPE, 'name'=>$C_READ, 'tag'=>$C_NAME, 'value'=>$C_VALUE, 'min'=>$C_MIN, 'max'=>$C_MAX, 'def'=>$C_DEF, 'step'=>$C_STEP );
  165. $C_MIN = 0;
  166. $C_MAX = 0;
  167. $C_DEF = 0;
  168. $C_STEP = 0;
  169. $C_VALUE = 0;
  170. };
  171. } else {
  172. $T_NAME = trim( substr( $R, $C3+1 ) );
  173. $T_VALUE = trim( substr( $R, 0, $C3 ) );
  174. $SUB_CAT[$T_VALUE]=$T_NAME;
  175. };
  176. } else {
  177. $C3 = stripos( $R, ':' );
  178. $T_NAME = trim( substr( $R, $C3+1 ) );
  179. $T_VALUE = trim( substr( $R, 0, $C3 ) );
  180. $SUB_CAT[$T_VALUE]=$T_NAME;
  181. };
  182. };
  183. return $RetVal;
  184. };
  185. function createExtJS_int_field( $AA, $id, $listeners = '' ){
  186. $RetVal = array();
  187. $RetVal['xtype'] = 'slider';
  188. $RetVal['value'] = $AA['value'];
  189. $RetVal['fieldLabel'] = $AA['name'];
  190. $RetVal['name'] = $AA['tag'] . '#' . $id;
  191. $RetVal['width'] = 160;
  192. $RetVal['minValue'] = $AA['min'];
  193. $RetVal['maxValue'] = $AA['max'];
  194. if( $listeners == '' ){
  195. return json_encode( $RetVal );
  196. };
  197. $TVal = json_encode( $RetVal );
  198. $TTVal = substr( $TVal, 0, strlen( $TVal )-1 ) . ', listeners:{';
  199. foreach( $listeners as $Key=>$Value ){
  200. $TTVal .= $Key . ':' . $Value .',';
  201. };
  202. $TTVal .= 'scope: this}}';
  203. return $TTVal;
  204. };
  205. function createExtJS_bool_field( $AA, $id, $listeners = '' ){
  206. $RetVal = array();
  207. $RetVal['xtype'] = 'checkbox';
  208. $RetVal['value'] = $AA['value'];
  209. $RetVal['fieldLabel'] = $AA['name'];
  210. $RetVal['name'] = $AA['tag'] . '#' . $id;
  211. if( intval($AA['value'])>0 ){
  212. $RetVal['checked'] = true;
  213. }else{
  214. $RetVal['checked'] = false;
  215. };
  216. if( $listeners == '' ){
  217. return json_encode( $RetVal );
  218. };
  219. $TVal = json_encode( $RetVal );
  220. $TTVal = substr( $TVal, 0, strlen( $TVal )-1 ) . ', listeners:{';
  221. foreach( $listeners as $Key=>$Value ){
  222. $TTVal .= $Key . ':' . $Value .',';
  223. };
  224. $TTVal .= 'scope: this}}';
  225. return $TTVal;
  226. };
  227. $GLOB_DSID = 0;
  228. function isAssoc( array $arr ){
  229. if (array() === $arr) return false;
  230. return array_keys($arr) !== range(0, count($arr) - 1);
  231. }
  232. function createExtJS_menu_field( $AA, $id , $listeners = '' ){
  233. global $GLOB_DSID;
  234. $DS = array();
  235. $DS['xtype']='arraystore';
  236. $DS['id'] = 0;//$GLOB_DSID;
  237. //$GLOB_DSID++;
  238. $DS['fields'] = array('myID','displayText');
  239. $DS['data'] = array();
  240. if( isAssoc( $AA['items'] ) ){
  241. foreach( $AA['items'] as $Key=>$Val ) $DS['data'][] = array( $Key, $Val );
  242. } else {
  243. $index = 0;
  244. foreach( $AA['items'] as $A ){
  245. $DS['data'][] = array($index, $A);
  246. $index++;
  247. };
  248. };
  249. $RetVal = array();
  250. $RetVal['xtype'] = 'combo';
  251. $RetVal['fieldLabel'] = $AA['name'];
  252. $RetVal['name'] = $AA['tag'] . '#' . $id;
  253. $RetVal['value'] = $AA['value'];
  254. $RetVal['mode'] = 'local';
  255. $RetVal['store'] = $DS;
  256. $RetVal['valueField'] = 'myID';
  257. $RetVal['displayField'] = 'displayText';
  258. if( $listeners == '' ){
  259. return json_encode( $RetVal );
  260. };
  261. $TVal = json_encode( $RetVal );
  262. $TTVal = substr( $TVal, 0, strlen( $TVal )-1 ) . ', listeners:{';
  263. foreach( $listeners as $Key=>$Value ){
  264. $TTVal .= $Key . ':' . $Value .',';
  265. };
  266. $TTVal .= 'scope: this}}';
  267. return $TTVal;
  268. };
  269. //https://il.iherb.com/pr/Cellucor-CLK-Stimulant-Free-Fat-Loss-Raspberry-Flavored-90-Softgels/85513?fbclid=IwAR0AuMjRf23-tac7QAzdWX1OgIhpSUbRlUMH24ih3v-Fzzc-AYMiqSKzPHs
  270. function createExtJS_spacer_field( $AA ){
  271. $RetVal = array();
  272. $RetVal['xtype'] = 'spacer';
  273. $RetVal['labelStyle'] = "font-weight: bold; font-color: yellow; background: #00ff00;";
  274. $RetVal['fieldLabel'] = $AA['name'];
  275. return json_encode( $RetVal );
  276. };
  277. function buildExtJSForm( $AA, $id ){
  278. $RetVal = "{'xtype':'form', 'title': 'Video Source $id','plain': true,'frame':false,'items':[";
  279. foreach( $AA as $A ){
  280. switch( $A['type'] ){
  281. case 'int': $RetVal .= createExtJS_int_field( $A, $id, array('change'=>'ChangeHandler') ). ','; break;
  282. case 'bool': $RetVal .= createExtJS_bool_field( $A, $id, array('change'=>'ChangeHandler') ). ','; break;
  283. case 'intmenu':
  284. case 'menu': $RetVal .= createExtJS_menu_field( $A, $id, array('change'=>'ChangeHandler') ). ','; break;
  285. case 'section': $RetVal .= createExtJS_spacer_field( $A ) . ','; break;
  286. };
  287. };
  288. $RetVal .="{html:''}],'border':false,'autoScroll':true,'layout':'form','hideLabels':false,'labelWidth':250,'labelPad':8 }";
  289. return $RetVal;
  290. };
  291. //var_dump( buildExtJSForm( getDeviceCtrl( 0 ), 0 ) );
  292. //echo getDeviceIdByBusID('usb-3f980000.usb-1.2') . "\n\n";
  293. ?>