Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ class SignData:
expiration: datetime.datetime

def to_subprocess_command(self) -> str:
# use lstrip('#') instead of [1:] in order to handle cases where the color might not start with '#'
return [
os.path.join(WORKING_DIRECTORY, "sce_sign.exe"),
"--set-speed",
str(self.scrollSpeed) + " px/vsync",
"--set-background-color",
self.backgroundColor[1:],
self.backgroundColor.lstrip('#'),
"--set-font-color",
self.textColor[1:],
self.textColor.lstrip('#'),
"--set-border-color",
self.borderColor[1:],
self.borderColor.lstrip('#'),
"--set-font-filename",
os.path.join(WORKING_DIRECTORY, "10x20.bdf"),
"--set-brightness",
Expand Down Expand Up @@ -153,10 +154,13 @@ def write_message_to_sign(new_data):
"starting sign process with command "
+ " \\\n\t".join(new_data.to_subprocess_command())
)
process = subprocess.Popen(
args=new_data.to_subprocess_command(),
)
logging.info(f"sign process started with pid {process.pid}")
try:
process = subprocess.Popen(
args=new_data.to_subprocess_command(),
)
logging.info(f"sign process started with pid {process.pid}")
except Exception as e:
logging.exception("Failed to start sign process")

sign_data = new_data

Expand Down
81 changes: 55 additions & 26 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,81 @@
</head>

<body>
<h3 id="isOff" style="display: none">Sign is Off</h3>
<marquee
id="sign-preview"
direction="left"
style="
width: 150px;
border-style: solid;
border-width: 5px;
font-family: monospace;
font-size: 20px;
"
/>
<div style="max-width: 700px; margin: 40px auto; text-align: center;">
<div style="text-align: left; font-size: 1.5em; margin-bottom: 8px; color: #23292c;">Preview</div>
<div id="sign-preview" style="background: #eae6de; color: #23302c; border: 6px solid #d32f2f; border-radius: 14px; font-size: 3em; font-family: Arial, sans-serif; font-weight: bold; text-align: center; padding: 20px 0; width: 100%;"> </div>
<form id="update-form" style="margin: 0 auto; display: inline-block; text-align: left;">
<h3>Update Sign (Debug)</h3>
<label>Text: <input type="text" name="text" required></label><br>
<label>Background Color: <input type="color" name="backgroundColor" value="#eae6de" style="width: 60px;"></label><br>
<label>Text Color: <input type="color" name="textColor" value="#23302c" style="width: 60px;"></label><br>
<label>Border Color: <input type="color" name="borderColor" value="#d32f2f" style="width: 60px;"></label><br>
<label>Scroll Speed: <input type="text" name="scrollSpeed" value="50"></label><br>
<label>Brightness: <input type="text" name="brightness" value="100"></label><br>
<label>Expiration: <input type="datetime-local" name="expiration"></label><br>
<button type="submit">Update Sign</button>
</form>
<div id="update-message" style="margin-top:10px;color:#d32f2f;font-weight:bold;"></div>
</div>

<script>
const handleFetch = async () => {
url = new URL("health-check", window.location.origin);
const url = new URL("health-check", window.location.origin);
try {
const res = await fetch(url.href);
if (!res.ok) {
throw new Error("Could not fetch resource");
}

const data = await res.json();

const sign = document.getElementById("sign-preview");
console.log(Object.hasOwn(data, "text"));

if (!Object.hasOwn(data, "text")) {
document.getElementById("sign-preview").style.display = "none";

document.getElementById("isOff").style.display = "block";
sign.textContent = "Sign is Off";
sign.style.background = "#eae6de";
sign.style.color = "#23302c";
sign.style.borderColor = "#d32f2f";
return;
}
document.getElementById("sign-preview").style.color = data.textColor;
document.getElementById("sign-preview").style.backgroundColor =
data.backgroundColor;
document.getElementById("sign-preview").style.borderColor =
data.borderColor;
document.getElementById("sign-preview").innerHTML = data.text;
document
.getElementById("sign-preview")
.setAttribute("scrollamount", data.scrollSpeed);
sign.textContent = data.text;
sign.style.background = data.backgroundColor;
sign.style.color = data.textColor;
sign.style.borderColor = data.borderColor;
} catch (err) {
console.log(err);
}
};
handleFetch();
document.getElementById('update-form').onsubmit = async function(e) {
e.preventDefault();
const form = e.target;
const payload = {
text: form.text.value,
backgroundColor: form.backgroundColor.value,
textColor: form.textColor.value,
borderColor: form.borderColor.value,
scrollSpeed: Number(form.scrollSpeed.value),
brightness: form.brightness.value ? Number(form.brightness.value) : 100,
expiration: form.expiration.value ? new Date(form.expiration.value).toISOString() : null
};
try {
const res = await fetch('/update-sign', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
if (res.ok) {
document.getElementById('update-message').textContent = 'Sign updated';
setTimeout(() => { document.getElementById('update-message').textContent = ''; }, 1500);
setTimeout(handleFetch, 500);
} else {
document.getElementById('update-message').textContent = 'Failed to update sign';
}
} catch (err) {
document.getElementById('update-message').textContent = 'Error updating sign';
}
};
</script>
</body>
</html>