Implemented Settings and optimized logger

This commit is contained in:
janis
2022-05-14 10:45:14 +02:00
parent 7d999988be
commit 43687c7581
3 changed files with 88 additions and 43 deletions

View File

@@ -180,9 +180,8 @@ RootScreen:
###################################### ######################################
# SCREENS # SCREENS
###################################### ######################################
<HomeScreen>: <HomeScreen>:
name: "Home" name: "HomeS"
canvas.before: canvas.before:
Color: Color:
rgba: (50,50,50,0.2) rgba: (50,50,50,0.2)
@@ -215,7 +214,8 @@ RootScreen:
on_release: on_release:
root.exitapp() root.exitapp()
Label: Label:
text: "You are currently running Version 2.3.0 - If you encounter a bug, please report it!" text: root.reset()
id: app_version
font_size: 13 font_size: 13
pos_hint: {"y": -0.45, "x":0.05} pos_hint: {"y": -0.45, "x":0.05}
Button: Button:
@@ -294,7 +294,7 @@ RootScreen:
background_color: (255, 0, 0, 0.6) background_color: (255, 0, 0, 0.6)
on_release: on_release:
root.leave_screen() root.leave_screen()
app.root.current = "Home" app.root.current = "HomeS"
root.manager.transition.direction = "left" root.manager.transition.direction = "left"
ToggleButton: ToggleButton:
id: mode_sel id: mode_sel
@@ -652,7 +652,7 @@ RootScreen:
text: "Back" text: "Back"
background_color: (255,0,0,0.6) background_color: (255,0,0,0.6)
on_release: on_release:
app.root.current = "Home" app.root.current = "HomeS"
root.manager.transition.direction = "up" root.manager.transition.direction = "up"
Button: Button:
text: "Report a\nBug" text: "Report a\nBug"

View File

