;switch1   --  tests switches on strip
;              2nd version: extracts switch to be investigated from
;              the other parts
;*****************************************************
#include timdefs.h

parms
  int windis
endparms
int tlr
int aant
int pos1
int pos2
int xfrm
int yfrm
int ok
int pat
int err

cls
print "Learning phase ..."
era p
era q
dest r
thre r 1
;err = chk lut 2 4
*selut 4
*windispl h (windis+NO_DITHER+WINLUT4)
dest s
thre s 1
*windispl i (windis+NO_DITHER)
tlr = 8
while tlr > 0
  dest p
  bit a tlr
  bord 1
  aant = label
  dest q
  era q
  mark p 2
  pos1 = curs
  mark p aant
  pos2 = curs
  drln pos1 pos2 255
  mark p 3
;pos1 = curs
;drln pos1 pos2 255
  mark q 255
  aant = frmt         ;reduce format
  xfrm = (aant & 255) - 2
  yfrm = ((aant >> 16) & 255) - 2
  frmt yfrm xfrm
  era
  curs p q   ; p
  copy pc qc
  bord qc 1
  aant = label
  if tlr == 8              ;first device
    ok = aant              ;learn value
    print @8 "  ... Known good device has", aant, "holes" 
    scroll
    print ""
    print "   Image         # holes       Result"
    pat = 2
  else
    if aant == ok
      print @5 (9-tlr), @20 aant, @35 " OK"
      pat = 2
    else
      print @5 (9-tlr), @20 aant, @32 " ERROR"
      pat = 1
    endif
  endif
  if tlr > 6
	dest r
    if tlr == 8 and r1 pat
    if tlr == 7 and r2 pat
    *windispl h (windis+NO_DITHER)
  elseif tlr > 4
	dest s
    if tlr == 6 and s1 pat
    if tlr == 5 and s2 pat
    *windispl i (windis+NO_DITHER)
  elseif tlr > 2
	dest r
    if tlr == 4 and r3 pat
    if tlr == 3 and r4 pat
    *windispl h (windis+NO_DITHER)
  else
	dest s
    if tlr == 2 and s3 pat
    if tlr == 1 and s4 pat
    *windispl i (windis+NO_DITHER)
  endif
  tlr -= 1
endw

stop

