Sfoglia il codice sorgente

The websocket.lua script sends positions for the clock hands as well

bel 11 anni fa
parent
commit
c4669103f1
1 ha cambiato i file con 12 aggiunte e 1 eliminazioni
  1. 12 1
      test/websocket.lua

+ 12 - 1
test/websocket.lua

@@ -31,10 +31,21 @@ coroutine.yield(true); -- first yield returns (true) or (false) to accept or rej
 
 ready()
 
+local lasthand = ""
+
 repeat
     local cont, bits, content = coroutine.yield(true, 1.0)
 
-    mg.write("text", os.date());
+    local date = os.date('*t');
+    local hand = (date.hour%12)*60+date.min;
+
+    mg.write("text", string.format("%u:%02u:%02u", date.hour, date.min, date.sec));
+
+    if (hand ~= lasthand) then
+        mg.write("text", string.format("-->h %u", hand*360/(12*60)));
+        mg.write("text", string.format("-->m %u", date.min*360/60));
+        lasthand = hand;
+    end
 
     if bits and content then
         data(bits, content)