void WRITE(pin_t pin, bool s) { bool old_state = state[pin]; uint64_t nseconds = sim_runtime_ns(); sim_assert(pin < PIN_NB, "WRITE: Pin number out of range"); if (direction[pin] == out) { state[pin] = s; } if (old_state != s) { record_pin(TRACE_PINS + pin, s, nseconds); #ifdef TRACE_ALL_PINS fgreen(); for (int i = 0; i < PIN_NB; i++) { if (state[i]) bred(); else bblack(); fputc('A' + i, stdout); } fbreset(); printf("\n"); #else bred(); if (s) sim_tick('A' + pin); else sim_tick('a' + pin); fbreset(); #endif } if (s && !old_state) { /* rising edge */ int axis = AXIS_NONE; int dir; switch (pin) { case X_STEP_PIN: dir = state[X_DIR_PIN] ? 1 : -1; axis = X_AXIS; break; case Y_STEP_PIN: dir = state[Y_DIR_PIN] ? 1 : -1; axis = Y_AXIS; break; case Z_STEP_PIN: dir = state[Z_DIR_PIN] ? 1 : -1; axis = Z_AXIS; break; case E_STEP_PIN: dir = state[E_DIR_PIN] ? 1 : -1; axis = E_AXIS; break; default: break; } if ( axis != AXIS_NONE ) { pos[axis] += dir; record_pin(TRACE_POS + axis, pos[axis], nseconds); print_pos(); } } }
void sim_gcode_ch(char ch) { // Got CR, LF or buffer full if ( gcode_buffer_index == sizeof(gcode_buffer)-1 || ch == '\r' || ch == '\n' || ch == 0 ) { // Terminate string, reset buffer, emit gcode if (gcode_buffer_index) { gcode_buffer[gcode_buffer_index] = 0; gcode_buffer_index = 0; if (trace_gcode) { clearline(); fyellow(); printf("%s\n", gcode_buffer); fbreset(); fflush(stdout); } // Send gcode to data_recorder record_comment(gcode_buffer); } if (ch == '\r' || ch == '\n' || ch == 0) return; } // Acumulate char from stream gcode_buffer[gcode_buffer_index++] = ch; }
void sim_tick(char ch) { if (verbose < 2) return; fcyan(); fprintf(stdout, "%c", ch); fbreset(); fflush(stdout); }
void sim_tick(char ch) { if (!show_pintous) return; fcyan(); fprintf(stdout, "%c", ch); fbreset(); fflush(stdout); }
void sim_error(const char msg[]) { clearline(); fred(); printf("ERROR: %s\n", msg); fputc('\n', stdout); fbreset(); exit(-1); }
void sim_debug(const char fmt[], ...) { va_list ap; if (verbose < 3) return; clearline(); fcyan(); va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); fputc('\n', stdout); fbreset(); }
/** Simulate min endstops. "on" at -10, "off" at 0. */ static void sim_endstop( int axis ) { bool on ; if (axis == AXIS_NONE) return; else if (pos[axis] <= -20) on = true; else if (pos[axis] >= 0) on = false; else return ; const char * strstate = on ? "ON" : "OFF"; int minpin; switch (axis) { case X_AXIS: #ifdef X_INVERT_MIN on = ! on; #endif minpin = X_MIN_PIN; break; case Y_AXIS: #ifdef Y_INVERT_MIN on = ! on; #endif minpin = Y_MIN_PIN; break; case Z_AXIS: #ifdef Z_INVERT_MIN on = ! on; #endif minpin = Z_MIN_PIN; break; default: return; } // No change if (state[minpin] == on) return; // Change the endstop state and report it state[minpin] = on; record_pin(TRACE_PINS + minpin, on, sim_runtime_ns()); bred(); if (on) sim_tick('A' + minpin); else sim_tick('a' + minpin); fbreset(); sim_info("%c-Endstop: %s", "XYZE???"[axis], strstate); }
static void vsim_info_cont(const char fmt[], va_list ap) { if (verbose < 1) return; fgreen(); vprintf(fmt, ap); fbreset(); }
void _WRITE(pin_t pin, bool s) { bool old_state = state[pin]; uint64_t nseconds = sim_runtime_ns(); sim_assert(pin < PIN_NB, "WRITE: Pin number out of range"); if (direction[pin] == out) { state[pin] = s; } if (old_state != s) { record_pin(TRACE_PINS + pin, s, nseconds); #ifdef TRACE_ALL_PINS fgreen(); for (int i = 0; i < PIN_NB; i++) { if (state[i]) bred(); else bblack(); fputc('A' + i, stdout); } fbreset(); printf("\n"); #else bred(); if (s) sim_tick('A' + pin); else sim_tick('a' + pin); fbreset(); #endif } if (s && !old_state) { /* rising edge */ int axis = AXIS_NONE; int dir; switch (pin) { case X_STEP_PIN: dir = state[X_DIR_PIN] ? 1 : -1; #ifdef X_INVERT_DIR dir = -dir; #endif axis = X_AXIS; break; case Y_STEP_PIN: dir = state[Y_DIR_PIN] ? 1 : -1; #ifdef Y_INVERT_DIR dir = -dir; #endif axis = Y_AXIS; break; case Z_STEP_PIN: dir = state[Z_DIR_PIN] ? 1 : -1; #ifdef Z_INVERT_DIR dir = -dir; #endif axis = Z_AXIS; break; case E_STEP_PIN: dir = state[E_DIR_PIN] ? 1 : -1; #ifdef E_INVERT_DIR dir = -dir; #endif axis = E_AXIS; break; default: break; } switch ( axis ) { #ifdef KINEMATICS_COREXY case X_AXIS: pos[X_AXIS] += dir; pos[Y_AXIS] += dir; break; case Y_AXIS: pos[X_AXIS] += dir; pos[Y_AXIS] -= dir; break; #endif case Z_AXIS: case E_AXIS: default: pos[axis] += 2 * dir; break; case AXIS_NONE: break; } if ( axis != AXIS_NONE ) { for (int a = X_AXIS; a <= E_AXIS; a++) record_pin(TRACE_POS + axis, pos[axis] / 2, nseconds); static uint64_t prev_ns = -1; if (prev_ns != nseconds) print_pos(); prev_ns = nseconds; for (int a = X_AXIS; a < E_AXIS; a++) sim_endstop(a); } } }