code wiki / (root) / nx_toner_ledger.nx

nx_toner_ledger.nx source

↩ module page · 46 lines · 2749 B

1const NX_MAGIC_10000: i64 = 10000 2// nx_toner_ledger.nx -- real toner accounting (pure math). Converts measured page coverage into a true 3// "toner remaining" reading, independent of the printer's lying gauge. 4// 5// Model (grounded, cited -- knowledge research 2026-06-20): 6// ISO/IEC 19752: a "standard page" = 5% coverage; a cartridge's rated YIELD = how many 5% pages it prints 7// to end-of-life. (Brother TN-630 = 1,200 pages; TN-660 = 2,600 pages.) 8// Full-cartridge capacity (in coverage-PPM units) = yield * 50,000 (since one 5% page = 50,000 ppm). 9// consumed = sum of each printed page's coverage_ppm (from nx_toner_meter). 10// remaining = capacity - consumed. This measures ACTUAL ink laid down -> more accurate than the 11// printer's flat-5%-per-page page counter, and works for any (incl. aftermarket) cartridge. 12// 13// HONEST CALIBRATION NOTE: this measures consumption FROM the moment tracking starts. Absolute % assumes a 14// known starting level (default: a freshly-installed full cartridge). The operator declares the start level 15// when installing a cart; from there the reading is real. Non-print toner use (drum cleaning) is minor and 16// not modeled. NEVER-BRICK (#26): pure arithmetic, no syscalls. Sovereign (no imports). license_tier: ORIGINAL 17// genealogy_id: project-printer-management-ipp-sclass-2026-06-20 18 19const NX_TONER_STD_PAGE_PPM: i64 = 50000 // ISO/IEC 19752 standard page = 5% coverage = 50,000 ppm 20const NX_TONER_YIELD_TN630: i64 = 1200 // Brother TN-630 standard yield (cited) 21const NX_TONER_YIELD_TN660: i64 = 2600 // Brother TN-660 high yield (cited) 22 23// full-cartridge capacity in coverage-ppm units 24func nx_ledger_capacity(yield_pages: i64) -> i64 { return yield_pages * NX_TONER_STD_PAGE_PPM } 25 26// accumulate one printed page's coverage into the running consumed total 27func nx_ledger_add(consumed: i64, coverage_ppm: i64) -> i64 { return consumed + coverage_ppm } 28 29// remaining toner in basis points (0..10000 = 0.00%..100.00%), clamped 30func nx_ledger_remaining_bp(yield_pages: i64, consumed: i64) -> i64 { 31 let cap: i64 = nx_ledger_capacity(yield_pages) 32 if cap <= 0 { return 0 } 33 if consumed < 0 { return NX_MAGIC_10000 } 34 if consumed >= cap { return 0 } 35 return (cap - consumed) * NX_MAGIC_10000 / cap 36} 37 38// remaining capacity expressed as standard (5%) pages still printable 39func nx_ledger_remaining_pages(yield_pages: i64, consumed: i64) -> i64 { 40 let cap: i64 = nx_ledger_capacity(yield_pages) 41 if consumed >= cap { return 0 } 42 return (cap - consumed) / NX_TONER_STD_PAGE_PPM 43} 44 45// how many real pages already printed (at the measured coverage), for display 46func nx_ledger_used_pages(consumed: i64) -> i64 { return consumed / NX_TONER_STD_PAGE_PPM }