Fixed time field updates. Improved debug message output.

This commit is contained in:
Dirk Jahnke 2019-02-01 15:15:59 +01:00
parent 3db402ae32
commit 0f0ad4756f
2 changed files with 46 additions and 8 deletions

View File

@ -8,8 +8,6 @@
<link href="main.css" rel="stylesheet" type="text/css" /> <link href="main.css" rel="stylesheet" type="text/css" />
<link rel="manifest" href="manifest.json"> <link rel="manifest" href="manifest.json">
<script type="text/javascript"> <script type="text/javascript">
var button = document.getElementById("button");
var led = document.getElementById("led");
function ajaxGet(url, responseCallback) { function ajaxGet(url, responseCallback) {
var xh = new XMLHttpRequest(); var xh = new XMLHttpRequest();
@ -25,16 +23,23 @@
xh.send(null); xh.send(null);
}; };
function showMessage(s) {
var displayMessageId = document.getElementById("displayMessageId");
displayMessageId.innerHTML = "<pre>" + s + "</pre>";
}
function handleFwdClockResponse(result) { function handleFwdClockResponse(result) {
var led = document.getElementById("led");
var msg = "";
if (result.result == "OK") { if (result.result == "OK") {
led.src = "led-on.png"; led.src = "led-on.png";
var clockName = document.getElementById("clockNameId"); var clockName = document.getElementById("clockNameId");
clockName.html = result.clockName; clockName.html = result.clockName;
var displayedTime = document.getElementById("displayedTimeId"); msg = result.real_hours + ":" + result.real_minutes + " " + result.real_seconds + "<br>";
displayedTime.html = result.hours + ":" + result.minutes + " " + result.seconds;
} else { } else {
led.src = "led-off.png"; led.src = "led-off.png";
} }
showMessage(msg + JSON.stringify(result, null, 2));
}; };
function fwdClock() { function fwdClock() {
@ -42,6 +47,10 @@
}; };
function handleClockStatusResponse(result) { function handleClockStatusResponse(result) {
//showMessage(JSON.stringify(result));
document.getElementById("clockNameId").textContent = result.clockName;
document.getElementById("realTimeId").textContent = result.real_hours + ":" + result.real_minutes + " " + result.real_seconds;
document.getElementById("modelTimeId").textContent = result.model_hours + ":" + result.model_minutes + " " + result.model_seconds;
}; };
@ -52,10 +61,26 @@
}, 400); }, 400);
}; };
function handleSetDisplayedTimeResponse(result) {
showMessage(JSON.stringify(result, null, 2));
};
function setDisplayedTime() { function setDisplayedTime() {
var hoursInput = document.getElementById("displayedHoursInputId"); var hoursInput = document.getElementById("displayedHoursInputId");
var minutesInput = document.getElementById("displayedMinutesInputId"); var minutesInput = document.getElementById("displayedMinutesInputId");
alert("Values=" + hoursInput.value + ":" + minutesInput.value); ajaxGet("/setDT?h=" + hoursInput.value + "&m=" + minutesInput.value, handleSetDisplayedTimeResponse);
}
function handleChangeClockResponse(result) {
showMessage(JSON.stringify(result, null, 2));
};
function setClockToModel() {
ajaxGet("/clock/model", handleChangeClockResponse);
}
function setClockToReal() {
ajaxGet("/clock/real", handleChangeClockResponse);
} }
function onBodyLoad() { function onBodyLoad() {
@ -82,12 +107,18 @@
<body id="index" onload="onBodyLoad()"> <body id="index" onload="onBodyLoad()">
<div class="hdr"><img src="fremoei.gif"></div> <div class="hdr"><img src="fremoei.gif"></div>
<div><label>Clock name: </label><span id="clockNameId"></span></div> <div><label>Clock name: </label><span id="clockNameId"></span></div>
<div><label>Time: </label><span id="displayedTimeId"></span></div> <div><label>Real time (h:m): </label><span id="realTimeId"></span></div>
<div><label>Model time (h:m): </label><span id="modelTimeId"></span></div>
<div> <div>
<input type="number" min="0" max="23" id="displayedHoursInputId"> <input type="number" min="0" max="23" id="displayedHoursInputId">:
<input type="number" min="0" max="59" id="displayedMinutesInputId"> <input type="number" min="0" max="59" id="displayedMinutesInputId">
<input type="button" onclick="setDisplayedTime"> <button onclick="setDisplayedTime()">Adjust to actual time</button>
</div> </div>
<div>
<button onClick="setClockToModel()">Model time</button>
<button onClick="setClockToReal()">Real time</button>
</div>
<div id="displayMessageId" class="logmsg"></div>
<div class="btn_cnt"><img id="led" src="led-off.png"><a href="#"><img id="button" src="btn.png"></a></div> <div class="btn_cnt"><img id="led" src="led-off.png"><a href="#"><img id="button" src="btn.png"></a></div>
</body> </body>

View File

@ -31,6 +31,13 @@ body {
color: #555; color: #555;
} }
.logmsg {
background: #CFC;
text-align: left;
color: #555;
padding-top: 8px;
}
.hdr { .hdr {
width: 100%; width: 100%;
padding: 15px 0 15px 0; padding: 15px 0 15px 0;