chiark / gitweb /
speed/dirn request immediate
[trains.git] / hostside / stopgap-controller
index 3b3348f24d2ab92ccfc0a7f2d381ef884f074451..df5595bcdb67f72b495c65faed53dd4396fce364 100755 (executable)
@@ -390,19 +390,23 @@ proc newfuncs {} {
     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"
@@ -419,7 +423,7 @@ proc maybechange {thing} {
 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
@@ -476,14 +480,17 @@ proc setup_complete {} {
 #----------
 # 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 10 0}
+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 }