mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2026-04-05 14:35:17 +00:00
rename globals. call to globalVars.
This commit is contained in:
parent
f8fcda94b6
commit
e938cdcd6d
27 changed files with 300 additions and 300 deletions
|
|
@ -79,14 +79,14 @@ try:
|
|||
#
|
||||
try:
|
||||
logging.debug("reading config file")
|
||||
globals.config = ConfigParser.SafeConfigParser()
|
||||
globals.config.read("config.ini")
|
||||
globalData.config = ConfigParser.SafeConfigParser()
|
||||
globalData.config.read("config.ini")
|
||||
# if given loglevel is debug:
|
||||
logging.debug("- [AlarmMonitor]")
|
||||
for key,val in globals.config.items("AlarmMonitor"):
|
||||
for key,val in globalData.config.items("AlarmMonitor"):
|
||||
logging.debug("-- %s = %s", key, val)
|
||||
logging.debug("- [Display]")
|
||||
for key,val in globals.config.items("Display"):
|
||||
for key,val in globalData.config.items("Display"):
|
||||
logging.debug("-- %s = %s", key, val)
|
||||
except:
|
||||
# we couldn't work without config -> exit
|
||||
|
|
@ -106,7 +106,7 @@ try:
|
|||
#
|
||||
try:
|
||||
from displayServices import displayPainter, autoTurnOffDisplay, eventHandler
|
||||
globals.screenBackground = pygame.Color(globals.config.get("AlarmMonitor","colourGreen"))
|
||||
globalData.screenBackground = pygame.Color(globalData.config.get("AlarmMonitor","colourGreen"))
|
||||
logging.debug("Start displayPainter-thread")
|
||||
Thread(target=displayPainter).start()
|
||||
logging.debug("start autoTurnOffDisplay-thread")
|
||||
|
|
@ -124,7 +124,7 @@ try:
|
|||
#
|
||||
logging.debug("Start socketServer")
|
||||
sock = socket.socket () # TCP
|
||||
sock.bind(("",globals.config.getint("AlarmMonitor","socketPort")))
|
||||
sock.bind(("",globalData.config.getint("AlarmMonitor","socketPort")))
|
||||
sock.listen(5)
|
||||
logging.debug("socketServer runs")
|
||||
|
||||
|
|
@ -132,45 +132,45 @@ try:
|
|||
# Build Lists out of config-entries
|
||||
#
|
||||
logging.debug("create lists")
|
||||
keepAliveRICs = [int(x.strip()) for x in globals.config.get("AlarmMonitor","keepAliveRICs").replace(";", ",").split(",")]
|
||||
keepAliveRICs = [int(x.strip()) for x in globalData.config.get("AlarmMonitor","keepAliveRICs").replace(";", ",").split(",")]
|
||||
logging.debug("-- keepAliveRICs: %s", keepAliveRICs)
|
||||
alarmRICs = [int(x.strip()) for x in globals.config.get("AlarmMonitor","alarmRICs").replace(";", ",").split(",")]
|
||||
alarmRICs = [int(x.strip()) for x in globalData.config.get("AlarmMonitor","alarmRICs").replace(";", ",").split(",")]
|
||||
logging.debug("-- alarmRICs: %s", alarmRICs)
|
||||
functionCharTestAlarm = [str(x.strip()) for x in globals.config.get("AlarmMonitor","functionCharTestAlarm").replace(";", ",").split(",")]
|
||||
functionCharTestAlarm = [str(x.strip()) for x in globalData.config.get("AlarmMonitor","functionCharTestAlarm").replace(";", ",").split(",")]
|
||||
logging.debug("-- functionCharTestAlarm: %s", functionCharTestAlarm)
|
||||
functionCharAlarm = [str(x.strip()) for x in globals.config.get("AlarmMonitor","functionCharAlarm").replace(";", ",").split(",")]
|
||||
functionCharAlarm = [str(x.strip()) for x in globalData.config.get("AlarmMonitor","functionCharAlarm").replace(";", ",").split(",")]
|
||||
logging.debug("-- functionCharAlarm: %s", functionCharAlarm)
|
||||
|
||||
#
|
||||
# try to read History from MySQL-DB
|
||||
#
|
||||
try:
|
||||
if globals.config.getboolean("AlarmMonitor","loadHistory") == True:
|
||||
if globalData.config.getboolean("AlarmMonitor","loadHistory") == True:
|
||||
import mysql.connector
|
||||
|
||||
for key,val in globals.config.items("MySQL"):
|
||||
for key,val in globalData.config.items("MySQL"):
|
||||
logging.debug("-- %s = %s", key, val)
|
||||
|
||||
# Connect to DB
|
||||
logging.debug("connect to MySQL")
|
||||
connection = mysql.connector.connect(host = globals.config.get("MySQL","dbserver"), user = globals.config.get("MySQL","dbuser"), passwd = globals.config.get("MySQL","dbpassword"), db = globals.config.get("MySQL","database"), charset='utf8')
|
||||
connection = mysql.connector.connect(host = globalData.config.get("MySQL","dbserver"), user = globalData.config.get("MySQL","dbuser"), passwd = globalData.config.get("MySQL","dbpassword"), db = globalData.config.get("MySQL","database"), charset='utf8')
|
||||
cursor = connection.cursor()
|
||||
logging.debug("MySQL connected")
|
||||
|
||||
# read countKeepAlive
|
||||
# precondition: keepAliveRICs set
|
||||
if (len(keepAliveRICs) > 0):
|
||||
sql = "SELECT COUNT(*) FROM "+globals.config.get("MySQL","tablePOC")+" WHERE ric IN ("+globals.config.get("AlarmMonitor","keepAliveRICs")+")"
|
||||
sql = "SELECT COUNT(*) FROM "+globalData.config.get("MySQL","tablePOC")+" WHERE ric IN ("+globalData.config.get("AlarmMonitor","keepAliveRICs")+")"
|
||||
cursor.execute(sql)
|
||||
result = int(cursor.fetchone()[0])
|
||||
if result > 0:
|
||||
globals.countKeepAlive = result
|
||||
logging.debug("-- countKeepAlive: %s", globals.countKeepAlive)
|
||||
globalData.countKeepAlive = result
|
||||
logging.debug("-- countKeepAlive: %s", globalData.countKeepAlive)
|
||||
|
||||
# read countAlarm
|
||||
# precondition: alarmRics and functionChar set
|
||||
if (len(alarmRICs) > 0) and (len(functionCharAlarm) > 0):
|
||||
sql = "SELECT COUNT(*) FROM "+globals.config.get("MySQL","tablePOC")+" WHERE ric IN ("+globals.config.get("AlarmMonitor","alarmRICs")+")"
|
||||
sql = "SELECT COUNT(*) FROM "+globalData.config.get("MySQL","tablePOC")+" WHERE ric IN ("+globalData.config.get("AlarmMonitor","alarmRICs")+")"
|
||||
if len(functionCharAlarm) == 1:
|
||||
sql += " AND functionChar IN ('" + functionCharAlarm[0] + "')"
|
||||
elif len(functionCharAlarm) > 1:
|
||||
|
|
@ -178,13 +178,13 @@ try:
|
|||
cursor.execute(sql)
|
||||
result = int(cursor.fetchone()[0])
|
||||
if result > 0:
|
||||
globals.countAlarm = result
|
||||
logging.debug("-- countAlarm: %s", globals.countAlarm)
|
||||
globalData.countAlarm = result
|
||||
logging.debug("-- countAlarm: %s", globalData.countAlarm)
|
||||
|
||||
# read countTestAlarm
|
||||
# precondition: alarmRics and functionCharTestAlarm set
|
||||
if (len(alarmRICs) > 0) and (len(functionCharTestAlarm) > 0):
|
||||
sql = "SELECT COUNT(*) FROM "+globals.config.get("MySQL","tablePOC")+" WHERE ric IN ("+globals.config.get("AlarmMonitor","alarmRICs")+")"
|
||||
sql = "SELECT COUNT(*) FROM "+globalData.config.get("MySQL","tablePOC")+" WHERE ric IN ("+globalData.config.get("AlarmMonitor","alarmRICs")+")"
|
||||
if len(functionCharTestAlarm) == 1:
|
||||
sql += " AND functionChar IN ('" + functionCharTestAlarm[0] + "')"
|
||||
elif len(functionCharTestAlarm) > 1:
|
||||
|
|
@ -192,14 +192,14 @@ try:
|
|||
cursor.execute(sql)
|
||||
result = int(cursor.fetchone()[0])
|
||||
if result > 0:
|
||||
globals.countTestAlarm = result
|
||||
logging.debug("-- countTestAlarm: %s", globals.countTestAlarm)
|
||||
globalData.countTestAlarm = result
|
||||
logging.debug("-- countTestAlarm: %s", globalData.countTestAlarm)
|
||||
|
||||
# read the last 5 events in reverse order
|
||||
# precondition: alarmRics and (functionChar or functionCharTestAlarm) set
|
||||
if (len(alarmRICs) > 0) and ((len(functionCharAlarm) > 0) or (len(functionCharTestAlarm) > 0)):
|
||||
sql = "SELECT UNIX_TIMESTAMP(time), ric, functionChar, msg, description FROM "+globals.config.get("MySQL","tablePOC")
|
||||
sql += " WHERE ric IN ("+globals.config.get("AlarmMonitor","alarmRICs")+")"
|
||||
sql = "SELECT UNIX_TIMESTAMP(time), ric, functionChar, msg, description FROM "+globalData.config.get("MySQL","tablePOC")
|
||||
sql += " WHERE ric IN ("+globalData.config.get("AlarmMonitor","alarmRICs")+")"
|
||||
functionChar = functionCharAlarm + functionCharTestAlarm
|
||||
if len(functionChar) == 1:
|
||||
sql += " AND functionChar IN ('" + functionChar[0] + "')"
|
||||
|
|
@ -215,8 +215,8 @@ try:
|
|||
data['functionChar'] = functionChar
|
||||
data['msg'] = msg
|
||||
data['description'] = description
|
||||
globals.alarmHistory.append(data)
|
||||
logging.debug("-- history data loaded: %s", len(globals.alarmHistory))
|
||||
globalData.alarmHistory.append(data)
|
||||
logging.debug("-- history data loaded: %s", len(globalData.alarmHistory))
|
||||
|
||||
logging.info("history loaded from database")
|
||||
# if db is enabled
|
||||
|
|
@ -239,10 +239,10 @@ try:
|
|||
#
|
||||
alarmSound = False
|
||||
try:
|
||||
if globals.config.getboolean("AlarmMonitor","playSound") == True:
|
||||
if not globals.config.get("AlarmMonitor","soundFile") == "":
|
||||
if globalData.config.getboolean("AlarmMonitor","playSound") == True:
|
||||
if not globalData.config.get("AlarmMonitor","soundFile") == "":
|
||||
pygame.mixer.init()
|
||||
alarmSound = pygame.mixer.Sound(globals.config.get("AlarmMonitor","soundFile"))
|
||||
alarmSound = pygame.mixer.Sound(globalData.config.get("AlarmMonitor","soundFile"))
|
||||
logging.info("alarm with sound")
|
||||
except:
|
||||
# error, but we could work without sound
|
||||
|
|
@ -250,14 +250,14 @@ try:
|
|||
logging.debug("cannot initialise alarm sound", exc_info=True)
|
||||
pass
|
||||
|
||||
globals.startTime = int(time.time())
|
||||
globalData.startTime = int(time.time())
|
||||
logging.info("alarmMonitor started - on standby")
|
||||
|
||||
#
|
||||
# Main Program
|
||||
# (Threads will set abort to True if an error occurs)
|
||||
#
|
||||
while globals.abort == False:
|
||||
while globalData.abort == False:
|
||||
# accept connections from outside
|
||||
(clientsocket, address) = sock.accept()
|
||||
logging.debug("connected client: %s", address)
|
||||
|
|
@ -284,35 +284,35 @@ try:
|
|||
# keep alive calculation with additional RICs
|
||||
if int(parsed_json['ric']) in keepAliveRICs:
|
||||
logging.info("POCSAG is alive")
|
||||
globals.lastAlarm = curtime
|
||||
globals.countKeepAlive += 1
|
||||
globalData.lastAlarm = curtime
|
||||
globalData.countKeepAlive += 1
|
||||
|
||||
# (test) alarm processing
|
||||
elif int(parsed_json['ric']) in alarmRICs:
|
||||
if parsed_json['functionChar'] in functionCharTestAlarm:
|
||||
logging.info("--> Probealarm: %s", parsed_json['ric'])
|
||||
globals.screenBackground = pygame.Color(globals.config.get("AlarmMonitor","colourYellow"))
|
||||
globals.countTestAlarm += 1
|
||||
globalData.screenBackground = pygame.Color(globalData.config.get("AlarmMonitor","colourYellow"))
|
||||
globalData.countTestAlarm += 1
|
||||
elif parsed_json['functionChar'] in functionCharAlarm:
|
||||
logging.info("--> Alarm: %s", parsed_json['ric'])
|
||||
globals.screenBackground = pygame.Color(globals.config.get("AlarmMonitor","colourRed"))
|
||||
globals.countAlarm += 1
|
||||
globalData.screenBackground = pygame.Color(globalData.config.get("AlarmMonitor","colourRed"))
|
||||
globalData.countAlarm += 1
|
||||
|
||||
# forward data to alarmMonitor
|
||||
globals.data = parsed_json
|
||||
globals.data['timestamp'] = curtime
|
||||
globalData.data = parsed_json
|
||||
globalData.data['timestamp'] = curtime
|
||||
logging.debug("-- data: %s", parsed_json)
|
||||
# save 5 alarm history entries
|
||||
globals.alarmHistory.append(globals.data)
|
||||
if len(globals.alarmHistory) > 5:
|
||||
globals.alarmHistory.pop(0)
|
||||
globalData.alarmHistory.append(globalData.data)
|
||||
if len(globalData.alarmHistory) > 5:
|
||||
globalData.alarmHistory.pop(0)
|
||||
# update lastAlarm for keep alive calculation
|
||||
globals.lastAlarm = curtime
|
||||
globalData.lastAlarm = curtime
|
||||
# enable display for n seconds:
|
||||
globals.enableDisplayUntil = curtime + globals.config.getint("AlarmMonitor","showAlarmTime")
|
||||
globalData.enableDisplayUntil = curtime + globalData.config.getint("AlarmMonitor","showAlarmTime")
|
||||
# tell alarm-thread to turn on the display
|
||||
globals.navigation = "alarmPage"
|
||||
globals.showDisplay = True;
|
||||
globalData.navigation = "alarmPage"
|
||||
globalData.showDisplay = True;
|
||||
|
||||
# play alarmSound...
|
||||
if not alarmSound == False:
|
||||
|
|
@ -337,7 +337,7 @@ except:
|
|||
finally:
|
||||
try:
|
||||
logging.info("socketServer shuting down")
|
||||
globals.running = False
|
||||
globalData.running = False
|
||||
sock.close()
|
||||
logging.debug("socket closed")
|
||||
if not alarmSound == False:
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@ def autoTurnOffDisplay():
|
|||
"""
|
||||
Asynchronous function to turn of the display backlight
|
||||
|
||||
@requires: globals.showDisplay - status of backlight
|
||||
@requires: globals.enableDisplayUntil - given timestamp to turn off backlight
|
||||
@requires: globals.running - service runs as long as this is True
|
||||
@requires: globalData.showDisplay - status of backlight
|
||||
@requires: globalData.enableDisplayUntil - given timestamp to turn off backlight
|
||||
@requires: globalData.running - service runs as long as this is True
|
||||
|
||||
In case of an exception the function set globals.abort to True.
|
||||
In case of an exception the function set globalData.abort to True.
|
||||
This will terminate the main program.
|
||||
|
||||
@return: nothing
|
||||
|
|
@ -37,11 +37,11 @@ def autoTurnOffDisplay():
|
|||
|
||||
try:
|
||||
# Running will be set to False if main program is shutting down
|
||||
while globals.running == True:
|
||||
while globalData.running == True:
|
||||
# check if timestamp is in the past
|
||||
if (globals.showDisplay == True) and (globals.enableDisplayUntil < int(time.time())):
|
||||
globals.showDisplay = False
|
||||
globals.navigation = "alarmPage"
|
||||
if (globalData.showDisplay == True) and (globalData.enableDisplayUntil < int(time.time())):
|
||||
globalData.showDisplay = False
|
||||
globalData.navigation = "alarmPage"
|
||||
logging.info("display turned off")
|
||||
# we will do this only one time per second
|
||||
time.sleep(1)
|
||||
|
|
@ -49,7 +49,7 @@ def autoTurnOffDisplay():
|
|||
logging.error("unknown error in autoTurnOffDisplay-thread")
|
||||
logging.debug("unknown error in autoTurnOffDisplay-thread", exc_info=True)
|
||||
# abort main program
|
||||
globals.abort = True
|
||||
globalData.abort = True
|
||||
sys.exit(1)
|
||||
finally:
|
||||
logging.debug("exit autoTurnOffDisplay-thread")
|
||||
|
|
@ -65,12 +65,12 @@ def eventHandler():
|
|||
Asynchronous function to handle pygames events
|
||||
in particular the touchscreen events
|
||||
|
||||
@requires: globals.showDisplay - status of backlight
|
||||
@requires: globals.enableDisplayUntil - timestamp to turn off backlight
|
||||
@requires: globals.running - service runs as long as this is True
|
||||
@requires: globalData.showDisplay - status of backlight
|
||||
@requires: globalData.enableDisplayUntil - timestamp to turn off backlight
|
||||
@requires: globalData.running - service runs as long as this is True
|
||||
@requires: configuration has to be set in the config.ini
|
||||
|
||||
In case of an exception the function set globals.abort to True.
|
||||
In case of an exception the function set globalData.abort to True.
|
||||
This will terminate the main program.
|
||||
|
||||
@return: nothing
|
||||
|
|
@ -89,7 +89,7 @@ def eventHandler():
|
|||
clock = pygame.time.Clock()
|
||||
|
||||
# Running will be set to False if main program is shutting down
|
||||
while globals.running == True:
|
||||
while globalData.running == True:
|
||||
# This limits the while loop to a max of 2 times per second.
|
||||
# Leave this out and we will use all CPU we can.
|
||||
clock.tick(2)
|
||||
|
|
@ -100,7 +100,7 @@ def eventHandler():
|
|||
for event in pygame.event.get():
|
||||
# event-handler for QUIT
|
||||
if event.type == pygame.QUIT:
|
||||
globals.running = False
|
||||
globalData.running = False
|
||||
|
||||
# if touchscreen pressed
|
||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||
|
|
@ -111,29 +111,29 @@ def eventHandler():
|
|||
pygame.mixer.stop()
|
||||
|
||||
# touching the dark display will turn it on for n sec
|
||||
if globals.showDisplay == False:
|
||||
if globalData.showDisplay == False:
|
||||
logging.info("turn ON display")
|
||||
globals.enableDisplayUntil = curtime + globals.config.getint("AlarmMonitor","showDisplayTime")
|
||||
globals.navigation == "alarmPage"
|
||||
globals.showDisplay = True
|
||||
globalData.enableDisplayUntil = curtime + globalData.config.getint("AlarmMonitor","showDisplayTime")
|
||||
globalData.navigation == "alarmPage"
|
||||
globalData.showDisplay = True
|
||||
else:
|
||||
# touching the enabled display will be content sensitive...
|
||||
# if top 2/3: turn of display
|
||||
yBoundary = globals.config.getint("Display","displayHeight") - 80
|
||||
yBoundary = globalData.config.getint("Display","displayHeight") - 80
|
||||
if 0 <= posY <= yBoundary:
|
||||
logging.info("turn OFF display")
|
||||
globals.showDisplay = False
|
||||
globals.navigation = "alarmPage"
|
||||
globalData.showDisplay = False
|
||||
globalData.navigation = "alarmPage"
|
||||
else:
|
||||
# we are in the navigation area
|
||||
globals.enableDisplayUntil = curtime + globals.config.getint("AlarmMonitor","showDisplayTime")
|
||||
globalData.enableDisplayUntil = curtime + globalData.config.getint("AlarmMonitor","showDisplayTime")
|
||||
if 0 <= posX <= 110:
|
||||
globals.navigation = "historyPage"
|
||||
globalData.navigation = "historyPage"
|
||||
elif 111 <= posX <= 210:
|
||||
globals.navigation = "statusPage"
|
||||
globalData.navigation = "statusPage"
|
||||
else:
|
||||
globals.screenBackground = pygame.Color(globals.config.get("AlarmMonitor","colourGreen"))
|
||||
globals.navigation = "alarmPage"
|
||||
globalData.screenBackground = pygame.Color(globalData.config.get("AlarmMonitor","colourGreen"))
|
||||
globalData.navigation = "alarmPage"
|
||||
## end if showDisplay
|
||||
## end if event MOUSEBUTTONDOWN
|
||||
## end for event
|
||||
|
|
@ -141,7 +141,7 @@ def eventHandler():
|
|||
logging.error("unknown error in eventHandler-thread")
|
||||
logging.debug("unknown error in eventHandler-thread", exc_info=True)
|
||||
# abort main program
|
||||
globals.abort = True
|
||||
globalData.abort = True
|
||||
sys.exit(1)
|
||||
finally:
|
||||
logging.debug("exit eventHandler-thread")
|
||||
|
|
@ -156,14 +156,14 @@ def displayPainter():
|
|||
"""
|
||||
Asynchronous function to build the display content
|
||||
|
||||
@requires: globals.showDisplay - status of backlight
|
||||
@requires: globals.enableDisplayUntil - given timestamp when backlight will turned off
|
||||
@requires: globals.running - service runs as long as this is True
|
||||
@requires: globals.data - data of the last alarm
|
||||
@requires: globals.lastAlarm - timestamp of the last processing (see alarmRICs and keepAliveRICs)
|
||||
@requires: globalData.showDisplay - status of backlight
|
||||
@requires: globalData.enableDisplayUntil - given timestamp when backlight will turned off
|
||||
@requires: globalData.running - service runs as long as this is True
|
||||
@requires: globalData.data - data of the last alarm
|
||||
@requires: globalData.lastAlarm - timestamp of the last processing (see alarmRICs and keepAliveRICs)
|
||||
@requires: configuration has to be set in the config.ini
|
||||
|
||||
In case of an exception the function set globals.abort to True.
|
||||
In case of an exception the function set globalData.abort to True.
|
||||
This will terminate the main program.
|
||||
|
||||
@return: nothing
|
||||
|
|
@ -187,12 +187,12 @@ def displayPainter():
|
|||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
# set up GPIO pin for output
|
||||
GPIO.setup(globals.config.getint("Display","GPIOPinForBacklight"), GPIO.OUT)
|
||||
GPIO.setup(globalData.config.getint("Display","GPIOPinForBacklight"), GPIO.OUT)
|
||||
|
||||
pygame.init()
|
||||
|
||||
#screen size
|
||||
size = (globals.config.getint("Display","displayWidth"), globals.config.getint("Display","displayHeight"))
|
||||
size = (globalData.config.getint("Display","displayWidth"), globalData.config.getint("Display","displayHeight"))
|
||||
screen = pygame.display.set_mode(size)
|
||||
|
||||
# disable mouse cursor
|
||||
|
|
@ -219,12 +219,12 @@ def displayPainter():
|
|||
clock = pygame.time.Clock()
|
||||
|
||||
# Build Lists out of config-entries
|
||||
functionCharTestAlarm = [x.strip() for x in globals.config.get("AlarmMonitor","functionCharTestAlarm").replace(";", ",").split(",")]
|
||||
functionCharTestAlarm = [x.strip() for x in globalData.config.get("AlarmMonitor","functionCharTestAlarm").replace(";", ",").split(",")]
|
||||
|
||||
logging.debug("displayPainter-thread started")
|
||||
|
||||
# Running will be set to False if main program is shutting down
|
||||
while globals.running == True:
|
||||
while globalData.running == True:
|
||||
# This limits the while loop to a max of 2 times per second.
|
||||
# Leave this out and we will use all CPU we can.
|
||||
clock.tick(2)
|
||||
|
|
@ -232,48 +232,48 @@ def displayPainter():
|
|||
# current time for this loop:
|
||||
curtime = int(time.time())
|
||||
|
||||
if globals.showDisplay == True:
|
||||
if globalData.showDisplay == True:
|
||||
# Enable LCD display
|
||||
GPIO.output(globals.config.getint("Display","GPIOPinForBacklight"), GPIO.HIGH)
|
||||
GPIO.output(globalData.config.getint("Display","GPIOPinForBacklight"), GPIO.HIGH)
|
||||
# Clear the screen and set the screen background
|
||||
screen.fill(globals.screenBackground)
|
||||
screen.fill(globalData.screenBackground)
|
||||
# paint black rect, so Background looks like a boarder
|
||||
widthX = globals.config.getint("Display","displayWidth") - 20
|
||||
widthY = globals.config.getint("Display","displayHeight") - 20
|
||||
pygame.draw.rect(screen, pygame.Color(globals.config.get("AlarmMonitor","colourBlack")), (10, 10, widthX, widthY))
|
||||
widthX = globalData.config.getint("Display","displayWidth") - 20
|
||||
widthY = globalData.config.getint("Display","displayHeight") - 20
|
||||
pygame.draw.rect(screen, pygame.Color(globalData.config.get("AlarmMonitor","colourBlack")), (10, 10, widthX, widthY))
|
||||
# header
|
||||
header = fontHeader.render("Alarm-Monitor", 1, pygame.Color(globals.config.get("AlarmMonitor","colourRed")))
|
||||
header = fontHeader.render("Alarm-Monitor", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourRed")))
|
||||
(width, height) = fontHeader.size("Alarm-Monitor")
|
||||
x = (int(globals.config.getint("Display","displayWidth")) - width)/2
|
||||
x = (int(globalData.config.getint("Display","displayWidth")) - width)/2
|
||||
screen.blit(header, (x, 20))
|
||||
|
||||
# show time of last alarm
|
||||
if globals.lastAlarm > 0:
|
||||
if globalData.lastAlarm > 0:
|
||||
try:
|
||||
# format last alarm
|
||||
lastAlarmString = time.strftime("%H:%M:%S", time.localtime(globals.lastAlarm))
|
||||
lastAlarmString = time.strftime("%H:%M:%S", time.localtime(globalData.lastAlarm))
|
||||
# Color time:
|
||||
# red: lastAlarm more than n (delayForRed) seconds past
|
||||
if (int(globals.lastAlarm) + globals.config.getint("AlarmMonitor","delayForRed")) < curtime:
|
||||
timeColour = pygame.Color(globals.config.get("AlarmMonitor","colourRed"))
|
||||
if (int(globalData.lastAlarm) + globalData.config.getint("AlarmMonitor","delayForRed")) < curtime:
|
||||
timeColour = pygame.Color(globalData.config.get("AlarmMonitor","colourRed"))
|
||||
# yellow: lastAlarm more than n (delayForYellow) seconds past
|
||||
elif (int(globals.lastAlarm) + globals.config.getint("AlarmMonitor","delayForYellow")) < curtime:
|
||||
timeColour = pygame.Color(globals.config.get("AlarmMonitor","colourYellow"))
|
||||
elif (int(globalData.lastAlarm) + globalData.config.getint("AlarmMonitor","delayForYellow")) < curtime:
|
||||
timeColour = pygame.Color(globalData.config.get("AlarmMonitor","colourYellow"))
|
||||
# dgrey: normal
|
||||
else:
|
||||
timeColour = pygame.Color(globals.config.get("AlarmMonitor","colourGreen"))
|
||||
timeColour = pygame.Color(globalData.config.get("AlarmMonitor","colourGreen"))
|
||||
lastAlarm = fontTime.render(lastAlarmString, 1, timeColour)
|
||||
(width, height) = fontTime.size(lastAlarmString)
|
||||
x = globals.config.getint("Display","displayWidth") - 20 - width
|
||||
x = globalData.config.getint("Display","displayWidth") - 20 - width
|
||||
screen.blit(lastAlarm, (x, 20))
|
||||
except:
|
||||
logging.debug("unknown error in lastAlarm", exc_info=True)
|
||||
pass
|
||||
## end if globals.lastAlarm > 0
|
||||
## end if globalData.lastAlarm > 0
|
||||
|
||||
# show remaining time before display will be turned off:
|
||||
restZeit = globals.enableDisplayUntil - curtime +1
|
||||
zeit = fontTime.render(str(restZeit), 1, pygame.Color(globals.config.get("AlarmMonitor","colourDimGrey")))
|
||||
restZeit = globalData.enableDisplayUntil - curtime +1
|
||||
zeit = fontTime.render(str(restZeit), 1, pygame.Color(globalData.config.get("AlarmMonitor","colourDimGrey")))
|
||||
screen.blit(zeit, (20, 20))
|
||||
|
||||
#
|
||||
|
|
@ -281,10 +281,10 @@ def displayPainter():
|
|||
# default is "alarmPage"
|
||||
#
|
||||
# Startpoint for content
|
||||
if globals.navigation == "historyPage":
|
||||
if globalData.navigation == "historyPage":
|
||||
try:
|
||||
y = 50
|
||||
for data in reversed(globals.alarmHistory):
|
||||
for data in reversed(globalData.alarmHistory):
|
||||
# Layout:
|
||||
# Date Description
|
||||
# Time Msg
|
||||
|
|
@ -300,9 +300,9 @@ def displayPainter():
|
|||
|
||||
# get colour
|
||||
if data['functionChar'] in functionCharTestAlarm:
|
||||
colour = globals.config.get("AlarmMonitor","colourYellow")
|
||||
colour = globalData.config.get("AlarmMonitor","colourYellow")
|
||||
else:
|
||||
colour = globals.config.get("AlarmMonitor","colourRed")
|
||||
colour = globalData.config.get("AlarmMonitor","colourRed")
|
||||
|
||||
# Paint Date/Time
|
||||
screen.blit(fontHistory.render(dateString, 1, pygame.Color(colour)), (20, y))
|
||||
|
|
@ -310,9 +310,9 @@ def displayPainter():
|
|||
|
||||
# Paint Description
|
||||
try:
|
||||
textLines = wrapline(data['description'], fontHistory, (globals.config.getint("Display","displayWidth") - shifting - 40))
|
||||
textLines = wrapline(data['description'], fontHistory, (globalData.config.getint("Display","displayWidth") - shifting - 40))
|
||||
for index, item in enumerate(textLines):
|
||||
textZeile = fontHistory.render(item, 1, pygame.Color(globals.config.get("AlarmMonitor","colourWhite")))
|
||||
textZeile = fontHistory.render(item, 1, pygame.Color(globalData.config.get("AlarmMonitor","colourWhite")))
|
||||
screen.blit(textZeile, (20 + shifting, y))
|
||||
y += height
|
||||
except KeyError:
|
||||
|
|
@ -320,9 +320,9 @@ def displayPainter():
|
|||
|
||||
# Paint Msg
|
||||
try:
|
||||
textLines = wrapline(data['msg'].replace("*", " * "), fontHistory, (globals.config.getint("Display","displayWidth") - shifting - 40))
|
||||
textLines = wrapline(data['msg'].replace("*", " * "), fontHistory, (globalData.config.getint("Display","displayWidth") - shifting - 40))
|
||||
for index, item in enumerate(textLines):
|
||||
textZeile = fontHistory.render(item, 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
||||
textZeile = fontHistory.render(item, 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||
screen.blit(textZeile, (20 + shifting, y))
|
||||
y += height
|
||||
except KeyError:
|
||||
|
|
@ -331,65 +331,65 @@ def displayPainter():
|
|||
# line spacing for next dataset
|
||||
y += 2
|
||||
|
||||
## end for globals.alarmHistory
|
||||
## end for globalData.alarmHistory
|
||||
|
||||
except KeyError:
|
||||
pass
|
||||
## end if globals.navigation == "historyPage"
|
||||
## end if globalData.navigation == "historyPage"
|
||||
|
||||
elif globals.navigation == "statusPage":
|
||||
elif globalData.navigation == "statusPage":
|
||||
(width, height) = fontStatusContent.size("Anzahl Test-Alarme:")
|
||||
y = 70
|
||||
x = width + 10
|
||||
# Running since:
|
||||
title = fontStatusContent.render("Gestartet:", 1, pygame.Color(globals.config.get("AlarmMonitor","colourWhite")))
|
||||
content = fontStatusContent.render(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(globals.startTime)), 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
||||
title = fontStatusContent.render("Gestartet:", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourWhite")))
|
||||
content = fontStatusContent.render(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(globalData.startTime)), 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||
screen.blit(title, (20, y))
|
||||
screen.blit(content, (20 +x, y))
|
||||
y += height + 10
|
||||
|
||||
# Last Alarm
|
||||
title = fontStatusContent.render("Letzte Nachricht:", 1, pygame.Color(globals.config.get("AlarmMonitor","colourWhite")))
|
||||
if globals.lastAlarm > 0:
|
||||
content = fontStatusContent.render(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(globals.lastAlarm)), 1, timeColour)
|
||||
title = fontStatusContent.render("Letzte Nachricht:", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourWhite")))
|
||||
if globalData.lastAlarm > 0:
|
||||
content = fontStatusContent.render(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(globalData.lastAlarm)), 1, timeColour)
|
||||
else:
|
||||
content = fontStatusContent.render("-", 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
||||
content = fontStatusContent.render("-", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||
screen.blit(title, (20, y))
|
||||
screen.blit(content, (20 +x, y))
|
||||
y += height + 10
|
||||
|
||||
# Number of Alarms
|
||||
title = fontStatusContent.render("Anzahl Alarme:", 1, pygame.Color(globals.config.get("AlarmMonitor","colourWhite")))
|
||||
content = fontStatusContent.render(str(globals.countAlarm), 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
||||
title = fontStatusContent.render("Anzahl Alarme:", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourWhite")))
|
||||
content = fontStatusContent.render(str(globalData.countAlarm), 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||
screen.blit(title, (20, y))
|
||||
screen.blit(content, (20 +x, y))
|
||||
y += height + 10
|
||||
|
||||
# Number of TestAlarms
|
||||
title = fontStatusContent.render("Anzahl Test-Alarme:", 1, pygame.Color(globals.config.get("AlarmMonitor","colourWhite")))
|
||||
content = fontStatusContent.render(str(globals.countTestAlarm), 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
||||
title = fontStatusContent.render("Anzahl Test-Alarme:", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourWhite")))
|
||||
content = fontStatusContent.render(str(globalData.countTestAlarm), 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||
screen.blit(title, (20, y))
|
||||
screen.blit(content, (20 +x, y))
|
||||
y += height + 10
|
||||
|
||||
# Number of DAU-Msgs
|
||||
title = fontStatusContent.render("Anzahl DAU-Tests:", 1, pygame.Color(globals.config.get("AlarmMonitor","colourWhite")))
|
||||
content = fontStatusContent.render(str(globals.countKeepAlive), 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
||||
title = fontStatusContent.render("Anzahl DAU-Tests:", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourWhite")))
|
||||
content = fontStatusContent.render(str(globalData.countKeepAlive), 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||
screen.blit(title, (20, y))
|
||||
screen.blit(content, (20 +x, y))
|
||||
y += height + 10
|
||||
|
||||
## end if globals.navigation == "statusPage"
|
||||
## end if globalData.navigation == "statusPage"
|
||||
|
||||
else:
|
||||
y = 50
|
||||
|
||||
# Paint Date/Time
|
||||
try:
|
||||
dateTimeString = time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(globals.data['timestamp']))
|
||||
dateTimeRow = fontStatus.render(dateTimeString, 1, pygame.Color(globals.config.get("AlarmMonitor","colourDimGrey")))
|
||||
dateTimeString = time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(globalData.data['timestamp']))
|
||||
dateTimeRow = fontStatus.render(dateTimeString, 1, pygame.Color(globalData.config.get("AlarmMonitor","colourDimGrey")))
|
||||
(width, height) = fontStatus.size(dateTimeString)
|
||||
x = (int(globals.config.getint("Display","displayWidth")) - width)/2
|
||||
x = (int(globalData.config.getint("Display","displayWidth")) - width)/2
|
||||
screen.blit(dateTimeRow, (x, y))
|
||||
y += height + 10
|
||||
except KeyError:
|
||||
|
|
@ -397,10 +397,10 @@ def displayPainter():
|
|||
|
||||
# Paint Description
|
||||
try:
|
||||
textLines = wrapline(globals.data['description'], fontRIC, (globals.config.getint("Display","displayWidth") - 40))
|
||||
(width, height) = fontStatus.size(globals.data['description'])
|
||||
textLines = wrapline(globalData.data['description'], fontRIC, (globalData.config.getint("Display","displayWidth") - 40))
|
||||
(width, height) = fontStatus.size(globalData.data['description'])
|
||||
for index, item in enumerate(textLines):
|
||||
textRow = fontRIC.render(item, 1, pygame.Color(globals.config.get("AlarmMonitor","colourWhite")))
|
||||
textRow = fontRIC.render(item, 1, pygame.Color(globalData.config.get("AlarmMonitor","colourWhite")))
|
||||
screen.blit(textRow, (20, y))
|
||||
y += height + 5
|
||||
except KeyError:
|
||||
|
|
@ -409,10 +409,10 @@ def displayPainter():
|
|||
# Paint Msg
|
||||
try:
|
||||
y += 10
|
||||
textLines = wrapline(globals.data['msg'].replace("*", " * "), fontMsg, (globals.config.getint("Display","displayWidth") - 40))
|
||||
(width, height) = fontStatus.size(globals.data['msg'])
|
||||
textLines = wrapline(globalData.data['msg'].replace("*", " * "), fontMsg, (globalData.config.getint("Display","displayWidth") - 40))
|
||||
(width, height) = fontStatus.size(globalData.data['msg'])
|
||||
for index, item in enumerate(textLines):
|
||||
textRow = fontMsg.render(item, 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
||||
textRow = fontMsg.render(item, 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||
screen.blit(textRow, (20, y))
|
||||
y += height
|
||||
except KeyError:
|
||||
|
|
@ -422,47 +422,47 @@ def displayPainter():
|
|||
# paint navigation buttons
|
||||
buttonWidth = 80
|
||||
buttonHeight = 25
|
||||
buttonY = globals.config.getint("Display","displayHeight") - buttonHeight - 2
|
||||
buttonY = globalData.config.getint("Display","displayHeight") - buttonHeight - 2
|
||||
|
||||
round_rect(screen, ( 20, buttonY, buttonWidth, buttonHeight), pygame.Color(globals.config.get("AlarmMonitor","colourDimGrey")), 10, 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
||||
buttonText = fontButton.render("Verlauf", 1, pygame.Color(globals.config.get("AlarmMonitor","colourBlack")))
|
||||
round_rect(screen, ( 20, buttonY, buttonWidth, buttonHeight), pygame.Color(globalData.config.get("AlarmMonitor","colourDimGrey")), 10, 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||
buttonText = fontButton.render("Verlauf", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourBlack")))
|
||||
(width, height) = fontButton.size("Verlauf")
|
||||
textX = 20 + (buttonWidth - width)/2
|
||||
textY = buttonY + (buttonHeight - height)/2
|
||||
screen.blit(buttonText, (textX, textY))
|
||||
|
||||
round_rect(screen, (120, buttonY, buttonWidth, buttonHeight), pygame.Color(globals.config.get("AlarmMonitor","colourDimGrey")), 10, 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
||||
buttonText = fontButton.render("Status", 1, pygame.Color(globals.config.get("AlarmMonitor","colourBlack")))
|
||||
round_rect(screen, (120, buttonY, buttonWidth, buttonHeight), pygame.Color(globalData.config.get("AlarmMonitor","colourDimGrey")), 10, 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||
buttonText = fontButton.render("Status", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourBlack")))
|
||||
(width, height) = fontButton.size("Status")
|
||||
textX = 120 + (buttonWidth - width)/2
|
||||
textY = buttonY + (buttonHeight - height)/2
|
||||
screen.blit(buttonText, (textX, textY))
|
||||
|
||||
round_rect(screen, (220, buttonY, buttonWidth, buttonHeight), pygame.Color(globals.config.get("AlarmMonitor","colourDimGrey")), 10, 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
||||
buttonText = fontButton.render("Gelesen", 1, pygame.Color(globals.config.get("AlarmMonitor","colourBlack")))
|
||||
round_rect(screen, (220, buttonY, buttonWidth, buttonHeight), pygame.Color(globalData.config.get("AlarmMonitor","colourDimGrey")), 10, 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||
buttonText = fontButton.render("Gelesen", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourBlack")))
|
||||
(width, height) = fontButton.size("Gelesen")
|
||||
textX = 220 + (buttonWidth - width)/2
|
||||
textY = buttonY + (buttonHeight - height)/2
|
||||
screen.blit(buttonText, (textX, textY))
|
||||
|
||||
## end if globals.showDisplay == True
|
||||
## end if globalData.showDisplay == True
|
||||
|
||||
else:
|
||||
GPIO.output(globals.config.getint("Display","GPIOPinForBacklight"), GPIO.LOW)
|
||||
GPIO.output(globalData.config.getint("Display","GPIOPinForBacklight"), GPIO.LOW)
|
||||
|
||||
# Update display...
|
||||
pygame.display.update()
|
||||
## end while globals.running == True
|
||||
## end while globalData.running == True
|
||||
|
||||
except:
|
||||
logging.error("unknown error in displayPainter-thread")
|
||||
logging.debug("unknown error in displayPainter-thread", exc_info=True)
|
||||
# abort main program
|
||||
globals.abort = True
|
||||
globalData.abort = True
|
||||
sys.exit(1)
|
||||
finally:
|
||||
logging.debug("exit displayPainter-thread")
|
||||
GPIO.output(globals.config.getint("Display","GPIOPinForBacklight"), GPIO.LOW)
|
||||
GPIO.output(globalData.config.getint("Display","GPIOPinForBacklight"), GPIO.LOW)
|
||||
GPIO.cleanup()
|
||||
pygame.quit()
|
||||
exit(0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue