set ch(scale) 1
set ch(minint) 5000
-# unset always
-# set always 0
+
+#unset pointasked
+# 0 1 (settings) M0 M1 (manual, settings) unset (random) M (manual)
+
set nmrawhich 0
set lastptchosen xx
proc gui_init {} {
global watchdog polarity segdetect
gui "M A2 0"
-# gui "M A5 0 J"
-# gui "M A6 0 J"
+ gui "M A5 0 J"
+ gui "M A6 0 J"
+ gui "EOE"
if {[info exists watchdog]} { gui "P 1" }
gui_polarity
foreach seg [array names segdetect] {
catch { after cancel $watchdog; unset watchdog }
puts "failing $m"
tellpic 9801 ;# 16ms
- after 10000 fail_now
+ after 1000 fail_now
fileevent $p readable {}
}
pt_must $thenpoint $thenpos
}
+proc badwatchdog {} {
+ global pq
+ puts "watchdog - oh well"
+ if {![info exists pq]} { set pq {} }
+}
+
proc pm_charged {} {
global pq
if {[llength $pq]} {
}
proc pt_maybe {point oneisright} {
- global always lastptchosen
- if {[info exists always]} {
- set pos $always
- } else {
+ global pointasked lastptchosen
+ if {![info exists pointasked]} {
if {![string compare $point $lastptchosen]} return
set lastptchosen $point
set x [randbyte]
set pos [expr [regexp {^[89a-f]} $x] ? 1 : 0]
debug "chose point $point pos=$pos (x=$x)"
+ } elseif {[regexp {^M([01])$} $pointasked dummy pos]} {
+ if {[lsearch -exact {40 02} [lindex $point 0]] >= 0} {
+ set pos [expr {!$pos}]
+ debug "chose point $point pos=$pos manual-rl"
+ } else {
+ debug "chose point $point pos=$pos manual-lr"
+ }
+ set pointasked M
+ } elseif {![string compare $pointasked M]} {
+ debug "leave point $point pos=$pos manual"
+ return
+ } else {
+ debug "fixed point $point pos=$pos"
+ set pos $pointasked
}
pt_must $point $pos
}
01 - 02 { tellnmra $m }
09 { fp $m; pm_hello }
07 { puts "short circuit"; exit 1 }
+ 0d { fp $m; badwatchdog }
28 { fp $m; pm_charged }
9[0-7] { fp $m; pm_maydetect 0 $v }
9? { fp $m; pm_maydetect 1 $v }
return "funcs5to8 2 $value"
}
-proc maybechange {thing} {
+proc maybechange {thing force} {
global $thing ch
upvar #0 ${thing}_fixed fixed
if {![info exists fixed]} {
- set rb 0x[randbyte][randbyte]
- if {
- $rb / 65536.0 >
- 1.0 / (($ch(${thing}every) - $ch(minint)*0.001) * $ch(scale))
- } {
- debug "maybechange $thing rb=$rb no"
- return 0
+ if {$force} {
+ debug "maybechange $thing forced ..."
+ } else {
+ set rb 0x[randbyte][randbyte]
+ if {
+ $rb / 65536.0 >
+ 1.0 / (($ch(${thing}every) - $ch(minint)*0.001) * $ch(scale))
+ } {
+ debug "maybechange $thing rb=$rb no"
+ return 0
+ }
+ debug "maybechange $thing rb=$rb yes ..."
}
- debug "maybechange $thing rb=$rb yes ..."
set l [new$thing]
} else {
debug "fixed $thing $fixed"
proc changewhat {} {
global ch chwa
catch { after cancel $chwa }
- if {[maybechange speeddirn] || [maybechange funcs]} {
+ if {[maybechange speeddirn 0] || [maybechange funcs 0]} {
set interval $ch(minint)
} else {
set interval 1000
proc onreadcmd {} {
if {[gets stdin l] < 0} {
if {[eof stdin]} {
- puts stderr "stopgap-controller got eof, quitting"
puts "GUI exit 0"
- exit 0
+ fail "stopgap-controller got eof, quitting"
+ fileevent stdin readable {}
}
return
}
#----------
# for keyboard control
-proc ask_fast {} {
- global speeddirn_fixed; set speeddirn_fixed {speed126 2 126 0}
-}
-proc ask_slow {} {
- global speeddirn_fixed; set speeddirn_fixed {speed126 2 126 10}
+proc ask_speed_now {l} {
+ global speeddirn_fixed
+ set speeddirn_fixed $l
+ maybechange speeddirn 1
}
+
+proc ask_fast {} { ask_speed_now {speed126 2 126 0} }
+proc ask_slow {} { ask_speed_now {speed126 2 10 0} }
proc ask_randspeed {} {
global speeddirn_fixed; catch { unset speeddirn_fixed }
+ maybechange speeddirn 1
}
+proc ask_manual {rightp} { global pointasked; set pointasked M$rightp }
+proc ask_figureeightt {} { global pointasked; set pointasked 0 }
+proc ask_loop {} { global pointasked; set pointasked 1 }
+proc ask_randpath {} { global pointasked; catch { unset pointasked } }
+
setup
gui_init
vwait end