//sending next line from buffer void Printer::send_next(){ //if printer inst connected then return if(!this->isConnected()){ return; } //resend commands if(this->resendFrom<this->lineNum && this->resendFrom>-1){ writeToPort(this->sentLines.at(this->resendFrom),this->resendFrom,false); this->resendFrom++; return; } this->resendFrom=-1; //send all commands from pri query while(this->priQuery.size()>0){ writeToPort(this->priQuery.takeFirst()); return; } //if there are lines to send in main buffer if(this->isPrinting && this->mainQuery.size()>0){ writeToPort(this->mainQuery.takeFirst(),this->lineNum,true); emit progress(this->mainQuery.size()); this->lineNum++; } else{ if(this->isPrinting){ emit printFinished(true); } this->isPrinting=false; } }
bool QSerialPortPrivate::writeDataOneShot() { Q_Q(QSerialPort); pendingBytesWritten = -1; while (!writeBuffer.isEmpty()) { pendingBytesWritten = writeToPort(writeBuffer.readPointer(), writeBuffer.nextDataBlockSize()); if (pendingBytesWritten <= 0) { QSerialPort::SerialPortError errorL = decodeSystemError(); if (errorL != QSerialPort::ResourceError) errorL = QSerialPort::WriteError; q->setError(errorL); return false; } writeBuffer.free(pendingBytesWritten); emit q->bytesWritten(pendingBytesWritten); } return (pendingBytesWritten < 0)? false: true; }
//ending without checksum checking void Printer::send_now(QString command){ if(this->isPrinting){ this->priQuery.append(command); } else{ writeToPort(command); } }
//sending command with checksum checking void Printer::send(QString command){ if(this->isPrinting){ this->mainQuery.append(command); } else{ writeToPort(command,this->lineNum,true); this->lineNum++; } }
void speaker::dext(Event x, double t) { //The input event is in the 'x' variable. //where: // 'x.value' is the value (pointer to void) // 'x.port' is the port number double *Aux = (double*)x.value; int value = Aux[0] > 0 ? 0xff : 0x00; writeToPort(value , 0x61); }
void ArduinoSerial::setNumberOfChannelsAndSamplingRate(int numberOfChannels, int samplingRate) { _numberOfChannels = numberOfChannels; _samplingRate = samplingRate; //"conf s:%d;c:%d;" std::stringstream sstm; sstm << "conf s:" << samplingRate<<";c:"<<numberOfChannels<<";\n"; writeToPort(sstm.str().c_str(),sstm.str().length()); }
void RoboMotor::accelerateMotorSmoothly() { /* Causes the motors to slowly accelerate rather than a huge jump between speeds. This function was inspired from the motors causing the entire electrical system to crash because it was pulling too much power all at one time. */ const int ACCELERATION_STEP = 20; //The amount of value to increase per acceleration step const int ACCELERATION_DELAY = 50; //How many milliseconds between each step const int MIDDLE_SPEED = 0; //The middle speed between positive and negative speeds //Increments the speed that the motor needs to adjust, //this function will help reduce the motors from reving up too fast //mutexAccelerateMotor.lock(); double prevSpeed = getPreviousSpeed(); double thisSpeed = getTotalSpeed(); //cout << "Pitch:" << pitchSpeed << "\tRoll:" << rollSpeed << "\tPrev:" << prevSpeed << "\tSpeed:" << thisSpeed << endl; //Do some calculations to slowly accelerate the motor depending on the constant int amountOfSteps = (int)abs(thisSpeed - prevSpeed) / ACCELERATION_STEP; int remainderSpeed = (int)abs(thisSpeed - prevSpeed) % ACCELERATION_STEP; //The amount left over int direction = 1; //This is used to determine if we need to adjust forward or backword if(thisSpeed < prevSpeed) direction = -1; //cout << "Prev: " << prevSpeed << ", ThisSpeed: " << thisSpeed << ", Steps: " << amountOfSteps << ", Remain: " << remainderSpeed << ", Dir: " << direction << endl; for(int i = 0; i < amountOfSteps; i++) { writeToPort(prevSpeed + (i * ACCELERATION_STEP * direction) + MIDDLE_SPEED); timer.wait(ACCELERATION_DELAY); } //if(remainderSpeed != 0) writeToPort(prevSpeed + (amountOfSteps * ACCELERATION_STEP * direction) + (remainderSpeed * direction) + MIDDLE_SPEED); //Add the leftovers setPreviousSpeed(thisSpeed); //mutexAccelerateMotor.unlock(); }
void speaker::exit() { writeToPort(0 , 0x61); }