1
0
Files
BasaltMeter/BasaltTrainer/main.py

40 lines
987 B
Python
Raw Normal View History

2026-01-06 21:24:47 +08:00
from command_server import CommandServer, HandshakePayload, PixelKind
2026-01-06 22:04:52 +08:00
from while_stopper import WhileStopper
2026-01-06 21:24:47 +08:00
import logging
2026-01-06 22:04:52 +08:00
import signal
2026-01-06 21:24:47 +08:00
def receive_data() -> None:
logging.info('Data received')
2025-11-25 13:38:17 +08:00
def main():
2026-01-06 21:24:47 +08:00
server = CommandServer()
2026-01-06 22:04:52 +08:00
print('Please launch BasaltPresenter now.')
print('Then press Enter to continue...')
2026-01-06 21:24:47 +08:00
input()
logging.info('Waiting BasaltPresenter...')
server.wait_handshake(HandshakePayload(PixelKind.GRAY_U8, 600, 600))
logging.info('Start to running.')
2026-01-06 22:04:52 +08:00
stopper = WhileStopper()
stopper.register()
2026-01-06 21:24:47 +08:00
while True:
2026-01-06 22:04:52 +08:00
if server.tick(receive_data, stopper.is_stop_requested()):
2026-01-06 21:24:47 +08:00
break
2026-01-06 22:04:52 +08:00
stopper.unregister()
2026-01-06 21:24:47 +08:00
logging.info('Program stop.')
2025-11-25 13:38:17 +08:00
2026-01-06 22:04:52 +08:00
print('Press Enter to exit...')
input()
2025-11-25 13:38:17 +08:00
if __name__ == "__main__":
2026-01-06 21:24:47 +08:00
logging.basicConfig(level=logging.DEBUG,
format='[%(asctime)s] [%(levelname)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
2025-11-25 13:38:17 +08:00
main()