int main(int argc, char const *argv[]) { struct commit *first = new_commit(0, 0, "First !"); struct commit *tmp, *victim, *last; /*first->display = display_commit_major;*/ list_add(&first->lhead, &list_complete); list_add(&first->major_list, &list_major); display_commit_major(first); printf("\n"); display_history(first); tmp = add_minor_commit(first, "Work 1"); tmp = add_minor_commit(tmp, "Work 2"); victim = add_minor_commit(tmp, "Work 3"); last = add_minor_commit(victim, "Work 4"); display_history(first); del_commit(victim); display_history(first); tmp = add_major_commit(last, "Release 1"); tmp = add_minor_commit(tmp, "Work 1"); tmp = add_minor_commit(tmp, "Work 2"); tmp = add_major_commit(tmp, "Release 2"); tmp = add_minor_commit(tmp, "Work 1"); display_history(first); add_minor_commit(last, "Oversight !!!"); display_history(first); infos(first, 1, 2); infos(first, 1, 7); infos(first, 4, 2); #ifdef DEBUG printf("\n== TEST SUPP MAJEUR ==\n"); del_commit(first); display_history(NULL); #endif freeHistory(); return 0; }
void XRandRScreens::update() { auto fallback = [this]() { m_geometries << QRect(); setCount(1); }; m_geometries.clear(); T resources(rootWindow()); if (resources.isNull()) { fallback(); return; } xcb_randr_crtc_t *crtcs = resources.crtcs(); QVector<Xcb::RandR::CrtcInfo> infos(resources->num_crtcs); for (int i = 0; i < resources->num_crtcs; ++i) { infos[i] = Xcb::RandR::CrtcInfo(crtcs[i], resources->config_timestamp); } for (int i = 0; i < resources->num_crtcs; ++i) { Xcb::RandR::CrtcInfo info(infos.at(i)); const QRect geo = info.rect(); if (geo.isValid()) { m_geometries << geo; } } if (m_geometries.isEmpty()) { fallback(); return; } setCount(m_geometries.count()); }
void ProcessUnitList::pushUnit(boost::shared_ptr<org::esb::hive::job::ProcessUnit> unit) { //_unit_list.insert(unit); std::string uuid=org::esb::util::PUUID(); _unit_map[unit->_sequence]=uuid; org::esb::io::File file(_user_data_path+"/"+uuid); org::esb::io::FileOutputStream fos(&file); org::esb::io::ObjectOutputStream ous(&fos); ous.writeObject(unit); ous.close(); while(_unit_map.size()&&(*_unit_map.begin()).first==lastSequence){ std::cerr<<"lastSequence found:"<<lastSequence<<std::endl; std::string nuuid=(*_unit_map.begin()).second; org::esb::io::File infile(_user_data_path+"/"+nuuid); org::esb::io::FileInputStream infos(&infile); org::esb::io::ObjectInputStream inous(&infos); inous.readObject(unit); inous.close(); infos.close(); infile.deleteFile(); if(_func) _func(unit); /*foreach(boost::shared_ptr<Packet> p,(*_unit_list.begin())->_output_packets){ Task::pushBuffer(Ptr<Packet>(p)); }*/ _unit_map.erase(_unit_map.begin()); lastSequence++; } }
::DDS::ReturnCode_t read (::DDS::DataReader_ptr reader, ACE_Array<bool>& pub_finished) { R_ptr pt_dr = R::_narrow(reader); Rimpl* dr_servant = ::TAO::DCPS::reference_to_servant< Rimpl, R_ptr> (pt_dr); const ::CORBA::Long max_read_samples = 100; Tseq samples(max_read_samples); ::DDS::SampleInfoSeq infos(max_read_samples); int samples_recvd = 0; DDS::ReturnCode_t status; // initialize to zero. status = dr_servant->read ( samples, infos, max_read_samples, ::DDS::NOT_READ_SAMPLE_STATE, ::DDS::ANY_VIEW_STATE, ::DDS::ANY_INSTANCE_STATE); if (status == ::DDS::RETCODE_OK) { if ((samples[samples.length () - 1].sequence_num == -1) || (samples[0].sequence_num == -1)) { for (unsigned i = 0; i < samples.length (); i ++) { if (samples[i].sequence_num != -1) { samples_recvd ++; } else { pub_finished[samples[i].data_source] = true; } } } else { samples_recvd = samples.length (); } } else if (status == ::DDS::RETCODE_NO_DATA) { ACE_ERROR((LM_ERROR, " Empty read!\n")); } else { ACE_OS::printf (" read data: Error: %d\n", status) ; } return samples_recvd; }
NoteDialog::NoteDialog(Note *note) : QWidget() { setWindowTitle(note == 0 ? "Nouvelle note" : note->title()); // Récupération des options m_settings = new QSettings("yellownote.ini", QSettings::IniFormat); // Création des champs title et content m_noteEdit = new NoteEdit(m_settings, this); m_note = note; // Assignation du dialog à la note attachToNote(); // Si on est en modification, on remplit les champs if (note != 0) { m_noteEdit->update(note->title(), note->content()); } QAction *actionInfos = new QAction("&Infos", this); actionInfos->setIcon(QIcon(":/note/infos")); actionInfos->setIconText("Infos"); connect(actionInfos, SIGNAL(triggered()), this, SLOT(infos())); m_actionDelete = new QAction("&Supprimer", this); m_actionDelete->setIcon(QIcon(":/note/delete")); m_actionDelete->setIconText("Supprimer"); connect(m_actionDelete, SIGNAL(triggered()), this, SLOT(deleteMe())); QWidget *spacerWidget = new QWidget(this); spacerWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); spacerWidget->setVisible(true); QToolBar *toolBar = new QToolBar; toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); toolBar->addWidget(spacerWidget); toolBar->addAction(actionInfos); toolBar->addAction(m_actionDelete); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->setMargin(0); mainLayout->setSpacing(0); mainLayout->addWidget(toolBar); mainLayout->addWidget(m_noteEdit); setLayout(mainLayout); // Réassignation de la taille de la fenêtre if (m_settings->contains("note/size")) { resize(m_settings->value("note/size").toSize()); } // Donne le focus à la fenêtre (quand elle est créée // depuis un raccouri clavier global) setFocus(); }
bool MkSShell::install() { mDock = new MkSShellDock( MonkeyCore::mainWindow() ); // add dock to dock toolbar entry MonkeyCore::mainWindow()->dockToolBar( Qt::TopToolBarArea )->addDock( mDock, infos().Caption, QIcon( infos().Pixmap ) ); // create menu action for the dock pActionsManager::setDefaultShortcut( mDock->toggleViewAction(), QKeySequence( "F6" ) ); return true; }
detail::exception_info< T >* get_info( ) { for ( auto& info : infos( ) ) { auto ei = detail::exception_info< T >::cast( *info ); if ( ei ) return ei; } return nullptr; }
std::tuple<Tensor,Tensor> _gesv_helper_cpu(const Tensor& self, const Tensor& A) { std::vector<int64_t> infos(batchCount(A), 0); auto A_working_copy = cloneBatchedColumnMajor(A); auto b_working_copy = cloneBatchedColumnMajor(self); AT_DISPATCH_FLOATING_TYPES(self.type(), "gesv", [&]{ applyGesv<scalar_t>(b_working_copy, A_working_copy, infos); }); checkErrors(infos); return std::tuple<Tensor,Tensor>(b_working_copy, A_working_copy); }
const detail::exception_info< T >* get_info( ) const { auto& _infos = infos( ); for ( const auto& info : _infos ) { auto ei = detail::exception_info< T >::cast( *info ); if ( ei ) return ei; } return nullptr; }
void NetworkRenderer::renderer_thread() { while(1) { int id = network.get_first_nonempty_client(); while (id==-1) { network.get_recv_cond().wait(); id = network.get_first_nonempty_client(); } Client *cl = network.get_client(id); string recv = cl->unstack_message(); if(recv=="CALCULATING") { rendering_clients[id].status=CLIENT_RENDERING; } else if(recv.find("RESULT")==0) { stringstream recv_ss(stringstream::in | stringstream::out); recv_ss<<recv.substr(6); parse_network_result_output(recv_ss); rendering_clients[id].status=CLIENT_WAITING; int sent_task = send_task_to_client(id); stringstream newstring(stringstream::in); newstring<<rendering_clients[id].hostname; if(sent_task!=-1) { newstring<<" // "<<sent_task; } ncursesui.get_clients_win()->modify_string( rendering_clients[id].curses_id, newstring.str()); result_number++; if(result_number==rendering_task_number) { rstatus=RENDERER_WAITING; display.refresh_display(); Logger::log()<<"Network rendering finished in " <<(SDL_GetTicks()-initial_tick)/(float)1000 <<" seconds"<<std::endl; } } else if(recv.find("LOGIN")==0) { Rendering_Client newcl; newcl.status=CLIENT_WAITING; newcl.hostname=recv.substr(6); newcl.curses_id=ncursesui.get_clients_win()->add_string(newcl.hostname); rendering_clients.insert(rendering_clients.begin()+id,newcl); stringstream infos(stringstream::out); infos<<"INFO "<<Settings::getAsInt("window_width")<<" "<<Settings::getAsInt("window_height"); cl->send_message(infos.str()); } } }
/*! Install plugin to the system \return Status code of action \retval true Successfull \retval false Some error ocurred */ bool FileBrowser::install() { // create dock mDock = new pDockFileBrowser(); // add dock to dock toolbar entry MonkeyCore::mainWindow()->dockToolBar( Qt::LeftToolBarArea )->addDock( mDock, infos().Caption, QIcon( infos().Pixmap ) ); // create menu action for the dock pActionsManager::setDefaultShortcut( mDock->toggleViewAction(), QKeySequence( "F7" ) ); // restore settings restoreSettings(); return true; }
int main(int argc, char const* argv[]) { struct commit *first = new_commit(0, 0, "First !"); struct commit *tmp, *victim, *last; display_commit(first); printf("\n"); display_history(first); tmp = add_minor_commit(first, "Work 1"); tmp = add_minor_commit(tmp, "Work 2"); victim = add_minor_commit(tmp, "Work 3"); last = add_minor_commit(victim, "Work 4"); display_history(first); del_commit(victim); display_history(first); tmp = add_major_commit(last, "Realse 1"); tmp = add_minor_commit(tmp, "Work 1"); tmp = add_minor_commit(tmp, "Work 2"); tmp = add_major_commit(tmp, "Realse 2"); tmp = add_minor_commit(tmp, "Work 1"); display_history(first); add_minor_commit(last, "Oversight !!!"); display_history(first); infos(first, 1, 2); infos(first, 1, 7); infos(first, 4, 2); return 0; }
bool ServerConfig::isValid() const { bool rightFile; bool err; bool res; QFileInfo infos(m_filePath); res = false; if (m_settings != NULL) { rightFile = QFile::exists(m_filePath) && m_settings->fileName().compare(infos.baseName()); err = !(m_settings->status() == QSettings::NoError); res = (!err && rightFile); } return res; }
void MetadataHubMngr::slotApplyPending() { QMutexLocker lock(&d->mutex); if (d->pendingItems.isEmpty()) return; ImageInfoList infos(d->pendingItems); d->pendingItems.clear(); emit signalPendingMetadata(0); MetadataSynchronizer* const tool = new MetadataSynchronizer(infos, MetadataSynchronizer::WriteFromDatabaseToFile); tool->start(); }
ACE_CDR::ULong read (::DDS::DataReader_ptr reader) { // TWF: There is an optimization to the test by // using a pointer to the known servant and // static_casting it to the servant typename R::_var_type var_dr = R::_narrow (reader); Rimpl* dr_servant = ::TAO::DCPS::reference_to_servant<Rimpl, typename R::_ptr_type> ( var_dr.in ()); const ::CORBA::Long max_read_samples = 100; Tseq samples (max_read_samples); ::DDS::SampleInfoSeq infos (max_read_samples); DDS::ReturnCode_t status = dr_servant->take (samples, infos, max_read_samples, ::DDS::NOT_READ_SAMPLE_STATE, ::DDS::ANY_VIEW_STATE, ::DDS::ANY_INSTANCE_STATE); if (::DDS::RETCODE_OK == status) { if (samples.length () > 1) { ACE_DEBUG ((LM_DEBUG, "multiple samples read\n")); } } else if (::DDS::RETCODE_NO_DATA == status) { ACE_ERROR ((LM_ERROR, "Empty read!\n")); } else { ACE_ERROR ((LM_ERROR, "read data: Error: %d\n", status)); } return samples[0].timestamp; }
QDomElement ModelPlus::toXmlData(QDomDocument &doc) { QDomElement root = doc.createElement(ModelPlus::className()); // Project info QDomElement cBasic = doc.createElement( "Basic" ); cBasic.setAttribute( "name", name() ); cBasic.setAttribute( "modelName", modelName()); cBasic.setAttribute( "modelType", modelType()); root.appendChild(cBasic); // Infos QDomElement cInfos = doc.createElement( "Infos" ); cInfos.setAttribute("text",infos()); root.appendChild(cInfos); // Variables QDomElement cVariables = variables()->toXmlData(doc,"Variables"); root.appendChild(cVariables); return root; }
bool csBulletRigidBody::AddBulletObject () { // TODO: don't recompute everything if the internal scale hasn't changed if (insideWorld) RemoveBulletObject (); btVector3 localInertia (0.0f, 0.0f, 0.0f); float mass = GetMass (); btCollisionShape* shape; btTransform principalAxis; principalAxis.setIdentity (); btVector3 principalInertia(0,0,0); //Create btRigidBody if (compoundShape) { int shapeCount = compoundShape->getNumChildShapes (); CS_ALLOC_STACK_ARRAY(btScalar, masses, shapeCount); for (int i = 0; i < shapeCount; i++) masses[i] = density * colliders[i]->GetVolume (); if (shapeChanged) { compoundShape->calculatePrincipalAxisTransform (masses, principalAxis, principalInertia); // apply principal axis // creation is faster using a new compound to store the shifted children btCompoundShape* newCompoundShape = new btCompoundShape(); for (int i = 0; i < shapeCount; i++) { btTransform newChildTransform = principalAxis.inverse() * compoundShape->getChildTransform (i); newCompoundShape->addChildShape(newChildTransform, compoundShape->getChildShape (i)); shapeChanged = false; } delete compoundShape; compoundShape = newCompoundShape; } shape = compoundShape; } else { shape = colliders[0]->shape; principalAxis = CSToBullet (relaTransforms[0], system->getInternalScale ()); } // create new motion state btTransform trans; motionState->getWorldTransform (trans); trans = trans * motionState->inversePrincipalAxis; delete motionState; motionState = new csBulletMotionState (this, trans * principalAxis, principalAxis); //shape->calculateLocalInertia (mass, localInertia); btRigidBody::btRigidBodyConstructionInfo infos (mass, motionState, shape, localInertia); infos.m_friction = friction; infos.m_restitution = elasticity; infos.m_linearDamping = linearDampening; infos.m_angularDamping = angularDampening; // create new rigid body btBody = new btRigidBody (infos); btObject = btBody; if (haveStaticColliders > 0) physicalState = CS::Physics::STATE_STATIC; SetState (physicalState); sector->bulletWorld->addRigidBody (btBody, collGroup.value, collGroup.mask); btBody->setUserPointer (dynamic_cast<CS::Collisions::iCollisionObject*> ( dynamic_cast<csBulletCollisionObject*>(this))); insideWorld = true; return true; }
bool UpdateChecker::install() { // create action QAction* a = MonkeyCore::menuBar()->action( "mHelp/aUpdateChecker", tr( "Check for update..." ), QIcon( ":/icons/UpdateChecker.png" ), QString::null, infos().Description ); connect( a, SIGNAL( triggered() ), this, SLOT( checkForUpdate_triggered() ) ); QTimer::singleShot( 15000, this, SLOT( checkForUpdate() ) ); return true; }
// Update breakpoint information bool BreakPoint::update(string& info_output, std::ostream& undo_commands, bool& need_total_undo) { string file = file_name(); BreakPoint new_bp(info_output, arg(), number(), file); bool changed = false; myenabled_changed = false; myposition_changed = false; myfile_changed = false; myaddress_changed = false; need_total_undo = false; const string num = "@" + itostring(number()) + "@"; if (new_bp.number() != number()) { mynumber = new_bp.number(); need_total_undo = changed = true; } if (new_bp.type() != type()) { mytype = new_bp.type(); need_total_undo = changed = myenabled_changed = true; } if (new_bp.dispo() != dispo()) { need_total_undo = changed = myenabled_changed = true; mydispo = new_bp.dispo(); } if (new_bp.watch_mode() != watch_mode()) { need_total_undo = changed = myenabled_changed = true; mywatch_mode = new_bp.watch_mode(); } if (new_bp.myenabled != myenabled) { changed = myenabled_changed = true; myenabled = new_bp.myenabled; if (myenabled) { if (gdb->has_disable_command()) undo_commands << gdb->disable_command(num) << "\n"; else need_total_undo = true; } else { if (gdb->has_enable_command()) undo_commands << gdb->enable_command(num) << "\n"; else need_total_undo = true; } } if (type() == BREAKPOINT) { if (new_bp.address() != address()) { changed = myaddress_changed = true; myaddress = new_bp.address(); } if (new_bp.func() != func()) { changed = myposition_changed = true; myfunc = new_bp.func(); } if (new_bp.file_name() != file_name()) { changed = myposition_changed = myfile_changed = true; myfile_name = new_bp.file_name(); } if (new_bp.line_nr() != line_nr()) { changed = myposition_changed = true; myline_nr = new_bp.line_nr(); } } else if (type() == WATCHPOINT) { if (new_bp.expr() != expr()) { changed = true; myexpr = new_bp.expr(); } } if (new_bp.infos() != infos()) { changed = true; myinfos = new_bp.infos(); } if (new_bp.ignore_count() != ignore_count()) { if (gdb->has_ignore_command()) undo_commands << gdb->ignore_command(num, myignore_count) << "\n"; else need_total_undo = true; changed = myenabled_changed = true; myignore_count = new_bp.ignore_count(); } if (new_bp.mycondition != mycondition) { if (gdb->has_condition_command()) undo_commands << gdb->condition_command(num, condition()) << "\n"; else need_total_undo = true; changed = myenabled_changed = true; mycondition = new_bp.mycondition; } if (!equal(new_bp.commands(), commands())) { if (gdb->type() == GDB || gdb->type() == PYDB || gdb->type() == BASH) { undo_commands << "commands " << num << '\n'; for (int i = 0; i < commands().size(); i++) undo_commands << commands()[i] << '\n'; undo_commands << "end\n"; } changed = myenabled_changed = true; mycommands = new_bp.commands(); } return changed; }
bool Irc::install() { // create docks mIrcDock = IrcDock::instance(); // add docks to main window MonkeyCore::mainWindow()->dockToolBar( Qt::BottomToolBarArea )->addDock( mIrcDock, infos().Caption, QIcon( infos().Pixmap ) ); return true; }
int read (::DDS::DataReader_ptr reader, bool use_zero_copy_reads) { // TWF: There is an optimization to the test by // using a pointer to the known servant and // static_casting it to the servant R_var var_dr = R::_narrow(reader); R_ptr pt_dr = var_dr.ptr(); Rimpl* dr_servant = ::TAO::DCPS::reference_to_servant< Rimpl, R_ptr> (pt_dr); if (subscriber_delay_msec) { ACE_Time_Value delay ( subscriber_delay_msec / 1000, (subscriber_delay_msec % 1000) * 1000); ACE_OS::sleep (delay); } const ::CORBA::Long max_read_samples = 100; #ifdef WITH_ZERO_COPY_ONLY Tseq samples(use_zero_copy_reads ? 0 : max_read_samples, max_read_samples); Iseq infos( use_zero_copy_reads ? 0 : max_read_samples, max_read_samples); #else Tseq samples(0); //max_read_samples); Iseq infos(0); //max_read_samples); #endif int samples_recvd = 0; DDS::ReturnCode_t status; // initialize to zero. status = dr_servant->read ( samples, infos, max_read_samples, ::DDS::NOT_READ_SAMPLE_STATE, ::DDS::ANY_VIEW_STATE, ::DDS::ANY_INSTANCE_STATE); if (status == ::DDS::RETCODE_OK) { samples_recvd = samples.length (); } else if (status == ::DDS::RETCODE_NO_DATA) { ACE_ERROR((LM_ERROR, " Empty read!\n")); } else { ACE_OS::printf (" read data: Error: %d\n", status) ; } status = dr_servant->return_loan(samples, infos); if (status != ::DDS::RETCODE_OK) { // TBD - why is printf used for errors? ACE_OS::printf (" return_loan: Error: %d\n", status) ; ACE_ERROR((LM_ERROR, " return_loan gave error status %d\n", status)); } return samples_recvd; }
int robot_command (uint16_t *cmd, uint16_t *resp, uint8_t *resplen) { unsigned long start = 0; uint8_t infolen = 0; int checkdir; int motor_state_save; int error = -1; int ret = SUCCESS; lcd.clear(); // clear LCD reset_leds(); // turn off all leds digitalWrite(Led_Blue, HIGH); // turn on led blue switch (cmd[0]) { case CMD_STOP: Serial.println("CMD_STOP"); lcd.print("STOP"); stop(); motor_state = STATE_STOP; *resplen = 0; break; case CMD_START: if (cmd[1] == 0) { Serial.println("CMD_START"); lcd.print("START"); start_forward(); } else { Serial.print("CMD_START_TEST motor: "); Serial.println((int)cmd[1]); lcd.print("START motor: "); lcd.print((int)cmd[1]); start_forward_test(cmd[1]); } motor_state = STATE_GO; *resplen = 0; break; case CMD_CHECK_AROUND: Serial.println("CMD_CHECK_AROUND"); lcd.print("CHECK AROUND"); checkdir = check_around(); lcd.setCursor(0,1); if (checkdir == DIRECTION_LEFT) lcd.print("LEFT"); else if (checkdir == DIRECTION_RIGHT) lcd.print("RIGHT"); else if (checkdir == OBSTACLE_LEFT) lcd.print("OBSTACLE LEFT"); else if (checkdir == OBSTACLE_RIGHT) lcd.print("OBSTACLE RIGHT"); else if (checkdir == OBSTACLE) lcd.print("OBSTACLE"); else lcd.print("?"); resp[0] = checkdir; *resplen = 0+1; break; case CMD_MOVE_TILT_PAN: Serial.print("CMD_MOVE_TILT_PAN: "); Serial.print((int)cmd[1]);Serial.print((int)cmd[2]);Serial.print((int)cmd[3]);Serial.println((int)cmd[4]); if (cmd[2] == 0) HPos = (int)cmd[1] + 90; else HPos = 90 - (int)cmd[1]; if (cmd[4] == 0) VPos = (int)cmd[3] + 90; else VPos = 90 - (int)cmd[3]; Serial.print("CMD_MOVE_TILT_PAN, HPos VPos: "); Serial.print(HPos);Serial.println(VPos); lcd.print("MOVE TILT&PAN"); lcd.setCursor(0,1); lcd.print("X: "); lcd.print(HPos); lcd.print(" Y: "); lcd.print(VPos); TiltPan_move(HPos, VPos); *resplen = 0; break; case CMD_TURN: if (cmd[1] == 180) { Serial.print("CMD_TURN_BACK"); lcd.print("TURN BACK "); ret = turnback (10); // 10s max if (ret != SUCCESS){ Serial.print("turnback error"); Serial.println(ret); lcd.setCursor(0,1); lcd.print("turnback error: "); lcd.print(ret); error = 1; } } else if (motor_state == STATE_GO) { Serial.print("CMD_TURN, alpha: "); Serial.print((cmd[2] != 1) ? ('+'):('-')); Serial.println((int)cmd[1]); lcd.print("TURN"); lcd.print((cmd[2] != 1) ? ('+'):('-')); lcd.print((int)cmd[1]);lcd.print((char)223); //degree ret = turn ((double)((cmd[2] != 1) ? (cmd[1]):(-cmd[1])), 5); // 5s max if (ret != SUCCESS){ Serial.print("turn error"); Serial.println(ret); lcd.setCursor(0,1); lcd.print(" turn error: "); lcd.print(ret); error = 1; } } *resplen = 0; break; case CMD_INFOS: Serial.println("CMD_INFOS"); ret = infos (resp, &infolen); if (resp[MOTOR_STATE] == STATE_GO) { lcd.print("RUNING"); } else { lcd.print("STOPPED"); } lcd.setCursor(0,1); lcd.print((int)resp[TEMPERATURE]); lcd.print((byte)lcd_celcius);lcd.write(lcd_pipe); lcd.print((int)resp[DISTANCE]); lcd.print("cm");lcd.write(lcd_pipe); lcd.print((int)resp[DIRECTION]); lcd.print((char)223); //degree *resplen = infolen; break; case CMD_PICTURE: Serial.print("CMD_PICTURE, no_picture: "); no_picture++; Serial.println(no_picture); lcd.print("PICTURE "); motor_state_save = motor_state; if (motor_state == STATE_GO) { Serial.println("Stop"); stop(); motor_state = STATE_STOP; } ret = JPEGCamera.makePicture (no_picture); if (ret == SUCCESS) { lcd.setCursor(0,1); lcd.print("picture: "); lcd.print(no_picture); } else { Serial.print("makePicture error: "); Serial.println(ret); lcd.setCursor(0,1); lcd.print("error: "); lcd.print(ret); error = 1; } if (motor_state_save == STATE_GO) { Serial.println("Start"); start_forward(); motor_state = STATE_GO; } // byte 0: picture number resp[0] = no_picture; *resplen = 0+1; break; case CMD_ALERT: Serial.println("CMD_ALERT"); lcd.print("Alert"); blink(Led_Blue); buzz(5); // If motor_state == STATE_GO => Stop if (motor_state == STATE_GO) { Serial.println("Stop"); stop(); motor_state = STATE_STOP; } // Make 3 pictures left, front and right if ((HPos != 90) || (VPos !=90)) { HPos = 90; VPos = 90; TiltPan_move(HPos, VPos); } Serial.print("makePicture, no_picture: "); no_picture++; Serial.println(no_picture); lcd.print("PICTURE "); ret = JPEGCamera.makePicture (no_picture); if (ret == SUCCESS) { lcd.setCursor(0,1); lcd.print("picture: "); lcd.print(no_picture); } else { Serial.print("makePicture error: "); Serial.println(ret); lcd.setCursor(0,1); lcd.print("error: "); lcd.print(ret); error = 1; } if (ret == SUCCESS) { HPos = 0; VPos = 90; TiltPan_move(HPos, VPos); Serial.print("makePicture, no_picture: "); no_picture++; Serial.println(no_picture); lcd.print("PICTURE "); ret = JPEGCamera.makePicture (no_picture); lcd.setCursor(0,1); lcd.print("picture: "); lcd.print(no_picture); } else { Serial.print("makePicture error: "); Serial.println(ret); lcd.setCursor(0,1); lcd.print("error: "); lcd.print(ret); error = 1; } if (ret == SUCCESS) { HPos = 180; VPos = 90; TiltPan_move(HPos, VPos); Serial.print("makePicture, no_picture: "); no_picture++; Serial.println(no_picture); lcd.print("PICTURE "); ret = JPEGCamera.makePicture (no_picture); lcd.setCursor(0,1); lcd.print("picture: "); lcd.print(no_picture); } else { Serial.print("makePicture error: "); Serial.println(ret); lcd.setCursor(0,1); lcd.print("error: "); lcd.print(ret); error = 1; } // byte 0: last picture number resp[0] = no_picture; *resplen = 0+1; HPos = 90; VPos = 90; TiltPan_move(HPos, VPos); break; case CMD_CHECK: Serial.println("CMD_CHECK"); lcd.print("Check"); alert_status = check(); if (alert_status != SUCCESS) { Serial.print("Alert detected: ");Serial.println(alert_status); lcd.setCursor(0,1); lcd.print("Alert: "); lcd.print(alert_status); } else { Serial.print("No alert detected: "); lcd.setCursor(0,1); lcd.print(" No Alert"); } // byte 0: alert resp[0] = alert_status; *resplen = 0+1; break; case CMD_GO: Serial.print("CMD_GO, nb seconds: "); Serial.print((int)cmd[1]); lcd.print("GO ");lcd.print((int)cmd[1]);lcd.print("secs"); if (motor_state != STATE_GO) { Serial.println("start_forward"); start_forward(); motor_state = STATE_GO; } error = -1; GOtimeout = (unsigned long)cmd[1]; start = millis(); while((millis() - start < GOtimeout*1000) && (error == -1)) { ret = go(GOtimeout); if ((ret != SUCCESS) && (ret != OBSTACLE) && (ret != OBSTACLE_LEFT) && (ret != OBSTACLE_RIGHT)) { stop(); motor_state = STATE_STOP; error = 1; Serial.print("CMD_GO error: "); Serial.println(ret); Serial.println("Stop"); lcd.setCursor(0,1); lcd.print("error: "); lcd.print(ret); } else if ((ret == OBSTACLE) || (ret == OBSTACLE_LEFT) || (ret == OBSTACLE_RIGHT)) { stop(); motor_state = STATE_STOP; buzz(3); blink(Led_Red); Serial.print("CMD_GO Obstacle: ");Serial.println(ret); Serial.println("Stop"); lcd.setCursor(0,1); if (ret == OBSTACLE_LEFT) lcd.print("OBSTACLE LEFT"); else if (ret == OBSTACLE_RIGHT) lcd.print("OBSTACLE RIGHT"); else if (ret == OBSTACLE) lcd.print("OBSTACLE"); else ret = SUCCESS; checkdir = check_around(); Serial.print("check_around, direction: "); Serial.println(checkdir); lcd.clear(); lcd.print("check around"); lcd.setCursor(0,1); if (checkdir == DIRECTION_LEFT) lcd.print("LEFT"); else if (checkdir == DIRECTION_RIGHT) lcd.print("RIGHT"); else if (checkdir == OBSTACLE_LEFT) lcd.print("OBSTACLE LEFT"); else if (checkdir == OBSTACLE_RIGHT) lcd.print("OBSTACLE RIGHT"); else if (checkdir == OBSTACLE) lcd.print("OBSTACLE"); else lcd.print("?");; if (checkdir == DIRECTION_LEFT) { start_forward(); motor_state = STATE_GO; ret = turn (-45, 5); // turn -45 degrees during 5s max if (ret != SUCCESS) { stop(); motor_state = STATE_STOP; error = 1; Serial.print("turn error: "); Serial.println(ret); Serial.println("Stop"); lcd.clear(); lcd.print("turn left"); lcd.setCursor(0,1); lcd.print("error: "); lcd.print(ret); } else { lcd.clear(); lcd.print("turn left OK"); } } else if (checkdir == DIRECTION_RIGHT) { start_forward(); motor_state = STATE_GO; ret = turn (+45, 5); // turn +45 degrees during 5s max if (ret != SUCCESS) { stop(); motor_state = STATE_STOP; error = 1; Serial.print("turn error: "); Serial.println(ret); Serial.println("Stop"); lcd.clear(); lcd.print("turn right"); lcd.setCursor(0,1); lcd.print("error: "); lcd.print(ret); } else { lcd.clear(); lcd.print("turn right OK"); } } else { buzz(3); blink(Led_Red); motor_state = STATE_GO; ret = turnback (10); // turn back during 10s max if (ret != SUCCESS) { stop(); motor_state = STATE_STOP; error = 1; Serial.print("turnback error"); Serial.println(ret); Serial.println("Stop"); lcd.clear(); lcd.print("turnback"); lcd.setCursor(0,1); lcd.print("error: "); lcd.print(ret); } else { lcd.clear(); lcd.print("turnback OK"); } } } else { Serial.println("GO OK"); lcd.clear(); lcd.print("GO OK"); error = 0; } } // end while ret = infos (resp, &infolen); if (error == 0) { if (resp[MOTOR_STATE] == STATE_GO) { lcd.print("RUNNING"); } else { lcd.print("STOPPED"); } lcd.setCursor(0,1); lcd.print((int)resp[TEMPERATURE]); lcd.print((byte)lcd_celcius);lcd.write(lcd_pipe); lcd.print((int)resp[DISTANCE]); lcd.print("cm");lcd.write(lcd_pipe); lcd.print((int)resp[DIRECTION]); lcd.print((char)223); //degree } *resplen = infolen; break; case CMD_PI: Serial.print("CMD_PI activated, type: "); Serial.print((int)cmd[1]); Serial.print(" - freq: ");Serial.println((int)cmd[2]); lcd.print("PI activated ");lcd.print((int)cmd[1]); PI_activated = (int)cmd[1]; if (PI_activated <> PI_NO_COMM) PI_freqInfos = (int)cmd[2]* 1000; Serial.print("PI_activated: "); Serial.println(PI_activated); Serial.print("PI_freqInfos: ");Serial.println(PI_freqInfos); *resplen = 0; break; default: Serial.println("invalid command"); lcd.print("invalid command"); *resplen = 0; break; } //end switch if (error == 1) { blink(Led_Red); blink(Led_Red); buzz(7); *resplen = 0; } reset_leds(); // turn off all leds return ret; }
SegmentInfosPtr SegmentInfos::range(int32_t first, int32_t last) { SegmentInfosPtr infos(newLucene<SegmentInfos>()); infos->segmentInfos.addAll(segmentInfos.begin() + first, segmentInfos.begin() + last); return infos; }