Exemple #1
0
static void dummy_inform_display_offset(void *user, const float *o) {
  fprintf(stderr, "GCodeParser: display offset [");
  for (int i = 0; i < GCODE_NUM_AXES;  ++i) {
    fprintf(stderr, "%s%c:%.3f", i == 0 ? "" : ", ", gcodep_axis2letter(i),o[i]);
  }
  fprintf(stderr, "]\n");
}
Exemple #2
0
static char dummy_probe_axis(void *user, float feed, enum GCodeParserAxis axis,
                             float *reached_pos) {
  fprintf(stderr, "GCodeParser: probe-axis(%c)", gcodep_axis2letter(axis));
  if (feed > 0)
    fprintf(stderr, " feed=%.1f\n", feed);
  else
    fprintf(stderr, "\n");
  return 0;
}
static const char *special_commands(void *userdata, char letter, float value,
				    const char *remaining) {
  GCodeMachineControl_t *state = (GCodeMachineControl_t*)userdata;
  const int code = (int)value;

  if (letter == 'M') {
    int pin = -1;
    int aux_bit = -1;

    switch (code) {
    case 0: set_gpio(ESTOP_SW_GPIO); break;
    case 3:
    case 4:
      for (;;) {
        const char* after_pair = gcodep_parse_pair(remaining, &letter, &value,
                                                   state->msg_stream);
        if (after_pair == NULL) break;
        else if (letter == 'S') state->spindle_rpm = round2int(value);
        else break;
        remaining = after_pair;
      }
      if (state->spindle_rpm) {
        state->aux_bits |= AUX_BIT_SPINDLE_ON;
	if (code == 3) state->aux_bits &= ~AUX_BIT_SPINDLE_DIR;
        else state->aux_bits |= AUX_BIT_SPINDLE_DIR;
      }
      break;
    case 5: state->aux_bits &= ~(AUX_BIT_SPINDLE_ON | AUX_BIT_SPINDLE_DIR); break;
    case 7: state->aux_bits |= AUX_BIT_MIST; break;
    case 8: state->aux_bits |= AUX_BIT_FLOOD; break;
    case 9: state->aux_bits &= ~(AUX_BIT_MIST | AUX_BIT_FLOOD); break;
    case 10: state->aux_bits |= AUX_BIT_VACUUM; break;
    case 11: state->aux_bits &= ~AUX_BIT_VACUUM; break;
    case 42:
    case 62:
    case 63:
    case 64:
    case 65:
      for (;;) {
        const char* after_pair = gcodep_parse_pair(remaining, &letter, &value,
                                                   state->msg_stream);
        if (after_pair == NULL) break;
        if (letter == 'P') pin = round2int(value);
        else if (letter == 'S' && code == 42) aux_bit = round2int(value);
        else break;
        remaining = after_pair;
      }
      if (code == 62 || code == 64)
        aux_bit = 1;
      else if (code == 63 || code == 65)
        aux_bit = 0;
      if (pin >= 0 && pin <= MAX_AUX_PIN) {
        if (aux_bit >= 0 && aux_bit <= 1) {
          if (aux_bit) state->aux_bits |= 1 << pin;
          else state->aux_bits &= ~(1 << pin);
        } else if (code == 42 && state->msg_stream) {  // Just read operation.
          mprintf(state, "%d\n", (state->aux_bits >> pin) & 1);
	}
      }
      break;
    case 80: set_gpio(MACHINE_PWR_GPIO); break;
    case 81: clr_gpio(MACHINE_PWR_GPIO); break;
    case 105: mprintf(state, "T-300\n"); break;  // no temp yet.
    case 114:
      if (buffer_available(&state->buffer)) {
        struct AxisTarget *current = buffer_at(&state->buffer, 0);
        const int *mpos = current->position_steps;
        const float x = 1.0f * mpos[AXIS_X] / state->cfg.steps_per_mm[AXIS_X];
        const float y = 1.0f * mpos[AXIS_Y] / state->cfg.steps_per_mm[AXIS_Y];
        const float z = 1.0f * mpos[AXIS_Z] / state->cfg.steps_per_mm[AXIS_Z];
        const float e = 1.0f * mpos[AXIS_E] / state->cfg.steps_per_mm[AXIS_E];
        const float *origin = state->coordinate_display_origin;
        mprintf(state, "X:%.3f Y:%.3f Z:%.3f E:%.3f",
                x - origin[AXIS_X], y - origin[AXIS_Y], z - origin[AXIS_Z],
                e - origin[AXIS_E]);
        mprintf(state, " [ABS. MACHINE CUBE X:%.3f Y:%.3f Z:%.3f]", x, y, z);
        switch (state->homing_state) {
        case HOMING_STATE_NEVER_HOMED:
          mprintf(state, " (Unsure: machine never homed!)\n");
          break;
        case HOMING_STATE_HOMED_BUT_MOTORS_UNPOWERED:
          mprintf(state, " (Lower confidence: motor power off at "
                  "least once after homing)\n");
          break;
        case HOMING_STATE_HOMED:
          mprintf(state, " (confident: machine was homed)\n");
          break;
        }
      } else {
        mprintf(state, "// no current pos\n");
      }
      break;
    case 115: mprintf(state, "%s\n", VERSION_STRING); break;
    case 117:
      mprintf(state, "// Msg: %s\n", remaining); // TODO: different output ?
      remaining = NULL;  // consume the full line.
      break;
    case 119: {
      char any_enstops_found = 0;
      for (int axis = 0; axis < GCODE_NUM_AXES; ++axis) {
        struct EndstopConfig config = state->min_endstop[axis];
        if (config.endstop_number) {
          int value = get_gpio(get_endstop_gpio_descriptor(config));
          mprintf(state, "%c_min:%s ",
                  tolower(gcodep_axis2letter(axis)),
                  value == config.trigger_value ? "TRIGGERED" : "open");
          any_enstops_found = 1;
        }
        config = state->max_endstop[axis];
        if (config.endstop_number) {
          int value = get_gpio(get_endstop_gpio_descriptor(config));
          mprintf(state, "%c_max:%s ",
                  tolower(gcodep_axis2letter(axis)),
                  value == config.trigger_value ? "TRIGGERED" : "open");
          any_enstops_found = 1;
        }
      }
      if (any_enstops_found) {
        mprintf(state, "\n");
      } else {
        mprintf(state, "// This machine has no endstops configured.\n");
      }
    }
      break;
    case 999: clr_gpio(ESTOP_SW_GPIO); break;
    default:
      mprintf(state, "// BeagleG: didn't understand ('%c', %d, '%s')\n",
              letter, code, remaining);
      remaining = NULL;  // In this case, let's just discard remainig block.
      break;
    }