code wiki / (root) / nx_toner_ledger.nx

nx_toner_ledger.nx source

↩ module page · 47 lines · 2861 B

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