Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # --- Device Aliases ---
- alias gasSensor d0 # gas sensor to read room pressure
- alias leverSwitch01 d1 # lever to enable disable entire system
- alias leverSwitch02 d2 # lever to control filling/emptying
- alias pressureRegulator d3 # keep the intake pipe filled upto target pressure
- alias pipeAnalyzer d4 # Read pipe pressure for pressureRegulator
- # --- Registers ---
- alias currentRoomPressure r8
- alias currentRoomTemperature r9
- alias leverState01 r10 # 0 for system disable, 1 for enable
- alias leverState02 r11# 0 for emptying, 1 for filling
- alias currentPipePressure r12
- alias targetPipePressure r13
- alias roomTargetPressure r14
- alias regulatorSwitch r15 # Switch for pressure regulator 0 or 1
- # --- Constants ---
- define ActiveVentHASH -1129453144 # Hash for ActiveVent devices
- define TargetPipePressureKPA 5000 # 5MPa = 5000 kPa
- define TargetRoomPressureKPA 100 # Target room pressure
- define fillVentBatch HASH("ActiveVentExhaust") # Stores hash for "FillVent" batch
- define emptyVentBatch HASH("ActiveVentInlet") # Stores hash for "EmptyVent" batch
- #Set the initial state of these vents - mode will never change, set it once here:
- sbn ActiveVentHASH fillVentBatch Mode 0
- sbn ActiveVentHASH emptyVentBatch Mode 1
- IdleLoop:
- # Name the Vents with a Labeler to "ActiveVentExhaust" and "ActiveVentInlet"
- sbn ActiveVentHASH fillVentBatch On 0
- sbn ActiveVentHASH emptyVentBatch On 0
- sleep 1
- StartLoop:
- # Read sensor inputs
- l currentRoomPressure gasSensor Pressure # Read room pressure
- l currentRoomTemperature gasSensor Temperature # Read room temperature
- # convert temperature to Celsius from Kelvin
- sub currentRoomTemperature currentRoomTemperature 273.15
- # Display current room pressure and temperature on IC Housing
- s db Setting currentRoomPressure
- sleep 2 #?! cannot be tick perfect with such instructions!
- s db Setting currentRoomTemperature
- l leverState01 leverSwitch01 Open # lever state for system enable/disable
- # If leverState is 0, jump to IdleLoop else continue
- beqz leverState01 IdleLoop
- l leverState02 leverSwitch02 Open # lever state for filling/emptying mode
- l currentPipePressure pipeAnalyzer Pressure # Read current pipe pressure
- # Control Pressure Regulator for filling pipe
- # regulatorSwitch = 1 if currentPipePressure < TargetPipePressureKPA, else 0
- slt regulatorSwitch currentPipePressure targetPipePressure
- s pressureRegulator On regulatorSwitch # Set regulator On state
- # If leverState is 1, Exhaust will be on and Inlet off, else vice-versa
- sbn ActiveVentHASH fillVentBatch On leverState02
- seqz r0 leverState02
- sbn ActiveVentHASH emptyVentBatch On r0
- sleep 3 #?! cannot be tick perfect with such instructions!
- j StartLoop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement