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

📄 control.c

📁 This is a CNCPro source file. It is include the G-Code interpreter source.
💻 C
📖 第 1 页 / 共 5 页
字号:
            break;
         case 'i':
         case 'I':
            gettext(22,19,59,24,buffer);
            box(22,19,59,24, RED,BLACK,WHITE,WHITE);
            gotoxy(13,1); cprintf("<Esc> To Exit");
            gotoxy(7,3); cprintf("Enter New Jog Increment:");
            _setcursortype(_NORMALCURSOR);
            gotoxy(16,4); get_value(&ctrl.jog_inc);
            _setcursortype(_NOCURSOR);
            puttext(22,19,59,24,buffer);
            break;
         case 71+1000: //home
            if(software.limit==OFF)
              {message("Limit Switches Must Be On To Home.");
               break;
              }
            gettext(22,19,59,24,buffer);
            box(22,19,59,24, RED,BLACK,WHITE,WHITE);
            gotoxy(2,1); cprintf("<Esc> To Exit    <Enter> To Home All");
            gotoxy(4,3); cprintf("<%c>->Home %c",software.x_label, software.x_label);
            gotoxy(21,3); cprintf("<%c>->Home %c",software.y_label, software.y_label);
            gotoxy(4,4); cprintf("<%c>->Home %c",software.z_label, software.z_label);
            if(software.a_status==ON) {gotoxy(21,4); cprintf("<%c>->Home %c",software.a_label, software.a_label);}
            gettext(2,6,22,12,buffer4);
            while((i=getch())!=27)
              {if(i==software.x_label || i==software.x_label+32)
                 {move_menu(1); if((msg=homing(&hardware, &software, &world, X_AXIS, NULL, NULL, NULL))!=COMPLETE) break;}
               if(i==software.y_label || i==software.y_label+32)
                 {move_menu(1); if((msg=homing(&hardware, &software, &world, Y_AXIS, NULL, NULL, NULL))!=COMPLETE) break;}
               if(i==software.z_label || i==software.z_label+32)
                 {move_menu(1); if((msg=homing(&hardware, &software, &world, Z_AXIS, NULL, NULL, NULL))!=COMPLETE) break;}
               if((i==software.a_label || i==software.a_label+32) && software.a_status==ON)
                 {move_menu(1); if((msg=homing(&hardware, &software, &world, A_AXIS, NULL, NULL, NULL))!=COMPLETE) break;}
               if(i==13) 
                 {move_menu(1);
                  if((msg=homing(&hardware, &software, &world, Z_AXIS, POS, A_AXIS, POS))!=COMPLETE) break;
                  if((msg=homing(&hardware, &software, &world, X_AXIS, NULL, Y_AXIS, NULL))!=COMPLETE) break;
                  if(software.home_z==NEG && software.home_a==NEG)
                     if((msg=homing(&hardware, &software, &world, Z_AXIS, NULL, A_AXIS, NULL))!=COMPLETE) break;
                  if(software.home_z==NEG && software.home_a==POS)
                     if((msg=homing(&hardware, &software, &world, Z_AXIS, NULL, NULL, NULL))!=COMPLETE) break;
                  if(software.home_a==NEG && software.home_z==POS)
                     if((msg=homing(&hardware, &software, &world, A_AXIS, NULL, NULL, NULL))!=COMPLETE) break;
                  break;
                 }
               puttext(2,6,22,12,buffer4);
               pt.x_pos=(world.x_pos-gcode.x_coord[ctrl.cs])*ctrl.pty;
               pt.y_pos=(world.y_pos-gcode.y_coord[ctrl.cs])*ctrl.pty;
               pt.z_pos=(world.z_pos-gcode.z_coord[ctrl.cs])*ctrl.pty;
               pt.a_pos=(world.a_pos-gcode.a_coord[ctrl.cs])*ctrl.pty;
               update_display(&software, pt.x_pos, pt.y_pos, pt.z_pos, pt.a_pos, 0, 0, ctrl.frate, ALL);
              }
            puttext(2,6,22,12,buffer4);
            puttext(22,19,59,24,buffer);
            break;
         case 31+1000:     //alt s
            temp_software=software;
            end_realtime();
            setup(&hardware, &software);

            //reset for new freq if neccessary
            load_setup(&hardware, &software, software.file);
            if(software.update_after==ON) begin_realtime(&software, fast_freq);
            else begin_realtime(&software, slow_freq);
            load_setup(&hardware, &software, software.file);

            change_units(&hardware, &software, software.units, software.units);
            ctrl.frate=change_unit(&software, ctrl.frate, software.units);
            change_pt_units(&temp_software, &world, software.units, software.a_units);
            change_gcode_units(&temp_software, &gcode, software.units, software.a_units);
            save_setup(&hardware, &software, "SETUP.INI");
            break;
         case 33+1000:     //alt f
            if(ctrl.M00==ON) {do_gcode(&hardware, &software, &gcode, &ctrl, &pt, 'M', 30);
                              ctrl.M00=OFF; message("");}
            if(strcmp(ctrl.file,"NONE")!=0) fclose(ifp);
            temp_software=software;
            end_realtime();
            get_file(ctrl.file, software.file);

            //reset for new freq if neccessary
            load_setup(&hardware, &software, software.file);
            if(software.update_after==ON) begin_realtime(&software, fast_freq);
            else begin_realtime(&software, slow_freq);
            load_setup(&hardware, &software, software.file);

            change_units(&hardware, &software, software.units, software.units);
            ctrl.frate=change_unit(&software, ctrl.frate, software.units);
            change_pt_units(&temp_software, &world, software.units, software.a_units);
            change_gcode_units(&temp_software, &gcode, software.units, software.a_units);
            save_setup(&hardware, &software, "SETUP.INI");
            
            window(43,3,78,18); textcolor(WHITE); textbackground(BLACK); clrscr();
            if(strcmp(ctrl.file,"NONE")==0) {window(1,1,80,25); break;}
            sprintf(tstring,"GCODE\\%s",ctrl.file);
            if((ifp=fopen(tstring,"r"))!=NULL)
              {//go to after M30
               while((ch=fgetc(ifp))!=EOF)
                 {if(ch=='(')
                    {while((ch=fgetc(ifp))!=EOF && ch!='\n');
                     if(ch==EOF) break;
                    }
                  if(ch=='M' || ch=='m')
                    {if(NULL==fscanf(ifp, "%lf", &num)) continue;
                     if(num==30) break;
                    }
                 }
               //clear old subs from memory and get new subs id's and file positions
               for(i=0;i<100;i++) sub[i].id=-1;
               while(ch!=EOF && (ch=fgetc(ifp))!=EOF)
                 {if(ch=='(')
                    {while((ch=fgetc(ifp))!=EOF && ch!='\n');
                     if(ch==EOF) break;
                    }
                  if(ch=='$')
                    {if(NULL==fscanf(ifp, "%lf", &num)) continue;
                     if(num>=0) for(i=0;i<100;i++) if(sub[i].id==-1) {sub[i].id=num; fgetpos(ifp,&sub[i].pos); break;}
                    }
                 }
               //reset file
               rewind(ifp);
               //clear all variables
               get_var(0,0,CLEAR);
               //set up file positions
               fgetpos(ifp,&fpos1);
               for(i=0;i<8;i++)
                 {if(fgets(fstring, 200, ifp)!=NULL)
                    {fstring[36]=0; textcolor(WHITE); textbackground(BLACK); gotoxy(1,8+i); cprintf("%s",fstring);}
                 }
               fgetpos(ifp,&fpos2); fsetpos(ifp, &fpos1);
              }
            else sprintf(ctrl.file,"NONE");
            window(1,1,80,25);
            break;
         case 24+1000:    //alt o
            temp_software=software;
            operator_setup(&hardware, &software, &gcode);
            ctrl.frate=change_unit(&software, ctrl.frate, software.units);
            change_pt_units(&temp_software, &world, software.units, software.a_units);
            save_gcode_setup(&gcode);
            break;
         case 72+1000:     //up
         case 77+1000:     //right
            if((kp==72+1000 && software.invert_arrows==OFF) || (kp==77+1000 && software.invert_arrows==ON))
               msg=jog(&hardware, &software, &pt, ctrl.jog_type, ctrl.jog_inc, Y_AXIS, POS);
            else msg=jog(&hardware, &software, &pt, ctrl.jog_type, ctrl.jog_inc, X_AXIS, POS);
            break;
         case 80+1000:    //down
         case 75+1000:    //left
            if((kp==80+1000 && software.invert_arrows==OFF) || (kp==75+1000 && software.invert_arrows==ON))
               msg=jog(&hardware, &software, &pt, ctrl.jog_type, ctrl.jog_inc, Y_AXIS, NEG);
            else msg=jog(&hardware, &software, &pt, ctrl.jog_type, ctrl.jog_inc, X_AXIS, NEG);
            break;
         case 73+1000:   //page up
            msg=jog(&hardware, &software, &pt, ctrl.jog_type, ctrl.jog_inc, Z_AXIS, POS);
            break;
         case 81+1000:   //page down
            msg=jog(&hardware, &software, &pt, ctrl.jog_type, ctrl.jog_inc, Z_AXIS, NEG);
            break;
         case '+':
         case '=':
            msg=jog(&hardware, &software, &pt, ctrl.jog_type, ctrl.jog_inc, A_AXIS, POS);
            break;
         case '-':
            msg=jog(&hardware, &software, &pt, ctrl.jog_type, ctrl.jog_inc, A_AXIS, NEG);
            break;
         case 'z':
         case 'Z':
            if(ctrl.cs!=0)
              {message("Must Be In MCS/G53 To Adjust Axis.");
               break;
              }
            gettext(22,19,59,24,buffer);
            box(22,19,59,24, RED,BLACK,WHITE,WHITE);
            gotoxy(2,1); cprintf("<Esc> To Exit   <Enter> To Zero All");
            gotoxy(4,3); cprintf("<%c> -> Adjust %c",software.x_label, software.x_label);
            gotoxy(21,3); cprintf("<%c> -> Adjust %c",software.y_label, software.y_label);
            gotoxy(4,4); cprintf("<%c> -> Adjust %c",software.z_label, software.z_label);
            if(software.a_status==ON) {gotoxy(21,4); cprintf("<%c> -> Adjust %c",software.a_label, software.a_label);}
            while((i=getch())!=27)
              {if(i>96 && i<123) i=i-32;
               if(i==software.x_label || i==software.y_label || i==software.z_label || (i==software.a_label && software.a_status==ON))
                 {_setcursortype(_NORMALCURSOR);
                  gotoxy(6,6); cprintf("Enter New '%c' Value:",i); gotoxy(27,6);
                  if(i==software.x_label) {tfloat=pt.x_pos; get_value_all(&tfloat); pt.x_pos=tfloat;}
                  if(i==software.y_label) {tfloat=pt.y_pos; get_value_all(&tfloat); pt.y_pos=tfloat;}
                  if(i==software.z_label) {tfloat=pt.z_pos; get_value_all(&tfloat); pt.z_pos=tfloat;}
                  if(i==software.a_label) {tfloat=pt.a_pos; get_value_all(&tfloat); pt.a_pos=tfloat;}
                  gotoxy(6,6); cprintf("                             "); _setcursortype(_NOCURSOR);
                 }
               if(i==13) {pt.x_pos=pt.y_pos=pt.z_pos=pt.a_pos=0; break;}
               update_display(&software, pt.x_pos, pt.y_pos, pt.z_pos, pt.a_pos, 0, 0, ctrl.frate, ALL);
              }
            puttext(22,19,59,24,buffer);
            break;
         case 'm':
         case 'M':
            if(ctrl.frate<.00009) {message("F/R Must Be >0 To Move."); break;}
            gettext(22,19,59,24,buffer);
            box(22,19,59,24, RED,BLACK,WHITE,WHITE);
            gotoxy(2,1); cprintf("<Esc> To Exit        <Enter> To Move");
            gotoxy(4,3); cprintf("<%c> -> %s",software.x_label, prn_val_all(dist_x));
            gotoxy(21,3); cprintf("<%c> -> %s",software.y_label, prn_val_all(dist_y));
            gotoxy(4,4); cprintf("<%c> -> %s",software.z_label, prn_val_all(dist_z));
            if(software.a_status==ON) {gotoxy(21,4); cprintf("<%c> -> %s",software.a_label, prn_val_all(dist_a));}
            while((i=getch())!=27 && i!=13)
              {if(i>96 && i<123) i=i-32;
               if(i==software.x_label || i==software.y_label || i==software.z_label || (i==software.a_label && software.a_status==ON))
                 {_setcursortype(_NORMALCURSOR);
                  gotoxy(6,6); cprintf("Enter New '%c' Value:",i); gotoxy(27,6);
                  if(i==software.x_label) {get_value_all(&dist_x); gotoxy(4,3); cprintf("<%c> -> %s",i,prn_val_all(dist_x));}
                  if(i==software.y_label) {get_value_all(&dist_y); gotoxy(21,3); cprintf("<%c> -> %s",i,prn_val_all(dist_y));}
                  if(i==software.z_label) {get_value_all(&dist_z); gotoxy(4,4); cprintf("<%c> -> %s",i,prn_val_all(dist_z));}
                  if(i==software.a_label) {get_value_all(&dist_a); gotoxy(21,4); cprintf("<%c> -> %s",i,prn_val_all(dist_a));}
                  gotoxy(6,6); cprintf("                             "); _setcursortype(_NOCURSOR);
                 }
              }
            puttext(22,19,59,24,buffer);
            if(i==27) break;
            gettext(2,6,22,12,buffer4);
            move_menu(2);
            message("Machine Move In Progress.");
            msg=move(&hardware, &software, &pt, &cur_speed, &ctrl.frate,
                     dist_x-(world.x_pos-gcode.x_coord[ctrl.cs])*ctrl.pty,
                     dist_y-(world.y_pos-gcode.y_coord[ctrl.cs])*ctrl.pty,
                     dist_z-(world.z_pos-gcode.z_coord[ctrl.cs])*ctrl.pty,
                     dist_a-(world.a_pos-gcode.a_coord[ctrl.cs])*ctrl.pty,
                     NULL,LINE_ENT,0,0,0,0,NULL,LINE_ENT);
            message("");
            puttext(2,6,22,12,buffer4);
            break;
         case 'p':
         case 'P':
            if(strcmp(ctrl.file,"NONE")==0)
              {gettext(22,19,59,24,buffer);
               box(22,19,59,24, RED,BLACK,WHITE,WHITE);
               gotoxy(4,3); cprintf("        No Program Loaded");
               gotoxy(4,4); cprintf("            <Any Key>");
               getch();
               window(1,1,80,25);
               puttext(22,19,59,24,buffer);
               break;
              }
            gettext(22,19,59,24,buffer);
            box(22,19,59,24, RED,BLACK,WHITE,WHITE);
            gotoxy(5,1); cprintf("Program Control <Esc> To Exit");
            gotoxy(4,3); cprintf("<%c> Skip Forward   <%c> Skip Back",25,24);
            gotoxy(4,4); cprintf("<R> Rewind And Reset Program");
            window(1,1,80,25);
            while(1)
              {while((ch=getch())!=27 && ch!=80 && ch!=72 && ch!='r' && ch!='R');
               if(ch==27) break;
               if(ch==80)
                 {while((ch2=fgetc(ifp))!='\n' && ch2!=EOF);
                  if(ch2==EOF) {message("End Of Program"); fsetpos(ifp,&fpos1); continue;}
                  gettext(43,5,78,17,buffer2); puttext(43,4,78,16,buffer2); puttext(43,17,78,17,buffer3);
                  fgetpos(ifp,&fpos1); fsetpos(ifp,&fpos2);
                  if(fgets(fstring, 200, ifp)!=NULL)
                    {fstring[36]=0; gotoxy(43,17); textcolor(WHITE); textbackground(BLACK); cprintf("%s",fstring);}
                  fgetpos(ifp,&fpos2); fsetpos(ifp,&fpos1);
                  message("Skipped Forward");
                  goloop=OFF;
                 }
               if(ch==72)
                 {place_holder=ftell(ifp);
                  rewind(ifp);

⌨️ 快捷键说明

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