mirror of
https://github.com/janishutz/BiogasControllerApp.git
synced 2025-11-25 05:44:23 +00:00
Main, Program Screen basically done, UI Tweaks, backend fixes, start writing testing library
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
<ProgramScreen>:
|
||||
name: "program"
|
||||
on_pre_enter: self.config_loader = root.load_config()
|
||||
canvas.before:
|
||||
Color:
|
||||
rgba: (50,50,50,0.2)
|
||||
Rectangle:
|
||||
size: self.size
|
||||
pos: self.pos
|
||||
FloatLayout:
|
||||
Label:
|
||||
text: "Configuration"
|
||||
font_size: 40
|
||||
color: (0, 113, 0, 1)
|
||||
bold: True
|
||||
pos_hint: {"y":0.4}
|
||||
GridLayout:
|
||||
size_hint: 0.8, 0.5
|
||||
pos_hint: {"x":0.1, "y":0.2}
|
||||
cols: 4
|
||||
Label:
|
||||
text: "Sensor 1, a:"
|
||||
TextInput:
|
||||
id: s1_a
|
||||
multiline: False
|
||||
input_filter: "float"
|
||||
Label:
|
||||
text: "Sensor 1, b:"
|
||||
TextInput:
|
||||
id: s1_b
|
||||
multiline: False
|
||||
input_filter: "float"
|
||||
Label:
|
||||
text: "Sensor 1, c:"
|
||||
TextInput:
|
||||
id: s1_c
|
||||
multiline: False
|
||||
input_filter: "float"
|
||||
Label:
|
||||
text: "Sensor 1, Temp:"
|
||||
TextInput:
|
||||
id: s1_t
|
||||
multiline: False
|
||||
input_filter: "float"
|
||||
Label:
|
||||
text: "Sensor 2, a:"
|
||||
TextInput:
|
||||
id: s2_a
|
||||
multiline: False
|
||||
input_filter: "float"
|
||||
Label:
|
||||
text: "Sensor 2, b:"
|
||||
TextInput:
|
||||
id: s2_b
|
||||
multiline: False
|
||||
input_filter: "float"
|
||||
Label:
|
||||
text: "Sensor 2, c:"
|
||||
TextInput:
|
||||
id: s2_c
|
||||
multiline: False
|
||||
input_filter: "float"
|
||||
Label:
|
||||
text: "Sensor 2, Temp:"
|
||||
TextInput:
|
||||
id: s2_t
|
||||
multiline: False
|
||||
input_filter: "float"
|
||||
Label:
|
||||
text: "Sensor 3, a:"
|
||||
TextInput:
|
||||
id: s3_a
|
||||
multiline: False
|
||||
input_filter: "float"
|
||||
Label:
|
||||
text: "Sensor 3, b:"
|
||||
TextInput:
|
||||
id: s3_b
|
||||
multiline: False
|
||||
input_filter: "float"
|
||||
Label:
|
||||
text: "Sensor 3, c:"
|
||||
TextInput:
|
||||
id: s3_c
|
||||
multiline: False
|
||||
input_filter: "float"
|
||||
Label:
|
||||
text: "Sensor 3, Temp:"
|
||||
TextInput:
|
||||
id: s3_t
|
||||
multiline: False
|
||||
input_filter: "float"
|
||||
Label:
|
||||
text: "Sensor 4, a:"
|
||||
TextInput:
|
||||
id: s4_a
|
||||
multiline: False
|
||||
input_filter: "float"
|
||||
Label:
|
||||
text: "Sensor 4, b:"
|
||||
TextInput:
|
||||
id: s4_b
|
||||
multiline: False
|
||||
input_filter: "float"
|
||||
Label:
|
||||
text: "Sensor 4, c:"
|
||||
TextInput:
|
||||
id: s4_c
|
||||
multiline: False
|
||||
input_filter: "float"
|
||||
Label:
|
||||
text: "Sensor 4, Temp:"
|
||||
TextInput:
|
||||
id: s4_t
|
||||
multiline: False
|
||||
input_filter: "float"
|
||||
Button:
|
||||
text: "Back"
|
||||
size_hint: 0.1, 0.1
|
||||
pos_hint: {"x":0.1, "y":0.1}
|
||||
background_color: (255, 0, 0, 0.6)
|
||||
on_release:
|
||||
app.root.current = "main"
|
||||
root.manager.transition.direction = "up"
|
||||
Button:
|
||||
text: "Save"
|
||||
size_hint: 0.2, 0.1
|
||||
pos_hint: {"x":0.6, "y":0.1}
|
||||
background_color: (255, 0, 0, 0.6)
|
||||
on_release:
|
||||
root.save()
|
||||
|
||||
@@ -1,20 +1,94 @@
|
||||
from typing import List
|
||||
from kivy.uix.screenmanager import Screen
|
||||
from kivy.lang import Builder
|
||||
from lib.decoder import Decoder
|
||||
from lib.instructions import Instructions
|
||||
from gui.popups.popups import SingleRowPopup, TwoActionPopup, empty_func
|
||||
from lib.com import Com
|
||||
from kivy.clock import Clock
|
||||
|
||||
|
||||
class HomeScreen(Screen):
|
||||
# The below list maps 0, 1, 2, 3 to a, b, c and t respectively
|
||||
# This is used to set and read values of the UI
|
||||
name_map = [ "a", "b", "c", "t" ]
|
||||
|
||||
|
||||
class ProgramScreen(Screen):
|
||||
def __init__(self, com: Com, **kw):
|
||||
self._com = com;
|
||||
self._com = com
|
||||
self._instructions = Instructions(com)
|
||||
self._decoder = Decoder()
|
||||
super().__init__(**kw)
|
||||
|
||||
def start(self):
|
||||
pass
|
||||
def load_config(self):
|
||||
Clock.schedule_once(self._load)
|
||||
|
||||
def quit(self):
|
||||
pass
|
||||
# Load the current configuration from the micro-controller
|
||||
def _load(self, dt: float):
|
||||
if self._instructions.hook("RD", ["\n", "R", "D", "\n"]):
|
||||
config: List[List[str]] = []
|
||||
|
||||
def to_settings(self):
|
||||
pass
|
||||
# Load config for all four sensors
|
||||
for _ in range(4):
|
||||
# Receive 28 bytes of data
|
||||
received = self._com.receive(28)
|
||||
|
||||
# Create a list of strings to store the config for the sensor
|
||||
# This list has the following elements: a, b, c, temperature
|
||||
config_sensor_i: List[str] = []
|
||||
|
||||
# Create the list
|
||||
for j in range(4):
|
||||
config_sensor_i.append(str(self._decoder.decode_float(received[7 * j:7 * j + 6])))
|
||||
|
||||
# Add it to the config
|
||||
config.append(config_sensor_i)
|
||||
else:
|
||||
TwoActionPopup().open(
|
||||
"Failed to connect to micro-controller, retry?",
|
||||
"Cancel",
|
||||
empty_func,
|
||||
"Retry",
|
||||
lambda: self._load(0),
|
||||
)
|
||||
|
||||
# Set the elements of the UI to the values of the config
|
||||
def _set_ui(self, config: List[List[str]]):
|
||||
for sensor_id in range(4):
|
||||
for property in range(4):
|
||||
self.ids[f"s{sensor_id + 1}_{name_map[property]}"].text = config[sensor_id][property]
|
||||
|
||||
# Read values from the UI. Returns the values as a list or None if the check was infringed
|
||||
def _read_ui(self, enforce_none_empty: bool = True) -> List[float] | None:
|
||||
data: List[float] = []
|
||||
|
||||
# Iterate over all sensor config input fields and collect the data
|
||||
for sensor_id in range(4):
|
||||
for property in range(4):
|
||||
value = self.ids[f"s{sensor_id + 1}_{name_map[property]}"].text
|
||||
|
||||
# If requested (by setting enforce_none_empty to True, which is the default)
|
||||
# test if the cells are not empty and if we find an empty cell return None
|
||||
if enforce_none_empty and value == "":
|
||||
return
|
||||
data.append(float(value))
|
||||
|
||||
return data
|
||||
|
||||
# Transmit the changed data to the micro-controller to reconfigure it
|
||||
def save(self):
|
||||
data = self._read_ui()
|
||||
if data == None:
|
||||
SingleRowPopup().open("Some fields are missing values!")
|
||||
else:
|
||||
try:
|
||||
self._instructions.change_config(data)
|
||||
except:
|
||||
SingleRowPopup().open("Could not save data!")
|
||||
SingleRowPopup().open("Data saved successfully")
|
||||
|
||||
|
||||
Builder.load_file('./gui/home/home.kv')
|
||||
# Load the design file for this screen (.kv files)
|
||||
# The path has to be relative to root of the app, i.e. where the biogascontrollerapp.py
|
||||
# file is located
|
||||
Builder.load_file("./gui/program/program.kv")
|
||||
|
||||
Reference in New Issue
Block a user