-- Dropper Controller -- Watches a dropper peripheral and pulses redstone until it's empty. local DROPPER_SIDE = "back" -- side where the dropper peripheral is local REDSTONE_SIDE = "back" -- side facing dropper (for redstone output) local PULSE_TIME = 0.3 -- redstone pulse duration in seconds local POLL_INTERVAL = 0.5 -- how often to check the dropper ------------------------------------------------- -- Load config from file if present ------------------------------------------------- local _baseDir = fs.getDir(shell.getRunningProgram()) -- Persistent config path: survives Opus package updates local _PERSIST_DIR = "usr/config/inventory-manager" local function _configPath(rel) if fs.isDir(_PERSIST_DIR) or fs.isDir("packages/inventory-manager") then if not fs.isDir(_PERSIST_DIR) then fs.makeDir(_PERSIST_DIR) end return fs.combine(_PERSIST_DIR, rel) end return fs.combine(_baseDir, rel) end local CONFIG_FILE = _configPath(".dropper_config") if fs.exists(CONFIG_FILE) then local f = fs.open(CONFIG_FILE, "r") local raw = f.readAll() f.close() local ok, cfg = pcall(textutils.unserialiseJSON, raw) if ok and cfg then if cfg.dropperSide then DROPPER_SIDE = cfg.dropperSide end if cfg.redstoneSide then REDSTONE_SIDE = cfg.redstoneSide end if cfg.pulseTime then PULSE_TIME = cfg.pulseTime end if cfg.pollInterval then POLL_INTERVAL = cfg.pollInterval end end end ------------------------------------------------- -- Helpers ------------------------------------------------- -- Send a redstone pulse to trigger the dropper local function pulseRedstone() redstone.setOutput(REDSTONE_SIDE, true) sleep(PULSE_TIME) redstone.setOutput(REDSTONE_SIDE, false) end -- Check if the dropper has any items local function dropperHasItems() local dropper = peripheral.wrap(DROPPER_SIDE) if not dropper then return false end local contents = dropper.list() if not contents then return false end return next(contents) ~= nil end ------------------------------------------------- -- Main ------------------------------------------------- print("=================================") print(" Dropper Controller (ID " .. os.getComputerID() .. ")") print("=================================") print("") print("Redstone side: " .. REDSTONE_SIDE) print("Watching dropper for items...") print("") while true do if dropperHasItems() then print("[DISPENSE] Items detected, firing dropper...") -- Keep pulsing until the dropper is empty while dropperHasItems() do pulseRedstone() sleep(0.1) end print("[OK] Dropper empty.") end sleep(POLL_INTERVAL) end