mirror of
https://github.com/janishutz/BiogasControllerApp.git
synced 2025-11-25 05:44:23 +00:00
@@ -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.2.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
|
||||||
@@ -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:
|
||||||
@@ -626,7 +625,7 @@ RootScreen:
|
|||||||
Label:
|
Label:
|
||||||
text: "This is a rework of the BiogasControllerApp V1, that was originally programmed by S. Reichmuth."
|
text: "This is a rework of the BiogasControllerApp V1, that was originally programmed by S. Reichmuth."
|
||||||
Label:
|
Label:
|
||||||
text: "Written by: Janis Hutz\nDesigned by: Janis Hutz\nDesign language: Kivy"
|
text: "Written by: Janis Hutz\nDesigned by: Janis Hutz\nDesign language: Kivy"
|
||||||
|
|
||||||
<Modify>:
|
<Modify>:
|
||||||
on_pre_enter: self.config = root.read_config()
|
on_pre_enter: self.config = root.read_config()
|
||||||
@@ -653,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"
|
||||||
@@ -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,78 @@
|
|||||||
print("""
|
import os
|
||||||
|
import configparser
|
||||||
|
|
||||||
=====================
|
import serial
|
||||||
|
|
||||||
BIOGASCONTROLLERAPP
|
config = configparser.ConfigParser()
|
||||||
|
config.read('./config/settings.ini')
|
||||||
|
co = config['Dev Settings']['verbose']
|
||||||
|
if co == "True":
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
os.environ["KIVY_NO_CONSOLELOG"] = "1"
|
||||||
|
|
||||||
----------
|
|
||||||
Version 2.2
|
|
||||||
Copyright 2022 J.Hutz""")
|
|
||||||
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.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
|
||||||
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 datetime
|
||||||
|
import time
|
||||||
|
|
||||||
|
version_app = f"{config['Info']['version']}{config['Info']['subVersion']}"
|
||||||
|
|
||||||
|
################################################################
|
||||||
|
# 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(config['Dev Settings']['log_level'])
|
||||||
|
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")
|
||||||
|
|
||||||
|
|
||||||
##################################################################
|
##################################################################
|
||||||
# Popups
|
# Popups
|
||||||
##################################################################
|
##################################################################
|
||||||
@@ -35,6 +81,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):
|
||||||
@@ -117,14 +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:
|
self.info = f"You are currently running Version {version_app} - If you encounter a bug, please report it!"
|
||||||
connected = 0
|
try:
|
||||||
|
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:
|
||||||
@@ -133,9 +185,15 @@ 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
|
if config['Dev Settings']['disableConnectionCheck'] == "True":
|
||||||
self.open_popup()
|
self.connected = 1
|
||||||
|
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()
|
||||||
@@ -148,17 +206,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 +238,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 +252,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 +261,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 +277,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 +320,28 @@ class ReadoutScreen(Screen):
|
|||||||
try:
|
try:
|
||||||
self.communication.join()
|
self.communication.join()
|
||||||
com.quitcom()
|
com.quitcom()
|
||||||
except:
|
self.com_ok = 1
|
||||||
pass
|
logger.info("Mode_Switch successful")
|
||||||
if text == "Normal Mode":
|
except Exception as e:
|
||||||
bin.lib.communication.SwitchMode().disable_fastmode()
|
if e == serial.SerialException:
|
||||||
|
logger.info("No running process found, continuing")
|
||||||
|
else:
|
||||||
|
logger.fatal(f"FATAL ERROR OCCURED, APP WILL LEAVE NOW: {e}")
|
||||||
|
self.com_ok = 0
|
||||||
|
|
||||||
|
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
|
||||||
self.openpupups()
|
self.ids.mode_sel.state = "normal"
|
||||||
self.comstart(0)
|
self.openconnectionfailpu()
|
||||||
|
|
||||||
@mainthread
|
@mainthread
|
||||||
def change_screen(self, pos, value):
|
def change_screen(self, pos, value):
|
||||||
@@ -276,6 +354,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,9 +379,11 @@ 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):
|
||||||
|
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 = ""
|
||||||
@@ -312,11 +393,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 +421,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 +453,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 +474,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 +486,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 +516,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 +530,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 +554,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 +576,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 +599,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 +615,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 +631,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 +657,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 +669,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 +685,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 +699,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 +720,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 +739,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 +765,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 +777,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 +797,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 +815,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)
|
||||||
|
|
||||||
|
|
||||||
@@ -729,14 +853,14 @@ class RootScreen(ScreenManager):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
kv = Builder.load_file("./bin/gui/gui.kv")
|
|
||||||
|
|
||||||
|
|
||||||
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")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
BiogasControllerApp().run()
|
BiogasControllerApp().run()
|
||||||
|
|||||||
16
BiogasControllerApp-V2.2/config/settings.ini
Normal file
16
BiogasControllerApp-V2.2/config/settings.ini
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[Port Settings]
|
||||||
|
specificPort = None
|
||||||
|
|
||||||
|
[UI Config]
|
||||||
|
sizeH = 600
|
||||||
|
sizeW = 800
|
||||||
|
|
||||||
|
[Dev Settings]
|
||||||
|
# Settings generally aimed towards the devs of this software!
|
||||||
|
verbose = True
|
||||||
|
log_level = DEBUG
|
||||||
|
disableConnectionCheck = True
|
||||||
|
|
||||||
|
[Info]
|
||||||
|
version = V2.3.0
|
||||||
|
subVersion = -dev1
|
||||||
Reference in New Issue
Block a user