From f619dc3c7e309ede955a73b1a25cf9fe664d8f4a Mon Sep 17 00:00:00 2001 From: gferraro Date: Wed, 7 Sep 2022 15:55:26 +1200 Subject: [PATCH 1/3] resize canvas to res x and res y and dont normalize ir values --- cmd/managementd/main.go | 2 +- static/js/camera.ts | 30 +++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/cmd/managementd/main.go b/cmd/managementd/main.go index 940684f..8c3780c 100644 --- a/cmd/managementd/main.go +++ b/cmd/managementd/main.go @@ -184,7 +184,7 @@ func WebsocketServer(ws *websocket.Conn) { } socketsLock.Unlock() if firstSocket { - log.Print("Git new client register") + log.Print("Get new client register") haveClients <- true } } diff --git a/static/js/camera.ts b/static/js/camera.ts index de153f1..354fe58 100644 --- a/static/js/camera.ts +++ b/static/js/camera.ts @@ -150,13 +150,21 @@ function drawRectWithText( async function processFrame(frame: Frame) { const canvas = document.getElementById("frameCanvas") as HTMLCanvasElement; + const trackCanvas = document.getElementById( "trackCanvas" ) as HTMLCanvasElement; - if (canvas == null) { return; } + if( canvas.width != frame.frameInfo.Camera.ResX){ + canvas.width = frame.frameInfo.Camera.ResX + trackCanvas.width = frame.frameInfo.Camera.ResX + } + if(canvas.height != frame.frameInfo.Camera.ResY){ + canvas.height = frame.frameInfo.Camera.ResY + trackCanvas.height = frame.frameInfo.Camera.ResY + } const context = canvas.getContext("2d") as CanvasRenderingContext2D; const imgData = context.getImageData( 0, @@ -164,12 +172,24 @@ async function processFrame(frame: Frame) { frame.frameInfo.Camera.ResX, frame.frameInfo.Camera.ResY ); - const max = Math.max(...frame.frame); - const min = Math.min(...frame.frame); - const range = max - min; + // gp hack to see if ir camera + let irCamera = frame.frameInfo.Camera.ResX == 640; + let max=0; + let min=0; + let range=0; + if (!irCamera){ + max = Math.max(...frame.frame); + min = Math.min(...frame.frame); + range = max - min; + } let maxI = 0; for (let i = 0; i < frame.frame.length; i++) { - const pix = Math.min(255, ((frame.frame[i] - min) / range) * 255.0); + let pix = 0 + if(irCamera){ + pix = frame.frame[i] + }else{ + pix = Math.min(255, ((frame.frame[i] - min) / range) * 255.0); + } let index = i * 4; imgData.data[index] = pix; imgData.data[index + 1] = pix; From 4d996456b67b12484c6e49341c25dce98265dead Mon Sep 17 00:00:00 2001 From: cam Date: Fri, 27 Jan 2023 10:57:50 +1300 Subject: [PATCH 2/3] Added button to trigger trap --- .goreleaser.yml | 4 +++- api/api.go | 15 +++++++++++++++ cmd/managementd/main.go | 1 + html/camera.html | 3 +++ static/js/camera.ts | 20 ++++++++++++++++++++ 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 6e3eb40..7edcd4a 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -18,7 +18,9 @@ builds: - "7" ldflags: -s -w -X main.version={{.Version}} hooks: - pre: packr + pre: + - packr + - tsc post: packr clean - id: "signal-strength" binary: "signal-strength" diff --git a/api/api.go b/api/api.go index d7df7ce..001f2bb 100644 --- a/api/api.go +++ b/api/api.go @@ -453,6 +453,21 @@ func (api *ManagementAPI) DeleteEvents(w http.ResponseWriter, r *http.Request) { } } +// Trigger trap +func (api *ManagementAPI) TriggerTrap(w http.ResponseWriter, r *http.Request) { + log.Println("triggering trap") + err := eventclient.AddEvent(eventclient.Event{ + Timestamp: time.Now(), + Type: "trapped", + Details: map[string]interface{}{"test": true}, + }) + + if err != nil { + badRequest(&w, err) + return + } +} + // CheckSaltConnection will try to ping the salt server and return the response func (api *ManagementAPI) CheckSaltConnection(w http.ResponseWriter, r *http.Request) { log.Println("pinging salt server") diff --git a/cmd/managementd/main.go b/cmd/managementd/main.go index 8c3780c..99547ad 100644 --- a/cmd/managementd/main.go +++ b/cmd/managementd/main.go @@ -119,6 +119,7 @@ func main() { apiRouter.HandleFunc("/event-keys", apiObj.GetEventKeys).Methods("GET") apiRouter.HandleFunc("/events", apiObj.GetEvents).Methods("GET") apiRouter.HandleFunc("/events", apiObj.DeleteEvents).Methods("DELETE") + apiRouter.HandleFunc("/trigger-trap", apiObj.TriggerTrap).Methods("PUT") apiRouter.HandleFunc("/check-salt-connection", apiObj.CheckSaltConnection).Methods("GET") apiRouter.HandleFunc("/salt-update", apiObj.StartSaltUpdate).Methods("POST") apiRouter.HandleFunc("/salt-update", apiObj.GetSaltUpdateState).Methods("GET") diff --git a/html/camera.html b/html/camera.html index c33b708..9604178 100644 --- a/html/camera.html +++ b/html/camera.html @@ -13,6 +13,9 @@

Camera

+