#----- ITC temperature controller ------
proc makeItc args {
  scanargs $args var -port 0
  makenv te itc -port $port
  Layout itc
}

proc itcLayout args {
#  if {[result lc t3] != 315.9} {
#    Style Warning
#    Label "connect magnet top sensor to channel 3"
#  }
  if {[string compare [sicsdescriptor te] notfound] == 0} return 
  Input "vti set temperature" "run te/[result te targetValue]"
  Group itc "ITC temperature controller"
}

proc nvItcGroup {} {
  nvPars nv nv
}

proc itcGroup {} {
  showStatus te

  Tip upper limit for the temperature set value
  Input "set limit" "te upperlimit"

  Tip Timeout for drive command \[sec\], 0 = infinite
  Input "drive timeout" "te maxwait"

  Tip tolerance for drive command
  Input "tolerance" "te tolerance"
  
  Tip settling time  after beeing within tolerance
  Input "settling time (sec)" "te settle"
  
if {0} {
  Newline
  Label needle valve control
  RadioGroup "te gasMode"
  NoNewline
  RadioButton 0 off
  NoNewline
  RadioButton 1 manual
  NoNewline
  RadioButton 2 automatic
  Newline

  if {[result te gasmode] == 2} {
    Tip "needle valve flow for stable temperature \[mbar\]"
    Input "n.v. flow (stable)" "flowpars flowstd"
   
    Tip "needle valve flow for max. cooling \[mbar\]"
    Input "n.v. flow (cooling)" "flowpars flowlim"
   
    Tip needle valve opening
    Input "valve setting \[%\]" "te setGas"

    if {[result te heatermode] == 3} {
      Label AutoGas on (n.v. controlled by ITC)
    } else {
      Label AutoGas off (n.v. software controlled)
    }
#    Group nvItc "n.v. controller parameter"
  } else {   
    Tip needle valve opening
    Input "valve setting \[%\]" "te setGas"
  } 
}
  Group itcPid "ITC pid control"
}

proc itcPidGroup {} {
  RadioGroup "te pidMode"
  Label "PID mode"
  NoNewline
  RadioButton 1 manual
  NoNewline
  RadioButton 2 automatic

  Tip "maximum heater power \[W\]"
  Input "max. power" "te maxPower"

  Tip proportional band \[%\]
  Input "prop" "te prop"

  Tip integral parameter \[min\]
  Input "int" "te int"
  
  Tip derivative parameter \[min\] (0 is mostly used)
  Input "deriv" "te deriv"
}

