mirror of
https://github.com/janishutz/BiogasControllerApp.git
synced 2025-11-25 13:54:24 +00:00
Added logger & settings.ini file
This commit is contained in:
@@ -215,7 +215,7 @@ RootScreen:
|
|||||||
on_release:
|
on_release:
|
||||||
root.exitapp()
|
root.exitapp()
|
||||||
Label:
|
Label:
|
||||||
text: "You are currently running Version 2.2.0 - If you encounter a bug, please report it!"
|
text: "You are currently running Version 2.3.0 - If you encounter a bug, please report it!"
|
||||||
font_size: 13
|
font_size: 13
|
||||||
pos_hint: {"y": -0.45, "x":0.05}
|
pos_hint: {"y": -0.45, "x":0.05}
|
||||||
Button:
|
Button:
|
||||||
@@ -404,7 +404,6 @@ RootScreen:
|
|||||||
Rectangle:
|
Rectangle:
|
||||||
size: self.size
|
size: self.size
|
||||||
pos: self.pos
|
pos: self.pos
|
||||||
GridLayout:
|
|
||||||
FloatLayout:
|
FloatLayout:
|
||||||
Label:
|
Label:
|
||||||
text: "Change Temperature"
|
text: "Change Temperature"
|
||||||
@@ -452,7 +451,7 @@ RootScreen:
|
|||||||
id: prsel
|
id: prsel
|
||||||
size_hint: 0.2, 0.1
|
size_hint: 0.2, 0.1
|
||||||
pos_hint: {"x":0.35, "y": 0.1}
|
pos_hint: {"x":0.35, "y": 0.1}
|
||||||
text: "Easy\nreprogramming" if self.state == "normal" else "Advanced\nreprogramming"
|
text: "Full\nreprogramming" if self.state == "normal" else "Partial\nreprogramming"
|
||||||
on_release: root.change_mode()
|
on_release: root.change_mode()
|
||||||
background_color: (255,0,0,0.6) if self.state == "normal" else (0,0,255,0.6)
|
background_color: (255,0,0,0.6) if self.state == "normal" else (0,0,255,0.6)
|
||||||
Button:
|
Button:
|
||||||
@@ -591,7 +590,7 @@ RootScreen:
|
|||||||
id: prsel
|
id: prsel
|
||||||
size_hint: 0.2, 0.1
|
size_hint: 0.2, 0.1
|
||||||
pos_hint: {"x":0.35, "y": 0.1}
|
pos_hint: {"x":0.35, "y": 0.1}
|
||||||
text: "Easy\nreprogramming" if self.state == "normal" else "Advanced\nreprogramming"
|
text: "Full\nreprogramming" if self.state == "normal" else "Partial\nreprogramming"
|
||||||
on_release: root.change_mode()
|
on_release: root.change_mode()
|
||||||
background_color: (255,0,0,0.6) if self.state == "normal" else (0,0,255,0.6)
|
background_color: (255,0,0,0.6) if self.state == "normal" else (0,0,255,0.6)
|
||||||
Button:
|
Button:
|
||||||
@@ -662,7 +661,7 @@ RootScreen:
|
|||||||
root.issue_reporting()
|
root.issue_reporting()
|
||||||
ToggleButton:
|
ToggleButton:
|
||||||
id: prsel
|
id: prsel
|
||||||
text: "Easy\nreprogramming" if self.state == "normal" else "Advanced\nreprogramming"
|
text: "Full\nreprogramming" if self.state == "normal" else "Partial\nreprogramming"
|
||||||
on_release: root.change_programming()
|
on_release: root.change_programming()
|
||||||
background_color: (255,0,0,0.6) if self.state == "normal" else (0,0,255,0.6)
|
background_color: (255,0,0,0.6) if self.state == "normal" else (0,0,255,0.6)
|
||||||
Button:
|
Button:
|
||||||
|
|||||||
@@ -1,32 +1,47 @@
|
|||||||
print("""
|
import os
|
||||||
|
os.environ["KIVY_NO_CONSOLELOG"] = "1"
|
||||||
|
|
||||||
=====================
|
|
||||||
|
|
||||||
BIOGASCONTROLLERAPP
|
|
||||||
|
|
||||||
----------
|
|
||||||
Version 2.2
|
|
||||||
Copyright 2022 J.Hutz""")
|
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
import platform
|
import platform
|
||||||
import os
|
|
||||||
import webbrowser
|
import webbrowser
|
||||||
os.environ["KIVY_NO_CONSOLELOG"] = "1"
|
|
||||||
from kivy.uix.screenmanager import Screen, ScreenManager
|
from kivy.uix.screenmanager import Screen, ScreenManager
|
||||||
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
|
||||||
from kivy.clock import mainthread
|
from kivy.clock import mainthread, Clock
|
||||||
import bin.lib.lib
|
import bin.lib.lib
|
||||||
import bin.lib.communication
|
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 configparser
|
||||||
|
import datetime
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
################################################################
|
||||||
|
# LOGGER SETUP
|
||||||
|
##################
|
||||||
|
logging.basicConfig(level=logging.DEBUG, filename="./log/main_log.log", filemode="w")
|
||||||
|
logs = f"./log/{datetime.datetime.now()}-log-main.log"
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
handler = logging.FileHandler(logs)
|
||||||
|
formatter = logging.Formatter("%(levelname)s - %(asctime)s - %(name)s: %(message)s -- %(lineno)d")
|
||||||
|
handler.setFormatter(formatter)
|
||||||
|
logger.addHandler(handler)
|
||||||
|
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
|
logger.info("Logger initialized")
|
||||||
|
#################################################################
|
||||||
|
|
||||||
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()
|
||||||
|
|
||||||
|
logger.info("Started modules")
|
||||||
|
|
||||||
|
|
||||||
##################################################################
|
##################################################################
|
||||||
# Popups
|
# Popups
|
||||||
##################################################################
|
##################################################################
|
||||||
@@ -35,6 +50,7 @@ com = bin.lib.lib.Com()
|
|||||||
class QuitPU(Popup):
|
class QuitPU(Popup):
|
||||||
def quitapp(self):
|
def quitapp(self):
|
||||||
com.quitcom()
|
com.quitcom()
|
||||||
|
logger.debug("App stopped")
|
||||||
|
|
||||||
|
|
||||||
class NoConnection(Popup):
|
class NoConnection(Popup):
|
||||||
@@ -123,8 +139,9 @@ class HomeScreen(Screen):
|
|||||||
try:
|
try:
|
||||||
com.connect(19200, "")
|
com.connect(19200, "")
|
||||||
com.quitcom()
|
com.quitcom()
|
||||||
except:
|
except Exception as e:
|
||||||
connected = 0
|
connected = 0
|
||||||
|
logger.error(e)
|
||||||
|
|
||||||
def tryconnection(self):
|
def tryconnection(self):
|
||||||
try:
|
try:
|
||||||
@@ -133,8 +150,9 @@ class HomeScreen(Screen):
|
|||||||
self.connected = 1
|
self.connected = 1
|
||||||
self.manager.current = "Readout"
|
self.manager.current = "Readout"
|
||||||
self.manager.transition.direction = "right"
|
self.manager.transition.direction = "right"
|
||||||
except:
|
except Exception as ex:
|
||||||
self.connected = 0
|
self.connected = 0
|
||||||
|
logger.error(f"COM_error: {ex}")
|
||||||
self.open_popup()
|
self.open_popup()
|
||||||
|
|
||||||
def open_popup(self):
|
def open_popup(self):
|
||||||
@@ -148,17 +166,21 @@ class HomeScreen(Screen):
|
|||||||
|
|
||||||
class ReadoutScreen(Screen):
|
class ReadoutScreen(Screen):
|
||||||
go = 1
|
go = 1
|
||||||
|
|
||||||
def start_com(self):
|
def start_com(self):
|
||||||
self.comstart(1)
|
self.comstart(1)
|
||||||
|
logger.info("Trying to start COM")
|
||||||
|
|
||||||
def comstart(self, pu_on):
|
def comstart(self, pu_on):
|
||||||
try:
|
try:
|
||||||
com.connect(19200, "")
|
com.connect(19200, "")
|
||||||
self.go = 1
|
self.go = 1
|
||||||
except:
|
except Exception as e:
|
||||||
self.go = 0
|
self.go = 0
|
||||||
|
logger.error(f"COM_error: {e}")
|
||||||
|
|
||||||
if self.go == 1:
|
if self.go == 1:
|
||||||
|
logger.debug("COM start success")
|
||||||
self.parent.current = "Readout"
|
self.parent.current = "Readout"
|
||||||
if pu_on == 1:
|
if pu_on == 1:
|
||||||
self.openstartpu()
|
self.openstartpu()
|
||||||
@@ -176,8 +198,8 @@ class ReadoutScreen(Screen):
|
|||||||
self.go = 0
|
self.go = 0
|
||||||
try:
|
try:
|
||||||
self.communication.join()
|
self.communication.join()
|
||||||
except:
|
except Exception as e:
|
||||||
pass
|
logger.warning(f"COM_Close_Error: {e}")
|
||||||
if pu_on == 1:
|
if pu_on == 1:
|
||||||
self.openendpu()
|
self.openendpu()
|
||||||
else:
|
else:
|
||||||
@@ -190,6 +212,7 @@ class ReadoutScreen(Screen):
|
|||||||
self.__x = ""
|
self.__x = ""
|
||||||
self.__begin = time.time()
|
self.__begin = time.time()
|
||||||
self.go = 1
|
self.go = 1
|
||||||
|
logger.info("Starting COM_Hook")
|
||||||
while self.__x != "\n":
|
while self.__x != "\n":
|
||||||
if time.time() - self.__begin > 5:
|
if time.time() - self.__begin > 5:
|
||||||
self.go = 0
|
self.go = 0
|
||||||
@@ -198,6 +221,7 @@ class ReadoutScreen(Screen):
|
|||||||
self.__x = com.decode_ascii(com.receive(1))
|
self.__x = com.decode_ascii(com.receive(1))
|
||||||
|
|
||||||
if self.go == 1:
|
if self.go == 1:
|
||||||
|
logger.info("COM_Hook 1 success")
|
||||||
while self.__level < 3:
|
while self.__level < 3:
|
||||||
self.__x = com.decode_ascii(com.receive(1))
|
self.__x = com.decode_ascii(com.receive(1))
|
||||||
if self.__x == " ":
|
if self.__x == " ":
|
||||||
@@ -213,9 +237,9 @@ class ReadoutScreen(Screen):
|
|||||||
else:
|
else:
|
||||||
self.__distance += 1
|
self.__distance += 1
|
||||||
self.check = 1
|
self.check = 1
|
||||||
|
logger.info("COM_Hook successful")
|
||||||
com.receive(5)
|
com.receive(5)
|
||||||
else:
|
else:
|
||||||
self.go = 0
|
|
||||||
self.check = 0
|
self.check = 0
|
||||||
|
|
||||||
while self.go == 1:
|
while self.go == 1:
|
||||||
@@ -256,14 +280,20 @@ class ReadoutScreen(Screen):
|
|||||||
try:
|
try:
|
||||||
self.communication.join()
|
self.communication.join()
|
||||||
com.quitcom()
|
com.quitcom()
|
||||||
except:
|
logger.info("Mode_Switch successful")
|
||||||
pass
|
except Exception as e:
|
||||||
|
if e == AttributeError:
|
||||||
|
logger.info("No running process found, continuing")
|
||||||
|
else:
|
||||||
|
logger.fatal(f"FATAL ERROR OCCURED, APP WILL LEAVE NOW: {e}")
|
||||||
if text == "Normal Mode":
|
if text == "Normal Mode":
|
||||||
bin.lib.communication.SwitchMode().disable_fastmode()
|
bin.lib.communication.SwitchMode().disable_fastmode()
|
||||||
else:
|
else:
|
||||||
bin.lib.communication.SwitchMode().enable_fastmode()
|
bin.lib.communication.SwitchMode().enable_fastmode()
|
||||||
|
logger.info("Switched mode, restarting COM")
|
||||||
self.openpupups()
|
self.openpupups()
|
||||||
self.comstart(0)
|
self.comstart(0)
|
||||||
|
logger.info("COM restarted successfully")
|
||||||
|
|
||||||
@mainthread
|
@mainthread
|
||||||
def change_screen(self, pos, value):
|
def change_screen(self, pos, value):
|
||||||
@@ -276,6 +306,7 @@ class ReadoutScreen(Screen):
|
|||||||
elif pos == 4:
|
elif pos == 4:
|
||||||
self.ids.sonde4.text = value
|
self.ids.sonde4.text = value
|
||||||
elif pos == 6:
|
elif pos == 6:
|
||||||
|
logger.error("COM_fail")
|
||||||
self.openconnectionfailpu()
|
self.openconnectionfailpu()
|
||||||
else:
|
else:
|
||||||
self.ids.frequency.text = value
|
self.ids.frequency.text = value
|
||||||
@@ -300,6 +331,7 @@ class ReadoutScreen(Screen):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def leave_screen(self):
|
def leave_screen(self):
|
||||||
|
logger.info("Stopping COM")
|
||||||
self.stopcom(0)
|
self.stopcom(0)
|
||||||
|
|
||||||
def resscreen(self):
|
def resscreen(self):
|
||||||
@@ -312,11 +344,13 @@ class ReadoutScreen(Screen):
|
|||||||
|
|
||||||
class Program(Screen):
|
class Program(Screen):
|
||||||
def read_config(self):
|
def read_config(self):
|
||||||
|
logger.debug("Reading config")
|
||||||
self.config_imp = []
|
self.config_imp = []
|
||||||
self.__export = []
|
self.__export = []
|
||||||
self.config_imp = cvr.importing("./config/config.csv")
|
self.config_imp = cvr.importing("./config/config.csv")
|
||||||
self.__export = self.config_imp.pop(0)
|
self.__export = self.config_imp.pop(0)
|
||||||
self.__extracted = self.__export.pop(0)
|
self.__extracted = self.__export.pop(0)
|
||||||
|
logger.debug(f"config {self.__extracted}")
|
||||||
if self.__extracted == "1":
|
if self.__extracted == "1":
|
||||||
self.ids.prsel.state = "normal"
|
self.ids.prsel.state = "normal"
|
||||||
self.ids.s1_a.text = ""
|
self.ids.s1_a.text = ""
|
||||||
@@ -338,12 +372,14 @@ class Program(Screen):
|
|||||||
self.__mode = 1
|
self.__mode = 1
|
||||||
else:
|
else:
|
||||||
self.ids.prsel.state = "down"
|
self.ids.prsel.state = "down"
|
||||||
self.read_data()
|
Clock.schedule_once(self.read_data())
|
||||||
self.__mode = 2
|
self.__mode = 2
|
||||||
|
|
||||||
def change_mode(self):
|
def change_mode(self):
|
||||||
|
logger.info("Changing mode")
|
||||||
|
logger.debug(f"mode was: {self.__mode}")
|
||||||
if self.__mode == "1":
|
if self.__mode == "1":
|
||||||
self.read_data()
|
Clock.schedule_once(self.read_data())
|
||||||
self.__mode = 2
|
self.__mode = 2
|
||||||
else:
|
else:
|
||||||
self.ids.s1_a.text = ""
|
self.ids.s1_a.text = ""
|
||||||
@@ -368,14 +404,16 @@ class Program(Screen):
|
|||||||
try:
|
try:
|
||||||
com.connect(19200, "")
|
com.connect(19200, "")
|
||||||
self.go = 1
|
self.go = 1
|
||||||
except:
|
except Exception as e:
|
||||||
self.go = 0
|
self.go = 0
|
||||||
|
logger.error(f"COM_error: {e}")
|
||||||
|
|
||||||
if self.go == 1:
|
if self.go == 1:
|
||||||
|
logger.info("Sending instructions")
|
||||||
com.send("RD")
|
com.send("RD")
|
||||||
self.__pos = 1
|
self.__pos = 1
|
||||||
self.__beginning = time.time()
|
self.__beginning = time.time()
|
||||||
self.go = 1
|
logger.info("Awaiting confirmation from the microcontroller for hook")
|
||||||
while True:
|
while True:
|
||||||
if time.time() - self.__beginning < 5:
|
if time.time() - self.__beginning < 5:
|
||||||
self.__data_recieve = com.decode_ascii(com.receive(1))
|
self.__data_recieve = com.decode_ascii(com.receive(1))
|
||||||
@@ -387,6 +425,7 @@ class Program(Screen):
|
|||||||
self.__data_recieve = com.decode_ascii(com.receive(1))
|
self.__data_recieve = com.decode_ascii(com.receive(1))
|
||||||
if self.__data_recieve == "\n":
|
if self.__data_recieve == "\n":
|
||||||
self.go = 1
|
self.go = 1
|
||||||
|
logger.info("Hook successful")
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
@@ -398,6 +437,7 @@ class Program(Screen):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.go = 0
|
self.go = 0
|
||||||
|
logger.error("Microcontroller not available, stopping connection")
|
||||||
break
|
break
|
||||||
if self.go == 1:
|
if self.go == 1:
|
||||||
for i in range(4):
|
for i in range(4):
|
||||||
@@ -427,6 +467,7 @@ class Program(Screen):
|
|||||||
self.ids.s4_c.text = self.__c
|
self.ids.s4_c.text = self.__c
|
||||||
self.ids.s4_t.text = self.__temp
|
self.ids.s4_t.text = self.__temp
|
||||||
self.__pos += 1
|
self.__pos += 1
|
||||||
|
logger.info("Recieved info from microcontroller")
|
||||||
else:
|
else:
|
||||||
self.open_confail_pu()
|
self.open_confail_pu()
|
||||||
com.quitcom()
|
com.quitcom()
|
||||||
@@ -440,10 +481,12 @@ class Program(Screen):
|
|||||||
try:
|
try:
|
||||||
self.create_com()
|
self.create_com()
|
||||||
self.go = 1
|
self.go = 1
|
||||||
except:
|
except Exception as e:
|
||||||
self.go = 0
|
self.go = 0
|
||||||
|
logger.critical(f"TRANSMISSION_Error: {e}")
|
||||||
|
|
||||||
if self.go == 1:
|
if self.go == 1:
|
||||||
|
logger.info("Preparing data to be sent")
|
||||||
self.__transmit = []
|
self.__transmit = []
|
||||||
if self.ids.s1_a.text != "" and self.ids.s1_b.text != "" and self.ids.s1_c.text != "" and self.ids.s1_t.text != "" and self.ids.s2_a.text != "" and self.ids.s2_b.text != "" and self.ids.s2_c.text != "" and self.ids.s2_t.text != "" and self.ids.s3_a.text != "" and self.ids.s3_b.text != "" and self.ids.s3_c.text != "" and self.ids.s3_t.text != "" and self.ids.s4_a.text != "" and self.ids.s4_b.text != "" and self.ids.s4_c.text != "" and self.ids.s4_t.text != "":
|
if self.ids.s1_a.text != "" and self.ids.s1_b.text != "" and self.ids.s1_c.text != "" and self.ids.s1_t.text != "" and self.ids.s2_a.text != "" and self.ids.s2_b.text != "" and self.ids.s2_c.text != "" and self.ids.s2_t.text != "" and self.ids.s3_a.text != "" and self.ids.s3_b.text != "" and self.ids.s3_c.text != "" and self.ids.s3_t.text != "" and self.ids.s4_a.text != "" and self.ids.s4_b.text != "" and self.ids.s4_c.text != "" and self.ids.s4_t.text != "":
|
||||||
self.__transmit.append(self.ids.s1_a.text)
|
self.__transmit.append(self.ids.s1_a.text)
|
||||||
@@ -462,8 +505,11 @@ class Program(Screen):
|
|||||||
self.__transmit.append(self.ids.s4_b.text)
|
self.__transmit.append(self.ids.s4_b.text)
|
||||||
self.__transmit.append(self.ids.s4_c.text)
|
self.__transmit.append(self.ids.s4_c.text)
|
||||||
self.__transmit.append(self.ids.s4_t.text)
|
self.__transmit.append(self.ids.s4_t.text)
|
||||||
|
logger.debug("trying to send...")
|
||||||
try:
|
try:
|
||||||
self.coms.change_all(self.__transmit, "")
|
self.coms.change_all(self.__transmit, "")
|
||||||
|
logger.info("Transmission successful")
|
||||||
|
logger.debug("purging fields...")
|
||||||
self.ids.s1_a.text = ""
|
self.ids.s1_a.text = ""
|
||||||
self.ids.s1_b.text = ""
|
self.ids.s1_b.text = ""
|
||||||
self.ids.s1_c.text = ""
|
self.ids.s1_c.text = ""
|
||||||
@@ -481,8 +527,9 @@ class Program(Screen):
|
|||||||
self.ids.s4_c.text = ""
|
self.ids.s4_c.text = ""
|
||||||
self.ids.s4_t.text = ""
|
self.ids.s4_t.text = ""
|
||||||
self.openconfpu()
|
self.openconfpu()
|
||||||
except:
|
except Exception as e:
|
||||||
self.open_confail_pu()
|
self.open_confail_pu()
|
||||||
|
logger.critical(f"TRANSMITION_Error: {e}")
|
||||||
else:
|
else:
|
||||||
self.openerrorpu()
|
self.openerrorpu()
|
||||||
else:
|
else:
|
||||||
@@ -503,11 +550,13 @@ class Program(Screen):
|
|||||||
|
|
||||||
class ProgramTemp(Screen):
|
class ProgramTemp(Screen):
|
||||||
def read_config(self):
|
def read_config(self):
|
||||||
|
logger.debug("Reading config")
|
||||||
self.config_imp = []
|
self.config_imp = []
|
||||||
self.__export = []
|
self.__export = []
|
||||||
self.config_imp = cvr.importing("./config/config.csv")
|
self.config_imp = cvr.importing("./config/config.csv")
|
||||||
self.__export = self.config_imp.pop(0)
|
self.__export = self.config_imp.pop(0)
|
||||||
self.__extracted = self.__export.pop(0)
|
self.__extracted = self.__export.pop(0)
|
||||||
|
logger.debug(f"Mode set is: {self.__extracted}")
|
||||||
if self.__extracted == "1":
|
if self.__extracted == "1":
|
||||||
self.ids.prsel.state = "normal"
|
self.ids.prsel.state = "normal"
|
||||||
self.ids.temp_s1.text = ""
|
self.ids.temp_s1.text = ""
|
||||||
@@ -517,12 +566,13 @@ class ProgramTemp(Screen):
|
|||||||
self.__mode = 1
|
self.__mode = 1
|
||||||
else:
|
else:
|
||||||
self.ids.prsel.state = "down"
|
self.ids.prsel.state = "down"
|
||||||
self.read_data()
|
Clock.schedule_once(self.read_data())
|
||||||
self.__mode = 2
|
self.__mode = 2
|
||||||
|
|
||||||
def change_mode(self):
|
def change_mode(self):
|
||||||
|
logger.info(f"Mode was: {self.__mode}")
|
||||||
if self.__mode == "1":
|
if self.__mode == "1":
|
||||||
self.read_data()
|
Clock.schedule_once(self.read_data())
|
||||||
self.__mode = 2
|
self.__mode = 2
|
||||||
else:
|
else:
|
||||||
self.ids.temp_s1.text = ""
|
self.ids.temp_s1.text = ""
|
||||||
@@ -532,17 +582,21 @@ class ProgramTemp(Screen):
|
|||||||
self.__mode = 1
|
self.__mode = 1
|
||||||
|
|
||||||
def read_data(self):
|
def read_data(self):
|
||||||
|
logger.info("Trying to establish connection...")
|
||||||
try:
|
try:
|
||||||
com.connect(19200, "")
|
com.connect(19200, "")
|
||||||
self.go = 1
|
self.go = 1
|
||||||
except:
|
except Exception as e:
|
||||||
self.go = 0
|
self.go = 0
|
||||||
|
logger.error(f"COM_Error: {e}")
|
||||||
|
|
||||||
if self.go == 1:
|
if self.go == 1:
|
||||||
|
logger.info("Sending instructions to microcontroller...")
|
||||||
com.send("RD")
|
com.send("RD")
|
||||||
self.__pos = 1
|
self.__pos = 1
|
||||||
self.__beginning = time.time()
|
self.__beginning = time.time()
|
||||||
self.go = 1
|
self.go = 1
|
||||||
|
logger.info("Awaiting confirmation from the microcontroller for hook")
|
||||||
while True:
|
while True:
|
||||||
if time.time() - self.__beginning < 5:
|
if time.time() - self.__beginning < 5:
|
||||||
self.__data_recieve = com.decode_ascii(com.receive(1))
|
self.__data_recieve = com.decode_ascii(com.receive(1))
|
||||||
@@ -554,6 +608,7 @@ class ProgramTemp(Screen):
|
|||||||
self.__data_recieve = com.decode_ascii(com.receive(1))
|
self.__data_recieve = com.decode_ascii(com.receive(1))
|
||||||
if self.__data_recieve == "\n":
|
if self.__data_recieve == "\n":
|
||||||
self.go = 1
|
self.go = 1
|
||||||
|
logger.info("Hook successful")
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
@@ -565,8 +620,10 @@ class ProgramTemp(Screen):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.go = 0
|
self.go = 0
|
||||||
|
logger.error("Microcontroller not available, stopping connection")
|
||||||
break
|
break
|
||||||
if self.go == 1:
|
if self.go == 1:
|
||||||
|
logger.info("Receiving data...")
|
||||||
for i in range(4):
|
for i in range(4):
|
||||||
self.__x = com.receive(28)
|
self.__x = com.receive(28)
|
||||||
self.__output = str(com.decode_float(self.__x[21:27]))
|
self.__output = str(com.decode_float(self.__x[21:27]))
|
||||||
@@ -579,6 +636,7 @@ class ProgramTemp(Screen):
|
|||||||
elif self.__pos == 4:
|
elif self.__pos == 4:
|
||||||
self.ids.temp_s4.text = self.__output
|
self.ids.temp_s4.text = self.__output
|
||||||
self.__pos += 1
|
self.__pos += 1
|
||||||
|
logger.info("Recieved data")
|
||||||
else:
|
else:
|
||||||
self.open_confail_pu()
|
self.open_confail_pu()
|
||||||
com.quitcom()
|
com.quitcom()
|
||||||
@@ -592,16 +650,19 @@ class ProgramTemp(Screen):
|
|||||||
try:
|
try:
|
||||||
self.create_com()
|
self.create_com()
|
||||||
self.go = 1
|
self.go = 1
|
||||||
except:
|
except Exception as e:
|
||||||
self.go = 0
|
self.go = 0
|
||||||
|
logger.critical(f"COM_Error: Microcontroller unavailable: {e}")
|
||||||
|
|
||||||
if self.go == 1:
|
if self.go == 1:
|
||||||
|
logger.info("Preparing transmission...")
|
||||||
self.__transmit = []
|
self.__transmit = []
|
||||||
if self.ids.temp_s1.text != "" and self.ids.temp_s2.text != "" and self.ids.temp_s3.text != "" and self.ids.temp_s4.text != "":
|
if self.ids.temp_s1.text != "" and self.ids.temp_s2.text != "" and self.ids.temp_s3.text != "" and self.ids.temp_s4.text != "":
|
||||||
self.__transmit.append(self.ids.temp_s1.text)
|
self.__transmit.append(self.ids.temp_s1.text)
|
||||||
self.__transmit.append(self.ids.temp_s2.text)
|
self.__transmit.append(self.ids.temp_s2.text)
|
||||||
self.__transmit.append(self.ids.temp_s3.text)
|
self.__transmit.append(self.ids.temp_s3.text)
|
||||||
self.__transmit.append(self.ids.temp_s4.text)
|
self.__transmit.append(self.ids.temp_s4.text)
|
||||||
|
logger.debug("Transmitting...")
|
||||||
self.coms.change_temp(self.__transmit, "")
|
self.coms.change_temp(self.__transmit, "")
|
||||||
self.ids.temp_s1.text = ""
|
self.ids.temp_s1.text = ""
|
||||||
self.ids.temp_s2.text = ""
|
self.ids.temp_s2.text = ""
|
||||||
@@ -610,6 +671,7 @@ class ProgramTemp(Screen):
|
|||||||
self.openconfpu()
|
self.openconfpu()
|
||||||
else:
|
else:
|
||||||
self.openerrorpu()
|
self.openerrorpu()
|
||||||
|
logger.debug("Missing fields")
|
||||||
else:
|
else:
|
||||||
self.open_confail_pu()
|
self.open_confail_pu()
|
||||||
|
|
||||||
@@ -628,17 +690,21 @@ class ProgramTemp(Screen):
|
|||||||
|
|
||||||
class ReadData(Screen):
|
class ReadData(Screen):
|
||||||
def read_data(self):
|
def read_data(self):
|
||||||
|
logger.info("Trying to connect to the microcontroller")
|
||||||
try:
|
try:
|
||||||
com.connect(19200, "")
|
com.connect(19200, "")
|
||||||
self.go = 1
|
self.go = 1
|
||||||
except:
|
except Exception as e:
|
||||||
self.go = 0
|
self.go = 0
|
||||||
|
logger.error(f"COM_Error: {e}")
|
||||||
|
|
||||||
if self.go == 1:
|
if self.go == 1:
|
||||||
|
logger.info("Sending instructions to the microcontroller...")
|
||||||
com.send("RD")
|
com.send("RD")
|
||||||
self.__pos = 1
|
self.__pos = 1
|
||||||
self.__beginning = time.time()
|
self.__beginning = time.time()
|
||||||
self.go = 1
|
self.go = 1
|
||||||
|
logger.info("Awaiting confirmation from the microcontroller for hook")
|
||||||
while True:
|
while True:
|
||||||
if time.time() - self.__beginning < 5:
|
if time.time() - self.__beginning < 5:
|
||||||
self.__data_recieve = com.decode_ascii(com.receive(1))
|
self.__data_recieve = com.decode_ascii(com.receive(1))
|
||||||
@@ -650,6 +716,7 @@ class ReadData(Screen):
|
|||||||
self.__data_recieve = com.decode_ascii(com.receive(1))
|
self.__data_recieve = com.decode_ascii(com.receive(1))
|
||||||
if self.__data_recieve == "\n":
|
if self.__data_recieve == "\n":
|
||||||
self.go = 1
|
self.go = 1
|
||||||
|
logger.info("Hook successful")
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
@@ -661,8 +728,10 @@ class ReadData(Screen):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.go = 0
|
self.go = 0
|
||||||
|
logger.error("Microcontroller not available, stopping connection")
|
||||||
break
|
break
|
||||||
if self.go == 1:
|
if self.go == 1:
|
||||||
|
logger.info("Receiving data")
|
||||||
for i in range(4):
|
for i in range(4):
|
||||||
self.__x = com.receive(28)
|
self.__x = com.receive(28)
|
||||||
self.__output = "a: "
|
self.__output = "a: "
|
||||||
@@ -679,6 +748,7 @@ class ReadData(Screen):
|
|||||||
elif self.__pos == 4:
|
elif self.__pos == 4:
|
||||||
self.ids.inf_sonde4.text = self.__output
|
self.ids.inf_sonde4.text = self.__output
|
||||||
self.__pos += 1
|
self.__pos += 1
|
||||||
|
logger.info("Received data")
|
||||||
else:
|
else:
|
||||||
self.open_confail_pu()
|
self.open_confail_pu()
|
||||||
com.quitcom()
|
com.quitcom()
|
||||||
@@ -696,27 +766,32 @@ class Credits(Screen):
|
|||||||
|
|
||||||
class Modify(Screen):
|
class Modify(Screen):
|
||||||
def read_config(self):
|
def read_config(self):
|
||||||
|
logger.debug("Reading config")
|
||||||
self.config_imp = []
|
self.config_imp = []
|
||||||
self.__export = []
|
self.__export = []
|
||||||
self.config_imp = cvr.importing("./config/config.csv")
|
self.config_imp = cvr.importing("./config/config.csv")
|
||||||
self.__export = self.config_imp.pop(0)
|
self.__export = self.config_imp.pop(0)
|
||||||
self.__extracted = self.__export.pop(0)
|
self.__extracted = self.__export.pop(0)
|
||||||
|
logger.debug(f"Mode at: {self.__extracted}")
|
||||||
if self.__extracted == "1":
|
if self.__extracted == "1":
|
||||||
self.ids.prsel.state = "normal"
|
self.ids.prsel.state = "normal"
|
||||||
else:
|
else:
|
||||||
self.ids.prsel.state = "down"
|
self.ids.prsel.state = "down"
|
||||||
|
|
||||||
def issue_reporting(self):
|
def issue_reporting(self):
|
||||||
|
logger.info("Clicked error reporting button")
|
||||||
webbrowser.open("https://github.com/simplePCBuilding/BiogasControllerApp/issues", new=2)
|
webbrowser.open("https://github.com/simplePCBuilding/BiogasControllerApp/issues", new=2)
|
||||||
|
|
||||||
def change_programming(self):
|
def change_programming(self):
|
||||||
|
logger.info("Switching programming mode")
|
||||||
self.csv_import = []
|
self.csv_import = []
|
||||||
self.csv_import = cvr.importing("./config/config.csv")
|
self.csv_import = cvr.importing("./config/config.csv")
|
||||||
self.csv_import.pop(0)
|
self.csv_import.pop(0)
|
||||||
if self.ids.prsel.text == "Easy\nreprogramming":
|
if self.ids.prsel.text == "Full\nreprogramming":
|
||||||
self.csv_import.insert(0, 1)
|
self.csv_import.insert(0, 1)
|
||||||
else:
|
else:
|
||||||
self.csv_import.insert(0, 2)
|
self.csv_import.insert(0, 2)
|
||||||
|
logger.debug("Mode now:", self.csv_import)
|
||||||
cvw.write_str("./config/config.csv", self.csv_import)
|
cvw.write_str("./config/config.csv", self.csv_import)
|
||||||
|
|
||||||
|
|
||||||
@@ -730,7 +805,7 @@ class RootScreen(ScreenManager):
|
|||||||
|
|
||||||
|
|
||||||
kv = Builder.load_file("./bin/gui/gui.kv")
|
kv = Builder.load_file("./bin/gui/gui.kv")
|
||||||
|
logger.info("Loaded GUI")
|
||||||
|
|
||||||
class BiogasControllerApp(App):
|
class BiogasControllerApp(App):
|
||||||
def build(self):
|
def build(self):
|
||||||
@@ -738,5 +813,7 @@ class BiogasControllerApp(App):
|
|||||||
return kv
|
return kv
|
||||||
|
|
||||||
|
|
||||||
|
logger.info("Init finished, starting UI")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
BiogasControllerApp().run()
|
BiogasControllerApp().run()
|
||||||
|
|||||||
18
BiogasControllerApp-V2.2/config/settings.ini
Normal file
18
BiogasControllerApp-V2.2/config/settings.ini
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
[Port Settings]
|
||||||
|
forceSpecificPort: False
|
||||||
|
specificPort: None
|
||||||
|
|
||||||
|
[UI Config]
|
||||||
|
sizeH: 600
|
||||||
|
sizeW: 800
|
||||||
|
showLoadingScreen: True
|
||||||
|
|
||||||
|
[Dev Settings]
|
||||||
|
# Settings generally aimed towards the devs of this software!
|
||||||
|
verbose: False
|
||||||
|
log_level: DEBUG
|
||||||
|
disableConnectionCheck: False
|
||||||
|
|
||||||
|
[Info]
|
||||||
|
version: V2.3.0
|
||||||
|
subVersion: None
|
||||||
Reference in New Issue
Block a user