void setTime(void) { RTC_t rtc; int c = -1, pos = 0, v = 0; win_showMsgWin(); scr_setScroll(false); rtc_gettime(&rtc); scr_puts("D-ENTER C-CANCEL A-Up B-Down"); scr_puts("\n'*' -Left '#' -RIGHT"); scr_printf("\n\nTime: %02d.%02d.%02d %02d:%02d:%02d", rtc.mday, rtc.month, rtc.year - 2000, rtc.hour, rtc.min, rtc.sec); do { switch (pos) { case 0: v = rtc.mday; break; case 1: v = rtc.month; break; case 2: v = rtc.year - 2000; break; case 3: v = rtc.hour; break; case 4: v = rtc.min; break; case 5: v = rtc.sec; break; } if (c == KEY_STAR) pos = pos <= 0 ? 5 : pos - 1; if (c == KEY_DIES) pos = pos >= 5 ? 0 : pos + 1; scr_gotoxy(0, 4); scr_fontColorNormal(); scr_printf(" New: %02d.%02d.%02d %02d:%02d:%02d", rtc.mday, rtc.month, rtc.year - 2000, rtc.hour, rtc.min, rtc.sec); scr_fontColorInvers(); scr_gotoxy(pos * 3 + 6, 3); scr_printf("%02d", v); while ((c = kbd_getKey()) < 0); if (c == KEY_A) v++; if (c == KEY_B) v--; switch (pos) { case 0: if (v >= 1 && v <= 31) rtc.mday = v; break; case 1: if (v >= 1 && v <= 12) rtc.month = v; break; case 2: if (v >= 12 && v <= 30) rtc.year = v + 2000; break; case 3: if (v >= 0 && v <= 23) rtc.hour = v; break; case 4: if (c >= 0 && v <= 59) rtc.min = v; break; case 5: if (v >= 0 && v <= 59) rtc.sec = v; break; } } while (c != KEY_C && c != KEY_D); if (c == KEY_D) rtc_settime(&rtc); }
void __debug_diplay_info() { mem_capacity = (1<<20) + (EXT_MEM_K<<10); // memory end scr_puts("Memory space: "); scr_putdec(mem_capacity); scr_puts("byte = "); scr_putdec(mem_capacity>>20); scr_puts("MB\n"); }
void readFileList(void) { #if (USE_SDCARD == 1) || defined( USE_USB_OTG_HS ) FRESULT fres; FILINFO finfo; DIR dirs; static char lfn[_MAX_LFN + 1]; int i; win_showMsgWin(); scr_gotoxy(2, 0); scr_printf("Open SD dir.. "); if ((fres = f_opendir(&dirs, path)) != FR_OK) { showCriticalStatus(" f_opendir()\n error [code:%d]\n Only RESET possible at now", fres); WAIT_KEY_C(); } scr_puts("\nRead file list"); finfo.lfname = lfn; finfo.lfsize = sizeof(lfn); for (fileListSz = 0; f_readdir(&dirs, &finfo) == FR_OK && fileListSz < MAX_FILE_LIST_SZ;) { scr_gotoxy(0, 3); scr_printf("files:[%d]", fileListSz); if (!finfo.fname[0]) break; if (finfo.fname[0] == '.') continue; if (!(finfo.fattrib & AM_DIR) && strcmp(CONF_FILE_NAME, *finfo.lfname ? finfo.lfname : finfo.fname) != 0) strncpy(&fileList[fileListSz++][0], *finfo.lfname ? finfo.lfname : finfo.fname, MAX_FILE_NAME_SZ); } if (loadedFileName[0] != 0) { // set last loaded file as selected file scr_printf("\nselect:'%s'..", loadedFileName); for (i = 0; i < fileListSz; i++) { if (!strcmp(&fileList[i][0], &loadedFileName[0])) { loadedFileName[0] = 0; // reset for next dir reload currentFile = i; if (currentFile < FILE_LIST_ROWS) firstFileInWin = 0; else if ((fileListSz - currentFile) < FILE_LIST_ROWS) firstFileInWin = fileListSz - FILE_LIST_ROWS; else firstFileInWin = currentFile; break; } } scr_printf("\npos in win/cur file:%d/%d", firstFileInWin, currentFile); } scr_puts("\n---- OK -----"); #endif }
/*************************************************** * Initialize _smParam and load from config file */ void initSmParam(void) { _smParam.smoothStartF_from0[0] = SM_SMOOTH_START_X*K_FRQ; _smParam.smoothStartF_from0[1] = SM_SMOOTH_START_Y*K_FRQ; _smParam.smoothStartF_from0[2] = SM_SMOOTH_START_Z*K_FRQ; _smParam.smoothStopF_to0[0] = SM_SMOOTH_STOP_X*K_FRQ; _smParam.smoothStopF_to0[1] = SM_SMOOTH_STOP_Y*K_FRQ; _smParam.smoothStopF_to0[2] = SM_SMOOTH_STOP_Z*K_FRQ; _smParam.smoothAF[0] = SM_SMOOTH_DFEED_X*SM_X_STEPS_PER_MM*SM_SMOOTH_TFEED*K_FRQ / 1000; _smParam.smoothAF[1] = SM_SMOOTH_DFEED_Y*SM_Y_STEPS_PER_MM*SM_SMOOTH_TFEED*K_FRQ / 1000; _smParam.smoothAF[2] = SM_SMOOTH_DFEED_Z*SM_Z_STEPS_PER_MM*SM_SMOOTH_TFEED / 1000 * K_FRQ; _smParam.maxFeedRate[0] = SM_X_MAX_STEPS_PER_SEC*K_FRQ; _smParam.maxFeedRate[1] = SM_Y_MAX_STEPS_PER_SEC*K_FRQ; _smParam.maxFeedRate[2] = SM_Z_MAX_STEPS_PER_SEC*K_FRQ; _smParam.maxSpindleTemperature = MAX_SPINDEL_TEMPERATURE; #if (USE_SDCARD == 1) FIL fid; char str[256], *p; int i; FRESULT fres = f_open(&fid, CONF_FILE_NAME, FA_READ); if (fres == FR_OK) { scr_printf("\nloading %s", CONF_FILE_NAME); for (i = 0; i < 3; i++) { scr_puts("."); if (f_gets(str, sizeof(str), &fid) == NULL) break; DBG("\nc:%d:'%s'", i, str); if (f_gets(str, sizeof(str), &fid) == NULL) break; DBG("\nd:%d:'%s'", i, str); p = str; _smParam.smoothStartF_from0[i] = strtod_M(p, &p); _smParam.smoothStopF_to0[i] = strtod_M(p, &p); _smParam.smoothAF[i] = strtod_M(p, &p); _smParam.maxFeedRate[i] = strtod_M(p, &p); } if (f_gets(str, sizeof(str), &fid) != NULL) { DBG("t:'%s'", str); if (f_gets(str, sizeof(str), &fid) != NULL) _smParam.maxSpindleTemperature = strtod_M(str, &p); } scr_puts("*"); f_close(&fid); scr_puts(" OK"); } #endif }
/*************************************************** * Save _smParam to config file */ void saveSmParam(void) { #if (USE_SDCARD == 1) FIL fid; int i; f_unlink(CONF_FILE_NAME); FRESULT fres = f_open(&fid, CONF_FILE_NAME, FA_CREATE_ALWAYS | FA_WRITE); if (fres != FR_OK) { win_showErrorWin(); scr_printf("Error save file:'%s'\n Status:%d [%d/%d]", CONF_FILE_NAME, fres, SD_errno, SD_step); scr_puts("\n\n\t PRESS C-KEY"); WAIT_KEY_C(); return; } scr_printf("\nSave into %s", CONF_FILE_NAME); for (i = 0; i < 3; i++) { f_printf(&fid, "Crd%d (F:steps*%d/sec): 'smoothStartF_from0,smoothStopF_to0,smoothAF,maxFeedRate\n", i, K_FRQ); f_printf(&fid, "%d,%d,%d,%d,%d\n", _smParam.smoothStartF_from0[i], _smParam.smoothStopF_to0[i], _smParam.smoothAF[i], _smParam.maxFeedRate[i] ); scr_puts("."); } f_printf(&fid, "Spindle switch-off temperature (C.degree)\n"); f_printf(&fid, "%d\n", _smParam.maxSpindleTemperature); scr_puts("*"); f_close(&fid); scr_puts(" - OK"); #endif }
uint8_t questionYesNo(char *msg, char *param) { win_showMsgWin(); scr_printf(msg, param); scr_gotoxy(5, 6); scr_puts("'D' - OK, 'C' - Cancel"); SetTouchKeys(kbdQuestion); while (true) switch(kbd_getKey()) { case KEY_D: return true; case KEY_C: return false; } }
void scr_putp32(void *ptr) { char char_map[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; u32int mem = (u32int)ptr; char row[9]; u32int col = 0; row[8] = '\0'; row[col++] = char_map[((u32int)mem >> 28) & 0xF]; row[col++] = char_map[((u32int)mem >> 24) & 0xF]; row[col++] = char_map[((u32int)mem >> 20) & 0xF]; row[col++] = char_map[((u32int)mem >> 16) & 0xF]; row[col++] = char_map[((u32int)mem >> 12) & 0xF]; row[col++] = char_map[((u32int)mem >> 8) & 0xF]; row[col++] = char_map[((u32int)mem >> 4) & 0xF]; row[col++] = char_map[(u32int)mem & 0xF]; scr_puts(row); }
void cnc_extruder_t(int temperature, int isWait) { extrudT_setTemperature((int16_t)temperature); if (isWait) { if ((curGCodeMode & GFILE_MODE_MASK_EXEC) != 0) { scr_fontColor(Red, Black); while (!extrudT_isReady()) { scr_gotoxy(3, 2); scr_fontColor(Yellow, Blue); scr_printf("extruder t:%03d/%03d", extrudT_getTemperatureReal(), extrudT_getTemperatureWait()); if (kbd_getKey() == KEY_C) return; } scr_gotoxy(3, 2); scr_fontColor(White, Black); scr_puts(" "); } } }
uint8_t sendLine(uint32_t fxyze[], uint32_t abs_dxyze[], uint8_t dir_xyze[]) { uint32_t f = 0; uint32_t i, n = 0; for (i = 0; i < 3; i++) { if (fxyze[i] > f) { f = fxyze[i]; n = i; } } // if(abs_dxyze[n] > 20) { // for(i = 0; i < 4; i++) fxyze[i] = (uint32_t)((uint64_t)f * (uint64_t)abs_dxyze[i]/abs_dxyze[n]); if (abs_dxyze[n] > 10) { for (i = 0; i < 4; i++) if (i != n) { fxyze[i] = (uint32_t)(((uint64_t)f * (uint64_t)abs_dxyze[i]) / abs_dxyze[n]) + 1; //+1 for debug } } if ((curGCodeMode & GFILE_MODE_MASK_EXEC) == 0) { int i; for (i = 0; i < 4; i++) if (fxyze[i] != 0) { commonTimeReal += abs_dxyze[i] * 1000L * K_FRQ / fxyze[i]; break; } if ((curGCodeMode & GFILE_MODE_MASK_SHOW) != 0) { if (dir_xyze[0]) linesBuffer.stepsX += abs_dxyze[0]; else linesBuffer.stepsX -= abs_dxyze[0]; if (dir_xyze[1]) linesBuffer.stepsY += abs_dxyze[1]; else linesBuffer.stepsY -= abs_dxyze[1]; if (dir_xyze[2]) linesBuffer.stepsZ += abs_dxyze[2]; else linesBuffer.stepsZ -= abs_dxyze[2]; #if (USE_LCD != 0) double x, y; short scrX, scrY; x = (double)linesBuffer.stepsX / SM_X_STEPS_PER_MM; y = (double)linesBuffer.stepsY / SM_Y_STEPS_PER_MM; scrX = crdXtoScr(TABLE_CENTER_X + x); scrY = crdYtoScr(TABLE_CENTER_Y + y); if (scrX != prev_scrX || prev_scrY != scrY) scr_Line(prev_scrX, prev_scrY, scrX, scrY, calcColor((uint8_t)(linesBuffer.stepsZ * 5 / SM_X_STEPS_PER_MM) & 0x1F)); prev_scrX = scrX; prev_scrY = scrY; #endif } return true; } #ifdef DEBUG_MODE DBG("\n\tsendLine dx:%c%d(%d)\tdy:%c%d(%d)\tdz:%c%d(%d) tz:%d ty:%d tz:%d", dir_xyze[0] ? '+' : '-', abs_dxyze[0], fxyze[0], dir_xyze[1] ? '+' : '-', abs_dxyze[1], fxyze[1], dir_xyze[2] ? '+' : '-', abs_dxyze[2], fxyze[2], fxyze[0] == 0 ? 0 : abs_dxyze[0] * 1000L * K_FRQ / fxyze[0], fxyze[1] == 0 ? 0 : abs_dxyze[1] * 1000L * K_FRQ / fxyze[1], fxyze[2] == 0 ? 0 : abs_dxyze[2] * 1000L * K_FRQ / fxyze[2]); { static uint32_t prevF[3] = { 0, 0, 0 }; static uint8_t prevDir[3] = { 0, 0, 0 }; int i; for (i = 0; i < 3; i++) { double p; if ((p = labs(prevF[i] - fxyze[i]) / (double)_smParam.smoothStartF_from0[i]) > 1.5) { p *= 100; DBG(" !!!!!! <%d:%d/%d\t%f> %s", i, labs(prevF[i] - fxyze[i]), _smParam.smoothStartF_from0[i], p, p > 250 ? "$$$" : ""); } if (prevDir[i] != dir_xyze[i] && (p = fxyze[i] / (double)_smParam.smoothStartF_from0[i]) > 1.5) { p *= 100; DBG(" !!!!!! ## <%d:%d/%d\t%f> %s", i, labs(prevF[i] - fxyze[i]), _smParam.smoothStartF_from0[i], p, p > 250 ? "$$$" : ""); } if (fxyze[i] > _smParam.maxFeedRate[i]) { DBG(" !!!!!! <%d:%d/%d too hight feedrate!> ", i, fxyze[i], _smParam.maxFeedRate[i]); } if (fxyze[i] < (50 * SM_X_STEPS_PER_MM / 60) && abs_dxyze[i] > 120) { DBG(" !!!!!! <%d:%d too slow feedrate!> ", i, fxyze[i]); } } for (i = 0; i < 3; i++) { prevF[i] = fxyze[i]; prevDir[i] = dir_xyze[i]; } } #endif if (!cnc_waitSMotorReady()) return false; if (isPause) { #if (USE_KEYBOARD != 0) #if (USE_KEYBOARD == 2) const TPKey_p * tp_save; tp_save = SetTouchKeys(kbdPause); #endif #if (USE_KEYBOARD == 1) scr_fontColor(Black, White); scr_gotoxy(1, 13); scr_puts(" PAUSE..'B'-continue 'C'-cancel"); scr_clrEndl(); #endif while (stepm_inProc()) { } stepm_EmergeStop(); while (isPause) { switch (kbd_getKey()) { case KEY_C: isPause = false; #if (USE_KEYBOARD == 2) SetTouchKeys(tp_save); #endif return false; case KEY_B: isPause = false; } } #if (USE_KEYBOARD == 1) scr_fontColor(White, Black); scr_gotoxy(1, 13); scr_clrEndl(); #endif #if (USE_KEYBOARD == 2) SetTouchKeys(tp_save); #endif #endif } stepm_addMove(abs_dxyze, fxyze, dir_xyze); return true; }
uint8_t cnc_waitSMotorReady(void) { #if (USE_LCD != 0) static uint32_t time = 0; #endif #if (USE_STEP_DEBUG == 1) static uint8_t isStepDump = false; #endif int i; do { if (stepm_getRemainLines() > 1) { scr_fontColor(Yellow, Black); for (i = 0; i < STEPS_MOTORS; i++) { int32_t globalSteps = stepm_getCurGlobalStepsNum(i); double n = (double)globalSteps / axisK[i]; scr_gotoxy(1 + i * 10, 3); scr_printf("%c:%f ", axisName[i], n); #if (USE_ENCODER == 1) if (i == 2) { int32_t enVal = encoderZvalue(); double encValmm = (double)(enVal * MM_PER_360) / ENCODER_Z_CNT_PER_360; scr_gotoxy(1 + 2 * 10, 4); scr_printf("errZ:%f ", encValmm - n); if (isEncoderCorrection) { scr_gotoxy(1, 6); scr_printf("dZ:%d[%d] ", encoderCorrectionDelta, encoderCorrectionMaxDelta); scr_gotoxy(15, 6); scr_printf("Up:%d Dn:%d ", encoderCorrectionCntUp, encoderCorrectionCntDown); } } #endif } #if (USE_STEP_DEBUG == 1) if (isStepDump) step_dump(); #endif #if (USE_LCD != 0) if (time != Seconds()) { uint32_t t; time = Seconds(); t = time - startWorkTime; scr_gotoxy(30, 12); scr_fontColor(Cyan, Black); scr_printf("%02d:%02d:%02d", t / 3600, (t / 60) % 60, t % 60); } #endif } #if (USE_KEYBOARD != 0) switch (kbd_getKey()) { case KEY_C: stepm_EmergeStop(); return false; case KEY_A: isPause = true; break; case KEY_0: #if (USE_ENCODER == 1) isEncoderCorrection = false; #endif scr_gotoxy(1, 6); scr_clrEndl(); break; case KEY_1: #if (USE_ENCODER == 1) isEncoderCorrection = true; #endif break; case KEY_7: #if (USE_STEP_DEBUG == 1) isStepDump = true; #endif break; case KEY_8: #if (USE_STEP_DEBUG == 1) isStepDump = false; #endif break; } #endif } while (stepm_LinesBufferIsFull()); if (limits_chk()) { stepm_EmergeStop(); #if (USE_LCD != 0) scr_fontColor(Red, Black); scr_gotoxy(7, 11); scr_puts("LIMITS ERROR!"); scr_clrEndl(); #endif return false; } return true; }
void cnc_gfile(char *fileName, int mode) { #if (USE_LCD != 0) && (MAX_SHOW_GCODE_LINES > 0) int n; #endif int lineNum; uint8_t hasMoreLines; initGcodeProc(); #if (USE_SDCARD != 0) FIL fid; FRESULT res = f_open(&fid, fileName, FA_READ); if (res != FR_OK) { win_showErrorWin(); #if (USE_SDCARD == 1) scr_printf("Error open file:'%s'\nStatus:%d [%d]", fileName, (int)res, SD_errno); #elif (USE_SDCARD == 2) scr_printf("Error open file:'%s'\nStatus:%d", fileName, (int)res); #endif return; } #endif curGCodeMode = mode; #if (USE_LCD != 0) if ((curGCodeMode & GFILE_MODE_MASK_SHOW) != 0) { scr_Rectangle(crdXtoScr(0), crdYtoScr(MAX_TABLE_SIZE_Y), crdXtoScr(MAX_TABLE_SIZE_X), crdYtoScr(0), Red, false); scr_Line(prev_scrX, 30, prev_scrX, 240 - 30, Green); scr_Line(50, prev_scrY, 320 - 50, prev_scrY, Green); } #endif if ((curGCodeMode & GFILE_MODE_MASK_EXEC) != 0) { #if (USE_KEYBOARD == 1) scr_fontColor(Blue, Black); scr_gotoxy(3, 14); scr_puts("C-Cancel A-Pause 0/1-encoder"); #elif (USE_KEYBOARD == 2) SetTouchKeys(kbdGFile); #endif } lineNum = 1; hasMoreLines = true; do { char *p = cncFileBuf, *str; while (true) { *p = 0; str = p + 1; if ((cncFileBuf + sizeof(cncFileBuf) - str) < (MAX_STR_SIZE + 1)) break; #if (USE_SDCARD != 0) if (f_gets(str, MAX_STR_SIZE, &fid) == NULL) { hasMoreLines = false; break; } #endif str_trim(str); *p = (uint8_t)strlen(str) + 1; p += *p + 1; } for (p = cncFileBuf; !isGcodeStop && *p != 0; lineNum++, p += *p + 1) { uint8_t st; str = p + 1; if ((curGCodeMode & GFILE_MODE_MASK_EXEC) != 0) { GCODE_CMD *gp; #if (USE_LCD != 0) && (MAX_SHOW_GCODE_LINES > 0) int i; #endif linesBuffer.gcodePtrCur++; if (linesBuffer.gcodePtrCur > (MAX_SHOW_GCODE_LINES - 1)) linesBuffer.gcodePtrCur = 0; gp = &linesBuffer.gcode[linesBuffer.gcodePtrCur]; strcpy(gp->cmd, str); gp->lineNum = lineNum; #if (USE_LCD != 0) && (MAX_SHOW_GCODE_LINES > 0) scr_fontColor(Green, Black); // if(stepm_getRemainLines() > 1) { for (i = 0, n = linesBuffer.gcodePtrCur + 1; i < MAX_SHOW_GCODE_LINES; i++, n++) { if (n > (MAX_SHOW_GCODE_LINES - 1)) n = 0; gp = &linesBuffer.gcode[n]; scr_gotoxy(1, i); if (gp->lineNum) scr_printf("%d:%s", gp->lineNum, gp->cmd); scr_clrEndl(); } // } #endif } DBG("\n [gcode:%d] %s", lineNum, str); st = gc_execute_line(str); if (st != GCSTATUS_OK) { #if (USE_LCD != 0) scr_fontColor(Red, Black); scr_gotoxy(1, 11); switch (st) { case GCSTATUS_BAD_NUMBER_FORMAT: scr_puts("BAD_NUMBER_FORMAT"); break; case GCSTATUS_EXPECTED_COMMAND_LETTER: scr_puts("EXPECTED_COMMAND_LETTER"); break; case GCSTATUS_UNSUPPORTED_STATEMENT: scr_puts("UNSUPPORTED_STATEMENT"); break; case GCSTATUS_FLOATING_POINT_ERROR: scr_puts("FLOATING_POINT_ERROR"); break; case GCSTATUS_UNSUPPORTED_PARAM: scr_puts("UNSUPPORTED_PARAM"); break; case GCSTATUS_UNSOPORTED_FEEDRATE: scr_puts("GCSTATUS_UNSUPPORTED_FEEDRATE"); break; case GCSTATUS_TABLE_SIZE_OVER_X: scr_puts("GCSTATUS_TABLE_SIZE_OVER_X"); break; case GCSTATUS_TABLE_SIZE_OVER_Y: scr_puts("GCSTATUS_TABLE_SIZE_OVER_Y"); break; case GCSTATUS_TABLE_SIZE_OVER_Z: scr_puts("GCSTATUS_TABLE_SIZE_OVER_Z"); break; case GCSTATUS_CANCELED: scr_puts("GCSTATUS_CANCELED"); break; } scr_printf(" at line %d:\n %s", lineNum, str); #endif #if (USE_SDCARD != 0) f_close(&fid); #endif return; } } } while (!isGcodeStop && hasMoreLines); #if (USE_SDCARD != 0) f_close(&fid); #endif if ((curGCodeMode & GFILE_MODE_MASK_EXEC) == 0) { #if (USE_LCD != 0) short scrX = crdXtoScr(TABLE_CENTER_X); short scrY = crdYtoScr(TABLE_CENTER_Y); int t1 = commonTimeIdeal / 1000; int t2 = commonTimeReal / 1000; scr_Line(scrX - 8, scrY, scrX + 8, scrY, Red); scr_Line(scrX, scrY - 8, scrX, scrY + 8, Red); scr_fontColor(Green, Black); scr_gotoxy(1, 0); scr_printf("Time %02d:%02d:%02d(%02d:%02d:%02d) N.cmd:%d", t1 / 3600, (t1 / 60) % 60, t1 % 60, t2 / 3600, (t2 / 60) % 60, t2 % 60, lineNum ); scr_printf("\n X%f/%f Y%f/%f Z%f/%f", minX, maxX, minY, maxY, minZ, maxZ); #endif } else { #ifndef NO_ACCELERATION_CORRECTION cnc_line(0, 0, 0, 0, 0, 0); cnc_line(0, 0, 0, 0, 0, 0); #endif } }
void __debug_smile() { scr_puts(":)\n"); hlt(); }
void manualMode(void) { static uint8_t limits = 0xFF; const double axisK[4] = { SM_X_STEPS_PER_MM, SM_Y_STEPS_PER_MM, SM_Z_STEPS_PER_MM, SM_E_STEPS_PER_MM }; int i, k = SM_X_STEPS_PER_MM; uint32_t frq[4] = { SM_MANUAL_MODE_STEPS_PER_SEC * K_FRQ, SM_MANUAL_MODE_STEPS_PER_SEC * K_FRQ, SM_MANUAL_MODE_STEPS_PER_SEC * K_FRQ, SM_MANUAL_MODE_STEPS_PER_SEC * K_FRQ }; uint8_t dir[4] = { 0, 0, 0, 0 }; uint32_t steps[4] = { 0, 0, 0, 0 }; LCD_Clear(Black); scr_setfullTextWindow(); scr_gotoxy(6, 0); scr_fontColor(Green, Black); scr_puts("CNC MANUAL MODE"); scr_fontColor(Yellow, Black); scr_puts("\n key '6' - [X+] key '4' - [X-] "); scr_puts("\n key '2' - [Y+] key '8' - [Y-] "); scr_puts("\n key '1' - [Z+] key '7' - [Z-] "); scr_puts("\n key '3' - [E+] key '9' - [E-] "); scr_puts("\n 'A'k+1 'B'k-1 '*'k=1 '#'k++"); scr_puts("\n step motors 'D' - full stop"); scr_puts("\n 0 - zero 5 - goto zero C - exit"); delayMs(700); while (kbd_getKey() >= 0) {}; while (true) { scr_fontColor(White, Black); for (i = 0; i < 3; i++) { double n = (double)stepm_getCurGlobalStepsNum(i) / axisK[i]; scr_gotoxy(1 + i * 10, TEXT_Y_MAX - 4); scr_printf("%c:%f ", axisName[i], n); if (i < 3) { scr_gotoxy(1, TEXT_Y_MAX - 3 + i); scr_printf("steps %c:%d ", axisName[i], stepm_getCurGlobalStepsNum(i)); } #if (USE_ENCODER == 1) if (i == 2) { int32_t v = encoderZvalue(); scr_gotoxy(25, TEXT_Y_MAX - 1); scr_printf("encZ:%d ", v); scr_gotoxy(1 + 2 * 10, TEXT_Y_MAX - 5); scr_printf("errZ:%f ", (double)(v*MM_PER_360) / ENCODER_Z_CNT_PER_360 - n); } #endif dir[i] = 0; steps[i] = 0; } scr_fontColor(Blue, Black); scr_gotoxy(2, TEXT_Y_MAX - 7); scr_printf("step per key press: %f mm ", (double)k / SM_X_STEPS_PER_MM); switch (kbd_getKey()) { case KEY_0: while (stepm_inProc() && kbd_getKey() != KEY_C) {} stepm_ZeroGlobalCrd(); #if (USE_ENCODER == 1) encoderZreset(); encoderCorrectionCntUp = encoderCorrectionCntDown = encoderCorrectionDelta = encoderCorrectionMaxDelta = 0; #endif break; case KEY_6: steps[0] = k; dir[0] = 1; stepm_addMove(steps, frq, dir); break; case KEY_4: steps[0] = k; dir[0] = 0; stepm_addMove(steps, frq, dir); break; case KEY_2: steps[1] = k; dir[1] = 1; stepm_addMove(steps, frq, dir); break; case KEY_8: steps[1] = k; dir[1] = 0; stepm_addMove(steps, frq, dir); break; case KEY_1: steps[2] = k; dir[2] = 1; stepm_addMove(steps, frq, dir); break; case KEY_7: steps[2] = k; dir[2] = 0; stepm_addMove(steps, frq, dir); break; case KEY_3: steps[3] = k; dir[3] = 1; stepm_addMove(steps, frq, dir); break; case KEY_9: steps[3] = k; dir[3] = 0; stepm_addMove(steps, frq, dir); break; case KEY_5: while (stepm_inProc() && kbd_getKey() != KEY_C) {} if (stepm_getCurGlobalStepsNum(0) != 0 || stepm_getCurGlobalStepsNum(1) != 0) { steps[0] = labs(stepm_getCurGlobalStepsNum(0)); dir[0] = stepm_getCurGlobalStepsNum(0) < 0; steps[1] = labs(stepm_getCurGlobalStepsNum(1)); dir[1] = stepm_getCurGlobalStepsNum(1) < 0; steps[2] = 0; dir[2] = 0; } else { steps[0] = steps[1] = 0; dir[0] = dir[1] = 0; steps[2] = labs(stepm_getCurGlobalStepsNum(2)); dir[2] = stepm_getCurGlobalStepsNum(2) < 0; } stepm_addMove(steps, frq, dir); break; case KEY_A: if (k < SM_X_STEPS_PER_MM) k++; break; case KEY_B: if (k > 1) k--; break; case KEY_STAR: k = 1; break; case KEY_DIES: if (k < SM_X_STEPS_PER_MM) k += SM_X_STEPS_PER_MM / 8; break; case KEY_C: stepm_EmergeStop(); return; case KEY_D: stepm_EmergeStop(); break; } if (limits != limits_chk()) { limits = limits_chk(); scr_Rectangle(304, 232, 309, 239, limitX_chk() ? Red : Green, true); scr_Rectangle(310, 232, 315, 239, limitY_chk() ? Red : Green, true); scr_Rectangle(314, 232, 319, 239, limitZ_chk() ? Red : Green, true); } } }
/*************************************************** * Main */ int main() { bool rereadDir = false, redrawScr = true, redrawDir = false; SystemStartup(); #if (USE_SDCARD == 1) rereadDir = true; FRESULT fres = f_mount(0, &fatfs); if (fres != FR_OK) { showCriticalStatus( " Mount SD error [code:%d]\n" " SD card used for any CNC process\n" " Only RESET possible at now", fres); WAIT_KEY_C(); } #elif (USE_SDCARD == 2) && (USE_KEYBOARD != 0) FRESULT fres; #endif initSmParam(); while (1) { if (SystemProcess() == SYS_READ_FLASH) rereadDir = true; if (rereadDir) { rereadDir = false; readFileList(); redrawScr = true; } if (redrawScr) { redrawScr = false; LCD_Clear(Black); #if (USE_KEYBOARD == 1) win_showMenu(0, 144, 40, 4); scr_puts( "0 - start gcode 1 - manual mode\n" "2 - show gcode 3 - delete file\n" "4 - set time 5 - file info\n" //"6 - scan mode\t " "7 - save conf.file (v1.1)"); #endif #if (USE_KEYBOARD == 2) SetTouchKeys(kbdSelectFile); #endif redrawDir = true; } if (redrawDir) { redrawDir = false; drawFileList(); } showStatusString(); #if (USE_KEYBOARD != 0) switch (kbd_getKey()) { case KEY_A: currentFile--; redrawDir = true; break; case KEY_B: currentFile++; redrawDir = true; break; #if (USE_KEYBOARD == 1) case KEY_STAR: currentFile += FILE_LIST_ROWS; redrawDir = true; break; case KEY_DIES: currentFile -= FILE_LIST_ROWS; redrawDir = true; break; #endif // // Start GCode // case KEY_0: { FLASH_KEYS(); #if (USE_LCD == 1) uint32_t stime; stime = Seconds(); #endif cnc_gfile(&fileList[currentFile][0], GFILE_MODE_MASK_EXEC); while (stepm_inProc()) { scr_fontColor(Yellow, Blue); scr_gotoxy(1, 13); scr_printf(" remain moves: %d", stepm_getRemainLines()); scr_clrEndl(); } stepm_EmergeStop(); #if (USE_LCD == 1) scr_fontColor(Yellow, Blue); scr_gotoxy(0, 13); scr_puts(" FINISH. PRESS C-KEY"); scr_clrEndl(); stime = Seconds() - stime; scr_fontColor(Yellow, Blue); scr_gotoxy(0, 14); scr_printf(" work time: %02d:%02d", stime / 60, stime % 60); scr_clrEndl(); #endif #if (USE_LCD == 2) SetTouchKeys(kbdLast2Lines); #endif FLASH_KEYS(); WAIT_KEY_C(); redrawScr = true; break; } // // Manual Mode // case KEY_1: manualMode(); redrawScr = true; break; #if (USE_SDCARD == 1) // // Show GCode // case KEY_2: FLASH_KEYS(); cnc_gfile(&fileList[currentFile][0], GFILE_MODE_MASK_SHOW | GFILE_MODE_MASK_CHK); scr_printf("\n PRESS C-KEY"); FLASH_KEYS(); while (kbd_getKey() != KEY_C); redrawScr = true; break; // // Delete file // case KEY_3: if (questionYesNo("Delete file:\n'%s'?", &fileList[currentFile][0])) { rereadDir = true; f_unlink(&fileList[currentFile][0]); } else redrawScr = true; break; #endif #if (USE_RTC == 1) // // Set time // case KEY_4: setTime(); redrawScr = true; break; // // Save conf. file // case KEY_7: win_showMsgWin(); saveSmParam(); scr_printf("\n\n\n PRESS C-KEY"); WAIT_KEY_C(); redrawScr = true; break; #endif #if (USE_SDCARD != 0) // // File info // case KEY_5: { FILINFO finf; FIL fid; int c, n; memset(&finf, 0, sizeof(finf)); win_showMsgWin(); scr_setScroll(false); scr_printf("File:%s", &fileList[currentFile][0]); f_stat(&fileList[currentFile][0], &finf); scr_gotoxy(0, 1); scr_printf("Size:%d\n", (uint32_t)finf.fsize); fres = f_open(&fid, &fileList[currentFile][0], FA_READ); if (fres != FR_OK) { #if (USE_SDCARD == 1) scr_printf("Error open file: '%s'\nStatus:%d [%d]", &fileList[currentFile][0], fres, SD_errno); #elif (USE_SDCARD == 2) scr_printf("Error open file: '%s'\nStatus:%d", &fileList[currentFile][0], fres); #endif } else { char str[150]; scr_fontColorInvers(); scr_setScroll(false); // Read lines from 3 to 6 from file and display it for (n = 2; n < 7 && f_gets(str, sizeof(str), &fid) != NULL; n++) { scr_gotoxy(0, n); scr_puts(str_trim(str)); } } scr_fontColorNormal(); scr_gotoxy(8, 7); scr_printf("PRESS C-KEY"); redrawScr = true; do { c = kbd_getKey(); if (c == KEY_B) { char str[150]; scr_fontColorInvers(); for (n = 2; n < 7 && f_gets(str, sizeof(str), &fid) != NULL; n++) { scr_gotoxy(0, n); scr_puts(str_trim(str)); scr_clrEndl(); } } } while (c != KEY_C); f_close(&fid); rereadDir = true; } break; #endif } #endif } }