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

📄 keystick.cc

📁 CNC 的开放码,EMC2 V2.2.8版
💻 CC
📖 第 1 页 / 共 5 页
字号:
/********************************************************************* Description:   keystick.cc*   Curses-based keyboard control panel**   Derived from a work by Fred Proctor & Will Shackleford** Author:* License: GPL Version 2* System: Linux*    * Copyright (c) 2004 All rights reserved.** Last change:* $Revision: 1.9 $* $Author: jepler $* $Date: 2007/03/22 22:15:32 $********************************************************************/#include <stdio.h>#include <string.h>#include <stdlib.h>#include <ctype.h>#include <signal.h>#include <errno.h>#include <sys/time.h>           // struct itimerval#include <sys/ioctl.h>          // ioctl(), TIOCGWINSZ, struct winsize#include <unistd.h>             // STDIN_FILENO#include "rcs.hh"               // rcs_print_error(), esleep()#include "emc.hh"               // EMC NML#include "emc_nml.hh"#include "emcglb.h"             // EMC_NMLFILE, TRAJ_MAX_VELOCITY#include "emccfg.h"             // DEFAULT_TRAJ_MAX_VELOCITY#include "inifile.hh"           // INIFILE#include "rcs_print.hh"#include "nml_oi.hh"#include "timer.hh"#include <ncurses.h>#define ESC 27#define TAB 9#define RETURN 13#define ALT(ch) ((ch) + 128)#define CTL(ch) ((ch) - 64)// paths to awk and xgraph, using to plot logs// fill these in for your system, if these are not in user's path#define AWK_PATH "awk"#define XGRAPH_PATH "xgraph"#define SYSTEM_STRING_LEN 1024// the NML channels to the EMC taskstatic RCS_CMD_CHANNEL *emcCommandBuffer = 0;static RCS_STAT_CHANNEL *emcStatusBuffer = 0;EMC_STAT *emcStatus = 0;// the NML channel for errorsstatic NML *emcErrorBuffer = 0;static char error_string[LINELEN] = "";// the current command numbers, set up updateStatus(), used in main()static int emcCommandSerialNumber = 0;// NML messagesstatic EMC_AXIS_HOME emc_axis_home_msg;static EMC_AXIS_ABORT emc_axis_abort_msg;static EMC_AXIS_JOG emc_axis_jog_msg;static EMC_AXIS_INCR_JOG emc_axis_incr_jog_msg;static EMC_TRAJ_SET_SCALE emc_traj_set_scale_msg;static EMC_TRAJ_ABORT emc_traj_abort_msg;static EMC_SPINDLE_ON emc_spindle_on_msg;static EMC_SPINDLE_OFF emc_spindle_off_msg;static EMC_SPINDLE_INCREASE emc_spindle_increase_msg;static EMC_SPINDLE_DECREASE emc_spindle_decrease_msg;static EMC_SPINDLE_CONSTANT emc_spindle_constant_msg;static EMC_SPINDLE_BRAKE_RELEASE emc_spindle_brake_release_msg;static EMC_SPINDLE_BRAKE_ENGAGE emc_spindle_brake_engage_msg;static EMC_COOLANT_MIST_ON emc_coolant_mist_on_msg;static EMC_COOLANT_MIST_OFF emc_coolant_mist_off_msg;static EMC_COOLANT_FLOOD_ON emc_coolant_flood_on_msg;static EMC_COOLANT_FLOOD_OFF emc_coolant_flood_off_msg;static EMC_LUBE_ON emc_lube_on_msg;static EMC_LUBE_OFF emc_lube_off_msg;static EMC_TOOL_LOAD_TOOL_TABLE emc_tool_load_tool_table_msg;static EMC_TASK_SET_MODE mode_msg;static EMC_TASK_SET_STATE state_msg;static EMC_TASK_ABORT task_abort_msg;static EMC_TASK_PLAN_INIT task_plan_init_msg;static EMC_TASK_PLAN_OPEN task_plan_open_msg;static EMC_TASK_PLAN_RUN task_plan_run_msg;static EMC_TASK_PLAN_EXECUTE task_plan_execute_msg;static EMC_TASK_PLAN_PAUSE task_plan_pause_msg;static EMC_TASK_PLAN_RESUME task_plan_resume_msg;static EMC_TASK_PLAN_STEP task_plan_step_msg;// critical section flag-- set to non-zero to prevent sig handler// from interrupting your window printingstatic unsigned char critFlag = 0;// the program path prefixstatic char programPrefix[LINELEN] = "";// the saved program namestatic char programFile[LINELEN] = "";static int programOpened = 0;static FILE * programFp = 0;static int programFpLine = 0;static int programActiveLine = 0;static char programLineText[LINELEN] = "";// error log filestatic FILE *errorFp = NULL;#define ERROR_FILE "keystick.err"typedef enum {  JOG_CONTINUOUS = 1,  JOG_INCREMENTAL} JOG_MODE;static JOG_MODE jogMode = JOG_CONTINUOUS;static double jogIncrement = 0.001;static double jogSpeed = 60.0;static int xJogPol = 1;static int yJogPol = 1;static int zJogPol = 1;typedef enum {  AXIS_NONE = 1,  AXIS_X,  AXIS_Y,  AXIS_Z} AXIS_TYPE;static AXIS_TYPE axisSelected = AXIS_X;static AXIS_TYPE axisJogging = AXIS_NONE;static const char * axisString(AXIS_TYPE a){  switch (a)    {    case AXIS_X:      return "    X SELECTED    ";    case AXIS_Y:      return "    Y SELECTED    ";    case AXIS_Z:      return "    Z SELECTED    ";    default:      return "    ? SELECTED    ";    }}static int axisIndex(AXIS_TYPE a){  if (a == AXIS_X)    return 0;  if (a == AXIS_Y)    return 1;  if (a == AXIS_Z)    return 2;  return 0;}typedef enum {  COORD_RELATIVE = 1,  COORD_ABSOLUTE} COORD_TYPE;static COORD_TYPE coords = COORD_RELATIVE;typedef enum {  POS_DISPLAY_ACT = 1,  POS_DISPLAY_CMD} POS_DISPLAY_TYPE;static POS_DISPLAY_TYPE posDisplay = POS_DISPLAY_ACT;static int spindleChanging = 0;#define INTERRUPT_USECS 50000static int usecs = INTERRUPT_USECS;static chtype ch = 0, oldch = 0;#define ASCLINELEN 80static char line_blank[ASCLINELEN + 1];static char scratch_string[ASCLINELEN] = "";static char state_string[ASCLINELEN] = "";static char mode_string[ASCLINELEN] = "";static char spindle_string[ASCLINELEN] = "";static char brake_string[ASCLINELEN] = "";static char mist_string[ASCLINELEN] = "";static char flood_string[ASCLINELEN] = "";static char lube_on_string[ASCLINELEN] = "";static char lube_level_string[ASCLINELEN] = "";static char home_string[ASCLINELEN] = "";static char pos_string[ASCLINELEN] = "";static char origin_string[ASCLINELEN] = "";static char speed_string[ASCLINELEN] = "";static char incr_string[ASCLINELEN] = "";static char prog_string[ASCLINELEN] = "";static char line_string[ASCLINELEN] = "";static char interp_string[ASCLINELEN] = "";static char active_g_codes_string[ASCLINELEN] = "";static char active_m_codes_string[ASCLINELEN] = "";// bottom string gill be set to "---Machine Version---"static char bottom_string[ASCLINELEN + 1] = "";// key repeat delays, in microseconds#define DEFAULT_FIRST_KEYUP_DELAY 300000 // works w/ 50000 alarmstatic int FIRST_KEYUP_DELAY = DEFAULT_FIRST_KEYUP_DELAY;#define DEFAULT_NEXT_KEYUP_DELAY  100000 // works w/ 50000 alarmstatic int NEXT_KEYUP_DELAY = DEFAULT_NEXT_KEYUP_DELAY;static int keyup_count = 0;static enum {DIAG_USECS = 1, DIAG_FIRST_KEYUP_DELAY, DIAG_NEXT_KEYUP_DELAY} diagtab = DIAG_USECS;static WINDOW * window = 0;static WINDOW * helpwin = 0;static WINDOW * diagwin = 0;static WINDOW * toolwin = 0;static WINDOW * logwin = 0;static WINDOW * progwin = 0;static int wbegy, wbegx;static int wmaxy, wmaxx;static void printFkeys(){  wattrset(window, A_BOLD);  mvwaddstr(window, 0, 1,  "F1 ");  mvwaddstr(window, 1, 1,  "F2 ");  mvwaddstr(window, 2, 1,  "F3 ");  mvwaddstr(window, 3, 1,  "F4 ");  mvwaddstr(window, 0, 21, "F5 ");  mvwaddstr(window, 1, 21, "F6 ");  mvwaddstr(window, 2, 21, "F7 ");  mvwaddstr(window, 3, 21, "F8 ");  mvwaddstr(window, 0, 41, "F9 ");  mvwaddstr(window, 1, 41, "F10");  mvwaddstr(window, 2, 41, "F11");  mvwaddstr(window, 3, 41, "F12");  mvwaddstr(window, 0, 61, "ESC");  mvwaddstr(window, 1, 61, "TAB");  mvwaddstr(window, 2, 61, "END");  mvwaddstr(window, 3, 61, " ? ");  wattrset(window, 0);  mvwaddstr(window, 0, 5,      "Estop On/Off  ");  mvwaddstr(window, 1, 5,      "Machine On/Off");  mvwaddstr(window, 2, 5,      "Manual Mode   ");  mvwaddstr(window, 3, 5,      "Auto Mode     ");  mvwaddstr(window, 0, 25,     "MDI Mode      ");  mvwaddstr(window, 1, 25,     "Reset Interp  ");  mvwaddstr(window, 2, 25,     "Mist On/Off   ");  mvwaddstr(window, 3, 25,     "Flood On/Off  ");  mvwaddstr(window, 0, 45,     "Spndl Fwd/Off ");  mvwaddstr(window, 1, 45,     "Spndl Rev/Off ");  mvwaddstr(window, 2, 45,     "Spndl Decrease");  mvwaddstr(window, 3, 45,     "Spndl Increase");  mvwaddstr(window, 0, 65,     "Aborts Actions");  mvwaddstr(window, 1, 65,     "Selects Params");  mvwaddstr(window, 2, 65,     "Quits Display ");  mvwaddstr(window, 3, 65,     "Toggles Help  ");}#define ERR_Y ((wmaxy) - 2)#define ERR_X (wbegx)static void clearWindow(){  int t;  critFlag = 1;  wattrset(window, A_BOLD);  for (t = wbegy; t <= wmaxy; t++)    {      mvwaddstr(window, t, 0, line_blank);    }  wrefresh(window);  wattrset(window, 0);  for (t = wbegy; t <= wmaxy; t++)    {      mvwaddstr(window, t, 0, line_blank);    }  wmove(window, wmaxy, wbegx);  wrefresh(window);  critFlag = 0;}static void printError(const char * errstring){  int savey, savex;  chtype saveattr;  // log to error file  if (errorFp)    {      fprintf(errorFp, "%f\t%s\n", etime(), errstring);    }  if (0 == window)    {      // no window yet      return;    }  critFlag = 1;  getyx(window, savey, savex);  saveattr = getattrs(window);  mvwaddstr(window, ERR_Y, ERR_X, line_blank);  wattrset(window, A_BOLD);  mvwaddstr(window, ERR_Y, ERR_X, errstring);  wattrset(window, (int) saveattr);  wmove(window, savey, savex);  wrefresh(window);  critFlag = 0;}static void printStatus(){  int savey, savex;  int t;  int line;  int override;  int len;  int code;  getyx(window, savey, savex);  if (window == helpwin)    {      printFkeys();      wattrset(window, 0);      mvwaddstr(window, 5, 1, "x/X y/Y z/Z");      mvwaddstr(window, 6, 1, "HOME");      mvwaddstr(window, 7, 1, "< > or , .");      mvwaddstr(window, 8, 1, "1-9, 0");      mvwaddstr(window, 9, 1, "<- arrow keys ->");      mvwaddstr(window, 10, 1, "^ arrow keys V");      mvwaddstr(window, 11, 1, "PageUp/PageDown");      mvwaddstr(window, 12, 1, "c/C");      mvwaddstr(window, 13, 1, "i/I");      mvwaddstr(window, 14, 1, "#");      mvwaddstr(window, 15, 1, "@");      wattrset(window, A_UNDERLINE);      mvwaddstr(window, 5, 19, "selects axis");      mvwaddstr(window, 6, 19, "homes selected axis");      mvwaddstr(window, 7, 19, "change jog speed");      mvwaddstr(window, 8, 19, "10%-90%, 100% feed");      mvwaddstr(window, 9, 19, "jog X");      mvwaddstr(window, 10, 19, "jog Y");      mvwaddstr(window, 11, 19, "jog Z");      mvwaddstr(window, 12, 19, "sets continuous jog");      mvwaddstr(window, 13, 19, "toggles incr jog");      mvwaddstr(window, 14, 19, "toggles abs/rel");      mvwaddstr(window, 15, 19, "toggles cmd/act");      wattrset(window, 0);      mvwaddstr(window, 5, 41, "B");      mvwaddstr(window, 6, 41, "b");      mvwaddstr(window, 7, 41, "o/O");      mvwaddstr(window, 8, 41, "r/R");      mvwaddstr(window, 9, 41, "p/P");      mvwaddstr(window, 10, 41, "s/S");      mvwaddstr(window, 11, 41, "quote/XYZGM");      mvwaddstr(window, 12, 41, "l/L");      mvwaddstr(window, 13, 41, "u/U");      wattrset(window, A_UNDERLINE);      mvwaddstr(window, 5, 54, "turns spindle brake on");      mvwaddstr(window, 6, 54, "turns spindle brake off");      mvwaddstr(window, 7, 54, "prompts for program");      mvwaddstr(window, 8, 54, "runs selected program");      mvwaddstr(window, 9, 54, "pauses motion");      mvwaddstr(window, 10, 54, "starts motion again");      mvwaddstr(window, 11, 54, "prompts for MDI command");      mvwaddstr(window, 12, 54, "prompts for tool table");      mvwaddstr(window, 13, 54, "turns lube off/on");      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);    }  else if (window == diagwin)    {      wattrset(window, A_BOLD);      mvwaddstr(window, 0, 34, "Diagnostics");      wattrset(window, 0);      mvwaddstr(window, 2, 1, "Task Heartbeat/Cmd:");      mvwaddstr(window, 3, 1, "IO Heartbeat/Cmd:");      mvwaddstr(window, 4, 1, "Motion Heartbeat/Cmd:");      if (diagtab == DIAG_USECS)          wattrset(window, A_BOLD);      mvwaddstr(window, 6, 1,  "Polling Period (usecs):");      wattrset(window, 0);      if (diagtab == DIAG_FIRST_KEYUP_DELAY)          wattrset(window, A_BOLD);      mvwaddstr(window, 7, 1, "Kbd Delay Until Repeat:");      wattrset(window, 0);      if (diagtab == DIAG_NEXT_KEYUP_DELAY)          wattrset(window, A_BOLD);      mvwaddstr(window, 8, 1, "Kbd Delay Between Repeats:");      wattrset(window, 0);      mvwaddstr(window, 10, 1, "Task Execution State:");      mvwaddstr(window, 12, 1, "Traj Scale:");      mvwaddstr(window, 13, 1, "X Scale:");      mvwaddstr(window, 14, 1, "Y Scale:");      mvwaddstr(window, 15, 1, "Z Scale:");      mvwaddstr(window, 17, 1, "V/Max V:");      mvwaddstr(window, 18, 1, "A/Max A:");      wattrset(window, A_UNDERLINE);      sprintf(scratch_string, "%10ld %10d %10d", emcStatus->task.heartbeat,              emcStatus->echo_serial_number,              emcStatus->status);

⌨️ 快捷键说明

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