Motor
The raspi now controls a motor to lock unlock
This commit is contained in:
@@ -5,6 +5,9 @@ class CLI:
|
||||
def __init__(self, tracker) -> None:
|
||||
self.tracker = tracker
|
||||
self.current_user = None
|
||||
from raspi.motor import Raspi
|
||||
self.motor = Raspi()
|
||||
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
@@ -157,20 +160,27 @@ class CLI:
|
||||
if confirm == "y":
|
||||
result = self.tracker.add_purchase(self.current_user, item_id)
|
||||
|
||||
self._clear_screen()
|
||||
print("=" * 50)
|
||||
print("PURCHASE ADDED")
|
||||
print("=" * 50)
|
||||
print()
|
||||
print(f"✓ {result['message']}")
|
||||
print(f"New debt: ${result['new_debt']:.2f}")
|
||||
print()
|
||||
if result["status"] == "success":
|
||||
self._clear_screen()
|
||||
print("=" * 50)
|
||||
print("PURCHASE ADDED")
|
||||
print("=" * 50)
|
||||
print()
|
||||
print(f"✓ {result['message']}")
|
||||
print(f"New debt: ${result['new_debt']:.2f}")
|
||||
print()
|
||||
|
||||
input("Press Enter to continue...")
|
||||
self.motor.unlock_async()
|
||||
input("Press Enter to continue...")
|
||||
self.motor.lock_async()
|
||||
else:
|
||||
print(f"Error: {result['message']}")
|
||||
input("Press Enter to continue...")
|
||||
else:
|
||||
print("Purchase cancelled.")
|
||||
input("Press Enter to continue...")
|
||||
|
||||
|
||||
def _view_user_debt(self):
|
||||
self._clear_screen()
|
||||
|
||||
@@ -237,7 +247,9 @@ class CLI:
|
||||
print("4. View transaction history")
|
||||
print("5. Manage users")
|
||||
print("6. Manage items")
|
||||
print("7. Logout")
|
||||
print("7. Open Kühlschrank (Unlock)")
|
||||
print("8. Close Kühlschrank (Lock)")
|
||||
print("9. Logout")
|
||||
print()
|
||||
|
||||
choice = input("Choose option: ").strip()
|
||||
@@ -255,6 +267,14 @@ class CLI:
|
||||
elif choice == "6":
|
||||
self._manage_items()
|
||||
elif choice == "7":
|
||||
print("Kühlschrank wird geöffnet (Entriegeln)...")
|
||||
self.motor.unlock_async()
|
||||
input("Press Enter to continue...")
|
||||
elif choice == "8":
|
||||
print("Kühlschrank wird geschlossen (Verriegeln)...")
|
||||
self.motor.lock_async()
|
||||
input("Press Enter to continue...")
|
||||
elif choice == "9":
|
||||
break
|
||||
else:
|
||||
self._invalid_choice()
|
||||
|
||||
+34
@@ -1305,6 +1305,8 @@ class AddPurchaseScreen(StyledScreen):
|
||||
title="Erfolg",
|
||||
message=f"Kauf erfolgreich!\n\nNeuer Schuldenstand: {result['new_debt']:.2f} €",
|
||||
)
|
||||
popup.bind(on_dismiss=lambda instance: app.motor.lock_async())
|
||||
app.motor.unlock_async()
|
||||
popup.open()
|
||||
self.manager.current = "user_menu"
|
||||
else:
|
||||
@@ -1312,6 +1314,7 @@ class AddPurchaseScreen(StyledScreen):
|
||||
popup.open()
|
||||
|
||||
|
||||
|
||||
class AllDebtsScreen(StyledScreen):
|
||||
def __init__(self, **kwargs):
|
||||
super(AllDebtsScreen, self).__init__(
|
||||
@@ -1531,6 +1534,26 @@ class AdminMenuScreen(StyledScreen):
|
||||
btn_manage_items.bind(on_release=self.go_manage_items)
|
||||
box.add_widget(btn_manage_items)
|
||||
|
||||
btn_open = RoundedButton(
|
||||
text="Kühlschrank öffnen",
|
||||
size_hint=(0.7, None),
|
||||
height="60dp",
|
||||
pos_hint={"center_x": 0.5},
|
||||
btn_color=[0.0, 0.65, 0.57, 1],
|
||||
)
|
||||
btn_open.bind(on_release=self.open_fridge)
|
||||
box.add_widget(btn_open)
|
||||
|
||||
btn_close = RoundedButton(
|
||||
text="Kühlschrank schließen",
|
||||
size_hint=(0.7, None),
|
||||
height="60dp",
|
||||
pos_hint={"center_x": 0.5},
|
||||
btn_color=[0.8, 0.2, 0.2, 1],
|
||||
)
|
||||
btn_close.bind(on_release=self.close_fridge)
|
||||
box.add_widget(btn_close)
|
||||
|
||||
btn_logout = RoundedButton(
|
||||
text="Admin-Bereich verlassen",
|
||||
size_hint=(0.7, None),
|
||||
@@ -1541,6 +1564,14 @@ class AdminMenuScreen(StyledScreen):
|
||||
btn_logout.bind(on_release=self.logout)
|
||||
box.add_widget(btn_logout)
|
||||
|
||||
def open_fridge(self, instance):
|
||||
app = App.get_running_app()
|
||||
app.motor.unlock_async()
|
||||
|
||||
def close_fridge(self, instance):
|
||||
app = App.get_running_app()
|
||||
app.motor.lock_async()
|
||||
|
||||
def go_all_debts(self, instance):
|
||||
self.manager.get_screen("all_debts").back_screen = "admin_menu"
|
||||
self.manager.current = "all_debts"
|
||||
@@ -1994,6 +2025,9 @@ class KuehlschrankApp(App):
|
||||
self.tracker = tracker
|
||||
self.current_user = None
|
||||
self.admin_password = None
|
||||
from raspi.motor import Raspi
|
||||
self.motor = Raspi()
|
||||
|
||||
|
||||
def build(self):
|
||||
self.title = "Getränkeliste"
|
||||
|
||||
Reference in New Issue
Block a user