esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

global ZOOM_LIGHT[]
global ZOOM_LIGHT_SETUP_DONE

def zoomlightsetup '{
  local zoom_ho, n_positions, i, pos, positions, position_offset

  unglobal ZOOM_LIGHT
  global ZOOM_LIGHT[]

  ZOOM_LIGHT_SETUP_DONE=0

  if (MINIDIFF_SETUP == 1) {
    zoom_ho = MINIDIFF["zoom"]["ho"]
    zoom_motor = MINIDIFF["zoom"]
    light_motor = MINIDIFF["light"]
    ZOOM_LIGHT["zoom_motor"]=zoom_motor
    ZOOM_LIGHT["light_motor"]=light_motor
  } else {
    printf("Minidiff setup is not done: cannot continue with zoomlight setup\n")
    exit
  }

  zoom_motor = motor_num(zoom_motor)
  light_motor = motor_num(light_motor)

  if ((zoom_motor == -1)||(light_motor == -1)) {
    eprintf("%s: invalid motors, not in Spec config !", "$0")
    exit
  }

  if (xml_read(zoom_ho, "/device/positions/position/offset") != 0) {
      eprintf("Cannot obtain predefined positions for motor %s", motor_mne(mnum))
  } else {
    n_positions = asso_len(XML_tmp)
    for (i=0; i<n_positions; i++) {
      position_offset = XML_tmp[i]["__value__"]
      positions[i] = position_offset
      ZOOM_LIGHT[zoom_motor][position_offset] = 0
    }

    if (xml_read(zoom_ho, "/device/positions/position/lightLevel") != 0) {
      eprintf("Cannot obtain light level for motor %s", motor_mne(mnum))
    } else {
      for (i=0; i<n_positions; i++) {
        pos = positions[i]
        ZOOM_LIGHT[zoom_motor][pos] = XML_tmp[i]["__value__"]
      }
    }
  }

  ZOOM_LIGHT_SETUP_DONE = 1
}'


def zoom_premove '{
  local zoom_mot light_mot offset

  zoom_mot = motor_num(ZOOM_LIGHT["zoom_motor"])
  light_mot = motor_num(ZOOM_LIGHT["light_motor"])

  if ( A[zoom_mot] != ZOOM_LIGHT["old_zoom_pos"] ) {
       ZOOM_LIGHT["old_zoom_pos"] = A[zoom_mot]

       # find where to put light
       offset = A[zoom_mot]
       if (offset in ZOOM_LIGHT[zoom_mot]) {
          printf("Moving zoom to %s, adjusting light level to %s\n", offset, ZOOM_LIGHT[zoom_mot][offset])
          A[light_mot] = ZOOM_LIGHT[zoom_mot][offset]
       }
  } 
}'


def zoomlighton '{
   if (ZOOM_LIGHT_SETUP_DONE == 1) {
     ZOOM_LIGHT["old_zoom_pos"]=-1
     cdef("user_premove", "zoom_premove\n", "zoomlight", 0x10 )
   } else {
     printf("%s: please run zoomsetuplight before.", "$0")
     exit 
   }
}'


def zoomlightoff '{
   cdef("", "", "zoomlight", "delete" )
}'