mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
Send state messages semi-frequently even if there's no changes
This commit is contained in:
parent
cf522bd41e
commit
c19586369e
|
@ -1,4 +1,4 @@
|
|||
|
||||
import time
|
||||
import ujson as json
|
||||
class STATES:
|
||||
def __init__(self, statequeue):
|
||||
|
@ -13,15 +13,19 @@ class STATES:
|
|||
self.is_arq_session = False
|
||||
self.arq_session_state = 'disconnected'
|
||||
self.audio_dbfs = 0
|
||||
self.last = time.time()
|
||||
|
||||
def set(self, key, value):
|
||||
setattr(self, key, value)
|
||||
|
||||
updateCandence = 3
|
||||
# only process data if changed
|
||||
# but also send an update if more than a 'updateCadence' second(s) has lapsed
|
||||
# Otherwise GUI can't tell if modem is active due to lack of state messages on startup
|
||||
new_state = self.getAsJSON()
|
||||
if new_state != self.newstate:
|
||||
if new_state != self.newstate or time.time() - self.last > updateCandence:
|
||||
self.statequeue.put(new_state)
|
||||
self.newstate = new_state
|
||||
self.last=time.time()
|
||||
|
||||
def getAsJSON(self):
|
||||
return json.dumps({
|
||||
|
|
Loading…
Reference in a new issue