⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keystick.cc

📁 CNC 的开放码,EMC2 V2.2.8版
💻 CC
📖 第 1 页 / 共 5 页
字号:
              emcStatus->task.motionLine < emcStatus->task.currentLine)            {              programActiveLine = emcStatus->task.motionLine;            }          else            {              programActiveLine = emcStatus->task.currentLine;            }          sprintf(line_string, "%d", programActiveLine);          if (programFp)            {              if (programFpLine > programActiveLine)                {                  rewind(programFp);                  programFpLine = 0;                  programLineText[0] = 0;                }              // fast forward over past lines              while (programFpLine < programActiveLine)                {                  fgets(programLineText, LINELEN, programFp);                  programFpLine++;                }              // now we have the current line              // knock off CR, LF              len = strlen(programLineText) - 1;              while (len >= 0)                {                  if (isspace(programLineText[len]))                    {                      programLineText[len] = 0;                      len--;                    }                  else                    {                      break;                    }                }            }          else            {              programLineText[0] = 0;            }        }      else        {          programActiveLine = 0;          programLineText[0] = 0;          line_string[0] = 0;        }      switch (emcStatus->task.interpState)        {        case EMC_TASK_INTERP_IDLE:          sprintf(interp_string, "%s", "IDLE    ");          break;        case EMC_TASK_INTERP_READING:          sprintf(interp_string, "%s", "RUNNING ");          break;        case EMC_TASK_INTERP_PAUSED:          sprintf(interp_string, "%s", "PAUSED  ");          break;        case EMC_TASK_INTERP_WAITING:          sprintf(interp_string, "%s", "RUNNING ");          break;        default:          sprintf(interp_string, "%s", "?       ");          break;        }      // fill in the active G codes      active_g_codes_string[0] = 0;      for (t = 1; t < ACTIVE_G_CODES; t++)        {          code = emcStatus->task.activeGCodes[t];          if (code == -1)            continue;          if (code % 10)            sprintf(scratch_string, "G%.1f ", (double) code / 10.0);          else            sprintf(scratch_string, "G%d ", code / 10);          strcat(active_g_codes_string, scratch_string);        }      // fill in the active M codes, settings too      active_m_codes_string[0] = 0;      for (t = 1; t < ACTIVE_M_CODES; t++)        {          code = emcStatus->task.activeMCodes[t];          if (code == -1)            continue;          sprintf(scratch_string, "M%d ", code);          strcat(active_m_codes_string, scratch_string);        }      sprintf(scratch_string, "F%.0f ", emcStatus->task.activeSettings[1]);      strcat(active_m_codes_string, scratch_string);      sprintf(scratch_string, "S%.0f ", emcStatus->task.activeSettings[2]);      strcat(active_m_codes_string, scratch_string);      // fill the screen in      override = (int) (emcStatus->motion.traj.scale * 100.0 + 0.5);      sprintf(scratch_string, "%4d%%", override);      if (override < 100)        wattrset(window, A_BOLD);      else        wattrset(window, A_UNDERLINE);      mvwaddstr(window, 6, 14, scratch_string);      sprintf(scratch_string, "%8d", emcStatus->io.tool.toolInSpindle);      wattrset(window, A_UNDERLINE);      mvwaddstr(window, 7, 11, scratch_string);      sprintf(scratch_string, "%8.4f", emcStatus->task.toolOffset.tran.z);      wattrset(window, A_UNDERLINE);      mvwaddstr(window, 8, 11, scratch_string);      wattrset(window, A_REVERSE);      mvwaddstr(window, 5, 1, state_string);      mvwaddstr(window, 5, 21, mode_string);      mvwaddstr(window, 6, 21, lube_on_string);      mvwaddstr(window, 7, 21, lube_level_string);      mvwaddstr(window, 5, 41, spindle_string);      mvwaddstr(window, 6, 41, brake_string);      mvwaddstr(window, 7, 41, mist_string);      mvwaddstr(window, 8, 41, flood_string);      mvwaddstr(window, 5, 61, home_string);      mvwaddstr(window, 6, 61, axisString(axisSelected));      wattrset(window, A_UNDERLINE);      mvwaddstr(window, 11, 21, pos_string);      if (coords == COORD_RELATIVE)        {          wattrset(window, 0);          mvwaddstr(window, 12, 21, origin_string);        }      wattrset(window, A_UNDERLINE);      mvwaddstr(window, 7, 69, speed_string);      mvwaddstr(window, 8, 69, incr_string);      if (emcStatus->task.mode == EMC_TASK_MODE_AUTO)        {          mvwaddstr(window, 14, 21, prog_string);          mvwaddstr(window, 15, 21, line_string);          if (emcStatus->task.interpState == EMC_TASK_INTERP_PAUSED)            wattrset(window, A_BOLD);          mvwaddstr(window, 16, 21, programLineText);          mvwaddstr(window, 17, 21, interp_string);          wattrset(window, A_UNDERLINE);          mvwaddstr(window, 18, 21, active_g_codes_string);          mvwaddstr(window, 19, 21, active_m_codes_string);        }      else if (emcStatus->task.mode == EMC_TASK_MODE_MDI)        {          if (emcStatus->task.interpState == EMC_TASK_INTERP_PAUSED)            wattrset(window, A_BOLD);          mvwaddstr(window, 16, 21, emcStatus->task.command);          mvwaddstr(window, 17, 21, interp_string);          wattrset(window, A_UNDERLINE);          mvwaddstr(window, 18, 21, active_g_codes_string);          mvwaddstr(window, 19, 21, active_m_codes_string);        }      if (error_string[0])        {          printError(error_string);        }      wattrset(window, A_REVERSE);      mvwaddstr(window, wmaxy - 1, wbegx, bottom_string);      wattrset(window, 0);      // restore cursor position      wmove(window, savey, savex);      wrefresh(window);    }}static int catchErrors = 1;static int updateStatus(){  NMLTYPE type;  if (0 == emcStatus ||      0 == emcStatusBuffer ||      ! emcStatusBuffer->valid())    {      return -1;    }  if (catchErrors)    {      if (0 == emcErrorBuffer ||          ! emcErrorBuffer->valid())        {          return -1;        }    }  switch (type = emcStatusBuffer->peek())    {    case -1:      // error on CMS channel      return -1;      break;    case 0:                     // no new data    case EMC_STAT_TYPE: // new data      // new data      break;    default:      return -1;      break;    }  if (catchErrors)    {      switch (type = emcErrorBuffer->read())        {        case -1:          // error reading channel          break;        case 0:          // nothing new          error_string[0] = 0;          break;        case EMC_OPERATOR_ERROR_TYPE:          strncpy(error_string,                  ((EMC_OPERATOR_ERROR *) (emcErrorBuffer->get_address()))->error,                  LINELEN - 1);          error_string[LINELEN - 1] = 0;          break;        case EMC_OPERATOR_TEXT_TYPE:          strncpy(error_string,                  ((EMC_OPERATOR_TEXT *) (emcErrorBuffer->get_address()))->text,                  LINELEN - 1);          error_string[LINELEN - 1] = 0;          break;        case EMC_OPERATOR_DISPLAY_TYPE:          strncpy(error_string,                  ((EMC_OPERATOR_DISPLAY *) (emcErrorBuffer->get_address()))->display,                  LINELEN - 1);          error_string[LINELEN - 1] = 0;          break;        case NML_ERROR_TYPE:          strncpy(error_string,                  ((NML_ERROR *) (emcErrorBuffer->get_address()))->error,                  NML_ERROR_LEN - 1);          error_string[NML_ERROR_LEN - 1] = 0;          break;        case NML_TEXT_TYPE:          strncpy(error_string,                  ((NML_TEXT *) (emcErrorBuffer->get_address()))->text,                  NML_ERROR_LEN - 1);          error_string[NML_ERROR_LEN - 1] = 0;          break;        case NML_DISPLAY_TYPE:          strncpy(error_string,                  ((NML_DISPLAY *) (emcErrorBuffer->get_address()))->display,                  NML_ERROR_LEN - 1);          error_string[NML_ERROR_LEN - 1] = 0;          break;        default:          strcpy(error_string, "unrecognized error");          break;        }    }  return 0;}/*  waits until the EMC reports that it's got the command with the  indicated serial_number. Sleeps between queries.*/#define EMC_COMMAND_TIMEOUT 1.0 // how long to wait until timeout#define EMC_COMMAND_DELAY   0.1 // how long to sleep between checksstatic int emcCommandWait(int serial_number){  double start = etime();  while (etime() - start < EMC_COMMAND_TIMEOUT)    {      updateStatus();      if (emcStatus->echo_serial_number == serial_number)        {          return 0;        }      esleep(EMC_COMMAND_DELAY);    }  printError("timeout sending command");  return -1;}/*  startTimer starts the timer to generate SIGALRM events, or stops the timer  if 'us' is 0. Enable a signal handler for SIGALRM before you call this.*/void startTimer(int us){  struct itimerval value;  value.it_interval.tv_sec = 0;  value.it_interval.tv_usec = us;  value.it_value.tv_sec = 0;  value.it_value.tv_usec = us;  setitimer(ITIMER_REAL, &value, 0);}/*  alarmHandler is attached to SIGALRM, and handles the reading of NML  status, the update of the status window, and key-up simulation and  handling*/static void alarmHandler(int sig){  // mask out this signal for now  signal(SIGALRM, SIG_IGN);  // read NML status  updateStatus();  // only print if main is not printing, so we don't clobber in the middle  if (! critFlag)    {      printStatus();    }  // simulate key-up event, as per comment below  keyup_count -= usecs;  if (keyup_count < 0)    {      keyup_count = 0;      oldch = 0;    }  /*    Key-up events are simulated as follows: each time a key is received,    keyup_count is loaded. If it's a new key, FIRST_KEYUP_DELAY is    loaded. If it's the same as the last key, NEXT_KEYUP_DELAY is loaded.    This is to handle the different delay between the first and subsequent    repeats.    Each time through this handler, keyup_count is decremented. If it    reaches 0, it means no key has been pressed before the delay expires,    and we see this as a key-up event.    If you have code that needs to respond to a key-up event, set a flag    when you do your key-down stuff, and put the key-up code in here,    like this:    if (myFlag && keyup_count == 0)      {        // do stuff for key up here        // and clear your flag        myFlag = 0;      }   */  // key up for jogs  if (axisJogging != AXIS_NONE && keyup_count == 0)    {      emc_axis_abort_msg.axis = axisIndex(axisJogging);      emc_axis_abort_msg.serial_number = ++emcCommandSerialNumber;      emcCommandBuffer->write(emc_axis_abort_msg);      emcCommandWait(emcCommandSerialNumber);      axisJogging = AXIS_NONE;    }  // key up for spindle speed changes  if (spindleChanging && keyup_count == 0)    {      emc_spindle_constant_msg.serial_number = ++emcCommandSerialNumber;      emcCommandBuffer->write(emc_spindle_constant_msg);      emcCommandWait(emcCommandSerialNumber);      spindleChanging = 0;    }  // reenable this signal  signal(SIGALRM, alarmHandler);  return;}static int done = 0;static void quit(int sig){  // disable timer  startTimer(0);  // clean up curses windows  delwin(progwin);  progwin = 0;  delwin(logwin);  logwin = 0;  delwin(toolwin);  toolwin = 0;  delwin(diagwin);  diagwin = 0;  delwin(helpwin);  helpwin = 0;  endwin();  // clean up NML buffers  if (emcErrorBuffer)    {      delete emcErrorBuffer;      emcErrorBuffer = 0;    }  if (emcStatusBuffer)    {      delete emcStatusBuffer;      emcStatusBuffer = 0;      emcStatus = 0;    }  if (emcCommandBuffer)    {      delete emcCommandBuffer;      emcCommandBuffer = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -