From 23e778caedeaacaee529b2d7d4d29c437136030d Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 10 May 2018 14:27:40 +0200 Subject: [PATCH] readLCD blocking added --- go/server.go | 11 ++++++++++- go/static/index.js | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/go/server.go b/go/server.go index 5f56bdc..27392a9 100644 --- a/go/server.go +++ b/go/server.go @@ -9,6 +9,7 @@ import ( "log" "net/http" "os" + "time" "github.com/Hundemeier/go-sacn/sacn" @@ -133,7 +134,15 @@ type lcd struct { Second string //`json:"second"` } +var readLCDLock = false + func readLCD(port io.ReadWriteCloser) lcd { + for readLCDLock { + //wait unitl the lock is over + time.Sleep(10 * time.Millisecond) + } + readLCDLock = true + result := lcd{} //Attemp to read the first line writeBytes(port, createBytes(projAddr, []byte{0x7a, 0x02}, []byte{0, 0})) @@ -156,7 +165,7 @@ func readLCD(port io.ReadWriteCloser) lcd { break } } - + readLCDLock = false return result } diff --git a/go/static/index.js b/go/static/index.js index 25087d2..ddc23ad 100644 --- a/go/static/index.js +++ b/go/static/index.js @@ -16,6 +16,7 @@ function apirequest(cmd, opt) { method: 'GET', credentials: 'same-origin', }) + readLCD(); } function readLCD() {