Skip to content

Commit

Permalink
fix: Fixes from testing (#2)
Browse files Browse the repository at this point in the history
* Update index.htm

* Update server.ino

* Fix font

* Add favicon

* Update favicon

* Fix centering
  • Loading branch information
MatiasG19 authored Jul 1, 2023
1 parent 81380a5 commit 60d0ab5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
47 changes: 26 additions & 21 deletions server/server.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ bool powerOn, standBy, reset, kill;
bool powerLed;

void setup() {
// PINs and serial
pinMode(IN_PIN_POWER_LED, INPUT_PULLUP);
pinMode(OUT_PIN_POWER, OUTPUT);
pinMode(OUT_PIN_RESET, OUTPUT);
Serial.begin(9600);

// Server
Ethernet.begin(mac, ip);
server.begin();
Serial.print("Server started at ");
Expand All @@ -37,11 +43,6 @@ void setup() {
return;
}
Serial.println("SUCCESS - Found file.");

// PINs
pinMode(IN_PIN_POWER_LED, INPUT_PULLUP);
pinMode(OUT_PIN_POWER, OUTPUT);
pinMode(OUT_PIN_RESET, OUTPUT);
}

void loop() {
Expand Down Expand Up @@ -104,7 +105,8 @@ void loop() {
controlOutput(OUT_PIN_RESET, 500);
reset = false;
} else if(kill) {
controlOutput(OUT_PIN_POWER, 4500);
Serial.println("kill");
controlOutput(OUT_PIN_POWER, 5000);
kill = false;
}
}
Expand All @@ -113,34 +115,37 @@ void sendResponse(String req, EthernetClient client) {
client.println("HTTP/1.1 200 OK");
if(req == "") req = "index.htm";

// Send file to client
if(req.endsWith(".htm")) {
client.println("Content-Type: text/html\n\r\n\r");
File webFile = SD.open(req);
if (webFile) {
while (webFile.available()) {
client.write(webFile.read());
}
webFile.close();
}
}
else
client.println("\n\r\n\r");

// Send file to client
File webFile = SD.open(req);
if (webFile) {
while (webFile.available()) {
client.write(webFile.read());
}
webFile.close();
}
// Other actions
else {
Serial.println("Other");
client.println("\n\r\n\r");
if(req == "powerStatus") {
if(powerLed) client.write("powerStatus:on");
else client.write("powerStatus:off");
}
else if(req == "powerOn")
else if(req == "powerOn") {
if (!powerLed) powerOn = true;
else if(req == "standBy")
}
else if(req == "standBy") {
if (powerLed) standBy = true;
else if(req == "reset")
}
else if(req == "reset") {
if (powerLed) reset = true;
else if(req == "kill")
}
else if(req == "kill") {
if (powerLed) kill = true;
}
else
client.println("HTTP/1.1 404 Not Found\n\r");
}
Expand Down
Binary file added web/favicon.kra
Binary file not shown.
Binary file added web/src/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 7 additions & 10 deletions web/src/index.htm
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>STORINATOR Switch</title>
<!-- TODO icon -->
<link rel="icon" type="image/png" href="power.png" />
<link rel="stylesheet" href="style.css" />
<title>PC Switch</title>
<link rel="icon" type="image/png" href="favicon.png" />
</head>
<body>
<div class="heading">STORINATOR</div>
<div class="heading">PC SWITCH</div>

<button id="powerStatus" type="button" class="statusButton" disabled>
NO CONNECTION
Expand Down Expand Up @@ -52,7 +50,7 @@
<style>
html {
height: 95%;
font-family: 'Lucida Console', 'Arial', monospace;
font-family: 'Tahoma', 'Arial', monospace;
}

body {
Expand All @@ -68,10 +66,8 @@

button {
position: relative;
display: inline-block;
width: calc(100% - 2vw);
min-width: 50px;
max-width: 200vh;
height: 15%;
min-height: 50px;
border: none;
Expand All @@ -80,6 +76,7 @@
font-size: 5vh;
color: #cfcfcf;
background-color: #313131;
font-family: 'Tahoma', 'Arial', monospace;
}

.statusButton {
Expand Down Expand Up @@ -156,11 +153,11 @@
var xhttp = new XMLHttpRequest()
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
console.debug(`sendCommand:${request}:${this.responseText}`)
console.debug(`sendCommand:${type}:${this.responseText}`)
alert('Action confirmed.')
}
}
xhttp.open('GET', request, true)
xhttp.open('GET', type, true)
xhttp.send()
}

Expand Down

0 comments on commit 60d0ab5

Please sign in to comment.