BOARD_INFORMATION = "FIDO Rev B"  # print this out on boot

# The following are the valve channel numbers.
# A total of 16 valves are spread across 2 boards of 8 valves each.
# board 0 handles 0-7 and board 1 handles 8-15
# Board 0 (0-7)
SAMPLEPUMP = 5
INTAKEVALVE = 0
NITROAIRVALVE = 1    # air is a pressurized N2 gas canister
PRESERVATIVEVALVE = 2

# Board 1 (8-15)
EXHAUSTVALVE = 8
VACUUMVALVE = 9
WASTEVALVE = 10
DECONVALVE = 11
SUCTIONVALVE = 12  # Vacuum arm valve
SUCTIONBREAKVALVE = 13
VACUUMCLEARVALVE = 14
VACUUMPUMPVALVE = 15

MIN_PRESSUREPOT_PRESSURE_PSI = 5.0

CLAMP_MIN_PRELOAD_LBS = 10

GOODVACUUM = 2000  # ADC counts related to a strong vacuum (field MSC hotfix; align with release when flashing)
# TODO: Qualify the actual limit of a good vacuum for the system.
CHECKSEAL_PUMP_TIME = 10  # seconds to run pump before reading
CHECKSEAL_POST_PUMP_SETTLE_SEC = 2  # seconds after pump off before baseline vacuum sample (avoids pump noise)
CHECKSEAL_HOLD_TIME = 10  # seconds to wait with pump off before hold reading
CHECKSEAL_MAX_HOLD_DELTA = 500  # max allowed increase in vacuum counts during hold (field MSC hotfix)
# TODO: The delta threshold could be made adaptive based on barometric pressure
# (available via thp). At lower atmospheric pressure, the pump achieves less gauge
# vacuum and oscillation amplitude may increase. A transfer function between
# barometric pressure and acceptable delta would make this check robust across
# all elevations. For now, CHECKSEAL_MAX_HOLD_DELTA is a static configuration value.

# Nitrogen presence detection
NITROGEN_PRESSURE_CHANNEL = 1    # ADC channel for nitrogen pressure sensor
MIN_NITROGEN_PRESSURE_PSI = 6.0  # Minimum pressure to confirm nitrogen present
MAX_NITROGEN_PRESSURE_DROP_PSI = 2.0  # Max allowed pressure drop during check (failing supply)

# default values for sample if not specified in parameters
pressurePot = False

# Clamp closes on puck with just enough force to hold it so
# arm can let go and back away, then it holds it in place,
# finally sealing
CLAMP_GRAB_LBS = 2.5    # lbs: just enough force to back away
CLAMP_CLOSE_LBS = 60    # lbs: crushed down on puck
CLAMP_SEAL_LBS = 65     # lbs: full seal, ready for sample

# distances the clamp needs to travel
CLAMP_MAX_DISTANCE = 60000      # full open to full close
CLAMP_GRAB_OPEN_DISTANCE = (2000*5)+3000  # full open to grab position
CLAMP_PUCK_CLOSE_DISTANCE = 30000       # from open to close on puck, bypass grab
PUCKCLOSE_RETIRES = 10    #how many times to try getting clamp closed on puck
PUCKCLOSE_SLEEP_TIME = 10 #number of seconds to delay before reading force
FULLCLOSE_RETIRES = 3     #how many times to try getting clamp closed
FULLCLOSE_SLEEP_TIME = 2  #seconds to delay before reading reading force

# Puck positioning detection via clamp travel distance
# Properly positioned pucks require clamp travel within expected range to reach close force
# Insufficient travel: flipped puck, misaligned puck, improperly assembled puck
# Excessive travel: no puck present, puck fell through, mechanical issue
CLAMP_MIN_PUCK_STEPS = 25000            # minimum steps for properly positioned puck
CLAMP_MAX_PUCK_STEPS = 30000            # maximum steps for properly positioned puck

CLAMP_MIN_FULL_STEPS = 55000            # minimum steps for full close
CLAMP_MAX_FULL_STEPS = 60000            # maximum steps for full close

CLAMP_AT_OPEN_LIMIT = 20
CLAMP_AT_CLOSE_LIMIT = 400
CLAMP_ABIT_PAST_RELEASE = -1000

CLAMP_PUCK_PURGE_UNDER = -1300

#these two values are used to pull the puck from the stack very quickly
ARM_FAST_ASTEP = 2000
ARM_FAST_PACE = 8000

#These are how to shake the cylinder during stuck puck
CYLINDER_SHAKE_ASTEP = 100
CYLINDER_SHAKE_PACE = 4000
CYLINDER_SHAKE_JOG = 10000

# Max per-call delivery volume (all reagents), in microliters (uL)
# Default 500 mL; adjust per deployment needs
MAX_DELIVERY_UL = 500_000

# Actuator stateSet wait time in milliseconds
# Time to wait after setting actuator state before checking fault flags
ACTUATOR_WAIT_MS = 1000

# Puck Counter Constants
# Physical distance between tube bottom and ridge between tubes
PUCK_PHYSICAL_DISTANCE_MM = 213

# Nominal stack heights by puck count
PUCK_NOMINAL_STACK_HEIGHTS = {
    0: 0,
    1: 10,
    2: 27,
    3: 44,
    4: 61,
    5: 78,
    6: 95,
    7: 112,
    8: 129,
    9: 146,
    10: 163,
    11: 180,
    12: 197
}
