17 namespace eval ExtHardware {
19 set engine "dgtdrv2.i686"
20 set port "/dev/ttyUSB0"
28 set bindbutton "::novag::connect"
34 proc saveHardwareOptions {} {
37 tk_messageBox -title "Scid: Unable to write file" -type ok -icon warning \
38 -message "Unable to write options file: [
scidConfigFile InputEngine]\n$optionF"
40 puts $optionF "# Scid options file"
41 puts $optionF "# Version: $::scidVersion, $::scidVersionDate"
42 puts $optionF "# This file contains commands in the Tcl language format."
43 puts $optionF "# If you edit this file, you must preserve valid Tcl"
44 puts $optionF "# format or it will not set your Scid options properly."
47 foreach i { ::ExtHardware::engine \
49 ::ExtHardware::param \
50 ::ExtHardware::hardware \
51 ::ExtHardware::showbutton \
52 ::ExtHardware::bindbutton } {
53 puts $optionF "set $i [list [
set $i]]"
58 set ::statusBar "External hardware options were saved to: [
scidConfigFile correspondence]"
61 if { [
winfo exists .main.fbutton.button.exthardware]} {
64 if { $::ExtHardware::showbutton == 1 } {
66 ttk::frame .main.fbutton.button.space4 -width 15
67 button .main.fbutton.button.exthardware -image tb_eng_disconnected
68 .main.fbutton.button.exthardware configure -relief flat -border 1 -highlightthickness 0 \
69 -anchor n -takefocus 0
70 bind .main.fbutton.button.exthardware <Any-Enter> "+.main.fbutton.button.exthardware configure -relief groove"
71 bind .main.fbutton.button.exthardware <Any-Leave> "+.main.fbutton.button.exthardware configure -relief flat; break"
72 pack .main.fbutton.button.space4 .main.fbutton.button.exthardware -side left -pady 1 -padx 0 -ipadx 0 -pady 0 -ipady 0
73 pack .main.fbutton.button.exthardware -side left -pady 1 -padx 0 -ipadx 0 -pady 0 -ipady 0
75 .main.fbutton.button.exthardware configure -command $::ExtHardware::bindbutton
84 proc HWbuttonImg {img} {
86 if { $::ExtHardware::showbutton == 1 } {
87 .main.fbutton.button.exthardware configure -image $img -relief flat
94 proc HWbuttonBind {cmd} {
96 if { $::ExtHardware::showbutton == 1 } {
97 set ::ExtHardware::bindbutton $cmd
107 global ::ExtHardware::port ::ExtHardware::engine ::ExtHardware::param ::ExtHardware::hardware
111 set w .exthardwareConfig
112 if { [
winfo exists $w]} {
return}
115 wm title $w [
::tr ExtHWConfigConnection]
117 ttk::label $w.lport -text [
::tr ExtHWPort]
118 ttk::entry $w.eport -width 50 -textvariable ::ExtHardware::port
120 ttk::label $w.lengine -text [
::tr ExtHWEngineCmd]
121 ttk::entry $w.eengine -width 50 -textvariable ::ExtHardware::engine
123 ttk::label $w.lparam -text [
::tr ExtHWEngineParam]
124 ttk::entry $w.eparam -width 50 -textvariable ::ExtHardware::param
126 ttk::label $w.options -text [
::tr ExtHWHardware]
128 ttk::checkbutton $w.showbutton -text [
::tr ExtHWShowButton] -variable ::ExtHardware::showbutton
132 ttk::radiobutton $w.novag -text [
::tr ExtHWNovag] -variable ::ExtHardware::hardware -value 1 -command { \
133 set ::ExtHardware::bindbutton "::novag::connect"
134 .exthardwareConfig.eengine configure -state disabled
135 .exthardwareConfig.eparam configure -state disabled
137 ttk::radiobutton $w.inputeng -text [
::tr ExtHWInputEngine] -variable ::ExtHardware::hardware -value 2 -command { \
138 set ::ExtHardware::bindbutton "::inputengine::connectdisconnect"
139 .exthardwareConfig.eengine configure -state normal
140 .exthardwareConfig.eparam configure -state normal
144 if { $::ExtHardware::hardware == 1 } {
145 .exthardwareConfig.eengine configure -state disabled
146 .exthardwareConfig.eparam configure -state disabled
149 ttk::frame $w.buttons
150 ttk::button $w.bOk -text OK -command { ::ExtHardware::saveHardwareOptions
151 ::ExtHardware::HWbuttonBind $::ExtHardware::bindbutton
152 destroy .exthardwareConfig
153 $::ExtHardware::bindbutton
155 ttk::button $w.bCancel -text [
::tr Cancel] -command "::ExtHardware::HWbuttonImg tb_eng_disconnected ; destroy $w"
158 grid $w.options -stick ew -row 0 -column 0
159 grid $w.novag -stick w -row 0 -column 1
160 grid $w.inputeng -stick w -row 1 -column 1
162 grid $w.lport -stick ew -row 2 -column 0
163 grid $w.eport -row 2 -column 1
165 grid $w.lengine -stick ew -row 3 -column 0
166 grid $w.eengine -row 3 -column 1
168 grid $w.lparam -stick ew -row 4 -column 0
169 grid $w.eparam -row 4 -column 1
171 grid $w.showbutton -stick w -row 5 -column 1
173 grid $w.buttons -sticky news -row 6 -column 0 -columnspan 2
174 bind $w <F1> { helpWindow HardwareConfig}
186 if { $::ExtHardware::showbutton == 1 } {
188 ttk::frame .main.fbutton.button.space4 -width 15
189 button .main.fbutton.button.exthardware -image tb_eng_disconnected
190 .main.fbutton.button.exthardware configure -relief flat -border 1 -highlightthickness 0 \
191 -anchor n -takefocus 0
192 bind .main.fbutton.button.exthardware <Any-Enter> "+.main.fbutton.button.exthardware configure -relief groove"
193 bind .main.fbutton.button.exthardware <Any-Leave> "+.main.fbutton.button.exthardware configure -relief flat; break"
194 pack .main.fbutton.button.space4 .main.fbutton.button.exthardware -side left -pady 1 -padx 0 -ipadx 0 -pady 0 -ipady 0
195 pack .main.fbutton.button.exthardware -side left -pady 1 -padx 0 -ipadx 0 -pady 0 -ipady 0
197 .main.fbutton.button.exthardware configure -command $::ExtHardware::bindbutton
200 ::splash::add "External hardware configuration was found and loaded."
207 namespace eval inputengine {
208 global ::ExtHardware::port ::ExtHardware::engine ::ExtHardware::param ::ExtHardware::hardware
210 set engine $::ExtHardware::engine
211 set port $::ExtHardware::port
212 set param $::ExtHardware::param
214 set InputEngine(pipe) ""
215 set InputEngine(log) ""
216 set InputEngine(logCount) 0
217 set InputEngine(init) 0
218 set connectimg tb_eng_ok
219 set MovingPieceImg $::board::letterToPiece(.)80
222 set NoClockTime "--:--"
225 set WhiteClock $::inputengine::NoClockTime
226 set BlackClock $::inputengine::NoClockTime
227 set oldWhiteClock $::inputengine::NoClockTime
228 set oldBlackClock $::inputengine::NoClockTime
231 font create moveFont -family Helvetica -size 56 -weight bold
236 proc consoleWindow {} {
238 set w .inputengineconsole
239 if { [
winfo exists $w]} {
245 $w configure -background [ttk::style lookup . -background]
248 ttk::scrollbar $w.ysc -command { .inputengineconsole.console yview }
249 text $w.console -height 5 -width 80 -wrap word -yscrollcommand "$w.ysc set"
251 ttk::label $w.lmode -text [
::tr IESending]
254 $w.bd configure -relief solid -borderwidth 1
256 ttk::label $w.engine -text "$::ExtHardware::engine $::ExtHardware::port $::ExtHardware::param"
258 ttk::radiobutton $w.sendboth -text [
::tr Both] -variable send -value 1 -command { ::inputengine::sendToEngine sendboth }
259 ttk::radiobutton $w.sendwhite -text [
::tr White] -variable send -value 2 -command { ::inputengine::sendToEngine sendwhite }
260 ttk::radiobutton $w.sendblack -text [
::tr Black] -variable send -value 3 -command { ::inputengine::sendToEngine sendblack }
262 ttk::button $w.bInfo -text Info -command { ::inputengine::sysinfo }
265 ttk::button $w.bRotate -text [
::tr IERotate] -command { ::inputengine::rotateboard }
267 ttk::button $w.bSync -text [
::tr IESynchronise] -command { ::inputengine::synchronise }
268 ttk::button $w.bClose -text [
::tr Close] -command { ::inputengine::connectdisconnect }
271 button $w.bPiece -image $inputengine::MovingPieceImg
272 button $w.bMove -font moveFont -text $inputengine::MoveText
273 $w.bPiece configure -relief flat -border 0 -highlightthickness 0 -takefocus 0
274 $w.bMove configure -relief flat -border 0 -highlightthickness 0 -takefocus 0
277 button $w.wClock -text $inputengine::WhiteClock
278 button $w.bClock -text $inputengine::BlackClock
279 $w.wClock configure -relief flat -border 0 -highlightthickness 0 -takefocus 0
280 $w.bClock configure -relief flat -border 0 -highlightthickness 0 -takefocus 0
284 ttk::checkbutton $w.bStoreClock -text "Store Clock" -variable ::inputengine::StoreClock
286 grid $w.console -stick ns -column 0 -row 0 -columnspan 12
287 grid $w.ysc -stick ns -column 12 -row 0
289 grid $w.engine -stick ewns -column 0 -row 1 -columnspan 9
291 grid $w.lmode -stick ew -column 0 -row 2
292 grid $w.sendboth -stick e -column 2 -row 2
293 grid $w.sendwhite -column 4 -row 2
294 grid $w.sendblack -stick w -column 6 -row 2
296 grid $w.bInfo -stick ew -column 0 -row 3
298 grid $w.bSync -stick ew -column 0 -row 5
299 grid $w.bStoreClock -stick ew -column 0 -row 6
300 grid $w.bClose -stick ew -column 0 -row 11
302 grid $w.bPiece -stick nwes -column 2 -row 3 -rowspan 9 -columnspan 3
303 grid $w.bMove -stick nwes -column 5 -row 3 -rowspan 9 -columnspan 3
305 grid $w.wClock -stick nwes -column 9 -row 11 -columnspan 7
306 grid $w.bClock -stick nwes -column 9 -row 1 -columnspan 7
308 grid $w.bd -stick nw -column 9 -row 2 -rowspan 9 -columnspan 7
310 bind $w <Destroy> { catch ::inputengine::connectdisconnect }
311 bind $w <F1> { helpWindow InputEngine}
316 proc updateConsole {line} {
317 set t .inputengineconsole.console
318 $t insert end "$line\n"
327 proc connectdisconnect {} {
328 global ::inputengine::InputEngine
330 set connection $::inputengine::InputEngine(pipe)
332 if {$connection == ""} {
346 global ::inputengine::InputEngine ::inputengine::engine \
347 ::inputengine::port ::inputengine::param
349 set ::inputengine::engine $::ExtHardware::engine
350 set ::inputengine::port $::ExtHardware::port
351 set ::inputengine::param $::ExtHardware::param
355 if {[
catch {
set InputEngine(pipe) [open "| $engine $port $param" "r+"]} result]} {
357 tk_messageBox -title "Scid: Input Engine" -icon warning -type ok \
358 -message "[
::tr IEUnableToStart]\n$engine $port $param"
371 global ::inputengine::InputEngine
372 set pipe $::inputengine::InputEngine(pipe)
374 set ::inputengine::connectimg tb_eng_connecting
378 set ::inputengine::connectimg tb_eng_disconnected
380 if { [
winfo exists ::inputengine::.inputengineconsole]} {
381 destroy ::inputengine::.inputengineconsole
389 proc logEngine {msg} {
397 proc sendToEngine {msg} {
398 global ::inputengine::InputEngine
399 set pipe $::inputengine::InputEngine(pipe)
411 global ::inputengine::InputEngine
412 set pipe $::inputengine::InputEngine(pipe)
415 set pipe $::inputengine::InputEngine(pipe)
416 fconfigure $pipe -buffering full -blocking 0
418 fileevent $pipe readable "::inputengine::readFromEngine"
427 proc resetEngine {} {
428 global ::inputengine::InputEngine
431 destroy .inputengineconsole
432 set ::inputengine::InputEngine(pipe) ""
433 set ::inputengine::InputEngine(log) ""
434 set ::inputengine::InputEngine(logCount) 0
435 set ::inputengine::InputEngine(init) 0
444 global ::inputengine::InputEngine
445 set pipe $::inputengine::InputEngine(pipe)
455 proc rotateboard {} {
456 global ::inputengine::InputEngine
457 set pipe $::inputengine::InputEngine(pipe)
477 sc_game tags set -event "InputEngine Input"
485 proc endgame {result} {
489 logEngine " info End Game $filternum: $result"
491 sc_game tags set -result $result
499 proc synchronise {} {
500 global ::inputengine::InputEngine
503 set InputEngine(init) 0
509 proc strreverse {str} {
511 set i [
string length $str]
512 while {$i > 0} {
append res [
string index $str [
incr i -1]]}
521 proc readFromEngine {} {
522 global ::inputengine::InputEngine ::inputengine::connectimg
523 set pipe $::inputengine::InputEngine(pipe)
525 set line [
string trim [
gets $pipe]]
534 switch -regexp -- $line \
536 set m [
string range $line 5 end]
538 set s1 [
string range $m 0 1]
539 set s2 [
string range $m 2 end]
549 if {[
catch {
sc_move addSan $m}]} {
553 .inputengineconsole.bPiece configure -background red
554 .inputengineconsole.bMove configure -background red -text $m
557 .inputengineconsole.bPiece configure -background green
558 .inputengineconsole.bMove configure -background green -text $m
568 set event [
string range $line 5 end]
569 switch -regexp -- $event \
571 set err [
string range $event 7 end]
572 tk_messageBox -title "Scid: Input Engine" \
573 -icon warning -type ok -message "Engine $err"
578 "string Chessboard found and initialised*" {
584 "Engine mode : xboard*" {
589 set InputEngine(init) 0
598 set fenstr [
string range $event 4 end]
599 set fenstr [
string trim $fenstr]
600 if { $::inputengine::InputEngine(init) == 0 } {
603 catch {
sc_game startBoard $fenstr}
605 set InputEngine(init) 1
615 set space [
string first " " $fenstr]
616 set fen [
string range $fenstr 0 $space]
618 set space [
string first " " [
sc_pos fen]]
619 set int [
string range [
sc_pos fen] 0 $space]
623 logEngine " info Wrong Position! $int (scid) != $fen (external)"
625 logEngine " info Board and internal position match."
646 {moving piece: [A-Z] *} {
647 .inputengineconsole.bPiece configure -image $::board::letterToPiece([
string range $event 14 end])80
649 {moving piece: [a-z] *} {
650 .inputengineconsole.bPiece configure -image $::board::letterToPiece([
string range $event 14 end])80
654 .inputengineconsole.bPiece configure -background blue
655 .inputengineconsole.bMove configure -background blue -text "OK"
656 .inputengineconsole.bPiece configure -image $::board::letterToPiece(K)80
664 .inputengineconsole.bPiece configure -background white
665 .inputengineconsole.bMove configure -background white -text "1-0"
666 .inputengineconsole.bPiece configure -image $::board::letterToPiece(K)80
671 .inputengineconsole.bPiece configure -background gray
672 .inputengineconsole.bMove configure -background gray -text "0-1"
673 .inputengineconsole.bPiece configure -image $::board::letterToPiece(k)80
675 "!end game 1/2-1/2!" {
678 .inputengineconsole.bPiece configure -background black
679 .inputengineconsole.bMove configure -background white -text "1/2-1/2"
680 .inputengineconsole.bPiece configure -image $::board::letterToPiece(.)80
682 "!enter setup mode!" {
683 .inputengineconsole.bPiece configure -background yellow
684 .inputengineconsole.bMove configure -background yellow -text "Setup"
685 .inputengineconsole.bPiece configure -image $::board::letterToPiece(K)80
691 .inputengineconsole.bPiece configure -background yellow
692 .inputengineconsole.bMove configure -background yellow -text "OK"
693 .inputengineconsole.bPiece configure -image $::board::letterToPiece(q)80
696 set ::inputengine::toMove "White"
697 .inputengineconsole.wClock configure -background white
698 .inputengineconsole.bClock configure -background gray -foreground black
700 if {$::inputengine::StoreClock == 1} {
701 if { ($::inputengine::oldWhiteClock != $::inputengine::NoClockTime) && \
702 ($::inputengine::WhiteClock != $::inputengine::NoClockTime) } {
703 set wHrs [
expr $::inputengine::WhiteClock / 60 / 60]
704 set wMin [
expr ($::inputengine::WhiteClock - $wHrs*60*60) / 60]
705 set wSec [
expr ($::inputengine::WhiteClock - $wHrs*60*60 - $wMin * 60)]
706 set timediff [
expr $::inputengine::oldWhiteClock - $::inputengine::WhiteClock]
707 set ::inputengine::oldWhiteClock $::inputengine::WhiteClock
708 sc_pos setComment "\[%ct $wHrs:$wMin:$wSec\] \[%emt $timediff\]"
713 set ::inputengine::toMove "Black"
714 .inputengineconsole.wClock configure -background gray
715 .inputengineconsole.bClock configure -background black -foreground white
717 if {$::inputengine::StoreClock == 1} {
718 if { ($::inputengine::oldBlackClock != $::inputengine::NoClockTime) && \
719 ($::inputengine::BlackClock != $::inputengine::NoClockTime) } {
720 set bHrs [
expr $::inputengine::BlackClock / 60 / 60]
721 set bMin [
expr ($::inputengine::BlackClock - $bHrs*60*60) / 60]
722 set bSec [
expr ($::inputengine::BlackClock - $bHrs*60*60 - $bMin * 60)]
723 set timediff [
expr $::inputengine::oldBlackClock - $::inputengine::BlackClock]
724 set ::inputengine::oldBlackClock $::inputengine::BlackClock
725 sc_pos setComment "\[%ct $bHrs:$bMin:$bSec\] \[%emt $timediff\]"
729 "No Clock detected" {
730 set ::inputengine::WhiteClock $::inputengine::NoClockTime
731 set ::inputengine::BlackClock $::inputengine::NoClockTime
732 .inputengineconsole.wClock configure -text $::inputengine::WhiteClock
733 .inputengineconsole.bClock configure -text $::inputengine::BlackClock
736 if { ($::inputengine::oldWhiteClock == $::inputengine::NoClockTime) } {
737 set ::inputengine::oldWhiteClock $::inputengine::WhiteClock
740 regsub -all {[A-Za-z:# ]} $event "" ::inputengine::WhiteClock
743 set wHrs [
expr $::inputengine::WhiteClock / 60 / 60]
744 set wMin [
expr ($::inputengine::WhiteClock - $wHrs*60*60) / 60]
745 set wSec [
expr ($::inputengine::WhiteClock - $wHrs*60*60 - $wMin * 60)]
748 .inputengineconsole.wClock configure -text "$wHrs:$wMin:$wSec (EXT)"
750 .inputengineconsole.wClock configure -text "$wMin:$wSec (EXT)"
757 if { ($::inputengine::oldBlackClock == $::inputengine::NoClockTime) } {
758 set ::inputengine::oldBlackClock $::inputengine::BlackClock
760 regsub -all {[A-Za-z:# ]} $event "" ::inputengine::BlackClock
762 set bHrs [
expr $::inputengine::BlackClock / 60 / 60]
763 set bMin [
expr ($::inputengine::BlackClock - $bHrs*60*60) / 60]
764 set bSec [
expr ($::inputengine::BlackClock - $bHrs*60*60 - $bMin * 60)]
767 .inputengineconsole.bClock configure -text "$bHrs:$bMin:$bSec (EXT)"
769 .inputengineconsole.bClock configure -text "$bMin:$bSec (EXT)"
775 "Wrong move performed:" {
784 "DGT Projects - This DGT board" {
785 set ::inputengine::connectimg tb_eng_dgt
786 set txt [
string range $event 7 end]