void Printer::getSDFilesList(){ this->sdFiles.clear(); if(!this->isPrinting){ send_now("M21"); send_now("M20"); } }
// Step #4: do each keystroke // void usb_keyboard_class::write_key(KEYCODE_TYPE key) { uint8_t modifier=0; #ifdef SHIFT_MASK if (key & SHIFT_MASK) modifier |= MODIFIERKEY_SHIFT; #endif #ifdef ALTGR_MASK if (key & ALTGR_MASK) modifier |= MODIFIERKEY_RIGHT_ALT; #endif #ifdef RCTRL_MASK if (key & RCTRL_MASK) modifier |= MODIFIERKEY_RIGHT_CTRL; #endif keyboard_report_data[0] = modifier; key &= 0x3F; #ifdef KEY_NON_US_100 if (key == KEY_NON_US_100) key = 100; #endif keyboard_report_data[1] = 0; keyboard_report_data[2] = key; keyboard_report_data[3] = 0; keyboard_report_data[4] = 0; keyboard_report_data[5] = 0; keyboard_report_data[6] = 0; keyboard_report_data[7] = 0; send_now(); keyboard_report_data[0] = 0; keyboard_report_data[2] = 0; send_now(); }
void Printer::moveHeadZ(double z, int speed, bool relative){ if(relative){ send_now("G91"); } send_now("G1 F"+QString::number(speed)); send_now("G1 Z"+QString::number(z)); if(relative){ send_now("G90"); } }
void Printer::getTemperature(){ if(this->isConnected()){ if(!this->uploadingToSD){ send_now("M105"); } if(this->sdPrint){ send_now("M27"); } } }
void Printer::uploadToSD(QString filename, QStringList data){ this->mainQuery.clear(); this->mainQuery.append(data); send_now("M28 "+filename); this->uploadedFileName=filename; this->uploadingToSD=true; while(mainQuery.size()>0){ send_now(mainQuery.takeFirst()); emit uploadProgress(mainQuery.size(), -1); } send_now("M29 "+filename); this->uploadingToSD=false; getSDFilesList(); }
// Step #4: do each keystroke // void usb_keyboard_class::write_key(KEYCODE_TYPE keycode) { keyboard_report_data[0] = keycode_to_modifier(keycode); keyboard_report_data[1] = 0; keyboard_report_data[2] = keycode_to_key(keycode); keyboard_report_data[3] = 0; keyboard_report_data[4] = 0; keyboard_report_data[5] = 0; keyboard_report_data[6] = 0; keyboard_report_data[7] = 0; send_now(); keyboard_report_data[0] = 0; keyboard_report_data[2] = 0; send_now(); }
void usb_keyboard_class::presskey(uint8_t key, uint8_t modifier) { bool send_required = false; uint8_t i; if (modifier) { if ((keyboard_report_data[0] & modifier) != modifier) { keyboard_report_data[0] |= modifier; send_required = true; } } if (key) { for (i=2; i < 8; i++) { if (keyboard_report_data[i] == key) goto end; } for (i=2; i < 8; i++) { if (keyboard_report_data[i] == 0) { keyboard_report_data[i] = key; send_required = true; goto end; } } } end: if (send_required) send_now(); }
void Printer::setTemp3(int temp){ if(!this->isPrinting){ this->writeToPort("M110", -1, true); send("M140 S"+QString::number(temp)); } else{ send_now("M140 S"+QString::number(temp)); } }
void net_ip_t::loop_send(){ const uint_ write_buffer_size = write_buffer.size(); total_sent_bytes = 0; write_buffer_lock.lock(); for(uint_ i = 0;i < write_buffer_size;i++){ send_now(&write_buffer[i]); } write_buffer.clear(); write_buffer_lock.unlock(); }
void usb_keyboard_class::write(uint8_t c) { uint8_t key, modifier=0; if (c >= 128) return; key = pgm_read_byte(keycodes + c); if (key & SHIFT) modifier |= MODIFIERKEY_SHIFT; if (key & CTRL) modifier |= MODIFIERKEY_CTRL; keyboard_modifier_keys = modifier; keyboard_keys[0] = key & 0x3F; keyboard_keys[1] = 0; keyboard_keys[2] = 0; keyboard_keys[3] = 0; keyboard_keys[4] = 0; keyboard_keys[5] = 0; send_now(); keyboard_modifier_keys = 0; keyboard_keys[0] = 0; send_now(); }
void usb_keyboard_class::releaseAll(void) { uint8_t i, anybits; anybits = keyboard_report_data[0]; for (i=2; i < 8; i++) { anybits |= keyboard_report_data[i]; keyboard_report_data[i] = 0; } if (!anybits) return; keyboard_report_data[0] = 0; send_now(); }
void usb_keyboard_class::releasekey(uint8_t key, uint8_t modifier) { bool send_required = false; uint8_t i; if (modifier) { if ((keyboard_report_data[0] & modifier) != 0) { keyboard_report_data[0] &= ~modifier; send_required = true; } } if (key) { for (i=2; i < 8; i++) { if (keyboard_report_data[i] == key) { keyboard_report_data[i] = 0; send_required = true; } } } if (send_required) send_now(); }
void usb_keyboard_class::press(uint16_t n) { uint8_t key, mod, msb, modrestore=0; msb = n >> 8; if (msb >= 0xC2 && msb <= 0xDF) { n = (n & 0x3F) | ((uint16_t)(msb & 0x1F) << 6); } else if (msb == 0x80) { presskey(0, n); return; } else if (msb == 0x40) { presskey(n, 0); return; } KEYCODE_TYPE keycode = unicode_to_keycode(n); if (!keycode) return; #ifdef DEADKEYS_MASK KEYCODE_TYPE deadkeycode = deadkey_to_keycode(keycode); if (deadkeycode) { modrestore = keyboard_report_data[0]; if (modrestore) { keyboard_report_data[0] = 0; send_now(); } // TODO: test if operating systems recognize // deadkey sequences when other keys are held mod = keycode_to_modifier(deadkeycode); key = keycode_to_key(deadkeycode); presskey(key, mod); releasekey(key, mod); } #endif mod = keycode_to_modifier(keycode); key = keycode_to_key(keycode); presskey(key, mod | modrestore); }
bool Printer::connectPort(QString port, int baud){ emit write_to_console(tr("Connecting...")); if(port!=""){ PortSettings settings = {(BaudRateType)baud, DATA_8, PAR_NONE, STOP_1, FLOW_OFF, 10}; delete this->portObj; this->portObj = new QextSerialPort(port,settings,QextSerialPort::Polling); if(this->portObj->open(QIODevice::ReadWrite | QIODevice::Unbuffered)){ emit write_to_console(tr("Printer connected")); send_now("M115"); this->readTimer->start(); return true; } else{ emit write_to_console(tr("Unable to connect")); emit connected(false); return false; } } else{ emit write_to_console(tr("Unknown port name")); emit connected(false); return false; } }
void Printer::getTemperature(){ if(this->isConnected()){ send_now("M105"); } }
//disable stepper void Printer::disableSteppers(){ send_now("M18"); }
//setting fan speed void Printer::setFan(int percent){ float value=255*((float)percent/(float)100); send_now("M106 S"+QString::number((int)value)); }
void Printer::homeAll(){ send_now("G28"); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); //about window this->aboutWindow = new AboutWindow(); this->aboutWindow->hide(); this->aboutWindow->move(this->geometry().center()-this->aboutWindow->geometry().center()); //calibrate Dialog this->calibrateDialog = new CalibrateDialog(); this->calibrateDialog->hide(); this->calibrateDialog->move(this->geometry().center()-this->calibrateDialog->geometry().center()); //option Dialog this->optionDialog = new OptionDialog(); this->optionDialog->hide(); this->optionDialog->move(this->geometry().center()-this->optionDialog->geometry().center()); //slice dialog this->sliceDialog = new SliceDialog(ui->glWidget, this); this->sliceDialog->hide(); this->sliceDialog->move(this->geometry().center()-this->sliceDialog->geometry().center()); //macros window this->macrosWindow = new MacrosWindow(); this->macrosWindow->hide(); this->macrosWindow->move(this->geometry().center()-this->macrosWindow->geometry().center()); connect(this->macrosWindow, SIGNAL(buttonAdded(MacroButton*)), this, SLOT(addMacroBtn(MacroButton*))); connect(this->macrosWindow, SIGNAL(buttonRemoved(MacroButton*)), this, SLOT(removeMacroBtn(MacroButton*))); //sd card window this->sdCardWindow = new SDCardWindow(); this->sdCardWindow->hide(); this->sdCardWindow->move(this->geometry().center()-this->sdCardWindow->geometry().center()); connect(this->sdCardWindow, SIGNAL(sdFile_selected(QString)), this, SLOT(sdFile_selected(QString))); connect(this->optionDialog, SIGNAL(slicerPathChanged(QString)), this->sliceDialog, SLOT(updateSlicerPath(QString))); connect(this->optionDialog, SIGNAL(outputPathChanged(QString)), this->sliceDialog, SLOT(updateOutputPath(QString))); connect(this->optionDialog, SIGNAL(newSize(QVector3D)), this, SLOT(updatadeSize(QVector3D))); connect(this->optionDialog, SIGNAL(newList(QList<Material*>*)), this->sliceDialog, SLOT(setMaterialList(QList<Material*>*))); connect(this->sliceDialog, SIGNAL(fileSliced(QString)), this, SLOT(loadFile(QString))); //set version number this->setWindowTitle("YARRH v"+QString::number(VERSION_MAJOR)+"."+QString::number(VERSION_MINOR)+"."+QString::number(VERSION_REVISION)); this->aboutWindow->setVersion(VERSION_MAJOR,VERSION_MINOR,VERSION_REVISION); //setting up printer and its thread this->printerObj = new Printer(); QThread *qthread = new QThread(); //connecting ui to printer connect(printerObj, SIGNAL(write_to_console(QString)), ui->inConsole, SLOT(appendPlainText(QString)), Qt::QueuedConnection); connect(this->macrosWindow, SIGNAL(writeToPrinter(QString)), printerObj, SLOT(send_now(QString)),Qt::QueuedConnection); connect(ui->fanSpinBox, SIGNAL(valueChanged(int)), printerObj, SLOT(setFan(int)), Qt::QueuedConnection); ui->fanSpinBox->blockSignals(true); connect(this->printerObj, SIGNAL(SDFileList(QStringList)), this->sdCardWindow, SLOT(updateFileList(QStringList))); connect(this->printerObj, SIGNAL(uploadProgress(int,int)), this->sdCardWindow, SLOT(updateProgress(int,int))); this->sdCardWindow->setPrinter(this->printerObj); //connecting move btns connect(ui->homeX, SIGNAL(clicked()), printerObj, SLOT(homeX()), Qt::QueuedConnection); connect(ui->homeY, SIGNAL(clicked()), printerObj, SLOT(homeY()), Qt::QueuedConnection); connect(ui->homeAll, SIGNAL(clicked()), printerObj, SLOT(homeAll()), Qt::QueuedConnection); //connect monit temp checkbox connect(ui->graphGroupBox, SIGNAL(toggled(bool)), printerObj, SLOT(setMonitorTemperature(bool)),Qt::QueuedConnection); //connect printer to temp widget connect(printerObj, SIGNAL(currentTemp(double,double,double)), this, SLOT(drawTemp(double,double,double))); connect(printerObj, SIGNAL(progress(int,int)), this, SLOT(updateProgress(int,int))); connect(printerObj, SIGNAL(connected(bool)), this, SLOT(printerConnected(bool))); //setting ui temp from gcode connect(printerObj, SIGNAL(settingTemp1(double)), this, SLOT(setTemp1FromGcode(double))); connect(printerObj, SIGNAL(settingTemp3(double)), this, SLOT(setTemp3FromGcode(double))); //updating head position in ui connect(printerObj, SIGNAL(currentPosition(QVector3D)), this, SLOT(updateHeadPosition(QVector3D))); //print finished signal connect(printerObj, SIGNAL(printFinished(bool)), this, SLOT(printFinished(bool))); //connect calibration dialog to printer connect(calibrateDialog, SIGNAL(writeToPrinter(QString)), printerObj, SLOT(send_now(QString)),Qt::QueuedConnection); //connect z slider connect(ui->zSlider, SIGNAL(valueChanged(int)), this, SLOT(moveZ(int))); connect(ui->zSlider, SIGNAL(sliderMoved(int)), this, SLOT(updateZ(int))); //connect action load connect(ui->actionLoad, SIGNAL(triggered()), this, SLOT(loadFile())); printerObj->moveToThread(qthread); qthread->start(QThread::HighestPriority); this->portEnum = new QextSerialEnumerator(this); this->portEnum->setUpNotifications(); QList<QextPortInfo> ports = this->portEnum->getPorts(); //finding avalible ports foreach (QextPortInfo info, ports) { ui->portCombo->addItem(info.portName); }
void Printer::homeZ(){ send_now("G28 Z0"); }
void Printer::pauseSDPrint(){ send_now("M25"); }
void Printer::startResumeSdPrint(){ send_now("M24"); }
void Printer::selectSDFile(QString filename){ send_now("M23 "+filename); this->sdPrint=true; }
void Printer::extrude(int lenght, int speed){ send_now("G91"); send_now("G1 E"+QString::number(lenght)+" F"+QString::number(speed*60)); send_now("G90"); }
void Printer::retrackt(int lenght, int speed){ send_now("G91"); send_now("G1 E"+QString::number(lenght*-1)+" F"+QString::number(speed*60)); send_now("G90"); }
void Printer::homeAll(){ send_now("G28 X0 Y0 Z0"); }
//homing axis void Printer::homeX(){ send_now("G28 X0"); }
//moving head void Printer::moveHead(QPoint point, int speed){ send_now("G1 F"+QString::number(speed)); send_now("G1 X"+QString::number(point.x())+" Y"+QString::number(point.y())); }
void Printer::homeY(){ send_now("G28 Y0"); }
void Printer::setTemp3(int temp){ send_now("M140 S"+QString::number(temp)); }