void MainWindow::mouseMoved(int x, int y) { // Get number the number of pixel between the last // und current mouse position int dx = x - m_mouseX; int dy = y - m_mouseY; // Check which button was pressend and apply action if(m_button == GLUT_LEFT_BUTTON) { moveXY(dx, dy); } if(m_button == GLUT_RIGHT_BUTTON) { moveHead(dx, dy); } if(m_button == GLUT_MIDDLE_BUTTON) { moveZ(dy); } // Transform viewport m_cam.apply(); // Save new coodinates m_mouseX = x; m_mouseY = y; }
void movey(int Ydist) { moveXY(0,Ydist); }
int xyControl() { define_key("\033Op", 1000); define_key("\033Oq", 1001); define_key("\033Or", 1002); define_key("\033Os", 1003); define_key("\033Ot", 1004); define_key("\033Ou", 1005); define_key("\033Ov", 1006); define_key("\033Ow", 1007); define_key("\033Ox", 1008); define_key("\033Oy", 1009); // non-arrow keypad keys (for macros) define_key("\033OM", 1010); // Enter define_key("\033OP", 1011); // NumLock define_key("\033OQ", 1012); // / define_key("\033OR", 1013); // * define_key("\033OS", 1014); // - define_key("\033Oj", 1015); // * define_key("\033Ok", 1016); // + define_key("\033Ol", 1017); // + define_key("\033Om", 1018); // . define_key("\033On", 1019); // . define_key("\033Oo", 1020); // - clearScreen(); echo(); curs_set(2); int Xdist = 0; int Ydist = 0; while(!quit) { //must be acuroind to servoblaster wiring convention move(10,0); clrtoeol(); move(14,0); clrtoeol(); refresh(); mvprintw(10,5,"Curent Position: X:%d\tY:%d",posX,posY); mvprintw(14,5,"Move:"); mvprintw(14,12,"X:%d",Xdist); mvprintw(14,22,"Y:%d",Ydist); move(14,14); refresh(); char valueString [6]; char c = getch(); if(c=='q'||c=='Q') return 0; if(c!='\n') { printw(" "); refresh(); ungetch(c); move(14,14); getnstr(valueString,6); Xdist = atoi(valueString); } move(14,24); c = getch(); if(c=='q'||c=='Q') return 0; if(c!='\n') { printw(" "); refresh(); ungetch(c); move(14,24); getnstr(valueString,6); Ydist = atoi(valueString); } move(15,4); clrtoeol; //getch(); mvprintw(15,5,"MOVING X:%d, Y:%d ",Xdist,Ydist); refresh(); posX +=Xdist; posY +=Ydist; moveXY(Xdist,Ydist); } }
void movex(int Xdist) { moveXY(Xdist,0); }
int main(int argc, char **argv) { int ADCvalue01 = 0; int StepSpeed = 100; //Stepping speed (smaler value = faster) int i = 0; int KeyHit = 0; int KeyCode[5]; int SingleKey=0; char TextLine[300]; char FileName[100] = ""; char FileNameOld[100] = ""; char FullFileName[300]; char a; char IsDigit[]="-1234567890"; int ReadState = 0; int MenueLevel = 0; int FileSelected = 0; int FileStartRow = 0; int stopPlot = 0; long xMin = 1000000, xMax = -1000000; long yMin = 1000000, yMax = -1000000; long coordinateCount = 0; long coordinatePlot = 0; long currentPlotX = 0, currentPlotY = 0, currentPlotDown = 1; long xNow = 0, yNow = 0, zNow = 0; char *pEnd; FILE *PlotFile; double Scale = 1.0; double OldScale = 1.0; double PicWidth = 0.0; double PicHeight = 0.0; long MoveLength = 100; long OldMoveLength = 200; long PlotStartTime = 0; int MoveFinished = 0; long stepPause = 5000; long stepPauseNormal = 5000; long stepPauseMaterial = 20000; long zHub = 200; int plotterMode = 1; char FileInfo[3]; long FileSize; long LongTemp; long DataOffset; long HeaderSize; long PictureWidth; long PictureHeight; int IntTemp; int ColorDepth; long CompressionType; long PictureSize; long XPixelPerMeter; long YPixelPerMeter; long ColorNumber; long ColorUsed; int PixelRed, PixelGreen, PixelBlue; int PixOK = 0; long StepsPerPixelX = 50, StepsPerPixelY = 50; long JetOffset1 = 40, JetOffset2 = 40; //Mapping between wiringPi and pin order of my I/O board. //This was necessary, because I used a wrong description of the GPIOs //You have to change the order according to your board! //@@@THESE ARE ALL OUTPUS!! strcpy(FileName, "noFiLE"); if (wiringPiSetup () == -1){ printf("Could not run wiringPiSetup!"); exit(1); } getmaxyx(stdscr, MaxRows, MaxCols); MessageY = MaxRows-3; clrscr(1, MaxRows); PrintRow('-', MessageY - 1); initscr(); noecho(); cbreak(); start_color(); while(!quit) { clearScreen(); char * choices[] = {"Plot File","Manual Control","Servo Control","Opto Sensor Control","X&Y Control","initalize","Exit"}; char *description[] = { "You select a file to plot and will plot the file on the plotter", "Will give you full control over the plotter for debuging or demenstration", "Lets you enter and test different duration of pulses sent to the servo for fine tuning and debugging", "Will read in the togleing of the opto sensor for debuging", "Will let you have control how much to move in x and y by ticks more precisly", "Test initalization procedure", "Will exit the prgram"}; int result = menus("Hello and Welcome to my creation please sleect a mode", choices,description,7,20); switch (result) { case 1: ; /* FILE * fp; char * line = NULL; size_t len = 0; ssize_t read; fp = fopen ("sampleGcode.txt","r");*/ //Plot file char dir[1024]; getcwd(dir,sizeof(dir)); MessageText("3 seconds until plotting starts !!!!!!!!!!!!!!!!!", 1, 2, 0); delay(3000); if((PlotFile=chooseFile(dir))==NULL){ sprintf(TextLine, "Can't open file '%s'!\n", FullFileName); strcpy(FileName, "NoFiLE"); ErrorText(TextLine); } else{ currentPlotX = 0; currentPlotY = 0; PlotStartTime = time(0); PrintMenue_03(FullFileName, coordinateCount, 0, 0, 0, PlotStartTime,Scale); coordinatePlot = 0; stopPlot = 0; if(currentPlotDown == 1){ penMove(1); currentPlotDown = 0; } while(!(feof(PlotFile)) && stopPlot == 0){ fread(&a, 1, 1, PlotFile); if(a == '>'){ ReadState = 0; } if(ReadState == 0 || ReadState == 1){ TextLine[i] = a; TextLine[i+1] = '\0'; i++; } if(ReadState == 2 || ReadState == 3){ if(strchr(IsDigit, a) != NULL){ TextLine[i] = a; TextLine[i+1] = '\0'; i++; } } if(ReadState == 2){ if(strchr(IsDigit, a) == NULL){ if(strlen(TextLine) > 0){ xNow = (strtol(TextLine, &pEnd, 10) - xMin) * 0.33333 * Scale; ReadState = 3; i=0; TextLine[0]='\0'; } } } if(ReadState == 3){ if(strchr(IsDigit, a) == NULL){ if(strlen(TextLine) > 0){ yNow = ((yMax - strtol(TextLine, &pEnd, 10)) - yMin) * 0.33333 * Scale;//Flip around y-axis coordinatePlot++; PrintMenue_03(FullFileName, coordinateCount, coordinatePlot, xNow, yNow, PlotStartTime, Scale); if(stopPlot == 0){ stopPlot =0; moveXY(xNow - currentPlotX, yNow - currentPlotY); currentPlotX = xNow; currentPlotY = yNow; // sprintf(TextLine, "xNow=%ld, yNow=%ld", xNow, yNow); // MessageText(TextLine, MessageX+1, MessageY+1, 0); // getch(); } else{ if(currentPlotDown == 1){ if(plotterMode == 1){ penMove(1); } currentPlotDown = 0; } } if(currentPlotDown == 0){ if(stopPlot == 0){ penMove(0); currentPlotDown = 1; } } ReadState = 2; i=0; TextLine[0]='\0'; } } } if(strcmp(TextLine, "<path") == 0){ if(currentPlotDown == 1){ penMove(1); currentPlotDown = 0; } ReadState = 2; i = 0; TextLine[0]='\0'; } if(a == '<'){ i = 1; TextLine[0] = a; TextLine[1] = '\0'; ReadState = 1; } } fclose(PlotFile); if(currentPlotDown == 1){ penMove(1); currentPlotDown = 0; } PrintMenue_03(FullFileName, coordinateCount, coordinatePlot, 0, 0, PlotStartTime,Scale); moveXY(-currentPlotX, -currentPlotY); currentPlotX = 0; currentPlotY = 0; while(kbhit()){ getch(); } MessageText("Finished! Press any key to return to main menu.", MessageX, MessageY, 0); getch(); break; } break; case 2: manualControl(); break; case 3: servoControl(); break; case 4: optoControl(); break; case 5: xyControl(); break; case 6: initalize(); break; case -1: default: system("reset"); quit=true; break; } } allSTOP(); endwin(); return 0; }