forked from jromang/picochess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dgtvr.py
106 lines (92 loc) · 4 KB
/
dgtvr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Copyright (C) 2013-2016 Jean-Francois Romang ([email protected])
# Shivkumar Shivaji ()
# Jürgen Précour ([email protected])
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import chess
from dgtiface import *
from utilities import RepeatedTimer
class DgtVr(DgtIface):
def __init__(self, dgtserial, dgttranslate):
super(DgtVr, self).__init__(dgtserial, dgttranslate)
# virtual lib
self.rt = None
self.time_side = ClockSide.NONE
# setup virtual clock
main = 2 if dgtserial.is_pi else 0
DisplayMsg.show(Message.DGT_CLOCK_VERSION(main=main, sub=0, attached='virtual'))
# (START) dgtserial class simulation
def runclock(self):
if self.time_side == ClockSide.LEFT:
h, m, s = self.time_left
time_left = 3600*h + 60*m + s - 1
if time_left <= 0:
print('Clock flag: left')
self.rt.stop()
self.time_left = hours_minutes_seconds(time_left)
if self.time_side == ClockSide.RIGHT:
h, m, s = self.time_right
time_right = 3600*h + 60*m + s - 1
if time_right <= 0:
print('Clock flag: right')
self.rt.stop()
self.time_right = hours_minutes_seconds(time_right)
if self.maxtimer_running:
print('Clock maxtime not run out')
else:
print('Clock time: {} - {}'.format(self.time_left, self.time_right))
DisplayMsg.show(Message.DGT_CLOCK_TIME(time_left=self.time_left, time_right=self.time_right))
# (END) dgtserial simulation class
def display_move_on_clock(self, move, fen, side, beep=False, left_dots=0, right_dots=0):
if self.enable_dgt_3000:
bit_board = chess.Board(fen)
text = bit_board.san(move)
else:
text = str(move)
if side == ClockSide.RIGHT:
text = text.rjust(8 if self.enable_dgt_3000 else 6)
logging.debug(text)
print('Clock move: {} Beep: {}'. format(text, beep))
def display_text_on_clock(self, text, beep=False, left_dots=0, right_dots=0):
logging.debug(text)
print('Clock text: {} Beep: {}'. format(text, beep))
def display_time_on_clock(self, force=False):
if self.clock_running or force:
print('Clock showing time again - running state: {}'. format(self.clock_running))
else:
logging.debug('virtual clock isnt running - no need for endClock')
def stop_clock(self):
if self.rt:
print('Clock time stopped at {} - {}'. format(self.time_left, self.time_right))
self.rt.stop()
else:
print('Clock not ready')
self.clock_running = False
def resume_clock(self, side):
pass
def start_clock(self, time_left, time_right, side):
self.time_left = hours_minutes_seconds(time_left)
self.time_right = hours_minutes_seconds(time_right)
self.time_side = side
print('Clock time started at {} - {} on {}'. format(self.time_left, self.time_right, side))
if self.rt:
self.rt.stop()
if side != ClockSide.NONE:
self.rt = RepeatedTimer(1, self.runclock)
self.rt.start()
self.clock_running = (side != ClockSide.NONE)
def light_squares_revelation_board(self, squares):
pass
def clear_light_revelation_board(self):
pass