Hardware package¶
The hardware package contains all software required to interface with the hardware
Hardware.HardwareInterface¶
-
class
Hardware.HardwareInterface.
Offer
(value)[source]¶ Bases:
enum.Enum
An enumeration.
-
CONTINUE
= 0¶
-
DRAW
= 1¶
-
RESIGN
= 2¶
-
-
class
Hardware.HardwareInterface.
HardwareInterface
[source]¶ Bases:
abc.ABC
Defines interface to the hardware
-
abstract
mark_squares
(squares: List[List[bool]]) → None[source]¶ Marks squares on the chessboard where squares is an 8x8 matrix implemented as a 2s list
Note that squares are mapped as squares[file][rank] ie. a1 = squares[0][0], a2 = squares[0][1], b1 = squares[1][0] and h8 = squares[7][7]
- Parameters
squares – 8x8 matrix of squares to mark on the chessboard where square [file][rank] is marked if square[file][rank] == TRUE
-
abstract
get_occupancy
() → List[List[bool]][source]¶ Returns all occupied squares as 8x8 matrix implemented as a 2d list
Note that squares are mapped as squares[file][rank] so if square a2 is occupied then get_occupancy[0][1] equals TRUE :return: 8x8 matrix with all occupied squares on the chessboard
-
promotion_piece
() → chess.Piece[source]¶ Which piece to promote to
- Returns
Piece to promote to if not reimplemented returns queen
-
game_end_offers
() → Hardware.HardwareInterface.Offer[source]¶ Returns continue, draw or return offers
- Returns
Always returns continue
-
abstract
Hardware.HardwareImplementation¶
-
class
Hardware.HardwareImplementation.
HardwareImplementation
[source]¶ Bases:
Hardware.HardwareInterface.HardwareInterface
Interface to Hardware chessboard
-
mark_squares
(squares: List[List[bool]]) → None[source]¶ Marks squares on the chessboard where squares is an 8x8 matrix implemented as a 2s list
Note that squares are mapped as squares[file][rank] ie. a1 = squares[0][0], a2 = squares[0][1], b1 = squares[1][0] and h8 is squares[7][7]
- Parameters
squares – 8x8 matrix of squares to mark on the chessboard where square [file][rank] is marked if square[file][rank] == TRUE
-
get_occupancy
() → List[List[bool]][source]¶ Returns all occupied squares as 8x8 matrix implemented as a 2d list
Note that squares are mapped as squares[file][rank] so if square a2 is occupied then get_occupancy[0][1] is TRUE
- Returns
8x8 matrix with all occupied squares on the chessboard
-
promotion_piece
() → chess.Piece[source]¶ Which piece to promote to
Reads input button to select promotion piece, writes selected piece to display and waits for confirmation
- Returns
Piece to promote to
-
game_end_offers
() → Hardware.HardwareInterface.Offer[source]¶ Returns continue, draw or return offers
If no button pressed returns continue, otherwise wait for confirmation
- Returns
Always returns continue
-
Hardware.SafeDecorator¶
-
Hardware.SafeDecorator.
perform_safe_factory
(reset: Optional[Callable[[None], None]] = None, max_tries: int = 5) → Callable[[Callable[[Any], Any]], Callable[[Any], Any]][source]¶ Factory to create a decorator to perform an i2c operation safely
This factory returns the perform_safe decorator. This decorator will try to execute a function until it succeeds or until max_tries have failed. If a tca is supplied then the factory will also reset the tca lock after every SOError.
- Parameters
reset – Any other function to execute when recovering from an error
max_tries – Maximum amount of times that an operation will be attempted
- Returns
The decorator perform safe
-
Hardware.SafeDecorator.
perform_safe
(func: Callable[[Any], Any]) → Callable[[Any], Any]¶ ” Tries to execute func until no OSError is thrown or TRIES attempts have failed
The i2c buss is sensitive to noise. Corrupted messages can trigger an OSError on the buss device. We can recover from this error by simply resending the message until it arrives correctly. This method accepts a function func which could trigger an OSError which would cause the program to fail. We can easily recover from this error by retrying ‘func’ if the error is cause by noise. The perform safe decorator makes sure that an error is only trow if the operation fails max_tries times. Because of an error in the adafruit libraries the tca can soft lock after an exception. Resetting the lock to false after an exception prevents the errors
- Parameters
func – function to be executed
- Returns
function which executes func until it either succeeds or max_tries attempts have failed
- Return type
Same as func