@@ -68,23 +68,23 @@ function restartCameraViewing() {
6868 }
6969}
7070
71- async function takeTestRecording ( ) {
72- document . getElementById ( "take-snapshot-recording " ) ! . innerText = 'Making a test recording ' ;
73- document . getElementById ( "take-snapshot-recording " ) ! . setAttribute ( "disabled" , "true" ) ;
74- console . log ( "making a test recording " ) ;
75- fetch ( '/api/camera/snapshot-recording ' , {
71+ async function triggerTrap ( ) {
72+ document . getElementById ( "trigger-trap " ) ! . innerText = 'Triggering trap ' ;
73+ document . getElementById ( "trigger-trap " ) ! . setAttribute ( "disabled" , "true" ) ;
74+ console . log ( "triggering trap " ) ;
75+ fetch ( '/api/trigger-trap ' , {
7676 method : 'PUT' ,
7777 headers : {
7878 'Authorization' : 'Basic YWRtaW46ZmVhdGhlcnM='
7979 } } )
80-
80+
8181 . then ( response => console . log ( response ) )
8282 . then ( data => console . log ( data ) )
8383 . catch ( error => console . error ( error ) )
8484 //TODO handle errors better and check that recording was made properly instead of just waiting..
8585 await new Promise ( r => setTimeout ( r , 3000 ) ) ;
86- document . getElementById ( "take-snapshot-recording " ) ! . removeAttribute ( "disabled" ) ;
87- document . getElementById ( "take-snapshot-recording " ) ! . innerText = 'Take test recording ' ;
86+ document . getElementById ( "trigger-trap " ) ! . removeAttribute ( "disabled" ) ;
87+ document . getElementById ( "trigger-trap " ) ! . innerText = 'Trigger trap ' ;
8888}
8989
9090window . onload = function ( ) {
@@ -93,6 +93,7 @@ window.onload = function () {
9393 snapshotLimit = Number . MAX_SAFE_INTEGER ;
9494 }
9595 document . getElementById ( "snapshot-restart" ) ! . onclick = restartCameraViewing ;
96+ document . getElementById ( "trigger-trap" ) ! . onclick = triggerTrap ;
9697 document . getElementById ( "take-snapshot-recording" ) ! . onclick = takeTestRecording ;
9798 cameraConnection = new CameraConnection (
9899 window . location . hostname ,
@@ -102,6 +103,25 @@ window.onload = function () {
102103 ) ;
103104} ;
104105
106+ async function takeTestRecording ( ) {
107+ document . getElementById ( "take-snapshot-recording" ) ! . innerText = 'Making a test recording' ;
108+ document . getElementById ( "take-snapshot-recording" ) ! . setAttribute ( "disabled" , "true" ) ;
109+ console . log ( "making a test recording" ) ;
110+ fetch ( '/api/camera/snapshot-recording' , {
111+ method : 'PUT' ,
112+ headers : {
113+ 'Authorization' : 'Basic YWRtaW46ZmVhdGhlcnM='
114+ } } )
115+
116+ . then ( response => console . log ( response ) )
117+ . then ( data => console . log ( data ) )
118+ . catch ( error => console . error ( error ) )
119+ //TODO handle errors better and check that recording was made properly instead of just waiting..
120+ await new Promise ( r => setTimeout ( r , 3000 ) ) ;
121+ document . getElementById ( "take-snapshot-recording" ) ! . removeAttribute ( "disabled" ) ;
122+ document . getElementById ( "take-snapshot-recording" ) ! . innerText = 'Take test recording' ;
123+ }
124+
105125function stopSnapshots ( message : string ) {
106126 if ( cameraConnection ) {
107127 cameraConnection . close ( ) ;
@@ -170,26 +190,51 @@ function drawRectWithText(
170190
171191async function processFrame ( frame : Frame ) {
172192 const canvas = document . getElementById ( "frameCanvas" ) as HTMLCanvasElement ;
193+
173194 const trackCanvas = document . getElementById (
174195 "trackCanvas"
175196 ) as HTMLCanvasElement ;
176-
177197 if ( canvas == null ) {
178198 return ;
179199 }
200+ if ( canvas . width != frame . frameInfo . Camera . ResX ) {
201+ canvas . width = frame . frameInfo . Camera . ResX
202+ trackCanvas . width = frame . frameInfo . Camera . ResX
203+ }
204+ if ( canvas . height != frame . frameInfo . Camera . ResY ) {
205+ canvas . height = frame . frameInfo . Camera . ResY
206+ trackCanvas . height = frame . frameInfo . Camera . ResY
207+ }
180208 const context = canvas . getContext ( "2d" ) as CanvasRenderingContext2D ;
181209 const imgData = context . getImageData (
182210 0 ,
183211 0 ,
184212 frame . frameInfo . Camera . ResX ,
185213 frame . frameInfo . Camera . ResY
186214 ) ;
187- const max = Math . max ( ...frame . frame ) ;
188- const min = Math . min ( ...frame . frame ) ;
189- const range = max - min ;
215+ // gp hack to see if ir camera, dbus from python makes dictionary have to be all int type
216+ let irCamera = frame . frameInfo . Camera . Model == "2" ;
217+ if ( irCamera ) {
218+ document . getElementById ( "trigger-trap" ) ! . style . display = "" ;
219+ } else {
220+ document . getElementById ( "trigger-trap" ) ! . style . display = "none" ;
221+ }
222+ let max = 0 ;
223+ let min = 0 ;
224+ let range = 0 ;
225+ if ( ! irCamera ) {
226+ max = Math . max ( ...frame . frame ) ;
227+ min = Math . min ( ...frame . frame ) ;
228+ range = max - min ;
229+ }
190230 let maxI = 0 ;
191231 for ( let i = 0 ; i < frame . frame . length ; i ++ ) {
192- const pix = Math . min ( 255 , ( ( frame . frame [ i ] - min ) / range ) * 255.0 ) ;
232+ let pix = 0
233+ if ( irCamera ) {
234+ pix = frame . frame [ i ]
235+ } else {
236+ pix = Math . min ( 255 , ( ( frame . frame [ i ] - min ) / range ) * 255.0 ) ;
237+ }
193238 let index = i * 4 ;
194239 imgData . data [ index ] = pix ;
195240 imgData . data [ index + 1 ] = pix ;
0 commit comments