Skip to content

Commit

Permalink
testing and lights: rehal of the test module, fix on signal lights
Browse files Browse the repository at this point in the history
added some prettyer signal_lights and made test script more all
encompasing
  • Loading branch information
nicvagn committed Aug 8, 2024
1 parent a0ae964 commit 8c83706
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 15 deletions.
20 changes: 12 additions & 8 deletions nicsoft/niclink/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ def signal_lights(self, sig_num: int) -> None:
[
"11111111",
"10000001",
"10000001",
"10000001",
"10000001",
"10000001",
"10111101",
"10100101",
"10100101",
"10111101",
"10000001",
"11111111",
],
Expand Down Expand Up @@ -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_,
)
Expand All @@ -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_,
Expand All @@ -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()
Expand Down
49 changes: 44 additions & 5 deletions nicsoft/test/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand 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()

Expand All @@ -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:
Expand All @@ -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__":

Expand Down
6 changes: 4 additions & 2 deletions testNicLink.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8c83706

Please sign in to comment.