chiark / gitweb /
works (although we do not know why 02-07 etc. in pm_detect seem to have to be backwards
authorian <ian>
Sat, 31 Dec 2005 18:42:19 +0000 (18:42 +0000)
committerian <ian>
Sat, 31 Dec 2005 18:42:19 +0000 (18:42 +0000)
hostside/stopgap-controller

index ae8aa5c45bac29b86086eecd5aaabe134c7c0ee8..8669edae69ab5ab62f960c09a48b6a6762b86e88 100755 (executable)
@@ -10,8 +10,9 @@ set ch(scale) 1
 
 set ch(minint) 5000
 # unset always
-set always 0
+set always 0
 set nmrawhich 0
+set lastptchosen xx
 
 set polmsg(l) 908000
 set polmsg(x) 90f802
@@ -22,7 +23,7 @@ set segs {xx yy}
 set segsasgot {xx yy}
 set pq {} ;# unset: cdu charged and waiting
 set speeddirn ff7f
-set speeddirn_fixed {speed126 2 60 0}
+set speeddirn_fixed {speed126 2 80 0}
 set funcs ff7f
 # unset pointpos($point)
 # unset segdetect($seg) ;# unset: shown D0; {}: shown D1; or: after id, D1->0
@@ -124,6 +125,11 @@ proc pt_must {point newpos} {
     pt_now immed $point $pos {}
     set pq {}
 }
+proc pt_ifthenmust {ifpoint ifposwant thenpoint thenpos} {
+    upvar #0 pointpos($ifpoint) ifpos
+    if {![info exists ifpos] || $ifpos != $ifposwant} return
+    pt_must $thenpoint $thenpos
+}
 
 proc pm_charged {} {
     global pq
@@ -145,10 +151,12 @@ proc randbyte {} {
 }
 
 proc pt_maybe {point oneisright} {
-    global always
+    global always lastptchosen
     if {[info exists always]} {
        set pos $always
     } else {
+       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)"
@@ -232,16 +240,14 @@ proc pm_detect {seg} {
        0b { pt_must "40 41 X8" 0 }
        16 - 1c { pt_must "02 03 A5" 0 }
        1a - 10 { pt_must "42 43 A6" 0 }
+       14 { pt_ifthenmust "02 03 A5" 1 "42 43 A6" 1 }
+       20 { pt_ifthenmust "42 43 A6" 1 "02 03 A5" 1 }
     }
     switch -exact [join $segs -] {
-       14-20 { pt_must "42 43 A6" 1 }
-       20-14 { pt_must "02 03 A5" 1 }
-    }
-    switch -exact [join $segs -] {
-       07-02 { pt_maybe "00 01 X7" 0 }
-       02-07 { pt_maybe "02 03 A5" 1 }
-       06-09 { pt_maybe "40 41 X8" 1 }
-       09-06 { pt_maybe "42 43 A6" 0 }
+       02-07 { pt_maybe "00 01 X7" 0 }
+       07-02 { pt_maybe "02 03 A5" 1 }
+       09-06 { pt_maybe "40 41 X8" 1 }
+       06-09 { pt_maybe "42 43 A6" 0 }
     }
 }