Skip to content

Commit c8e6de6

Browse files
authored
Merge pull request #112 from TheCacophonyProject/ir-fix
Ir fix
2 parents 5dcd1ca + 3eb6c8d commit c8e6de6

File tree

4 files changed

+79
-15
lines changed

4 files changed

+79
-15
lines changed

api/api.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,21 @@ func (api *ManagementAPI) DeleteEvents(w http.ResponseWriter, r *http.Request) {
470470
}
471471
}
472472

473+
// Trigger trap
474+
func (api *ManagementAPI) TriggerTrap(w http.ResponseWriter, r *http.Request) {
475+
log.Println("triggering trap")
476+
err := eventclient.AddEvent(eventclient.Event{
477+
Timestamp: time.Now(),
478+
Type: "trapped",
479+
Details: map[string]interface{}{"test": true},
480+
})
481+
482+
if err != nil {
483+
badRequest(&w, err)
484+
return
485+
}
486+
}
487+
473488
// CheckSaltConnection will try to ping the salt server and return the response
474489
func (api *ManagementAPI) CheckSaltConnection(w http.ResponseWriter, r *http.Request) {
475490
log.Println("pinging salt server")

cmd/managementd/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func main() {
120120
apiRouter.HandleFunc("/event-keys", apiObj.GetEventKeys).Methods("GET")
121121
apiRouter.HandleFunc("/events", apiObj.GetEvents).Methods("GET")
122122
apiRouter.HandleFunc("/events", apiObj.DeleteEvents).Methods("DELETE")
123+
apiRouter.HandleFunc("/trigger-trap", apiObj.TriggerTrap).Methods("PUT")
123124
apiRouter.HandleFunc("/check-salt-connection", apiObj.CheckSaltConnection).Methods("GET")
124125
apiRouter.HandleFunc("/salt-update", apiObj.StartSaltUpdate).Methods("POST")
125126
apiRouter.HandleFunc("/salt-update", apiObj.GetSaltUpdateState).Methods("GET")
@@ -185,7 +186,7 @@ func WebsocketServer(ws *websocket.Conn) {
185186
}
186187
socketsLock.Unlock()
187188
if firstSocket {
188-
log.Print("Git new client register")
189+
log.Print("Get new client register")
189190
haveClients <- true
190191
}
191192
}

html/camera.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313

1414
<div class="container">
1515
<h2>Camera</h2>
16+
<button id="trigger-trap" style="position: relative;display: none" type="button">
17+
Trigger trap
18+
</button>
1619
<button id="take-snapshot-recording" style="position: relative" type="button">
1720
Take test recording
1821
</button>
1922
<div id="snapshot-stopped" style="display: none">
20-
23+
2124
<p id="snapshot-stopped-message"></p>
2225
<button id="snapshot-restart" type="button">
2326
Continue viewing camera

static/js/camera.ts

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

9090
window.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+
105125
function stopSnapshots(message: string) {
106126
if (cameraConnection) {
107127
cameraConnection.close();
@@ -170,26 +190,51 @@ function drawRectWithText(
170190

171191
async 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

Comments
 (0)