#================================================================================#
# LCLS-II MPS Threshold scale factor and offset PV template                      #
# Macro description:                                                             #
#   - P               : Record name prefix                                       #
#   - R               : Channel name.                                            #
#   - DESC            : Description                                              #
#   - SCAN            : Scan period                                              #
#   - SCALE_SLOPE_PV  : Name of the PV with the scale slope value                #
#   - SCALE_OFFSET_PV : Name of the PV with the scale offset value               #
#   - EGU             : Engineering units                                        #
#   - PREC            : Precision                                                #
#   - PORT            : Asyn port name                                           #
#   - BAY             : Bay number (0 or 1)                                      #
#   - APP             : Application name (BLM, BPM, BCM, BLEN)                   #
#   - CH              : Threhold channel (application specific)                  #
#     * BLM  => (X)(Y), X=input channel(0-2), Y=Integration channel (0-3)        #
#     * BPM  => (X),    X=Channel (0:X, 1:Y, 2, TIMIT)                           #
#     * BCM  => (X),    X=Channel (0:Charge, 1:Difference)                       #
#     * BLEN => 0                                                                #
#================================================================================#

# Scale Factor PVs
record(calcout, "$(P):$(R)_SS") {
    field(DESC, "$(DESC) slope")
    field(SCAN, "$(SCAN)")
    field(PHAS, "1")
    field(PINI, "NO")
    field(EGU,  "$(EGU)/raw")
    field(PREC, "$(PREC)")
    field(INPA, "$(SCALE_SLOPE_PV)")
    field(CALC, "A")
    field(DTYP, "Soft Channel")
    field(OUT,  "$(P):$(R)_SS_OUT PP")
    field(OOPT, "On Change")
}
record(ao,      "$(P):$(R)_SS_OUT") {
    field(DESC, "$(DESC) slope")
    field(SCAN, "Passive")
    field(PHAS, "1")
    field(PINI, "NO")
    field(EGU,  "$(EGU)/raw")
    field(PREC, "$(PREC)")
    field(OMSL, "closed_loop")
    field(OIF,  "Full")
    field(DOL,  "$(P):$(R)_SS")
    field(DTYP, "asynFloat64")
    field(OUT,  "@asyn($(PORT),$(BAY))$(APP)_SCALESLOPE_$(CH)")
}
record(ai,      "$(P):$(R)_SS_RBV") {
    field(DESC, "$(DESC) slope")
    field(SCAN, "I/O Intr")
    field(EGU,  "$(EGU)/raw")
    field(PREC, "$(PREC)")
    field(DTYP, "asynFloat64")
    field(INP,  "@asyn($(PORT),$(BAY))$(APP)_SCALESLOPE_$(CH)")
}
# Scale Offset PVs
record(calcout, "$(P):$(R)_SO") {
    field(DESC, "$(DESC) slope")
    field(SCAN, "$(SCAN)")
    field(PHAS, "1")
    field(PINI, "NO")
    field(EGU,  "raw")
    field(PREC, "$(PREC)")
    field(INPA, "$(SCALE_OFFSET_PV)")
    field(CALC, "A")
    field(DTYP, "Soft Channel")
    field(OUT,  "$(P):$(R)_SO_OUT PP")
    field(OOPT, "On Change")
}
record(ao,      "$(P):$(R)_SO_OUT") {
    field(DESC, "$(DESC) offset")
    field(SCAN, "Passive")
    field(PHAS, "1")
    field(PINI, "NO")
    field(EGU,  "raw")
    field(PREC, "0")
    field(OMSL, "closed_loop")
    field(OIF,  "Full")
    field(DOL,  "$(SCALE_OFFSET_PV)")
    field(DTYP, "asynFloat64")
    field(OUT,  "@asyn($(PORT),$(BAY))$(APP)_SCALEOFFSET_$(CH)")
}
record(ai,      "$(P):$(R)_SO_RBV") {
    field(DESC, "$(DESC)")
    field(SCAN, "I/O Intr")
    field(EGU,  "raw")
    field(PREC, "0")
    field(DTYP, "asynFloat64")
    field(INP,  "@asyn($(PORT),$(BAY))$(APP)_SCALEOFFSET_$(CH)")
}

