示例#1
0
static void gcodep_finish_program_and_reset(GCodeParser_t *object) {
  void *const userdata = object->callbacks.user_data;
  object->callbacks.gcode_finished(userdata);

  gcodep_program_start_defaults(object);
  object->program_in_progress = 0;
}
示例#2
0
struct GCodeParser *gcodep_new(struct GCodeParserConfig *config) {
  GCodeParser_t *result = (GCodeParser_t*)malloc(sizeof(*result));
  memset(result, 0x00, sizeof(*result));

  // In the 'constructor', this is the only time we set the const value. Cast.
  memcpy((float*) result->origin_machine, config->machine_origin,
         sizeof(result->origin_machine));

  // Setting up all callbacks
  result->callbacks = config->callbacks;

  // Set some reasonable defaults for unprovided callbacks:
  if (!result->callbacks.gcode_start)
    result->callbacks.gcode_start = &dummy_gcode_start;
  if (!result->callbacks.gcode_finished)
    result->callbacks.gcode_finished = &dummy_gcode_finished;
  if (!result->callbacks.inform_origin_offset)
    result->callbacks.inform_origin_offset = &dummy_inform_display_offset;
  if (!result->callbacks.go_home)
    result->callbacks.go_home = &dummy_go_home;
  if (!result->callbacks.probe_axis)
    result->callbacks.probe_axis = &dummy_probe_axis;
  if (!result->callbacks.set_fanspeed)
    result->callbacks.set_fanspeed = &dummy_set_fanspeed;
  if (!result->callbacks.set_speed_factor)
    result->callbacks.set_speed_factor = &dummy_set_speed_factor;
  if (!result->callbacks.set_temperature)
    result->callbacks.set_temperature = &dummy_set_temperature;
  if (!result->callbacks.wait_temperature)
    result->callbacks.wait_temperature = &dummy_wait_temperature;
  if (!result->callbacks.dwell)
    result->callbacks.dwell = &dummy_dwell;
  if (!result->callbacks.motors_enable)
    result->callbacks.motors_enable = &dummy_motors_enable;
  if (!result->callbacks.coordinated_move)
    result->callbacks.coordinated_move = &dummy_move;
  if (!result->callbacks.rapid_move)
    result->callbacks.rapid_move = result->callbacks.coordinated_move;
  if (!result->callbacks.unprocessed)
    result->callbacks.unprocessed = &dummy_unprocessed;
  if (!result->callbacks.gcode_command_done)
    result->callbacks.gcode_command_done = &dummy_gcode_command_executed;
  if (!result->callbacks.input_idle)
    result->callbacks.input_idle = &dummy_idle;

  gcodep_program_start_defaults(result);

  // When we initialize the machine, we assume the axes to
  // be at the origin (but it better is G28-ed later)
  memcpy(result->axes_pos, config->machine_origin, sizeof(result->axes_pos));

  return result;
}