Diff for /tclpuks/prgsrc/puks.tcl between versions 1.2 and 1.4

version 1.2, 2005/08/27 05:31:18 version 1.4, 2005/08/29 18:14:50
Line 1 Line 1
 #!/usr/bin/wish  #!/usr/bin/wish
 set DEVICE "/dev/ttyUSB0"  
   
 set SRLFILE [open $DEVICE r+]  ##############################################################
 fconfigure $SRLFILE -blocking 0  -translation binary -encoding binary -buffering none -mode  57600,n,8,1  #    Global flags and variables
   ##############################################################
 set idle 0  
 set waiting 1  # Flags
   set waiting_for_key 0
 set state $idle  set question_asked 0
   set timer_started 0
   
   # Channel to talk to the MRC device
   set MRC 0
   
   #  Mapping of MCR codes to keys:  button(code)
 set buttoncode 256  set buttoncode 256
 for {set i 1} {$i <=8} {incr i} {  for {set i 1} {$i <=8} {incr i} {
     set button($buttoncode) $i      set button($buttoncode) $i
     set buttoncode [expr $buttoncode*2]      set buttoncode [expr $buttoncode*2]
 }  }
   
   
   ##############################################################
   #  Procedures for talking with MRC
   ##############################################################
   
   # Open the given device for MRC.  Return 0 if successful, 1 otherwise
   proc open_mrc {device} {
       global MRC
       set result [catch {set MRC [open $device r+]}]
       if {$result !=0} {
           return $result
       }
       fconfigure $MRC -blocking 0  -translation binary \
           -encoding binary -buffering none -mode  57600,n,8,1
       
       puts $MRC s
       after 200
       read $MRC
       puts $MRC r
       after 200
       read $MRC
       return 0
   }
       
   
   
   # Return the key pressed or 0
 proc readbuffer {} {  proc readbuffer {} {
     global SRLFILE  button      global MRC  button
     set key 0      set key 0
     set message [read $SRLFILE]      set message [read $MRC]
     binary scan $message s key      binary scan $message s key
     set key [expr $key & 0xFFFF]      set key [expr $key & 0xFFFF]
     if {[catch {set key $button($key)}] == 0} {      if {[catch {set key $button($key)}] == 0} {
Line 28  proc readbuffer {} { Line 58  proc readbuffer {} {
     return 0      return 0
 }  }
   
 puts $SRLFILE s  ##############################################################
 after 200  #   Setup
 readbuffer  ##############################################################
 puts $SRLFILE r  
 after 200  
 readbuffer  
   
   
   
 button .start -text "Start" -command start  # Main menu
 pack .start  
 label .pressed   menu .mbar -type menubar -relief ridge -borderwidth 2
 pack .pressed  pack .mbar -fill x
   
   menubutton .mbar.file -text File -menu .mbar.file.m -underline 0 \
           -relief raised -borderwidth 2
   pack .mbar.file -side left 
   set m [menu .mbar.file.m]
   $m add command -label "Open" -state disabled
   $m add command -label "Save as..." -state disabled
   $m add command -label "Save" -state disabled
   $m add separator
   $m add command -label "Quit" -command exit
   
   menubutton .mbar.edit -text Edit -underline 0 -state disabled\
           -relief raised -borderwidth 2
   pack .mbar.edit -side left
   
   menubutton .mbar.help -text Help -menu .mbar.help.m -underline 0\
           -relief raised -borderwidth 2
   pack .mbar.help -side right
   set m [menu .mbar.help.m]
   $m add command -label "About..." -command {
       tk_dialog .about "About Puks" \
               "Система управления кнопками.
   (C) Teytelman, 2002 (MCR code)
   (C) Boris Veytsman, 2005 (Tcl/Tk version)"\
           info  0 "OK"}
       
   
   #Teams
   frame .teams 
   pack .teams -side top
   for {set  i 0} {$i < 8} {incr i} {
       frame .teams.frame($i) 
       pack .teams.frame($i) -side top -fill x
       label .teams.frame($i).button -text 0
       pack .teams.frame($i).button -side left
       entry .teams.frame($i).name -width 60 -textvariable name($i)
       pack .teams.frame($i).name -side left
       entry .teams.frame($i).score -width 6 -textvariable score($i)
       pack .teams.frame($i).score -side left
   }
   
   #  button .start -text "Start" -command start
   #  pack .start
   #  label .pressed 
   #  pack .pressed
   
   
 proc start {} {  proc start {} {
Line 56  proc body  {} { Line 128  proc body  {} {
     if { $state == $waiting } {      if { $state == $waiting } {
         set pressed [readbuffer]          set pressed [readbuffer]
         if { $pressed != 0 } {          if { $pressed != 0 } {
             set state $idle  #           set state $idle
             .start configure -state active -command start  #           .start configure -state active -command start
             .pressed configure -text "Pressed $pressed"              .pressed configure -text "Pressed $pressed"
             puts $pressed              puts $pressed
             readbuffer  }              readbuffer  }
Line 67  proc body  {} { Line 139  proc body  {} {
     after 10 body      after 10 body
 }  }
   
 body   #body 
   
   
   

Removed from v.1.2  
changed lines
  Added in v.1.4


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>