示例#1
0
// Wait for input from user, quit if recieved 'q' keypress
void Menu::get_keyboard_input() {
    while (! dying) {
        // Check if we need to resize window display
        if (is_term_resized(screen_lines, screen_cols)) {
            reframe_resized_window();
        }

        // Check if we need to update content (i.e. been longer than 5 seconds)
        std::chrono::steady_clock::time_point current_time = std::chrono::steady_clock::now();
        if (current_time > (last_update + std::chrono::seconds(5))) {
            get_lines();
        }

        // Update window display after each key press
        print_window();

        // This is blocking
        ch = getch();
        switch(ch) {
            case KEY_UP:
            case 'k':
                move_cursor_up();
                break;
            case KEY_DOWN:
            case 'j':
                move_cursor_down();
                break;
            case KEY_LEFT:
            case 'h':
                move_cursor_left();
                break;
            case KEY_RIGHT:
            case 'l':
                move_cursor_right();
                break;
            case 'q':
                endwin();
                dying = true;
                break;
            case KEY_PPAGE:
                handle_page_up();
                break;
            case KEY_NPAGE:
                handle_page_down();
                break;
            case KEY_HOME:
                handle_home();
                break;
            case KEY_END:
                handle_end();
                break;
            case KEY_ENTER:
            case 10:
            case 13:
                handle_enter_key();
                break;
            default:
                // Uncoded key, ignore
                break;
        }
    }
}
示例#2
0
// Note: changes here should be documented in G-code.md as well.
void gcodep_parse_line(struct GCodeParser *p, const char *line,
                       FILE *err_stream) {
  ++p->line_number;
  void *const userdata = p->callbacks.user_data;
  struct GCodeParserCb *cb = &p->callbacks;
  p->err_msg = err_stream;  // remember as 'instance' variable.
  char letter;
  float value;
  while ((line = gparse_pair(p, line, &letter, &value))) {
    if (!p->program_in_progress) {
      cb->gcode_start(userdata);
      p->program_in_progress = 1;
    }
    char processed_command = 1;
    if (letter == 'G') {
      switch ((int) value) {
      case  0: p->modal_g0_g1 = 0; line = handle_move(p, line, 0); break;
      case  1: p->modal_g0_g1 = 1; line = handle_move(p, line, 0); break;
      case  2: line = handle_arc(p, line, 1); break;
      case  3: line = handle_arc(p, line, 0); break;
      case  4: line = set_param(p, 'P', cb->dwell, 1.0f, line); break;
      case 17: p->arc_normal = AXIS_Z; break;
      case 18: p->arc_normal = AXIS_Y; break;
      case 19: p->arc_normal = AXIS_X; break;
      case 20: p->unit_to_mm_factor = 25.4f; break;
      case 21: p->unit_to_mm_factor = 1.0f; break;
      case 28: line = handle_home(p, line); break;
      case 30: line = handle_z_probe(p, line); break;
      case 70: p->unit_to_mm_factor = 25.4f; break;
      case 71: p->unit_to_mm_factor = 1.0f; break;
      case 90: set_all_axis_to_absolute(p, 1); break;
      case 91: set_all_axis_to_absolute(p, 0); break;
      case 92: line = handle_G92(value, p, line); break;
      default: line = cb->unprocessed(userdata, letter, value, line); break;
      }
    }
    else if (letter == 'M') {
      switch ((int) value) {
      case  2: gcodep_finish_program_and_reset(p); break;
      case 17: cb->motors_enable(userdata, 1); break;
      case 18: cb->motors_enable(userdata, 0); break;
      case 30: gcodep_finish_program_and_reset(p); break;
      case 82: p->axis_is_absolute[AXIS_E] = 1; break;
      case 83: p->axis_is_absolute[AXIS_E] = 0; break;
      case 84: cb->motors_enable(userdata, 0); break;
      case 104: line = set_param(p, 'S', cb->set_temperature, 1.0f, line); break;
      case 106: line = set_param(p, 'S', cb->set_fanspeed, 1.0f, line); break;
      case 107: cb->set_fanspeed(userdata, 0); break;
      case 109:
	line = set_param(p, 'S', cb->set_temperature, 1.0f, line);
	cb->wait_temperature(userdata);
	break;
      case 116: cb->wait_temperature(userdata); break;
      case 220:
	line = set_param(p, 'S', cb->set_speed_factor, 0.01f, line);
	break;
      default: line = cb->unprocessed(userdata, letter, value, line); break;
      }
    }
    else if (letter == 'N') {
      // Line number? Yeah, ignore for now :)
      processed_command = 0;
    }
    else {
      const enum GCodeParserAxis axis = gcodep_letter2axis(letter);
      if (axis == GCODE_NUM_AXES) {
        line = cb->unprocessed(userdata, letter, value, line);
      } else {
        // This line must be a continuation of a previous G0/G1 command.
        // Update the axis position then handle the move.
        const float unit_value = value * p->unit_to_mm_factor;
        p->axes_pos[axis] = abs_axis_pos(p, axis, unit_value);
	line = handle_move(p, line, 1);
	// make gcode_command_done() think this was a 'G0/G1' command
	letter = 'G';
	value = p->modal_g0_g1;
      }
    }
    if (processed_command) {
      cb->gcode_command_done(userdata, letter, value);
    }
  }
  p->err_msg = NULL;
}