Skip to content

Commit 60d0ab5

Browse files
authored
fix: Fixes from testing (#2)
* Update index.htm * Update server.ino * Fix font * Add favicon * Update favicon * Fix centering
1 parent 81380a5 commit 60d0ab5

File tree

4 files changed

+33
-31
lines changed

4 files changed

+33
-31
lines changed

server/server.ino

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ bool powerOn, standBy, reset, kill;
1616
bool powerLed;
1717

1818
void setup() {
19+
// PINs and serial
20+
pinMode(IN_PIN_POWER_LED, INPUT_PULLUP);
21+
pinMode(OUT_PIN_POWER, OUTPUT);
22+
pinMode(OUT_PIN_RESET, OUTPUT);
1923
Serial.begin(9600);
24+
25+
// Server
2026
Ethernet.begin(mac, ip);
2127
server.begin();
2228
Serial.print("Server started at ");
@@ -37,11 +43,6 @@ void setup() {
3743
return;
3844
}
3945
Serial.println("SUCCESS - Found file.");
40-
41-
// PINs
42-
pinMode(IN_PIN_POWER_LED, INPUT_PULLUP);
43-
pinMode(OUT_PIN_POWER, OUTPUT);
44-
pinMode(OUT_PIN_RESET, OUTPUT);
4546
}
4647

4748
void loop() {
@@ -104,7 +105,8 @@ void loop() {
104105
controlOutput(OUT_PIN_RESET, 500);
105106
reset = false;
106107
} else if(kill) {
107-
controlOutput(OUT_PIN_POWER, 4500);
108+
Serial.println("kill");
109+
controlOutput(OUT_PIN_POWER, 5000);
108110
kill = false;
109111
}
110112
}
@@ -113,34 +115,37 @@ void sendResponse(String req, EthernetClient client) {
113115
client.println("HTTP/1.1 200 OK");
114116
if(req == "") req = "index.htm";
115117

118+
// Send file to client
116119
if(req.endsWith(".htm")) {
117120
client.println("Content-Type: text/html\n\r\n\r");
121+
File webFile = SD.open(req);
122+
if (webFile) {
123+
while (webFile.available()) {
124+
client.write(webFile.read());
125+
}
126+
webFile.close();
127+
}
118128
}
119-
else
120-
client.println("\n\r\n\r");
121-
122-
// Send file to client
123-
File webFile = SD.open(req);
124-
if (webFile) {
125-
while (webFile.available()) {
126-
client.write(webFile.read());
127-
}
128-
webFile.close();
129-
}
130129
// Other actions
131130
else {
131+
Serial.println("Other");
132+
client.println("\n\r\n\r");
132133
if(req == "powerStatus") {
133134
if(powerLed) client.write("powerStatus:on");
134135
else client.write("powerStatus:off");
135136
}
136-
else if(req == "powerOn")
137+
else if(req == "powerOn") {
137138
if (!powerLed) powerOn = true;
138-
else if(req == "standBy")
139+
}
140+
else if(req == "standBy") {
139141
if (powerLed) standBy = true;
140-
else if(req == "reset")
142+
}
143+
else if(req == "reset") {
141144
if (powerLed) reset = true;
142-
else if(req == "kill")
145+
}
146+
else if(req == "kill") {
143147
if (powerLed) kill = true;
148+
}
144149
else
145150
client.println("HTTP/1.1 404 Not Found\n\r");
146151
}

web/favicon.kra

330 KB
Binary file not shown.

web/src/favicon.png

2.12 KB
Loading

web/src/index.htm

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>STORINATOR Switch</title>
5-
<!-- TODO icon -->
6-
<link rel="icon" type="image/png" href="power.png" />
7-
<link rel="stylesheet" href="style.css" />
4+
<title>PC Switch</title>
5+
<link rel="icon" type="image/png" href="favicon.png" />
86
</head>
97
<body>
10-
<div class="heading">STORINATOR</div>
8+
<div class="heading">PC SWITCH</div>
119

1210
<button id="powerStatus" type="button" class="statusButton" disabled>
1311
NO CONNECTION
@@ -52,7 +50,7 @@
5250
<style>
5351
html {
5452
height: 95%;
55-
font-family: 'Lucida Console', 'Arial', monospace;
53+
font-family: 'Tahoma', 'Arial', monospace;
5654
}
5755

5856
body {
@@ -68,10 +66,8 @@
6866

6967
button {
7068
position: relative;
71-
display: inline-block;
7269
width: calc(100% - 2vw);
7370
min-width: 50px;
74-
max-width: 200vh;
7571
height: 15%;
7672
min-height: 50px;
7773
border: none;
@@ -80,6 +76,7 @@
8076
font-size: 5vh;
8177
color: #cfcfcf;
8278
background-color: #313131;
79+
font-family: 'Tahoma', 'Arial', monospace;
8380
}
8481

8582
.statusButton {
@@ -156,11 +153,11 @@
156153
var xhttp = new XMLHttpRequest()
157154
xhttp.onreadystatechange = function () {
158155
if (this.readyState == 4 && this.status == 200) {
159-
console.debug(`sendCommand:${request}:${this.responseText}`)
156+
console.debug(`sendCommand:${type}:${this.responseText}`)
160157
alert('Action confirmed.')
161158
}
162159
}
163-
xhttp.open('GET', request, true)
160+
xhttp.open('GET', type, true)
164161
xhttp.send()
165162
}
166163

0 commit comments

Comments
 (0)