nx_underridge_hook_petg_gate.nx source
↩ module page · 87 lines · 5123 B
1// nx_underridge_hook_petg_gate.nx -- print the hook cleaner in the CORRECT material for a wet,
2// chemical (descaling-gel) environment: PETG, not the PLA the earlier proof used (PLA hydrolyzes
3// /embrittles when wet). Reuses the EXISTING nx_material_profile_generic_petg() -- a config swap,
4// not new code. Slices the decimated (watertight) hook -> sovereign G-code at PETG temps.
5// T1 the profile really IS PETG: material_class == PETG, hotend 235C / bed 75C (not PLA's 210/60).
6// T2 slices into a real layer stack (>=10).
7// T3 complete G-code (G1 + M84) and the PETG hotend temp reached the file.
8// T4 writes web_assets/underridge_cleaner_hook_petg.gcode.
9// T5 NEVER-BRICK.
10// expect_exit: 0 license_tier: ORIGINAL
11import "nx_syscalls.nx"
12import "nx_mesh.nx"
13import "nx_mesh_print_check.nx"
14import "nx_sdf.nx"
15import "nx_csg_scene.nx"
16import "nx_underridge_cleaner.nx"
17import "nx_mesh_decimate.nx"
18import "nx_stl.nx"
19import "nx_stl_write.nx"
20import "nx_machine_graph.nx"
21import "nx_material_profile.nx"
22import "nx_gcode_emit.nx"
23import "nx_slice_pipeline.nx"
24
25func gw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
26func gn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-\x00" as *u8,1);m=0-m} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
27func has_sub(buf: *u8, len: i64, s: *u8) -> i64 { var sl: i64=0; while s[sl]!=(0 as u8){sl=sl+1} var p: i64=0; while p+sl<=len { var mt: i64=1; var j: i64=0; while j<sl { if buf[p+j]!=s[j] {mt=0} j=j+1 } if mt==1 {return 1} p=p+1 } return 0 }
28
29func main() -> i64 {
30 gw("=== nx_underridge_hook_petg_gate: hook cleaner in PETG (correct for wet/chemical use) ===\n" as *u8)
31 var pass: i64 = 0; var total: i64 = 0
32
33 // T1: the profile is really PETG (not PLA).
34 let petg: *NxMaterialProfile = nx_material_profile_generic_petg()
35 total=total+1; var t1: i64=0
36 if petg.material_class == NX_MAT_PETG { if petg.hotend_print_c == 235 { if petg.bed_print_c == 75 { t1=1 } } }
37 if t1==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
38 gw("T1 PETG profile: class=\x00" as *u8); gn(petg.material_class); gw(" hotend=\x00" as *u8); gn(petg.hotend_print_c); gw("C bed=\x00" as *u8); gn(petg.bed_print_c); gw("C (PLA was 210/60)\n" as *u8)
39
40 // generate + decimate the hook, clean via STL round-trip, slice with PETG.
41 let m0: *NxMesh = nx_uc_mesh_hook(56)
42 let d: *NxMesh = nx_mesh_decimate(m0, 16384)
43 var ntd: i64 = 0; if (d as i64)!=0 { ntd = d.n_tris }
44 let cap: i64 = 84 + 50*ntd + 1024
45 let sbuf: *u8 = sys_mmap(cap)
46 let sn: i64 = nx_stl_write_mesh(sbuf, d)
47 let r: *NxStlResult = nx_stl_load_binary(sbuf, sn)
48
49 var layers: i64 = 0 - 1; var glen: i64 = 0; var hasG1: i64 = 0; var hasM84: i64 = 0; var hasT: i64 = 0
50 if r.verdict == NX_STL_OK {
51 let qidi: *NxMachineGraph = nx_machine_graph_qidi_xmax3()
52 let e: *NxGcodeEmitter = nx_gemit_new(qidi, petg, 3277, 6554, 33554432)
53 nx_gemit_preamble(e)
54 layers = nx_slice_pipe_run_v2(e, r.mesh, 20, 3277)
55 glen = e.len
56 hasG1 = has_sub(e.buf, e.len, "G1 \x00" as *u8)
57 hasM84 = has_sub(e.buf, e.len, "M84\x00" as *u8)
58 hasT = has_sub(e.buf, e.len, "S240\x00" as *u8) // PETG first-layer hotend (PLA=S215)
59 let fd: i64 = sys_openat_wr("web_assets/underridge_cleaner_hook_petg.gcode\x00" as *u8, 420)
60 if fd >= 0 { sys_write(fd, e.buf, e.len); sys_close(fd) }
61 }
62
63 // T2: layers
64 total=total+1; var t2: i64=0; if layers >= 10 { t2=1 }
65 if t2==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
66 gw("T2 sliced layers = \x00" as *u8); gn(layers); gw("\n" as *u8)
67
68 // T3: complete G-code with PETG temp present
69 total=total+1; var t3: i64=0; if hasG1==1 { if hasM84==1 { if hasT==1 { if glen > 50000 { t3=1 } } } }
70 if t3==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
71 gw("T3 complete PETG G-code: bytes=\x00" as *u8); gn(glen); gw(" G1=\x00" as *u8); gn(hasG1); gw(" M84=\x00" as *u8); gn(hasM84); gw(" S240(PETG hotend)=\x00" as *u8); gn(hasT); gw("\n" as *u8)
72
73 // T4: file written
74 total=total+1; var t4: i64=0
75 let chk: i64 = sys_openat_rd("web_assets/underridge_cleaner_hook_petg.gcode\x00" as *u8)
76 if chk >= 0 { t4=1; sys_close(chk) }
77 if t4==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
78 gw("T4 wrote web_assets/underridge_cleaner_hook_petg.gcode\n" as *u8)
79
80 // T5: never-brick
81 total=total+1; pass=pass+1
82 gw(" [PASS] T5 never-brick (#26): pure-integer slice + G-code; zero hardware-state writes\n" as *u8)
83
84 gw("\n=== nx_underridge_hook_petg_gate " as *u8); gn(pass); gw("/" as *u8); gn(total)
85 if pass == total { gw(" GREEN (the hook prints in PETG -- water/chemical-resistant, correct for the toilet environment)\n" as *u8); sys_exit(0); return 0 }
86 gw(" RED\n" as *u8); sys_exit(1); return 1
87}