void SerialComHelper::SendInstruction(HardwareSerial* pSerial, ERUINT8 cmd ,ERFLOAT32 c) { ERxParameterStream tempParaStream; tempParaStream.Write(c); SendInstruction(pSerial, cmd, tempParaStream); }
void SerialComHelper::SendInstruction(HardwareSerial* pSerial, ERUINT8 cmd ,const char str[]) { ERxParameterStream tempParaStream; tempParaStream.Write((ERINT8*)str); SendInstruction(pSerial, cmd, tempParaStream); }
void WatchDogClass::CheckControls() { WControls.Update(); SolidSystem = WControls.SolidGrid; CanTakeDistance = WControls.TakeDistance; LastTime = CurrentTime; CurrentTime = glfwGetTime(); DiffTime = CurrentTime - LastTime; MainMotorsSpeed = WControls.MainMotorsVelocity; float speed, aspeed; switch (MainMotorsSpeed) { case SPEED1: speed = Speed1; aspeed = Angle1; break; case SPEED2: speed = Speed2; aspeed = Angle2; break; case SPEED3: speed = Speed3; aspeed = Angle3; break; } if(WControls.MovingForward && !FronCollision) { MainMotorsMove = FORWARD; Position += Vector3f(speed * DiffTime, Angle); } else if(WControls.MovingBackward && !BackCollision) { MainMotorsMove = BACKWARD; Position -= Vector3f(speed * DiffTime, Angle); } else if(WControls.MovingLeft) { MainMotorsMove = RIGHT; if(Angle>360.0f)Angle-=360.0f; Angle+=aspeed * DiffTime; } else if(WControls.MovingRight) { MainMotorsMove = LEFT; if(Angle<0.0f)Angle+=360.0f; Angle-=aspeed * DiffTime; } else MainMotorsMove = STOP; if(WControls.MovingGripperUp) OtherMove = UP_GRIPPER; else if(WControls.MovingGripperDown) OtherMove = DOWN_GRIPPER; else if(WControls.MovingGripperClose) OtherMove = CLOSE_GRIPPER; else if(WControls.MovingGripperOpen) OtherMove = OPEN_GRIPPER; else OtherMove = STOP; if(WControls.MovingCamUp) SlaveMove = CAM2_UP; else if(WControls.MovingCamDown) SlaveMove= CAM2_DOWN; else if(WControls.MovingCamLeft) SlaveMove = CAM2_LEFT; else if(WControls.MovingCamRight) SlaveMove = CAM2_RIGHT; else if(WControls.Laser) { if(LaserON) { SlaveMove = LASERS_OFF; LaserON = false; } else { SlaveMove = LASERS_ON; LaserON = false; } } else SlaveMove = IDLE; if(GetKeyNewpress('P') && (USB->Error || !USB->HIDisOpen)) USB->HIDReOpen(); SendInstruction(); }
void SerialComHelper::SendInstruction(HardwareSerial* pSerial, ERUINT8 cmd , const ERxParameterStream& parameterStream) { SendInstruction(pSerial, DEVICE_BROADCAST, DEVICE_BROADCAST, cmd, parameterStream); }
void SCLang::Start(){ if(ready) return; std::string command = Config::Global().path_to_sclang; if(Utilities::GetFilename(command) != Utilities::OSSCLangBinName){ on_start_completed.Happen(false,"Invalid path to sclang: Selected file is not '" + Utilities::OSSCLangBinName + "'"); return; } if(!Utilities::GetFileExists(command)){ on_start_completed.Happen(false,"Invalid path to sclang: File does not exist"); return; } subprocess = std::make_unique<SCLangSubprocess>(command); subprocess->on_any_line_received.SubscribeForever([&](std::string l){ on_line_received.Happen(l); }); on_start_progress.Happen(1,"Starting SCLang..."); try{ subprocess->Start(); }catch(Exceptions::Subprocess ex){ on_start_completed.Happen(false,"Failed to start sclang subprocess:\n" + Utilities::Trim(ex.what())); return; } subprocess->on_started.SubscribeOnce([](){ // The SC dir should be in current directory. SetOSCDebug(osc_debug); on_start_progress.Happen(3,"Loading scripts..."); // TODO: Check if the directories and files exist. std::string main_script = Utilities::ConvertOSpathToUniPath(Utilities::GetCurrentDir()) + "/sc/main.sc"; if(!Utilities::GetFileExists( Utilities::ConvertUnipathToOSPath(main_script))){ on_start_completed.Happen(false,"Main SC scripts are missing"); return; } SendInstruction("(\"" + main_script + "\").loadPaths;"); subprocess->SendInstruction("NetAddr.localAddr.port.postln;", [&](std::string port){ port = Utilities::SplitString(port,"\n")[1]; std::cout << "SCLang is using port " << port << std::endl; on_start_progress.Happen(4,"Starting OSC..."); osc.reset(); // Resetting the pointer BEFORE creating new. Otherwise, the new OSC server would fail to start because the speficied port would be already in use. osc = std::make_unique<OSC>("localhost", port); osc->AddMethodHandler("/algaudio/midiin", ProcessMIDIInput); osc->AddMethodHandler("/algaudio/sendreply", [](lo::Message msg){SendReplyCatcher(msg.argv()[0]->i32, msg.argv()[1]->i32, msg.argv()[2]->f); }); SendOSCWithEmptyReply("/algaudioSC/hello").Then([](){ on_start_progress.Happen(5,"Booting server..."); BootServer(); on_server_started.SubscribeOnce([&](bool success){ if(success){ ready = true; on_start_progress.Happen(8,"Installing module templates..."); ModuleCollectionBase::InstallAllTemplatesIntoSC().Then([=](){ on_start_progress.Happen(10,"Complete."); on_start_completed.Happen(true,""); }); }else{ // Server failed to boot on_start_completed.Happen(false,"SC Server failed to start"); } }); // on_server_started }); // /algaudioSC/hello }); // sendinstruction port }); // subprocess started }
void SCLang::StopServer(){ SendInstruction("s.quit;"); }
void SCLang::SetOSCDebug(bool enabled){ if(enabled) SendInstruction("OSCFunc.trace(true);"); else SendInstruction("OSCFunc.trace(false);"); osc_debug = enabled; }