code wiki / (root) / nx_jam_response.nx

nx_jam_response.nx source

↩ module page · 26 lines · 1169 B

1// nx_jam_response.nx -- the JAM -> ACTION loop (auto-pause on a real jam, debounced 2// so a single noisy reading never false-pauses a good print). 3// 4// Composes nx_jam_detect (per-window clog/grind verdict) into a policy: 5// - a transient (1 window) jam -> CONTINUE (debounce) 6// - >= alert_after consecutive -> ALERT (warn operator) 7// - >= pause_after consecutive -> PAUSE (auto-pause via Moonraker) 8// Any OK window resets the streak. This is the sovereign "brain"; the last-mile 9// pause command is sent by the existing nx_moonraker_client. license_tier: ORIGINAL. 10 11import "nx_syscalls.nx" 12import "nx_jam_detect.nx" 13 14const JR_CONTINUE: i64 = 0 15const JR_ALERT: i64 = 1 16const JR_PAUSE: i64 = 2 17 18// jam_verdict = JAM_OK / JAM_CLOG / JAM_GRIND (from jam_step). 19// consec = caller-held streak counter (i64*, persists across windows). 20func jr_step(jam_verdict: i64, consec: *i64, alert_after: i64, pause_after: i64) -> i64 { 21 if jam_verdict == JAM_OK { consec[0] = 0; return JR_CONTINUE } 22 consec[0] = consec[0] + 1 23 if consec[0] >= pause_after { return JR_PAUSE } 24 if consec[0] >= alert_after { return JR_ALERT } 25 return JR_CONTINUE 26}