From 8c837065593de995bc719a80ab71f175e19a9092 Mon Sep 17 00:00:00 2001 From: Nicolas Vaagen Date: Thu, 8 Aug 2024 09:42:39 -0600 Subject: [PATCH] testing and lights: rehal of the test module, fix on signal lights added some prettyer signal_lights and made test script more all encompasing --- nicsoft/niclink/__main__.py | 20 +++++++++------ nicsoft/test/__main__.py | 49 +++++++++++++++++++++++++++++++++---- testNicLink.sh | 6 +++-- 3 files changed, 60 insertions(+), 15 deletions(-) diff --git a/nicsoft/niclink/__main__.py b/nicsoft/niclink/__main__.py index 12d806d..e091c6a 100644 --- a/nicsoft/niclink/__main__.py +++ b/nicsoft/niclink/__main__.py @@ -295,10 +295,10 @@ def signal_lights(self, sig_num: int) -> None: [ "11111111", "10000001", - "10000001", - "10000001", - "10000001", - "10000001", + "10111101", + "10100101", + "10100101", + "10111101", "10000001", "11111111", ], @@ -342,14 +342,14 @@ def signal_lights(self, sig_num: int) -> None: """Signal 4 - center line""" sig = np.array( [ - "00000000", + "11111111", "00000000", "00000000", "11111111", "11111111", "00000000", "00000000", - "00000000", + "11111111", ], dtype=np.str_, ) @@ -359,12 +359,12 @@ def signal_lights(self, sig_num: int) -> None: sig = np.array( [ "00011000", - "00011000", + "01011010", "00011000", "11111111", "11111111", "00011000", - "00011000", + "01011010", "00011000", ], dtype=np.str_, @@ -387,6 +387,10 @@ def signal_lights(self, sig_num: int) -> None: ) self.set_all_LEDs(sig) + if self.last_move is not None: + time.sleep(0.3) + self.set_move_LEDs(self.last_move) + def get_FEN(self) -> str: """get the board FEN from chessboard""" fen = self.nl_interface.get_FEN() diff --git a/nicsoft/test/__main__.py b/nicsoft/test/__main__.py index e1f00e8..6117142 100644 --- a/nicsoft/test/__main__.py +++ b/nicsoft/test/__main__.py @@ -8,8 +8,10 @@ print("NicLink: Running all tests") import logging +import time import chess +import numpy as np import readchar import test_niclink_board_compairison as nlbc import test_niclink_FEN as nlf @@ -18,6 +20,32 @@ from niclink import NicLinkManager +ONES = np.array( + [ + "11111111", + "11111111", + "11111111", + "11111111", + "11111111", + "11111111", + "11111111", + "11111111", + ], + dtype=np.str_, +) +ZEROS = np.array( + [ + "00000000", + "00000000", + "00000000", + "00000000", + "00000000", + "00000000", + "00000000", + "00000000", + ], + dtype=np.str_, +) global logger logger = logging.getLogger("test_all") @@ -43,7 +71,7 @@ def test_usb(): nl_man.set_move_LEDs("e2e4") readchar.readchar() print("BOARD CLEAR, press a key") - nl_man.set_all_LEDs(nl_man.ZEROS) + nl_man.set_all_LEDs(ZEROS) readchar.readchar() @@ -52,19 +80,25 @@ def test_usb(): readchar.readchar() print("(test usb connection) testing set_all_LEDs.") - # create a np.array of all true - nl_man.set_all_LEDs(nl_man.ONES) + nl_man.set_all_LEDs(ONES) print("all the lights should be on, confirm and press enter") readchar.readchar() - nl_man.set_all_LEDs(nl_man.ZEROS) + nl_man.set_all_LEDs(ZEROS) print("all the lights should be off, confirm and press enter") readchar.readchar() + print( + "testing man.signal_lights(). lights should flash on and return to showing last move" + ) + nl_man.signal_lights(1) + print("(test usb connection) set up the board and press enter.") nl_man.show_game_board() - print("= set up cb, and test move parsing and set_move_LEDs(move) ") + print( + "Now, make a move on the board and test move geting. Press return when ready. This is the last test." + ) readchar.readkey() while True: @@ -74,6 +108,11 @@ def test_usb(): print(move) time.sleep(2) + print( + "testing man.signal_lights(). lights should flash on and return to showing last move" + ) + nl_man.signal_lights(1) + if __name__ == "__main__": diff --git a/testNicLink.sh b/testNicLink.sh index 682fe03..f691eb1 100755 --- a/testNicLink.sh +++ b/testNicLink.sh @@ -1,8 +1,10 @@ #!/usr/bin/env bash -# enter the python venv -echo "must be in script dir" +SCRIPT_DIR=$( dirname $( readlink -m $( type -p ${0} ))) + +cd $SCRIPT_DIR +# enter the python venv source ./activate python ./nicsoft/test/__main__.py