Adding initial camera functions

This commit is contained in:
2026-03-16 17:16:13 -07:00
parent a6ac1ffcf9
commit 1daa071bbe
6 changed files with 922 additions and 3 deletions

143
src/templates/index.html Normal file
View File

@@ -0,0 +1,143 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pi Camera</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: sans-serif;
background: #0f0f0f;
color: #f0f0f0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
gap: 1.5rem;
padding: 2rem;
}
h1 {
font-size: 1.4rem;
letter-spacing: 0.05em;
}
#preview {
width: 100%;
max-width: 720px;
aspect-ratio: 16/9;
background: #1a1a1a;
border: 1px solid #333;
border-radius: 8px;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
color: #555;
font-size: 0.9rem;
}
#preview img {
width: 100%;
height: 100%;
object-fit: cover;
display: none;
}
.controls {
display: flex;
gap: 1rem;
}
button {
padding: 0.6rem 2rem;
font-size: 1rem;
border: none;
border-radius: 6px;
cursor: pointer;
transition: opacity 0.2s;
}
button:disabled {
opacity: 0.35;
cursor: not-allowed;
}
#btn-start {
background: #22c55e;
color: #000;
}
#btn-stop {
background: #ef4444;
color: #fff;
}
#status {
font-size: 0.85rem;
color: #888;
min-height: 1.2em;
}
</style>
</head>
<body>
<h1>Pi Camera Stream</h1>
<div id="preview">
<span id="placeholder">Stream not started</span>
<img id="stream-img" alt="Camera stream" />
</div>
<div class="controls">
<button id="btn-start">Start</button>
<button id="btn-stop" disabled>Stop</button>
</div>
<p id="status"></p>
<script>
const btnStart = document.getElementById("btn-start");
const btnStop = document.getElementById("btn-stop");
const streamImg = document.getElementById("stream-img");
const placeholder = document.getElementById("placeholder");
const status = document.getElementById("status");
async function postAction(url) {
const res = await fetch(url, { method: "POST" });
return res.json();
}
btnStart.addEventListener("click", async () => {
btnStart.disabled = true;
status.textContent = "Starting…";
await postAction("/camera/start");
streamImg.src = "/camera/stream";
streamImg.style.display = "block";
placeholder.style.display = "none";
btnStop.disabled = false;
status.textContent = "Streaming";
});
btnStop.addEventListener("click", async () => {
btnStop.disabled = true;
status.textContent = "Stopping…";
streamImg.style.display = "none";
streamImg.src = "";
placeholder.style.display = "block";
await postAction("/camera/stop");
btnStart.disabled = false;
status.textContent = "Stream stopped";
});
</script>
</body>
</html>