Files
board-mate/rpi/services/game_service.py
2025-12-31 16:12:14 +01:00

51 lines
1.5 KiB
Python

import threading
import requests
import _thread
from services.clock_service import ClockService
from services.detection_service import DetectionService
class GameService:
detection_service : DetectionService
clock_service : ClockService
def __init__(self):
self.detection_service = DetectionService()
self.clock_service = ClockService()
def start(self, white_name, back_name, time_control : int, increment : int ) -> None:
self.clock_service.start(time_control, increment)
self.clock_service.set_on_terminated(self.stop)
def stop(self):
self.clock_service.stop()
self.detection_service.stop()
def make_move(self) -> None:
try :
frame, fen = self.detection_service.analyze_single_frame()
print(fen)
url = "http://192.168.15.125:1880/party/image"
"""threading.Thread(
target=self.__send_detection_result,
args=(url, frame, fen),
daemon=True
).start()"""
except Exception as e:
print(e)
def __send_detection_result(self, url, img, fen):
try:
headers = {'Content-Type': 'image/jpeg'}
body = {'frame': img, 'fen': fen}
response = requests.post(
url,
data=body,
headers=headers,
verify=False)
print(response.status_code)
except Exception as e:
print(e)