code wiki / (root) / nx_gcode_emit.nx

nx_gcode_emit.nx

buildroot/runtime/nx_gcode_emit.nx

29324 B738 linesdepth 9pulls 22 transitivereach 44 importersview sourcekind librarytopic gcode
docsdependenciesstructsconstsfunctions

about

nx_gcode_emit.nx -- compose every P0-P2 primitive into actual Klipper-flavour G-code text. This is the closing-the-loop primitive: NxSliceContours + NxMachineGraph + NxMaterialProfile + nx_gcode_extrude + nx_q14_format -> .gcode file bytes that Klipper/Moonraker can execute. Per cardinal NISHI_3D_PRINT_ROADMAP ยง2.5: every emitted G-code file carries its provenance manifest as a comment-line header (composes nx_gcode_manifest). G-code comments are universally ignored by firmware -- zero behaviour impact, clean EXCEED axis vs every SOTA slicer (none of which embed source provenance). G-code structure emitted (subset for v1; richer post-processing queued): ; <manifest header lines if caller supplies one> M104 S<print_temp> ; hotend target (no wait) M140 S<bed_temp> ; bed target (no wait) M190 S<bed_first_layer> ; wait bed M109 S<hotend_first> ; wait hotend G28 ; home all G92 E0 ; reset extruder G1 Z<safe_z> F300 ; --- per layer --- ;LAYER:<n> M106 S<fan_pct> ; fan (post first-layer) ; --- per polygon --- G0 X<x> Y<y> Z<z> F<travel> G1 X<x> Y<y> E<acc> F<print> ; --- end --- M104 S0 M140 S0 G1 Z<top> M84 Coordinate convention: Q14 fixed-point inputs throughout, emitted as decimal text via nx_q14_to_decimal (3 fractional digits ->

dependencies 10 imports · 40 importers

nx_syscalls.nx nx_abs.nx nx_polygon.nx nx_slice_contour.nx nx_machine_graph.nx nx_material_profile.nx nx_gcode_extrude.nx nx_gcode_manifest.nx nx_q14_format.nx nx_bed_mesh.nx nx_gcode_emit.nx nx_bedmesh_emit_test.nx nx_cad_exceed.nx nx_cad_page.nx nx_cad_prims2_test.nx nx_cad_test.nx nx_christus_integration_test.nx nx_csg_fillet_test.nx nx_csg_test.nx nx_csg_torus_test.nx nx_cube_to_gcode_test.nx

diagram shows first 10 each side; +0 more imports, +30 more importers in the complete lists below.

imports: nx_syscalls.nxnx_abs.nxnx_polygon.nxnx_slice_contour.nxnx_machine_graph.nxnx_material_profile.nxnx_gcode_extrude.nxnx_gcode_manifest.nxnx_q14_format.nxnx_bed_mesh.nx

imported by: nx_bedmesh_emit_test.nxnx_cad_exceed.nxnx_cad_page.nxnx_cad_prims2_test.nxnx_cad_test.nxnx_christus_integration_test.nxnx_csg_fillet_test.nxnx_csg_test.nxnx_csg_torus_test.nxnx_cube_to_gcode_test.nxnx_dcc_slice_probe.nxnx_dcc_to_print_test.nxnx_gcode_arc_test.nxnx_gcode_brim_test.nxnx_gcode_emit_test.nxnx_klipper_gcode_validator_test.nxnx_mushroom_overhang_test.nxnx_print_e2e_test.nxnx_print_exceed_compose_test.nxnx_print_session.nxnx_print_session_test.nxnx_slice_auto_supports_test.nxnx_slice_pipe_v2_real_test.nxnx_slice_pipe_v2_test.nxnx_slice_pipeline.nxnx_slice_pipeline_test.nxnx_slicer.nxnx_slicer_gate.nxnx_slicer_lib.nxnx_stl_to_gcode_real_test.nxnx_supports.nxnx_supports_physics_test.nxnx_supports_v2_test.nxnx_underridge_gcode_gate.nxnx_underridge_hook_gcode_gate.nxnx_underridge_hook_petg_gate.nxnx_underridge_master_gate.nxnx_vessel_emit_gcode.nxnx_vessel_gcode.nxnx_vessel_gcode_test.nx

structs

80struct NxGcodeEmitter

consts

56const NX_MAGIC_16384: i64 = 16384
58const NX_GEMIT_Q14: i64 = 16384
59const NX_GEMIT_SAFE_Z_Q14: i64 = 81920 // 5mm = 5 * Q14
60const NX_GEMIT_END_Z_Q14: i64 = 1638400 // 100mm raise at end
64const NX_GEMIT_OK: i64 = 0
65const NX_GEMIT_ERR_CAPACITY: i64 = 1
66const NX_GEMIT_ERR_BAD_MACHINE: i64 = 2
67const NX_GEMIT_ERR_BAD_MATERIAL: i64 = 3
68const NX_GEMIT_N_VERDICTS: i64 = 4
99const NX_GEMIT_BYTES: i64 = 128
669const NX_GEMIT_DEFAULT_BEDMESH_SEG_Q14: i64 = 81920 // 5.0 mm in Q14

functions

70func nx_gemit_verdict_name(v: i64) -> *u8
103func nx_gemit_new(machine: *NxMachineGraph, material: *NxMaterialProfile,
131func nx_gemit_set_brim(e: *NxGcodeEmitter, n_loops: i64) -> i64
called by 2: mainmain
142func nx_gemit_set_arc_fitting(e: *NxGcodeEmitter, enabled: i64,
called by 1: main
156func nx_gemit_set_z_hop(e: *NxGcodeEmitter, hop_q14: i64) -> i64
165func nx_gemit_set_perimeters(e: *NxGcodeEmitter, n: i64) -> i64
174func nx_gemit_byte(e: *NxGcodeEmitter, b: i64) -> i64
184func nx_gemit_cstr(e: *NxGcodeEmitter, s: *u8) -> i64
193func nx_gemit_bytes(e: *NxGcodeEmitter, src: *u8, n: i64) -> i64
202func nx_gemit_int(e: *NxGcodeEmitter, value: i64) -> i64
209func nx_gemit_q14(e: *NxGcodeEmitter, value_q14: i64, frac_digits: i64) -> i64
222func nx_gemit_provenance(e: *NxGcodeEmitter, m: *NxGcodeManifest) -> i64
calls 1: nx_gemit_bytes
230func nx_gemit_preamble(e: *NxGcodeEmitter) -> i64
271func nx_gemit_retract(e: *NxGcodeEmitter) -> i64
287func nx_gemit_unretract(e: *NxGcodeEmitter) -> i64
303func nx_gemit_travel_to(e: *NxGcodeEmitter, x_q14: i64, y_q14: i64,
345func nx_gemit_extrude_to(e: *NxGcodeEmitter, from_x: i64, from_y: i64,
376func nx_gemit_skirt(e: *NxGcodeEmitter,
411func nx_gemit_arc(e: *NxGcodeEmitter,
446func nx_gemit_polygon(e: *NxGcodeEmitter, p: *NxPolygon,
548func nx_gemit_brim(e: *NxGcodeEmitter, contour: *NxPolygon,
577func nx_gemit_layer(e: *NxGcodeEmitter, contours: *NxSliceContours,
644func nx_gemit_postamble(e: *NxGcodeEmitter) -> i64
671func nx_gemit_extrude_to_bedmesh(e: *NxGcodeEmitter,