@@ -1,11 +1,21 @@
import os import os
os.environ["KIVY_NO_CONSOLELOG"] = "1" import configparser
import serial
config = configparser.ConfigParser()
config.read('./config/settings.ini')
co = config['Dev Settings']['verbose']
if co == "True":
pass
else:
os.environ["KIVY_NO_CONSOLELOG"] = "1"
import time
import threading import threading
import platform import platform
import webbrowser import webbrowser
from kivy.uix.screenmanager import Screen, ScreenManager from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.core.window import Window
from kivy.uix.popup import Popup from kivy.uix.popup import Popup
from kivy.app import App from kivy.app import App
from kivy.lang import Builder from kivy.lang import Builder
@@ -15,10 +25,10 @@ import bin.lib.communication
import bin.lib.comport_search import bin.lib.comport_search
import bin.lib.csv_parsers import bin.lib.csv_parsers
import logging import logging
import configparser
import datetime import datetime
import time import time
version_app = f"{config['Info']['version']}{config['Info']['subVersion']}"
################################################################ ################################################################
# LOGGER SETUP # LOGGER SETUP
@@ -31,14 +41,35 @@ formatter = logging.Formatter("%(levelname)s - %(asctime)s - %(name)s: %(message
handler.setFormatter(formatter) handler.setFormatter(formatter)
logger.addHandler(handler) logger.addHandler(handler)
logger.setLevel(logging.DEBUG) logger.setLevel(config['Dev Settings']['log_level'])
logger.info("Logger initialized") logger.info(f"Logger initialized, app is running Version: {version_app}")
################################################################# #################################################################
cvr = bin.lib.csv_parsers.CsvRead() cvr = bin.lib.csv_parsers.CsvRead()
cvw = bin.lib.csv_parsers.CsvWrite() cvw = bin.lib.csv_parsers.CsvWrite()
com = bin.lib.lib.Com() com = bin.lib.lib.Com()
#################################################################
# Settings Handler
#########################
class SettingsHandler:
def __init__(self):
self.ports = None
self.window_sizeh = 600
self.window_sizew = 800
def settingshandler(self):
self.ports = config['Port Settings']['specificPort']
self.window_sizeh = config['UI Config']['sizeH']
self.window_sizew = config['UI Config']['sizeW']
Window.size = (int(self.window_sizew), int(self.window_sizeh))
#################################################################
logger.info("Started modules") logger.info("Started modules")
@@ -133,15 +164,19 @@ class SaveConf(Popup):
#################################################################### ####################################################################
# SCREENS # SCREENS
#################################################################### ####################################################################
class HomeScreen(Screen): class HomeScreen(Screen):
connected = 1 def reset(self):
try: logger.info("HomeScreen initialised")
com.connect(19200, "") SettingsHandler().settingshandler()
com.quitcom() self.connected = 1
except Exception as e: self.info = f"You are currently running Version {version_app} - If you encounter a bug, please report it!"
connected = 0 try:
logger.error(e) com.connect(19200, "")
com.quitcom()
except Exception as e:
self.connected = 0
logger.error(e)
return self.info
def tryconnection(self): def tryconnection(self):
try: try:
@@ -151,9 +186,14 @@ class HomeScreen(Screen):
self.manager.current = "Readout" self.manager.current = "Readout"
self.manager.transition.direction = "right" self.manager.transition.direction = "right"
except Exception as ex: except Exception as ex:
self.connected = 0 if config['Dev Settings']['disableConnectionCheck'] == "True":
logger.error(f"COM_error: {ex}") self.connected = 1
self.open_popup() self.manager.current = "Readout"
self.manager.transition.direction = "right"
else:
self.connected = 0
logger.error(f"COM_error: {ex}")
self.open_popup()
def open_popup(self): def open_popup(self):
self.popups = NoConnection() self.popups = NoConnection()
@@ -280,20 +320,28 @@ class ReadoutScreen(Screen):
try: try:
self.communication.join() self.communication.join()
com.quitcom() com.quitcom()
self.com_ok = 1
logger.info("Mode_Switch successful") logger.info("Mode_Switch successful")
except Exception as e: except Exception as e:
if e == AttributeError: if e == serial.SerialException:
logger.info("No running process found, continuing") logger.info("No running process found, continuing")
else: else:
logger.fatal(f"FATAL ERROR OCCURED, APP WILL LEAVE NOW: {e}") logger.fatal(f"FATAL ERROR OCCURED, APP WILL LEAVE NOW: {e}")
if text == "Normal Mode": self.com_ok = 0
bin.lib.communication.SwitchMode().disable_fastmode()
if self.com_ok == 1:
if text == "Normal Mode":
bin.lib.communication.SwitchMode().disable_fastmode()
else:
bin.lib.communication.SwitchMode().enable_fastmode()
logger.info("Switched mode, restarting COM")
self.openpupups()
self.comstart(0)
logger.info("COM restarted successfully")
else: else:
bin.lib.communication.SwitchMode().enable_fastmode() self.check = 1
logger.info("Switched mode, restarting COM") self.ids.mode_sel.state = "normal"
self.openpupups() self.openconnectionfailpu()
self.comstart(0)
logger.info("COM restarted successfully")
@mainthread @mainthread
def change_screen(self, pos, value): def change_screen(self, pos, value):
@@ -335,6 +383,7 @@ class ReadoutScreen(Screen):
self.stopcom(0) self.stopcom(0)
def resscreen(self): def resscreen(self):
logger.info("Screen reset")
self.ids.sonde1.text = "" self.ids.sonde1.text = ""
self.ids.sonde2.text = "" self.ids.sonde2.text = ""
self.ids.sonde3.text = "" self.ids.sonde3.text = ""
@@ -804,13 +853,11 @@ class RootScreen(ScreenManager):
pass pass
kv = Builder.load_file("./bin/gui/gui.kv")
logger.info("Loaded GUI")
class BiogasControllerApp(App): class BiogasControllerApp(App):
def build(self): def build(self):
self.icon = "./BiogasControllerAppLogo.png" self.icon = "./BiogasControllerAppLogo.png"
return kv self.title = "BiogasControllerApp"
return Builder.load_file("./bin/gui/gui.kv")
logger.info("Init finished, starting UI") logger.info("Init finished, starting UI")

View File

@@ -1,18 +1,16 @@
[Port Settings] [Port Settings]
forceSpecificPort: False specificPort = None
specificPort: None
[UI Config] [UI Config]
sizeH: 600 sizeH = 600
sizeW: 800 sizeW = 800
showLoadingScreen: True
[Dev Settings] [Dev Settings]
# Settings generally aimed towards the devs of this software! # Settings generally aimed towards the devs of this software!
verbose: False verbose = True
log_level: DEBUG log_level = DEBUG
disableConnectionCheck: False disableConnectionCheck = True
[Info] [Info]
version: V2.3.0 version = V2.3.0
subVersion: None subVersion = -dev1