void CDVDMsgGeneralSynchronize::Wait(std::atomic<bool>& abort, unsigned int source) { while(!Wait(100, source) && !abort); }
void Robot::RightLeftAuton() { float targetValue; const float targetDistance = 295.0; Timer* timer = new Timer; timer->Reset(); robotDrive->resetEncoders(); timer->Start(); bool state = checkReflectiveStrips(); robotDrive->drive(0, 0); Wait(0.5); robotDrive->drive(-0.1, 0); Wait(.25); claw->SetAngle(115.0); Wait(0.5); /* "&& robotDrive->getRightDist() > -5.0" ensures robot doesn't drive * backwards */ while (robotDrive->getRightDist() < targetDistance && IsEnabled() && robotDrive->getRightDist() > -5.0 && IsAutonomous()) { targetValue = -0.6 * (1.f - robotDrive->getRightDist() / targetDistance); robotDrive->drive(targetValue, 0); // std::cout << "right distance: " << (robotDrive->getRightDist())<< // std::endl; // std::cout << "left distance: " << (robotDrive->getLeftDist()) << // std::endl; // std::cout << "targetValue: " << targetValue << std::endl; if (claw->onTarget()) { claw->SetWheelManual(0.0); } claw->Update(); Wait(0.1); } robotDrive->drive(0, 0); // std::cout << "final right distance: " << (robotDrive->getRightDist()) << // std::endl; // std::cout << "final left distance: " << (robotDrive->getLeftDist()) << // std::endl; while (robotDrive->getLeftDist() * -1 < robotDrive->getRightDist() && IsEnabled() && IsAutonomous()) { robotDrive->setLeftManual(0.3); } claw->SetWheelManual(0.0); robotDrive->drive(-0.1, 0); Wait(0.1); robotDrive->drive(0, 0); if (state == true) { claw->Shoot(); } else { while (timer->HasPeriodPassed(5) == false) { Wait(0.01); } claw->Shoot(); } while (IsEnabled() && IsAutonomous()) { claw->Update(); Wait(0.1); } }
void CMobController::DoRoamTick(time_point tick) { // If there's someone on our enmity list, go from roaming -> engaging if (PMob->PEnmityContainer->GetHighestEnmity() != nullptr && !(PMob->m_roamFlags & ROAMFLAG_IGNORE)) { Engage(PMob->PEnmityContainer->GetHighestEnmity()->targid); return; } else if (PMob->m_OwnerID.id != 0 && !(PMob->m_roamFlags & ROAMFLAG_IGNORE)) { // i'm claimed by someone and need hate towards this person PTarget = (CBattleEntity*)PMob->GetEntity(PMob->m_OwnerID.targid, TYPE_PC | TYPE_MOB | TYPE_PET); PMob->PEnmityContainer->AddBaseEnmity(PTarget); Engage(PTarget->targid); return; } //#TODO else if (PMob->GetDespawnTime() > time_point::min() && PMob->GetDespawnTime() < m_Tick) { Despawn(); return; } if (PMob->m_roamFlags & ROAMFLAG_IGNORE) { // don't claim me if I ignore PMob->m_OwnerID.clean(); } //skip roaming if waiting if (m_Tick >= m_WaitTime) { // don't aggro a little bit after I just disengaged PMob->m_neutral = PMob->CanBeNeutral() && m_Tick <= m_NeutralTime + 10s; if (PMob->PAI->PathFind->IsFollowingPath()) { FollowRoamPath(); } else if (m_Tick >= m_LastActionTime + std::chrono::milliseconds(PMob->getBigMobMod(MOBMOD_ROAM_COOL))) { // lets buff up or move around if (PMob->CalledForHelp()) { PMob->CallForHelp(false); } // can't rest with poison or disease if (PMob->CanRest()) { // recover 10% health if (PMob->Rest(0.1f)) { // health updated PMob->updatemask |= UPDATE_HP; } if (PMob->GetHPP() == 100) { // at max health undirty exp PMob->m_giveExp = true; } } // if I just disengaged check if I should despawn if (PMob->IsFarFromHome()) { if (PMob->CanRoamHome() && PMob->PAI->PathFind->PathTo(PMob->m_SpawnPoint)) { // walk back to spawn if too far away // limit total path to just 10 or // else we'll move straight back to spawn PMob->PAI->PathFind->LimitDistance(10.0f); FollowRoamPath(); // move back every 5 seconds m_LastActionTime = m_Tick - (std::chrono::milliseconds(PMob->getBigMobMod(MOBMOD_ROAM_COOL)) + 10s); } else if (!PMob->getMobMod(MOBMOD_NO_DESPAWN) != 0 && !map_config.mob_no_despawn) { PMob->PAI->Despawn(); return; } } else { // No longer including conditional for ROAMFLAG_AMBUSH now that using mixin to handle mob hiding if (PMob->getMobMod(MOBMOD_SPECIAL_SKILL) != 0 && m_Tick >= m_LastSpecialTime + std::chrono::milliseconds(PMob->getBigMobMod(MOBMOD_SPECIAL_COOL)) && TrySpecialSkill()) { // I spawned a pet } else if (PMob->GetMJob() == JOB_SMN && CanCastSpells() && PMob->SpellContainer->HasBuffSpells() && m_Tick >= m_LastMagicTime + std::chrono::milliseconds(PMob->getBigMobMod(MOBMOD_MAGIC_COOL))) { // summon pet auto spellID = PMob->SpellContainer->GetBuffSpell(); if(spellID) CastSpell(spellID.value()); } else if (CanCastSpells() && dsprand::GetRandomNumber(10) < 3 && PMob->SpellContainer->HasBuffSpells()) { // cast buff auto spellID = PMob->SpellContainer->GetBuffSpell(); if(spellID) CastSpell(spellID.value()); } else if (PMob->m_roamFlags & ROAMFLAG_EVENT) { // allow custom event action luautils::OnMobRoamAction(PMob); m_LastActionTime = m_Tick; } else if (PMob->CanRoam() && PMob->PAI->PathFind->RoamAround(PMob->m_SpawnPoint, PMob->GetRoamDistance(), (uint8)PMob->getMobMod(MOBMOD_ROAM_TURNS), PMob->m_roamFlags)) { //#TODO: #AIToScript (event probably) if (PMob->m_roamFlags & ROAMFLAG_WORM) { // move down PMob->animationsub = 1; PMob->HideName(true); PMob->Untargetable(true); // don't move around until i'm fully in the ground Wait(2s); } else if ((PMob->m_roamFlags & ROAMFLAG_STEALTH)) { // hidden name PMob->HideName(true); PMob->Untargetable(true); PMob->updatemask |= UPDATE_HP; } else { FollowRoamPath(); } } else { m_LastActionTime = m_Tick; } } } } if (m_Tick >= m_LastRoamScript + 3s) { PMob->PAI->EventHandler.triggerListener("ROAM_TICK", PMob); luautils::OnMobRoam(PMob); m_LastRoamScript = m_Tick; } }
int PL_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { // Should selected items be added to the current selection or // become the new selection (discarding previously selected items) m_additive = evt->Modifier( MD_SHIFT ); // Should selected items be REMOVED from the current selection? // This will be ignored if the SHIFT modifier is pressed m_subtractive = !m_additive && evt->Modifier( MD_CTRL ); // Is the user requesting that the selection list include all possible // items without removing less likely selection candidates m_skip_heuristics = !!evt->Modifier( MD_ALT ); // Single click? Select single object if( evt->IsClick( BUT_LEFT ) ) { // If no modifier keys are pressed, clear the selection if( !m_additive ) ClearSelection(); SelectPoint( evt->Position()); } // right click? if there is any object - show the context menu else if( evt->IsClick( BUT_RIGHT ) ) { bool selectionCancelled = false; if( m_selection.Empty() ) { SelectPoint( evt->Position(), &selectionCancelled ); m_selection.SetIsHover( true ); } if( !selectionCancelled ) m_menu.ShowContextMenu( m_selection ); } // double click? Display the properties window else if( evt->IsDblClick( BUT_LEFT ) ) { // No double-click actions currently defined } // drag with LMB? Select multiple objects (or at least draw a selection box) or drag them else if( evt->IsDrag( BUT_LEFT ) ) { if( m_additive || m_subtractive || m_selection.Empty() ) { selectMultiple(); } else { // Check if dragging has started within any of selected items bounding box if( selectionContains( evt->Position() ) ) { // Yes -> run the move tool and wait till it finishes m_toolMgr->InvokeTool( "plEditor.InteractiveEdit" ); } else { // No -> clear the selection list ClearSelection(); } } } else if( evt->IsAction( &ACTIONS::cancelInteractive ) || evt->IsCancel() ) { ClearSelection(); } else if( evt->Action() == TA_UNDO_REDO_PRE ) { ClearSelection(); } else if( evt->Action() == TA_CONTEXT_MENU_CLOSED ) { m_menu.CloseContextMenu( evt ); } else m_toolMgr->PassEvent(); } // This tool is supposed to be active forever assert( false ); return 0; }
bool PL_SELECTION_TOOL::doSelectionMenu( COLLECTOR* aCollector ) { EDA_ITEM* current = nullptr; ACTION_MENU menu; int limit = std::min( MAX_SELECT_ITEM_IDS, aCollector->GetCount() ); for( int i = 0; i < limit; ++i ) { wxString text; EDA_ITEM* item = ( *aCollector )[i]; text = item->GetSelectMenuText( m_frame->GetUserUnits() ); wxString menuText = wxString::Format("&%d. %s", i + 1, text ); menu.Add( menuText, i + 1, item->GetMenuImage() ); } if( aCollector->m_MenuTitle.Length() ) menu.SetTitle( aCollector->m_MenuTitle ); menu.SetIcon( info_xpm ); menu.DisplayTitle( true ); SetContextMenu( &menu, CMENU_NOW ); while( OPT_TOOL_EVENT evt = Wait() ) { if( evt->Action() == TA_CONTEXT_MENU_UPDATE ) { if( current ) unhighlight( current, BRIGHTENED ); int id = *evt->GetCommandId(); // User has pointed an item, so show it in a different way if( id > 0 && id <= limit ) { current = ( *aCollector )[id - 1]; highlight( current, BRIGHTENED ); } else { current = NULL; } } else if( evt->Action() == TA_CONTEXT_MENU_CHOICE ) { if( current ) unhighlight( current, BRIGHTENED ); OPT<int> id = evt->GetCommandId(); // User has selected an item, so this one will be returned if( id && ( *id > 0 ) ) current = ( *aCollector )[*id - 1]; else current = NULL; break; } getView()->UpdateItems(); m_frame->GetCanvas()->Refresh(); } if( current ) { unhighlight( current, BRIGHTENED ); getView()->UpdateItems(); m_frame->GetCanvas()->Refresh(); aCollector->Empty(); aCollector->Append( current ); return true; } return false; }
int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) { BOARD_ITEM* text = NULL; const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings(); BOARD_COMMIT commit( m_frame ); // Add a VIEW_GROUP that serves as a preview for the new item SELECTION preview( m_view ); m_view->Add( &preview ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); m_controls->ShowCursor( true ); m_controls->SetSnapping( true ); // do not capture or auto-pan until we start placing some text SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT ); Activate(); m_frame->SetToolID( m_editModules ? ID_MODEDIT_TEXT_TOOL : ID_PCB_ADD_TEXT_BUTT, wxCURSOR_PENCIL, _( "Add text" ) ); // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { VECTOR2I cursorPos = m_controls->GetCursorPosition(); if( evt->IsCancel() || evt->IsActivate() ) { if( text ) { // Delete the old text and have another try delete text; text = NULL; preview.Clear(); m_controls->SetAutoPan( false ); m_controls->CaptureCursor( false ); m_controls->ShowCursor( true ); } else break; if( evt->IsActivate() ) // now finish unconditionally break; } else if( text && evt->Category() == TC_COMMAND ) { if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) { text->Rotate( text->GetPosition(), m_frame->GetRotationAngle() ); m_view->Update( &preview ); } // TODO rotate CCW else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) { text->Flip( text->GetPosition() ); m_view->Update( &preview ); } } else if ( evt->IsClick( BUT_RIGHT ) ) { showContextMenu(); } else if( evt->IsClick( BUT_LEFT ) ) { if( !text ) { // Init the new item attributes if( m_editModules ) { TEXTE_MODULE* textMod = new TEXTE_MODULE( (MODULE*) m_frame->GetModel() ); textMod->SetLayer( m_frame->GetActiveLayer() ); textMod->SetSize( dsnSettings.m_ModuleTextSize ); textMod->SetThickness( dsnSettings.m_ModuleTextWidth ); textMod->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); DialogEditModuleText textDialog( m_frame, textMod, NULL ); bool placing; RunMainStack( [&]() { placing = textDialog.ShowModal() && ( textMod->GetText().Length() > 0 ); } ); if( placing ) text = textMod; else delete textMod; } else { TEXTE_PCB* textPcb = new TEXTE_PCB( m_frame->GetModel() ); // TODO we have to set IS_NEW, otherwise InstallTextPCB.. creates an undo entry :| LEGACY_CLEANUP textPcb->SetFlags( IS_NEW ); LAYER_ID layer = m_frame->GetActiveLayer(); textPcb->SetLayer( layer ); // Set the mirrored option for layers on the BACK side of the board if( IsBackLayer( layer ) ) textPcb->SetMirrored( true ); textPcb->SetSize( dsnSettings.m_PcbTextSize ); textPcb->SetThickness( dsnSettings.m_PcbTextWidth ); textPcb->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); RunMainStack( [&]() { getEditFrame<PCB_EDIT_FRAME>()->InstallTextPCBOptionsFrame( textPcb, NULL ); } ); if( textPcb->GetText().IsEmpty() ) delete textPcb; else text = textPcb; } if( text == NULL ) continue; m_controls->CaptureCursor( true ); m_controls->SetAutoPan( true ); //m_controls->ShowCursor( false ); preview.Add( text ); } else { //assert( text->GetText().Length() > 0 ); //assert( text->GetSize().x > 0 && text->GetSize().y > 0 ); text->ClearFlags(); preview.Remove( text ); commit.Add( text ); commit.Push( _( "Place a text" ) ); m_controls->CaptureCursor( false ); m_controls->SetAutoPan( false ); m_controls->ShowCursor( true ); text = NULL; } } else if( text && evt->IsMotion() ) { text->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); // Show a preview of the item m_view->Update( &preview ); } } m_controls->ShowCursor( false ); m_controls->SetSnapping( false ); m_controls->SetAutoPan( false ); m_controls->CaptureCursor( false ); m_view->Remove( &preview ); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; }
int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent ) { if( !m_frame->GetModel() ) return 0; DIALOG_DXF_IMPORT dlg( m_frame ); int dlgResult = dlg.ShowModal(); const std::list<BOARD_ITEM*>& list = dlg.GetImportedItems(); if( dlgResult != wxID_OK || list.empty() ) return 0; VECTOR2I cursorPos = m_controls->GetCursorPosition(); VECTOR2I delta = cursorPos - list.front()->GetPosition(); // Add a VIEW_GROUP that serves as a preview for the new item SELECTION preview( m_view ); BOARD_COMMIT commit( m_frame ); // Build the undo list & add items to the current view for( auto item : list ) { assert( item->Type() == PCB_LINE_T || item->Type() == PCB_TEXT_T ); preview.Add( item ); } BOARD_ITEM* firstItem = preview.Front(); m_view->Add( &preview ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); m_controls->ShowCursor( true ); m_controls->SetSnapping( true ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF ); Activate(); // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { cursorPos = m_controls->GetCursorPosition(); if( evt->IsMotion() ) { delta = cursorPos - firstItem->GetPosition(); for( auto item : preview ) item->Move( wxPoint( delta.x, delta.y ) ); m_view->Update( &preview ); } else if( evt->Category() == TC_COMMAND ) { // TODO it should be handled by EDIT_TOOL, so add items and select? if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) { for( auto item : preview ) item->Rotate( wxPoint( cursorPos.x, cursorPos.y ), m_frame->GetRotationAngle() ); m_view->Update( &preview ); } else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) { for( auto item : preview ) item->Flip( wxPoint( cursorPos.x, cursorPos.y ) ); m_view->Update( &preview ); } else if( evt->IsCancel() || evt->IsActivate() ) { preview.FreeItems(); break; } } else if ( evt->IsClick( BUT_RIGHT ) ) { showContextMenu(); } else if( evt->IsClick( BUT_LEFT ) ) { // Place the drawing BOARD_ITEM_CONTAINER* parent = m_frame->GetModel(); for( auto item : preview ) { if( m_editModules ) { // Modules use different types for the same things, // so we need to convert imported items to appropriate classes. BOARD_ITEM* converted = NULL; switch( item->Type() ) { case PCB_TEXT_T: { TEXTE_PCB* text = static_cast<TEXTE_PCB*>( item ); TEXTE_MODULE* textMod = new TEXTE_MODULE( (MODULE*) parent ); // Assignment operator also copies the item PCB_TEXT_T type, // so it cannot be added to a module which handles PCB_MODULE_TEXT_T textMod->SetPosition( text->GetPosition() ); textMod->SetText( text->GetText() ); textMod->SetSize( text->GetSize() ); textMod->SetThickness( text->GetThickness() ); textMod->SetOrientation( text->GetOrientation() ); textMod->SetTextPosition( text->GetTextPosition() ); textMod->SetSize( text->GetSize() ); textMod->SetMirrored( text->IsMirrored() ); textMod->SetAttributes( text->GetAttributes() ); textMod->SetItalic( text->IsItalic() ); textMod->SetBold( text->IsBold() ); textMod->SetHorizJustify( text->GetHorizJustify() ); textMod->SetVertJustify( text->GetVertJustify() ); textMod->SetMultilineAllowed( text->IsMultilineAllowed() ); converted = textMod; break; } case PCB_LINE_T: { DRAWSEGMENT* seg = static_cast<DRAWSEGMENT*>( item ); EDGE_MODULE* modSeg = new EDGE_MODULE( (MODULE*) parent ); // Assignment operator also copies the item PCB_LINE_T type, // so it cannot be added to a module which handles PCB_MODULE_EDGE_T modSeg->SetWidth( seg->GetWidth() ); modSeg->SetStart( seg->GetStart() ); modSeg->SetEnd( seg->GetEnd() ); modSeg->SetAngle( seg->GetAngle() ); modSeg->SetShape( seg->GetShape() ); modSeg->SetType( seg->GetType() ); modSeg->SetBezControl1( seg->GetBezControl1() ); modSeg->SetBezControl2( seg->GetBezControl2() ); modSeg->SetBezierPoints( seg->GetBezierPoints() ); modSeg->SetPolyPoints( seg->GetPolyPoints() ); converted = modSeg; break; } default: assert( false ); break; } if( converted ) converted->SetLayer( item->GetLayer() ); delete item; item = converted; } if( item ) commit.Add( item ); } commit.Push( _( "Place a DXF drawing" ) ); break; } } preview.Clear(); m_controls->ShowCursor( false ); m_controls->SetSnapping( false ); m_controls->SetAutoPan( false ); m_controls->CaptureCursor( false ); m_view->Remove( &preview ); return 0; }
int ComprDataIO::UnpRead(unsigned char *Addr,unsigned int Count) { int RetCode=0,TotalRead=0; unsigned char *ReadAddr; ReadAddr=Addr; while (Count > 0) { Archive *SrcArc=(Archive *)SrcFile; unsigned int ReadSize=(Count>UnpPackedSize) ? int64to32(UnpPackedSize):Count; if (UnpackFromMemory) { memcpy(Addr,UnpackFromMemoryAddr,UnpackFromMemorySize); RetCode=UnpackFromMemorySize; UnpackFromMemorySize=0; } else { if (!SrcFile->IsOpened()) return(-1); RetCode=SrcFile->Read(ReadAddr,ReadSize); FileHeader *hd=SubHead!=NULL ? SubHead:&SrcArc->NewLhd; if (hd->Flags & LHD_SPLIT_AFTER) PackedCRC=CRC(PackedCRC,ReadAddr,ReadSize); } CurUnpRead+=RetCode; ReadAddr+=RetCode; TotalRead+=RetCode; Count-=RetCode; UnpPackedSize-=RetCode; if (UnpPackedSize == 0 && UnpVolume) { #ifndef NOVOLUME if (!MergeArchive(*SrcArc,this,true,CurrentCommand)) #endif { NextVolumeMissing=true; return(-1); } } else break; } Archive *SrcArc=(Archive *)SrcFile; if (SrcArc!=NULL) ShowUnpRead(SrcArc->CurBlockPos+CurUnpRead,UnpArcSize); if (RetCode!=-1) { RetCode=TotalRead; #ifndef NOCRYPT if (Decryption) #ifndef SFX_MODULE if (Decryption<20) Decrypt.Crypt(Addr,RetCode,(Decryption==15) ? NEW_CRYPT : OLD_DECODE); else if (Decryption==20) for (unsigned int I=0;I<RetCode;I+=16) Decrypt.DecryptBlock20(&Addr[I]); else #endif { int CryptSize=(RetCode & 0xf)==0 ? RetCode:((RetCode & ~0xf)+16); Decrypt.DecryptBlock(Addr,CryptSize); } #endif } Wait(); return(RetCode); }
void cChunkSender::Stop(void) { m_ShouldTerminate = true; m_evtQueue.Set(); Wait(); }
//------------------------------------------------------------------------------ int main(void) { VICConfig(); TimingInit(); LEDInit(); UART1Init(); UART2Init(); I2CInit(); SPISlaveInit(); Wait(100); UART1Printf("University of Tokyo NaviCtrl firmware V2"); ReadEEPROM(); UBloxInit(); LSM303DLInit(); FlightCtrlCommsInit(); SDCardInit(); NavigationInit(); ExternalButtonInit(); // Enable the "new data" interrupt. VIC_Config(EXTIT0_ITLine, VIC_IRQ, IRQ_PRIORITY_NEW_DATA); VIC_ITCmd(EXTIT0_ITLine, ENABLE); // Enable the 50Hz Interrupt. VIC_Config(EXTIT3_ITLine, VIC_IRQ, IRQ_PRIORITY_50HZ); VIC_ITCmd(EXTIT3_ITLine, ENABLE); // Main loop. uint32_t led_timer = GetTimestamp(); for (;;) { #ifndef VISION // Check for new data from the magnetometer. ProcessIncomingLSM303DL(); // Skip the rest of the main loop if mag calibration is ongoing. if (MagCalibration(mag_calibration_)) continue; // Check for new data on the GPS UART port. ProcessIncomingUBlox(); #endif // Check for new data from the FlightCtrl. if (NewDataFromFlightCtrl()) { ClearNewDataFromFlightCtrlFlag(); #ifdef VISION KalmanAccelerometerUpdate(); #endif UpdateNavigation(); PrepareFlightCtrlDataExchange(); #ifndef VISION RequestLSM303DL(); #endif // Check if new data has come while processing the data. This indicates // that processing did not complete fast enough. if (NewDataFromFlightCtrl()) { overrun_counter_++; } } #ifndef VISION CheckUBXFreshness(); CheckLSM303DLFreshness(); // Normally the magnetometer is read every time new data comes from the // FlightCtrl. The following statement is a backup that ensures the // magnetometer is updated even if there is no connection to the FlightCtrl // and also deals with read errors. if (LSM303DLDataStale()) { if (MillisSinceTimestamp(LSM303DLLastRequestTimestamp()) > 20) RequestLSM303DL(); if (LSM303DLErrorBits() & LSM303DL_ERROR_BIT_I2C_BUSY) I2CReset(); } #else CheckVisionFreshness(); #endif // Check for incoming data on the "update & debug" UART port. ProcessIncomingUART1(); // Check for incoming data on the "FligthCtrl" UART port. ProcessIncomingUART2(); ProcessLogging(); if (TimestampInPast(led_timer)) { GreenLEDToggle(); while (TimestampInPast(led_timer)) led_timer += 100; // Debug output for GPS and magnetomter. Remove after testing is completed // UART1Printf("%+5.2f,%+5.2f,%+5.2f", // MagneticVector()[0], // MagneticVector()[1], // MagneticVector()[2]); // UART1Printf("%i,%i,%i", // MagnetometerVector()[0], // MagnetometerVector()[1], // MagnetometerVector()[2]); // UART1Printf("%i,%i,%i", // MagnetometerBiasVector()[0], // MagnetometerBiasVector()[1], // MagnetometerBiasVector()[2]); // UART1Printf("%f", CurrentHeading()); // UART1Printf("%f,%f,%f", // (float)(UBXPosLLH()->longitude * 1e-7), // (float)(UBXPosLLH()->latitude * 1e-7), // (float)(UBXPosLLH()->height_above_ellipsoid * 1e-3)); UART1PrintfSafe("%+5.2f,%+5.2f,%+5.2f,%+5.2f", PositionVector()[0], PositionVector()[1], PositionVector()[2], CurrentHeading()); } } }
void OperatorControl(void) { bool button1Bool; bool button2Bool; bool button3Bool; bool button4Bool; bool button5Bool; bool button6Bool; bool button7Bool; bool button8Bool; bool button9Bool; bool button10Bool; bool button11Bool; bool button12Bool; float LeftaxisYValue; float LeftaxisXValue; float RightaxisXValue; float RightaxisYValue; float TriggerValue; myRobot.SetSafetyEnabled(true); while (IsOperatorControl()) { button1Bool = button1.Get(); SmartDashboard::PutNumber("button1",button1Bool); button2Bool = button2.Get(); SmartDashboard::PutNumber("button2",button2Bool); button3Bool = button3.Get(); SmartDashboard::PutNumber("button3",button3Bool); button4Bool = button4.Get(); SmartDashboard::PutNumber("button4",button4Bool); button5Bool = button5.Get(); SmartDashboard::PutNumber("button5",button5Bool); button6Bool = button6.Get(); SmartDashboard::PutNumber("button6",button6Bool); button7Bool = button7.Get(); SmartDashboard::PutNumber("button7",button7Bool); button8Bool = button8.Get(); SmartDashboard::PutNumber("button8",button8Bool); button9Bool = button9.Get(); SmartDashboard::PutNumber("button9",button9Bool); button10Bool = button10.Get(); SmartDashboard::PutNumber("button10",button10Bool); button11Bool = button11.Get(); SmartDashboard::PutNumber("button11",button11Bool); button12Bool = button12.Get(); SmartDashboard::PutNumber("button12",button12Bool); LeftaxisXValue = stick.GetX(); SmartDashboard::PutNumber("Joystick1 X Axis",LeftaxisXValue); LeftaxisYValue = 0 - stick.GetY(); SmartDashboard::PutNumber("Joystick1 Y Axis",LeftaxisYValue); RightaxisXValue = stick.GetTwist(); SmartDashboard::PutNumber("Joystick2 X Axis", RightaxisXValue); RightaxisYValue = 0 - stick.GetRawAxis(5); SmartDashboard::PutNumber("Joystick2 Y Axis", RightaxisYValue); TriggerValue = stick.GetThrottle(); SmartDashboard::PutNumber("Trigger value", TriggerValue); Wait(0.005); // wait for a motor update time } }
//CommandSequentialGroupTest ported from CommandSequentialGroupTest.java TEST_F(CommandTest, ThreeCommandOnSubSystem){ ASubsystem subsystem("Three Command Test Subsystem"); MockCommand command1; command1.Requires(&subsystem); MockCommand command2; command2.Requires(&subsystem); MockCommand command3; command3.Requires(&subsystem); CommandGroup commandGroup; commandGroup.AddSequential(&command1, 1.0 ); commandGroup.AddSequential(&command2, 2.0 ); commandGroup.AddSequential(&command3); AssertCommandState(command1, 0, 0, 0, 0, 0); AssertCommandState(command2, 0, 0, 0, 0, 0); AssertCommandState(command3, 0, 0, 0, 0, 0); commandGroup.Start(); AssertCommandState(command1, 0, 0, 0, 0, 0); AssertCommandState(command2, 0, 0, 0, 0, 0); AssertCommandState(command3, 0, 0, 0, 0, 0); Scheduler::GetInstance()->Run(); AssertCommandState(command1, 0, 0, 0, 0, 0); AssertCommandState(command2, 0, 0, 0, 0, 0); AssertCommandState(command3, 0, 0, 0, 0, 0); Scheduler::GetInstance()->Run(); AssertCommandState(command1, 1, 1, 1, 0, 0); AssertCommandState(command2, 0, 0, 0, 0, 0); AssertCommandState(command3, 0, 0, 0, 0, 0); Wait(1);//command 1 timeout Scheduler::GetInstance()->Run(); AssertCommandState(command1, 1, 1, 1, 0, 1); AssertCommandState(command2, 1, 1, 1, 0, 0); AssertCommandState(command3, 0, 0, 0, 0, 0); Scheduler::GetInstance()->Run(); AssertCommandState(command1, 1, 1, 1, 0, 1); AssertCommandState(command2, 1, 2, 2, 0, 0); AssertCommandState(command3, 0, 0, 0, 0, 0); Wait(2);//command 2 timeout Scheduler::GetInstance()->Run(); AssertCommandState(command1, 1, 1, 1, 0, 1); AssertCommandState(command2, 1, 2, 2, 0, 1); AssertCommandState(command3, 1, 1 ,1, 0, 0); Scheduler::GetInstance()->Run(); AssertCommandState(command1, 1, 1, 1, 0, 1); AssertCommandState(command2, 1, 2, 2, 0, 1); AssertCommandState(command3, 1, 2, 2, 0, 0); command3.SetHasFinished(true); AssertCommandState(command1, 1, 1, 1, 0, 1); AssertCommandState(command2, 1, 2, 2, 0, 1); AssertCommandState(command3, 1, 2, 2, 0, 0); Scheduler::GetInstance()->Run(); AssertCommandState(command1, 1, 1, 1, 0, 1); AssertCommandState(command2, 1, 2, 2, 0, 1); AssertCommandState(command3, 1, 3, 3, 1, 0); Scheduler::GetInstance()->Run(); AssertCommandState(command1, 1, 1, 1, 0, 1); AssertCommandState(command2, 1, 2, 2, 0, 1); AssertCommandState(command3, 1, 3, 3, 1, 0); TeardownScheduler(); }
/** * \brief hsmci_multimedia_card Application entry point. * * \return Unused (ANSI-C compatibility). */ int main(void) { uint8_t connected = 0; /* Disable watchdog */ WDT_Disable( WDT ) ; SCB_EnableICache(); SCB_EnableDCache(); TimeTick_Configure(); /* Output example information*/ printf("-- MultiMedia Card Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); bMciID = 0; /* Initialize PIO pins */ _ConfigurePIOs(); /* Initialize drivers */ _ConfigureDrivers(); /* Card insert detection loop */ for(;;) { if (CardIsConnected(bMciID)) { if (connected == 0) { connected = 1; /* Delay before card initialize */ Wait(300); /* Do card test */ CardInit(bMciID); DumpMenu(); } } else if (connected) { connected = 0; printf("** Card Disconnected\n\r"); } if (DBG_IsRxReady()) { uint8_t key = DBG_GetChar(); switch(key) { /* Change performance test block size */ case 'c': case 'C': { if (performanceMultiBlock >= NB_MULTI_BLOCKS) performanceMultiBlock = 1; else performanceMultiBlock <<= 1; printf("-!- Performance Multi set to %d\n\r", (int)performanceMultiBlock); } break; /* Show help information */ default: if (!connected) { DumpMenu(); } else { switch(key){ /* Dump block contents */ case 'd': case 'D': BlockDump(bMciID); break; /* Initialize the card again */ case 'I': case 'i': CardInit(bMciID); break; /* Run test on whole disk */ case 't': case 'T': if (SD_GetCardType(&sdDrv[bMciID]) & CARD_TYPE_bmSDIO) SdioTest(bMciID); if (SD_GetCardType(&sdDrv[bMciID]) & CARD_TYPE_bmSDMMC) DiskTest(bMciID, 1, 1, 1); printf("\n\r"); break; /* Run performance test */ case 'P': case 'p': if (SD_GetCardType(&sdDrv[bMciID]) & CARD_TYPE_bmSDIO) SdioPerformanceTest(bMciID); if (SD_GetCardType(&sdDrv[bMciID]) & CARD_TYPE_bmSDMMC) DiskPerformanceTest(bMciID, 1, 1, 0); printf("\n\r"); break; /* Read/Verify ONLY test */ case 'r': case 'R': DiskTest(bMciID, 0, 0, 1); printf("\n\r"); break; /* Read/Verify ONLY performance test */ case 'V': case 'v': DiskPerformanceTest(bMciID, 0, 1, 1); printf("\n\r"); break; /* Show help information */ default: DumpMenu(); } } break; } } } }
VOID BL_ThreadPoolWorkThread::Run() { if (CheckQuit()) { return; } while (TRUE) { if (CheckQuit()) { CL_BOOL flag = CL_FALSE; m_cSyncObj.SynchronizeStart(); flag = m_cRunTaskList.empty(); m_cSyncObj.SynchronizeEnd(); if (flag) { break; } } while (GetRunTaskCnt() > 0) { m_cSyncObj.SynchronizeStart(); m_pCurrentRunTask = m_cRunTaskList.front(); m_cRunTaskList.pop_front(); m_cSyncObj.SynchronizeEnd(); m_sRunSyncObj.SynchronizeStart(); // Needn't be locked by m_cSyncObj, for the current task point is deleted by this thread. if (m_pCurrentRunTask != NULL) { if (m_pCurrentRunTask->IsCanceled()) { m_pCurrentRunTask->OnAbandon(BL_TASKABANDON_CANCELBYUSER); } else { RunTask(m_pCurrentRunTask); } } m_sRunSyncObj.SynchronizeEnd(); m_dwIdleTimeStamp = ::GetTickCount(); // update group map id map m_sGroupIdMapSyncObj.SynchronizeStart(); if (NULL != m_pCurrentRunTask) { INT nGroupId = m_pCurrentRunTask->GetTaskGroupId(); GroupIdMap::iterator it = m_cGroupIdMap.find(nGroupId); if (it != m_cGroupIdMap.end()) { it->second = it->second - 1; if (0 == it->second) { m_cGroupIdMap.erase(it); } } } m_sGroupIdMapSyncObj.SynchronizeEnd(); m_cSyncObj.SynchronizeStart(); if (NULL != m_pCurrentRunTask) { delete m_pCurrentRunTask; m_pCurrentRunTask = NULL; } m_cSyncObj.SynchronizeEnd(); } // Notify manage thread m_pcManager->Notify(); // Wait for notify if (!m_StopFlag) { Wait(); } } }
bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic ) { bool clockwise = true; // drawing direction of the arc double startAngle = 0.0f; // angle of the first arc line VECTOR2I cursorPos = m_controls->GetCursorPosition(); DRAWSEGMENT helperLine; helperLine.SetShape( S_SEGMENT ); helperLine.SetLayer( Dwgs_User ); helperLine.SetWidth( 1 ); // Add a VIEW_GROUP that serves as a preview for the new item SELECTION preview( m_view ); m_view->Add( &preview ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); m_controls->ShowCursor( true ); m_controls->SetSnapping( true ); Activate(); enum ARC_STEPS { SET_ORIGIN = 0, SET_END, SET_ANGLE, FINISHED }; int step = SET_ORIGIN; // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { cursorPos = m_controls->GetCursorPosition(); if( evt->IsCancel() || evt->IsActivate() ) { preview.Clear(); delete aGraphic; aGraphic = NULL; break; } else if( evt->IsClick( BUT_RIGHT ) ) { showContextMenu(); } else if( evt->IsClick( BUT_LEFT ) ) { switch( step ) { case SET_ORIGIN: { LAYER_ID layer = m_frame->GetScreen()->m_Active_Layer; if( IsCopperLayer( layer ) ) { DisplayInfoMessage( NULL, _( "Graphic not allowed on Copper layers" ) ); --step; } else { // Init the new item attributes aGraphic->SetShape( S_ARC ); aGraphic->SetAngle( 0.0 ); aGraphic->SetWidth( getSegmentWidth( layer ) ); aGraphic->SetCenter( wxPoint( cursorPos.x, cursorPos.y ) ); aGraphic->SetLayer( layer ); helperLine.SetStart( aGraphic->GetCenter() ); helperLine.SetEnd( aGraphic->GetCenter() ); preview.Add( aGraphic ); preview.Add( &helperLine ); m_controls->SetAutoPan( true ); m_controls->CaptureCursor( true ); } } break; case SET_END: { if( wxPoint( cursorPos.x, cursorPos.y ) != aGraphic->GetCenter() ) { VECTOR2D startLine( aGraphic->GetArcStart() - aGraphic->GetCenter() ); startAngle = startLine.Angle(); aGraphic->SetArcStart( wxPoint( cursorPos.x, cursorPos.y ) ); } else --step; // one another chance to draw a proper arc } break; case SET_ANGLE: { if( wxPoint( cursorPos.x, cursorPos.y ) != aGraphic->GetArcStart() && aGraphic->GetAngle() != 0 ) { assert( aGraphic->GetArcStart() != aGraphic->GetArcEnd() ); assert( aGraphic->GetWidth() > 0 ); m_view->Add( aGraphic ); preview.Remove( aGraphic ); preview.Remove( &helperLine ); } else --step; // one another chance to draw a proper arc } break; } if( ++step == FINISHED ) break; } else if( evt->IsMotion() ) { switch( step ) { case SET_END: helperLine.SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); aGraphic->SetArcStart( wxPoint( cursorPos.x, cursorPos.y ) ); break; case SET_ANGLE: { VECTOR2D endLine( wxPoint( cursorPos.x, cursorPos.y ) - aGraphic->GetCenter() ); double newAngle = RAD2DECIDEG( endLine.Angle() - startAngle ); // Adjust the new angle to (counter)clockwise setting if( clockwise && newAngle < 0.0 ) newAngle += 3600.0; else if( !clockwise && newAngle > 0.0 ) newAngle -= 3600.0; aGraphic->SetAngle( newAngle ); } break; } // Show a preview of the item m_view->Update( &preview ); } else if( evt->IsAction( &COMMON_ACTIONS::incWidth ) ) { aGraphic->SetWidth( aGraphic->GetWidth() + WIDTH_STEP ); m_view->Update( &preview ); } else if( evt->IsAction( &COMMON_ACTIONS::decWidth ) ) { int width = aGraphic->GetWidth(); if( width > WIDTH_STEP ) { aGraphic->SetWidth( width - WIDTH_STEP ); m_view->Update( &preview ); } } else if( evt->IsAction( &COMMON_ACTIONS::arcPosture ) ) { if( clockwise ) aGraphic->SetAngle( aGraphic->GetAngle() - 3600.0 ); else aGraphic->SetAngle( aGraphic->GetAngle() + 3600.0 ); clockwise = !clockwise; m_view->Update( &preview ); } } m_controls->ShowCursor( false ); m_controls->SetSnapping( false ); m_controls->SetAutoPan( false ); m_controls->CaptureCursor( false ); m_view->Remove( &preview ); return ( step > SET_ORIGIN ); }
void LineFollower :: WaitUntilLineDetected() { while ( not IsLineDetected() ) Wait( LineFollower::kWaitDelta ); }
int DRAWING_TOOL::drawZone( bool aKeepout ) { ZONE_CONTAINER* zone = NULL; DRAWSEGMENT line45; DRAWSEGMENT* helperLine = NULL; // we will need more than one helper line BOARD_COMMIT commit( m_frame ); // Add a VIEW_GROUP that serves as a preview for the new item SELECTION preview( m_view ); m_view->Add( &preview ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); m_controls->ShowCursor( true ); m_controls->SetSnapping( true ); Activate(); VECTOR2I origin; int numPoints = 0; bool direction45 = false; // 45 degrees only mode // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { bool updatePreview = false; // should preview be updated VECTOR2I cursorPos = m_controls->GetCursorPosition(); // Enable 45 degrees lines only mode by holding control if( direction45 != ( evt->Modifier( MD_CTRL ) && numPoints > 0 ) ) { direction45 = evt->Modifier( MD_CTRL ); if( direction45 ) { preview.Add( &line45 ); make45DegLine( helperLine, &line45 ); } else { preview.Remove( &line45 ); helperLine->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); } updatePreview = true; } if( evt->IsCancel() || evt->IsActivate() ) { if( numPoints > 0 ) // cancel the current zone { delete zone; zone = NULL; m_controls->SetAutoPan( false ); m_controls->CaptureCursor( false ); if( direction45 ) { preview.Remove( &line45 ); direction45 = false; } preview.FreeItems(); updatePreview = true; numPoints = 0; } else // there is no zone currently drawn - just stop the tool break; if( evt->IsActivate() ) // now finish unconditionally break; } else if( evt->IsClick( BUT_RIGHT ) ) { showContextMenu(); } else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) ) { // Check if it is double click / closing line (so we have to finish the zone) if( evt->IsDblClick( BUT_LEFT ) || ( numPoints > 0 && cursorPos == origin ) ) { if( numPoints > 2 ) // valid zone consists of more than 2 points { assert( zone->GetNumCorners() > 2 ); // Finish the zone if( direction45 ) zone->AppendCorner( cursorPos == origin ? line45.GetStart() : line45.GetEnd() ); zone->Outline()->CloseLastContour(); zone->Outline()->RemoveNullSegments(); if( !aKeepout ) static_cast<PCB_EDIT_FRAME*>( m_frame )->Fill_Zone( zone ); commit.Add( zone ); commit.Push( _( "Draw a zone" ) ); zone = NULL; } else { delete zone; zone = NULL; } numPoints = 0; m_controls->SetAutoPan( false ); m_controls->CaptureCursor( false ); if( direction45 ) { preview.Remove( &line45 ); direction45 = false; } preview.FreeItems(); updatePreview = true; } else { if( numPoints == 0 ) // it's the first click { // Get the current default settings for zones ZONE_SETTINGS zoneInfo = m_frame->GetZoneSettings(); zoneInfo.m_CurrentZone_Layer = m_frame->GetScreen()->m_Active_Layer; zoneInfo.SetIsKeepout( aKeepout ); m_controls->SetAutoPan( true ); m_controls->CaptureCursor( true ); // Show options dialog ZONE_EDIT_T dialogResult; if( aKeepout ) dialogResult = InvokeKeepoutAreaEditor( m_frame, &zoneInfo ); else { if( IsCopperLayer( zoneInfo.m_CurrentZone_Layer ) ) dialogResult = InvokeCopperZonesEditor( m_frame, &zoneInfo ); else dialogResult = InvokeNonCopperZonesEditor( m_frame, NULL, &zoneInfo ); } if( dialogResult == ZONE_ABORT ) { m_controls->SetAutoPan( false ); m_controls->CaptureCursor( false ); continue; } // Apply the selected settings zone = new ZONE_CONTAINER( m_board ); zoneInfo.ExportSetting( *zone ); m_frame->GetGalCanvas()->SetTopLayer( zoneInfo.m_CurrentZone_Layer ); // Add the first point zone->Outline()->Start( zoneInfo.m_CurrentZone_Layer, cursorPos.x, cursorPos.y, zone->GetHatchStyle() ); origin = cursorPos; // Helper line represents the currently drawn line of the zone polygon helperLine = new DRAWSEGMENT; helperLine->SetShape( S_SEGMENT ); helperLine->SetWidth( 1 ); helperLine->SetLayer( zoneInfo.m_CurrentZone_Layer ); helperLine->SetStart( wxPoint( cursorPos.x, cursorPos.y ) ); helperLine->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); line45 = *helperLine; preview.Add( helperLine ); } else { zone->AppendCorner( helperLine->GetEnd() ); helperLine = new DRAWSEGMENT( *helperLine ); helperLine->SetStart( helperLine->GetEnd() ); preview.Add( helperLine ); } ++numPoints; updatePreview = true; } } else if( evt->IsMotion() && numPoints > 0 ) { // 45 degree lines if( direction45 ) make45DegLine( helperLine, &line45 ); else helperLine->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); // Show a preview of the item updatePreview = true; } if( updatePreview ) m_view->Update( &preview ); } m_controls->ShowCursor( false ); m_controls->SetSnapping( false ); m_controls->SetAutoPan( false ); m_controls->CaptureCursor( false ); m_view->Remove( &preview ); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; }
void EventLoop(void) { while (1) { ULONG sigs = 0UL; switch(DoMethod(MUIApp, MUIM_Application_NewInput, &sigs)) { case MUIV_Application_ReturnID_Quit: return; case ACTID_OPEN: { struct FileRequester *request; request = MUI_AllocAslRequestTags(ASL_FileRequest, ASLFR_Window, xget(MUIWindow, MUIA_Window_Window), ASLFR_TitleText, msgTextProgramName, ASLFR_RejectIcons, TRUE, ASLFR_InitialDrawer, "SYS:Prefs/Presets", TAG_DONE ); if( request != NULL ) { DoMethod(MUIApp, MUIA_Application_Sleep, TRUE); if (MUI_AslRequest(request, NULL)) { char *file; DoMethod(MUIApp, MUIA_Application_Sleep, FALSE); file = AllocVec(strlen(request->fr_Drawer)+128,0); if( file != NULL ) { CopyMem(request->fr_Drawer, file, strlen(request->fr_Drawer)+1); AddPart(file, request->fr_File, 128); NewSettings(file); GUINewSettings(); FreeVec(file); } } else { DoMethod(MUIApp, MUIA_Application_Sleep, FALSE); } MUI_FreeAslRequest(request); } break; } case ACTID_SAVEAS: { struct FileRequester *request; request = MUI_AllocAslRequestTags(ASL_FileRequest, ASLFR_Window, xget(MUIWindow, MUIA_Window_Window), ASLFR_TitleText, msgTextProgramName, ASLFR_RejectIcons, TRUE, ASLFR_DoSaveMode, TRUE, ASLFR_InitialDrawer, "SYS:Prefs/Presets", TAG_DONE); if(request != NULL ) { DoMethod(MUIApp, MUIA_Application_Sleep, TRUE); FillUnit(); if (MUI_AslRequest(request, NULL)) { char *file; DoMethod(MUIApp, MUIA_Application_Sleep, FALSE); file = AllocVec(strlen(request->fr_Drawer)+128,0); if( file != NULL ) { CopyMem(request->fr_Drawer, file, strlen(request->fr_Drawer)+1); AddPart(file, request->fr_File, 128); SaveSettings(file, UnitList); if(SaveIcons) { WriteIcon(file); } FreeVec(file); } } else { DoMethod(MUIApp, MUIA_Application_Sleep, FALSE); } MUI_FreeAslRequest(request); } break; } case ACTID_ABOUT: { char* args[] = { "\033c", (char*)msgTextProgramName, "1996-2001 Stéphane Barbaray/Martin Blom" }; MUI_RequestA(MUIApp, MUIWindow, 0, (char *) msgTextProgramName, (char*)msgButtonOK, (char*)msgTextCopyright, args ); break; } case ACTID_SAVE: FillUnit(); SaveSettings(ENVFILE, UnitList); SaveSettings(ENVARCFILE, UnitList); return; case ACTID_USE: FillUnit(); SaveSettings(ENVFILE, UnitList); return; case ACTID_QUIT: return; case ACTID_DEFAULT: NewSettings(NULL); GUINewSettings(); break; case ACTID_LASTSAVED: NewSettings(ENVARCFILE); GUINewSettings(); break; case ACTID_RESTORE: NewSettings(args.from); GUINewSettings(); break; case ACTID_ICONS: { APTR item = (APTR)DoMethod(MUIMenu,MUIM_FindUData,ACTID_ICONS); if(item) { if(xget(item, MUIA_Menuitem_Checked)) { SaveIcons = TRUE; } else { SaveIcons = FALSE; } } break; } case ACTID_HELP: DoMethod(MUIApp,MUIM_Application_ShowHelp,NULL,NULL,"AHI",0); break; case ACTID_GUIDE: DoMethod(MUIApp,MUIM_Application_ShowHelp,NULL,NULL,"MAIN",0); break; case ACTID_HELPINDEX: DoMethod(MUIApp,MUIM_Application_ShowHelp,NULL,NULL,"Concept Index",0); break; case ACTID_UNIT: FillUnit(); NewUnit(xget(MUIUnit,MUIA_Cycle_Active)); GUINewUnit(); break; case ACTID_MODE: FillUnit(); NewMode(xget(MUIList, MUIA_List_Active)); GUINewMode(); break; case ACTID_PLAY: { int unit_id; struct UnitNode* unit; FillUnit(); unit_id = xget( MUIUnit, MUIA_Cycle_Active ); unit = (struct UnitNode *) GetNode( unit_id, UnitList ); PlaySound( &unit->prefs ); break; } case ACTID_DEBUG: case ACTID_SURROUND: case ACTID_ECHO: case ACTID_CPULIMIT: case ACTID_CLIPMV: case ACTID_ACTIME: { ULONG debug = AHI_DEBUG_NONE, surround = FALSE, echo = 0, cpu = 90; ULONG clip = FALSE, actime = 0; get(MUIDebug, MUIA_Cycle_Active, &debug); get(MUISurround, MUIA_Cycle_Active, &surround); get(MUIEcho, MUIA_Cycle_Active, &echo); get(MUIClipvol, MUIA_Cycle_Active, &clip); get(MUICpu, MUIA_Numeric_Value, &cpu); get(MUIACTime, MUIA_Numeric_Value, &actime); globalprefs.ahigp_DebugLevel = debug; globalprefs.ahigp_DisableSurround = surround; globalprefs.ahigp_DisableEcho = (echo == 2); globalprefs.ahigp_FastEcho = (echo == 1); globalprefs.ahigp_MaxCPU = ((cpu << 16) + 50) / 100; globalprefs.ahigp_ClipMasterVolume = clip; globalprefs.ahigp_AntiClickTime = ((actime << 16) + 500) / 1000; break; } default: if (sigs) { sigs = Wait(sigs | SIGBREAKF_CTRL_C); if (sigs & SIGBREAKF_CTRL_C) return; } break; } } }
int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) { DIMENSION* dimension = NULL; BOARD_COMMIT commit( m_frame ); int maxThickness; // Add a VIEW_GROUP that serves as a preview for the new item SELECTION preview( m_view ); m_view->Add( &preview ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); m_controls->ShowCursor( true ); m_controls->SetSnapping( true ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION ); Activate(); m_frame->SetToolID( ID_PCB_DIMENSION_BUTT, wxCURSOR_PENCIL, _( "Add dimension" ) ); enum DIMENSION_STEPS { SET_ORIGIN = 0, SET_END, SET_HEIGHT, FINISHED }; int step = SET_ORIGIN; // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { VECTOR2I cursorPos = m_controls->GetCursorPosition(); if( evt->IsCancel() || evt->IsActivate() ) { if( step != SET_ORIGIN ) // start from the beginning { preview.Clear(); delete dimension; step = SET_ORIGIN; } else break; if( evt->IsActivate() ) // now finish unconditionally break; } else if( evt->IsAction( &COMMON_ACTIONS::incWidth ) && step != SET_ORIGIN ) { dimension->SetWidth( dimension->GetWidth() + WIDTH_STEP ); m_view->Update( &preview ); } else if( evt->IsAction( &COMMON_ACTIONS::decWidth ) && step != SET_ORIGIN ) { int width = dimension->GetWidth(); if( width > WIDTH_STEP ) { dimension->SetWidth( width - WIDTH_STEP ); m_view->Update( &preview ); } } else if ( evt->IsClick( BUT_RIGHT ) ) { showContextMenu(); } else if( evt->IsClick( BUT_LEFT ) ) { switch( step ) { case SET_ORIGIN: { LAYER_ID layer = m_frame->GetScreen()->m_Active_Layer; if( IsCopperLayer( layer ) || layer == Edge_Cuts ) { DisplayInfoMessage( NULL, _( "Dimension not allowed on Copper or Edge Cut layers" ) ); --step; } else { // Init the new item attributes dimension = new DIMENSION( m_board ); dimension->SetLayer( layer ); dimension->SetOrigin( wxPoint( cursorPos.x, cursorPos.y ) ); dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); dimension->Text().SetSize( m_board->GetDesignSettings().m_PcbTextSize ); int width = m_board->GetDesignSettings().m_PcbTextWidth; maxThickness = Clamp_Text_PenSize( width, dimension->Text().GetSize() ); if( width > maxThickness ) width = maxThickness; dimension->Text().SetThickness( width ); dimension->SetWidth( width ); dimension->AdjustDimensionDetails(); preview.Add( dimension ); m_controls->SetAutoPan( true ); m_controls->CaptureCursor( true ); } } break; case SET_END: dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); // Dimensions that have origin and end in the same spot are not valid if( dimension->GetOrigin() == dimension->GetEnd() ) --step; break; case SET_HEIGHT: { if( wxPoint( cursorPos.x, cursorPos.y ) != dimension->GetPosition() ) { assert( dimension->GetOrigin() != dimension->GetEnd() ); assert( dimension->GetWidth() > 0 ); preview.Remove( dimension ); commit.Add( dimension ); commit.Push( _( "Draw a dimension" ) ); } } break; } if( ++step == FINISHED ) { step = SET_ORIGIN; m_controls->SetAutoPan( false ); m_controls->CaptureCursor( false ); } } else if( evt->IsMotion() ) { switch( step ) { case SET_END: dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); break; case SET_HEIGHT: { // Calculating the direction of travel perpendicular to the selected axis double angle = dimension->GetAngle() + ( M_PI / 2 ); wxPoint pos( cursorPos.x, cursorPos.y ); wxPoint delta( pos - dimension->m_featureLineDO ); double height = ( delta.x * cos( angle ) ) + ( delta.y * sin( angle ) ); dimension->SetHeight( height ); } break; } // Show a preview of the item m_view->Update( &preview ); } } if( step != SET_ORIGIN ) delete dimension; m_controls->ShowCursor( false ); m_controls->SetSnapping( false ); m_controls->SetAutoPan( false ); m_controls->CaptureCursor( false ); m_view->Remove( &preview ); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; }
int PlaySineEverywhere( void ) { int rc = RETURN_OK; int sine_length = 44100 / 100; BYTE* sine_m8s; BYTE* sine_s8s; WORD* sine_s16s; WORD* sine_m16s; LONG* sine_s32s; LONG* sine_m32s; sine_m8s = AllocVec( 1 * sizeof( BYTE ) * sine_length, MEMF_ANY | MEMF_PUBLIC ); sine_s8s = AllocVec( 2 * sizeof( BYTE ) * sine_length, MEMF_ANY | MEMF_PUBLIC ); sine_m16s = AllocVec( 1 * sizeof( WORD ) * sine_length, MEMF_ANY | MEMF_PUBLIC ); sine_s16s = AllocVec( 2 * sizeof( WORD ) * sine_length, MEMF_ANY | MEMF_PUBLIC ); sine_m32s = AllocVec( 1 * sizeof( LONG ) * sine_length, MEMF_ANY | MEMF_PUBLIC ); sine_s32s = AllocVec( 2 * sizeof( LONG ) * sine_length, MEMF_ANY | MEMF_PUBLIC ); if( sine_m8s != NULL && sine_s8s != NULL && sine_m16s != NULL && sine_s16s != NULL && sine_m32s != NULL && sine_s32s != NULL ) { ULONG mode = AHI_INVALID_ID; int i; for( i = 0; i < sine_length; ++i ) { double value = sin( i * 2 * M_PI / sine_length ); sine_m8s[ i ] = (BYTE) ( SCHAR_MAX * value ); sine_m16s[ i ] = (WORD) ( SHRT_MAX * value ); sine_m32s[ i ] = (LONG) ( LONG_MAX * value ); sine_s8s[ i * 2 + 0 ] = (BYTE) ( SCHAR_MAX * value ); sine_s8s[ i * 2 + 1 ] = (BYTE) ( SCHAR_MAX * value ); sine_s16s[ i * 2 + 0 ] = (WORD) ( SHRT_MAX * value ); sine_s16s[ i * 2 + 1 ] = (WORD) ( SHRT_MAX * value ); sine_s32s[ i * 2 + 0 ] = (LONG) ( LONG_MAX * value ); sine_s32s[ i * 2 + 1 ] = (LONG) ( LONG_MAX * value ); } while( rc == RETURN_OK && ( mode = AHI_NextAudioID( mode ) ) != AHI_INVALID_ID ) { struct AHIAudioCtrl* actrl; char name[ 64 ]; struct Hook sound_hook = { { NULL, NULL }, HookEntry, (HOOKFUNC) SoundFunc, FindTask( NULL ) }; AHI_GetAudioAttrs( mode, NULL, AHIDB_Name, (ULONG) &name, AHIDB_BufferLen, 64, TAG_DONE ); printf( "Mode 0x%08lx: %s\n", mode, name ); actrl = AHI_AllocAudio( AHIA_AudioID, mode, AHIA_MixFreq, 44100, AHIA_Channels, 1, AHIA_Sounds, 6, AHIA_SoundFunc, (ULONG) &sound_hook, AHIA_UserData, 0, TAG_DONE ); if( actrl != NULL ) { struct AHISampleInfo sample_m8s = { AHIST_M8S, sine_m8s, sine_length }; struct AHISampleInfo sample_s8s = { AHIST_S8S, sine_s8s, sine_length }; struct AHISampleInfo sample_m16s = { AHIST_M16S, sine_m16s, sine_length }; struct AHISampleInfo sample_s16s = { AHIST_S16S, sine_s16s, sine_length }; struct AHISampleInfo sample_m32s = { AHIST_M32S, sine_m32s, sine_length }; struct AHISampleInfo sample_s32s = { AHIST_S32S, sine_s32s, sine_length }; if( AHI_LoadSound( 0, AHIST_SAMPLE, &sample_m8s, actrl) == AHIE_OK && AHI_LoadSound( 1, AHIST_SAMPLE, &sample_s8s, actrl) == AHIE_OK && AHI_LoadSound( 2, AHIST_SAMPLE, &sample_m16s, actrl) == AHIE_OK && AHI_LoadSound( 3, AHIST_SAMPLE, &sample_s16s, actrl) == AHIE_OK && AHI_LoadSound( 4, AHIST_SAMPLE, &sample_m32s, actrl) == AHIE_OK && AHI_LoadSound( 5, AHIST_SAMPLE, &sample_s32s, actrl) == AHIE_OK ) { AHI_Play( actrl, AHIP_BeginChannel, 0, AHIP_Sound, 0, AHIP_Freq, 44100, AHIP_Vol, 0x10000, AHIP_Pan, 0x00000, AHIP_EndChannel, 0, TAG_DONE ); // Now, when everything is "armed", lets start processing. SetSignal( 0, SIGF_SINGLE ); if( AHI_ControlAudio( actrl, AHIC_Play, TRUE, TAG_DONE ) == AHIE_OK ) { Wait( SIGF_SINGLE ); AHI_ControlAudio( actrl, AHIC_Play, FALSE, TAG_DONE ); } else { fprintf( stderr, "Unable start playback.\n" ); rc = RETURN_ERROR; } // AHI_FreeAudio() will unload the sounds } else { fprintf( stderr, "Unable load sound.\n" ); rc = RETURN_ERROR; } AHI_FreeAudio( actrl ); } else { fprintf( stderr, "Unable to allocate audio.\n" ); rc = RETURN_ERROR; } } } else { fprintf( stderr, "Unable to allocate memory for sine\n" ); } FreeVec( sine_m8s ); FreeVec( sine_s8s ); FreeVec( sine_s16s ); FreeVec( sine_m16s ); FreeVec( sine_s32s ); FreeVec( sine_m32s ); return rc; }
bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, boost::optional<VECTOR2D> aStartingPoint ) { // Only two shapes are currently supported assert( aShape == S_SEGMENT || aShape == S_CIRCLE ); DRAWSEGMENT line45; // Add a VIEW_GROUP that serves as a preview for the new item SELECTION preview( m_view ); m_view->Add( &preview ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); m_controls->ShowCursor( true ); m_controls->SetSnapping( true ); Activate(); bool direction45 = false; // 45 degrees only mode bool started = false; VECTOR2I cursorPos = m_controls->GetCursorPosition(); if( aStartingPoint ) { LAYER_ID layer = m_frame->GetScreen()->m_Active_Layer; // Init the new item attributes aGraphic->SetShape( (STROKE_T) aShape ); aGraphic->SetWidth( m_lineWidth ); aGraphic->SetStart( wxPoint( aStartingPoint->x, aStartingPoint->y ) ); aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); aGraphic->SetLayer( layer ); if( aShape == S_SEGMENT ) line45 = *aGraphic; // used only for direction 45 mode with lines preview.Add( aGraphic ); m_controls->SetAutoPan( true ); m_controls->CaptureCursor( true ); started = true; } // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { bool updatePreview = false; // should preview be updated cursorPos = m_controls->GetCursorPosition(); // 45 degree angle constraint enabled with an option and toggled with Ctrl const bool limit45 = ( g_Segments_45_Only != !!( evt->Modifier( MD_CTRL ) ) ); if( direction45 != limit45 && started && aShape == S_SEGMENT ) { direction45 = limit45; if( direction45 ) { preview.Add( &line45 ); make45DegLine( aGraphic, &line45 ); } else { preview.Remove( &line45 ); aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); } updatePreview = true; } if( evt->IsCancel() || evt->IsActivate() || evt->IsAction( &COMMON_ACTIONS::layerChanged ) ) { preview.Clear(); updatePreview = true; delete aGraphic; aGraphic = NULL; break; } else if( evt->IsClick( BUT_RIGHT ) ) { showContextMenu(); } else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) ) { if( !started ) { LAYER_ID layer = m_frame->GetScreen()->m_Active_Layer; if( IsCopperLayer( layer ) ) { DisplayInfoMessage( NULL, _( "Graphic not allowed on Copper layers" ) ); } else { // Init the new item attributes aGraphic->SetShape( (STROKE_T) aShape ); m_lineWidth = getSegmentWidth( layer ); aGraphic->SetWidth( m_lineWidth ); aGraphic->SetStart( wxPoint( cursorPos.x, cursorPos.y ) ); aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); aGraphic->SetLayer( layer ); if( aShape == S_SEGMENT ) line45 = *aGraphic; // used only for direction 45 mode with lines preview.Add( aGraphic ); m_controls->SetAutoPan( true ); m_controls->CaptureCursor( true ); started = true; } } else { if( aGraphic->GetEnd() == aGraphic->GetStart() || ( evt->IsDblClick( BUT_LEFT ) && aShape == S_SEGMENT ) ) // User has clicked twice in the same spot { // a clear sign that the current drawing is finished // Now we have to add the helper line as well if( direction45 ) { BOARD_ITEM_CONTAINER* parent = m_frame->GetModel(); DRAWSEGMENT* l = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; // Copy coordinates, layer, etc. *static_cast<DRAWSEGMENT*>( l ) = line45; l->SetEnd( aGraphic->GetStart() ); BOARD_COMMIT commit( m_frame ); commit.Add( l ); commit.Push( _( "Draw a line" ) ); } delete aGraphic; aGraphic = NULL; } preview.Clear(); break; } } else if( evt->IsMotion() ) { // 45 degree lines if( direction45 && aShape == S_SEGMENT ) make45DegLine( aGraphic, &line45 ); else aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); updatePreview = true; } else if( evt->IsAction( &COMMON_ACTIONS::incWidth ) ) { m_lineWidth += WIDTH_STEP; aGraphic->SetWidth( m_lineWidth ); updatePreview = true; } else if( evt->IsAction( &COMMON_ACTIONS::decWidth ) ) { if( m_lineWidth > (unsigned) WIDTH_STEP ) { m_lineWidth -= WIDTH_STEP; aGraphic->SetWidth( m_lineWidth ); updatePreview = true; } } if( updatePreview ) m_view->Update( &preview ); } m_controls->ShowCursor( false ); m_controls->SetSnapping( false ); m_controls->SetAutoPan( false ); m_controls->CaptureCursor( false ); m_view->Remove( &preview ); return started; }
// DDNS client thread void DCThread(THREAD *thread, void *param) { DDNS_CLIENT *c; INTERRUPT_MANAGER *interrput; UINT last_ip_hash = 0; void *route_change_poller = NULL; bool last_time_ip_changed = false; UINT last_azure_ddns_trigger_int = 0; UINT last_vgs_ddns_trigger_int = 0; UINT n; INTERNET_SETTING last_t; // Validate arguments if (thread == NULL || param == NULL) { return; } c = (DDNS_CLIENT *)param; interrput = NewInterruptManager(); route_change_poller = NewRouteChange(); IsRouteChanged(route_change_poller); Zero(&last_t, sizeof(last_t)); n = 0; while (c->Halt == false) { UINT ip_hash = GetHostIPAddressHash32(); UINT interval; UINT64 now = Tick64(); bool ip_changed = false; bool azure_client_triggered = false; bool internet_setting_changed = false; bool vgs_server_triggered = false; if (c->Cedar->Server != NULL && c->Cedar->Server->AzureClient != NULL) { if (c->Cedar->Server->AzureClient->DDnsTriggerInt != last_azure_ddns_trigger_int) { azure_client_triggered = true; last_azure_ddns_trigger_int = c->Cedar->Server->AzureClient->DDnsTriggerInt; last_time_ip_changed = false; Debug("DDNS Thread Triggered by AzureClient.\n"); } } if (Cmp(&last_t, &c->InternetSetting, sizeof(INTERNET_SETTING)) != 0) { Copy(&last_t, &c->InternetSetting, sizeof(INTERNET_SETTING)); internet_setting_changed = true; last_time_ip_changed = false; } if (ip_hash != last_ip_hash) { last_time_ip_changed = false; Debug("DDNS Thread Triggered by IP Hash Changed.\n"); } if ((ip_hash != last_ip_hash) || (IsRouteChanged(route_change_poller)) || azure_client_triggered || internet_setting_changed || vgs_server_triggered) { if (last_time_ip_changed == false) { // Call all getting functions from the beginning if the routing // table or the IP address of this host has changed c->NextRegisterTick_IPv4 = 0; c->NextRegisterTick_IPv6 = 0; c->NextGetMyIpTick_IPv4 = 0; c->NextGetMyIpTick_IPv6 = 0; last_ip_hash = ip_hash; last_time_ip_changed = true; ip_changed = true; Debug("DDNS Internet Condition Changed.\n"); } } else { last_time_ip_changed = false; } if ((n++) >= 1) { // Self IPv4 address acquisition if (c->NextGetMyIpTick_IPv4 == 0 || now >= c->NextGetMyIpTick_IPv4) { UINT next_interval; char ip[MAX_SIZE]; Zero(ip, sizeof(ip)); c->Err_IPv4_GetMyIp = DCGetMyIp(c, false, ip, sizeof(ip), NULL); if (c->Err_IPv4_GetMyIp == ERR_NO_ERROR) { if (StrCmpi(c->LastMyIPv4, ip) != 0) { ip_changed = true; StrCpy(c->LastMyIPv4, sizeof(c->LastMyIPv4), ip); } next_interval = GenRandInterval(DDNS_GETMYIP_INTERVAL_OK_MIN, DDNS_GETMYIP_INTERVAL_OK_MAX); } else { if (IsEmptyStr(c->LastMyIPv4) == false) { ip_changed = true; } Zero(c->LastMyIPv4, sizeof(c->LastMyIPv4)); next_interval = GenRandInterval(DDNS_GETMYIP_INTERVAL_NG_MIN, DDNS_GETMYIP_INTERVAL_NG_MAX); } c->NextGetMyIpTick_IPv4 = Tick64() + (UINT64)next_interval; AddInterrupt(interrput, c->NextGetMyIpTick_IPv4); } // Self IPv6 address acquisition if (c->NextGetMyIpTick_IPv6 == 0 || now >= c->NextGetMyIpTick_IPv6) { UINT next_interval; char ip[MAX_SIZE]; Zero(ip, sizeof(ip)); c->Err_IPv6_GetMyIp = DCGetMyIp(c, true, ip, sizeof(ip), NULL); if (c->Err_IPv6_GetMyIp == ERR_NO_ERROR) { if (StrCmpi(c->LastMyIPv6, ip) != 0) { ip_changed = true; StrCpy(c->LastMyIPv6, sizeof(c->LastMyIPv6), ip); } next_interval = GenRandInterval(DDNS_GETMYIP_INTERVAL_OK_MIN, DDNS_GETMYIP_INTERVAL_OK_MAX); } else { if (IsEmptyStr(c->LastMyIPv6) == false) { ip_changed = true; } Zero(c->LastMyIPv6, sizeof(c->LastMyIPv6)); next_interval = GenRandInterval(DDNS_GETMYIP_INTERVAL_NG_MIN, DDNS_GETMYIP_INTERVAL_NG_MAX); } c->NextGetMyIpTick_IPv6 = Tick64() + (UINT64)next_interval; AddInterrupt(interrput, c->NextGetMyIpTick_IPv6); } } if (ip_changed) { c->NextRegisterTick_IPv4 = 0; c->NextRegisterTick_IPv6 = 0; } // IPv4 host registration if (c->NextRegisterTick_IPv4 == 0 || now >= c->NextRegisterTick_IPv4) { UINT next_interval; c->Err_IPv4 = DCRegister(c, false, NULL, NULL); if (c->Err_IPv4 == ERR_NO_ERROR) { next_interval = GenRandInterval(DDNS_REGISTER_INTERVAL_OK_MIN, DDNS_REGISTER_INTERVAL_OK_MAX); } else { next_interval = GenRandInterval(DDNS_REGISTER_INTERVAL_NG_MIN, DDNS_REGISTER_INTERVAL_NG_MAX); } //next_interval = 0; c->NextRegisterTick_IPv4 = Tick64() + (UINT64)next_interval; if (true) { DDNS_CLIENT_STATUS st; DCGetStatus(c, &st); SiApplyAzureConfig(c->Cedar->Server, &st); } AddInterrupt(interrput, c->NextRegisterTick_IPv4); } if (c->Halt) { break; } // IPv6 host registration if (c->NextRegisterTick_IPv6 == 0 || now >= c->NextRegisterTick_IPv6) { UINT next_interval; c->Err_IPv6 = DCRegister(c, true, NULL, NULL); if (c->Err_IPv6 == ERR_NO_ERROR) { next_interval = GenRandInterval(DDNS_REGISTER_INTERVAL_OK_MIN, DDNS_REGISTER_INTERVAL_OK_MAX); } else { next_interval = GenRandInterval(DDNS_REGISTER_INTERVAL_NG_MIN, DDNS_REGISTER_INTERVAL_NG_MAX); } c->NextRegisterTick_IPv6 = Tick64() + (UINT64)next_interval; if (true) { DDNS_CLIENT_STATUS st; DCGetStatus(c, &st); SiApplyAzureConfig(c->Cedar->Server, &st); } AddInterrupt(interrput, c->NextRegisterTick_IPv6); } interval = GetNextIntervalForInterrupt(interrput); interval = MIN(interval, 1234); if (n == 1) { interval = MIN(interval, 0); } if (c->Halt) { break; } if (c->KeyChanged) { c->KeyChanged = false; c->NextRegisterTick_IPv4 = c->NextRegisterTick_IPv6 = 0; interval = 0; } if (last_time_ip_changed) { if (c->Cedar->Server != NULL && c->Cedar->Server->AzureClient != NULL) { c->Cedar->Server->AzureClient->IpStatusRevision++; } } Wait(c->Event, interval); } FreeRouteChange(route_change_poller); FreeInterruptManager(interrput); }
bool PL_SELECTION_TOOL::selectMultiple() { bool cancelled = false; // Was the tool cancelled while it was running? m_multiple = true; // Multiple selection mode is active KIGFX::VIEW* view = getView(); KIGFX::PREVIEW::SELECTION_AREA area; view->Add( &area ); while( OPT_TOOL_EVENT evt = Wait() ) { if( evt->IsAction( &ACTIONS::cancelInteractive ) || evt->IsActivate() || evt->IsCancel() ) { cancelled = true; break; } if( evt->IsDrag( BUT_LEFT ) ) { // Start drawing a selection box area.SetOrigin( evt->DragOrigin() ); area.SetEnd( evt->Position() ); area.SetAdditive( m_additive ); area.SetSubtractive( m_subtractive ); view->SetVisible( &area, true ); view->Update( &area ); getViewControls()->SetAutoPan( true ); } if( evt->IsMouseUp( BUT_LEFT ) ) { getViewControls()->SetAutoPan( false ); // End drawing the selection box view->SetVisible( &area, false ); int width = area.GetEnd().x - area.GetOrigin().x; int height = area.GetEnd().y - area.GetOrigin().y; /* Selection mode depends on direction of drag-selection: * Left > Right : Select objects that are fully enclosed by selection * Right > Left : Select objects that are crossed by selection */ bool windowSelection = width >= 0 ? true : false; // Construct an EDA_RECT to determine EDA_ITEM selection EDA_RECT selectionRect( (wxPoint)area.GetOrigin(), wxSize( width, height ) ); selectionRect.Normalize(); for( WS_DATA_ITEM* dataItem : WS_DATA_MODEL::GetTheInstance().GetItems() ) { for( WS_DRAW_ITEM_BASE* item : dataItem->GetDrawItems() ) { if( item->HitTest( selectionRect, windowSelection ) ) { if( m_subtractive ) unselect( item ); else select( item ); } } } // Inform other potentially interested tools if( !m_selection.Empty() ) m_toolMgr->ProcessEvent( EVENTS::SelectedEvent ); break; // Stop waiting for events } } getViewControls()->SetAutoPan( false ); // Stop drawing the selection box view->Remove( &area ); m_multiple = false; // Multiple selection mode is inactive if( !cancelled ) m_selection.ClearReferencePoint(); return cancelled; }
cServer::cNotifyWriteThread::~cNotifyWriteThread() { m_ShouldTerminate = true; m_Event.Set(); Wait(); }
int main(int argc, char* argv[]) { int i,id,rwid; struct StudentList *infoptr; struct ReadCount *read_count; int sema_set; char NoChange[20] = "NOCHANGE"; char sid[20]; char upwd[10]; //validate input arguments if (argc != 5){ fprintf(stderr, "usage(linux): ./Change <Name> <SID> <address> <phone number>\nTo leave attribute unchanged enter <NOCHANGE>\n"); exit(3); } //Get the ids of the shared memory segments created in Load.c /* get the id of the shared memory segment with key "KEY" */ /* note that this is the segment where the data is stored */ id = shmget(KEY,SEGSIZE, 0); if (id <0){ perror("change: database shmget failed"); exit(1); } rwid = shmget(RWKEY,RWSEGSIZE,0); if (rwid <0) { perror("change: readers shmget failed"); exit(1); } //Attach the shared memory segments; /* attach the already created shared memory segment to infoptr so the shared memory segment can be accessed through 'infoptr' */ infoptr=(struct StudentList *)shmat(id,0,0); if (infoptr <= (struct StudentList *) (0)) { perror("change: database shmat failed"); exit(2); } read_count=(struct ReadCount *)shmat(rwid,0,0);/*attach the shared memory segment to the process's address space */ if (read_count <= (struct ReadCount *) (0)) { perror("change: readers shmat failed"); exit(2); } /* get the id of the semaphore set associated with SEMA_KEY */ sema_set=semget(SEMA_KEY, 0,0); if ((sema_set < 0) ){ perror("semget failed"); exit(2); } //Prompt the user for password; printf("Please enter your password: "******"%s", upwd); //Validate the password // just check if the user types 000; if (strcmp(upwd, "000")){ fprintf(stderr, "Unrecognized Password. Change aborted\n"); exit(3); } //Get the id of the student, the user wants to modify; // No need to get the new information about the student, handled as arguments; printf("Please enter your Student ID of record to change: "); scanf("%s", sid); Wait(sema_set, 0); // assuming semaset is the id of the semaphore set //Search the shared memory for the student record with // the student id typed by the user; int recordIndex = -1; for(i=0;i<20;i++){ if (!(strcmp((infoptr->Student[i]).SID, sid))) { recordIndex = i; } } //if the id is not found, print an error message; if (recordIndex == -1){ fprintf(stderr, "Search completed. Student ID not found. No Changes made.\n"); } else{ //update the student record with new information; if (strcmp(NoChange, argv[1])) strcpy((infoptr->Student[recordIndex]).Name,argv[1]); if (strcmp(NoChange, argv[2])) strcpy((infoptr->Student[recordIndex]).SID, argv[2]); if (strcmp(NoChange, argv[3])) strcpy((infoptr->Student[recordIndex]).address, argv[3]); if (strcmp(NoChange, argv[4])) strcpy((infoptr->Student[recordIndex]).telNumber, argv[4]); printf("Record found and updated\n"); } printf("Sleeping 10s for debug and testing...\n"); sleep(10); // for debugging and testing Signal(sema_set,0); exit(0); }
void NetworkClientSender::Stop(){ running = false; messageQueue.PushMessage(NULL); Wait(); }
void CGMSKRepeaterRXThread::wait() { Wait(); }
static void proxy_thread_main (void) { ULONG sigmask; int dont_exit = 1; struct ProxyMsg *msg = NULL; proxy_msgport = CreateMsgPort (); sigmask = SIGBREAKF_CTRL_C | (1 << proxy_msgport->mp_SigBit); /* Wait for and reply to startup msg */ handle_startup_msg (); while (dont_exit) { ULONG sigs = Wait (sigmask); /* * Handle any semaphore message sent us */ while ((msg = (struct ProxyMsg *) GetMsg (proxy_msgport))) { struct PSemaphore *psem = msg->sem; switch (msg->type) { case PROXY_MSG_BLOCK: /* Block requesting task on semaphore. * * We effect the block by not replying to this message now. Just * put the request in the waiting list and reply to it when we * get an unblock request for this semaphore. The process requesting * the block will sleep until we do (unless it is interrupted). */ AddTail ((struct List*)&psem->wait_queue, (struct Node *)msg); break; case PROXY_MSG_UNBLOCK: /* A request to unblock a task on semaphore. */ { struct ProxyMsg *wait_msg; Forbid (); /* If there's a task blocking on the semaphore, remove * it from the waiting list */ wait_msg = (struct ProxyMsg *) RemHead ((struct List *)&psem->wait_queue); /* Reply to the unblock request */ do_proxy_reply (msg); /* Reply to the block request - this will wake up the * blocked task. */ if (wait_msg) do_proxy_reply (wait_msg); Permit (); } break; case PROXY_MSG_DESTROY: Forbid (); { struct ProxyMsg *wait_msg; while ((wait_msg = (struct ProxyMsg *) RemHead ((struct List *)&psem->wait_queue))) { /* Break the block for all tasks blocked on the semaphore */ Signal (wait_msg->reply_task, SIGBREAKF_CTRL_C); } } do_proxy_reply (msg); Permit (); break; } /* switch (msg->type) */ } /* while */ /* * Check for break signal and exit if received */ if ((sigs & SIGBREAKF_CTRL_C) != 0) dont_exit = FALSE; } /* while (dont_exit) */ /* * Clean up and exit */ Forbid (); { struct ProxyMsg *rem_msg; /* Reply to any unanswered requests */ while ((rem_msg = (struct ProxyMsg *) GetMsg (proxy_msgport)) != NULL) do_proxy_reply (rem_msg); /* reply to the quit msg */ if (msg != NULL) do_proxy_reply (msg); DeleteMsgPort (proxy_msgport); proxy_msgport = 0; proxy_thread = 0; } Permit (); }
void main( void ) { int Done = FALSE; ULONG sig; static STRPTR styleoptions[] = { "IRC", "Email", "HTML", NULL }; if( !( MUIMasterBase = OpenLibrary( MUIMASTER_NAME, 19 ) ) ) return; if( app = ApplicationObject, MUIA_Application_Title, "TextInputDemo", MUIA_Application_Version, "$VER: TextInput Demo 2.0", MUIA_Application_Copyright, "© 1997-99 by Oliver Wagner, All Rights Reserved", MUIA_Application_Author, "Oliver Wagner", MUIA_Application_Description, "Demo for Textinput.mcc", MUIA_Application_Base, "TEXTINPUT-DEMO", SubWindow, win = WindowObject, MUIA_Window_ID, 42, MUIA_Window_Title, "TextInput Demo", WindowContents, VGroup, Child, HGroup, Child, Label1( "Style:" ), Child, Cycle( styleoptions ), End, Child, HGroup, GroupFrameT( "Single line" ), Child, ColGroup( 2 ), Child, Label2( "Input:" ), Child, ti1 = TextinputObject, StringFrame, MUIA_CycleChain, 1, MUIA_ControlChar, 'a', MUIA_Textinput_Multiline, FALSE, MUIA_Textinput_Contents, C1, End, Child, Label2( "NoInput:" ), Child, ti2 = TextinputObject, TextFrame, MUIA_Background, MUII_TextBack, MUIA_Textinput_NoInput, TRUE, MUIA_Textinput_Contents, C1, End, End, End, Child, VGroup, GroupFrameT( "Multi line with scroll" ), Child, timl1 = TextinputscrollObject, StringFrame, MUIA_CycleChain, 1, MUIA_ControlChar, 'b', MUIA_Textinput_Multiline, TRUE, MUIA_Textinput_Contents, C2, End, Child, bt_get = SimpleButton( "Get contents (to shell window)" ), End, Child, HGroup, GroupFrameT( "NoInput multi line with Scroll" ), Child, timl2 = TextinputscrollObject, TextFrame, MUIA_Background,MUII_TextBack,MUIA_CycleChain, 1, MUIA_ControlChar, 'c', MUIA_Textinput_NoInput, TRUE, MUIA_Textinput_Multiline, TRUE, MUIA_Textinput_AutoExpand, TRUE, MUIA_Textinput_Contents, C2, MUIA_Textinput_MinVersion, 12, MUIA_Textinput_WordWrap, 60, End, End, Child, HGroup, GroupFrameT( "Old stringgadget" ), Child, String( C1, 256 ), End, End, End, End ) { DoMethod( win, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit ); DoMethod( bt_get, MUIM_Notify, MUIA_Pressed, FALSE, app, 2, MUIM_Application_ReturnID, 2 ); DoMethod( ti1, MUIM_Notify, MUIA_String_Contents, MUIV_EveryTime, ti2, 3, MUIM_Set, MUIA_Text_Contents, MUIV_TriggerValue ); DoMethod( timl1, MUIM_Notify, MUIA_String_Contents, MUIV_EveryTime, timl2, 3, MUIM_Set, MUIA_Text_Contents, MUIV_TriggerValue ); DoMethod( ti1, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime, ti1, 3, MUIM_Set, MUIA_Textinput_Contents, "" ); set( win, MUIA_Window_Open, TRUE ); while( !Done ) { LONG id; id = DoMethod( app, MUIM_Application_Input, &sig ); switch( id ) { case MUIV_Application_ReturnID_Quit: Done = TRUE; case 2: { char *p; get( timl1, MUIA_Textinput_Contents, &p ); PutStr( ">>>>>\n" ); PutStr( p ); PutStr( "<<<<<\n" ); } break; } if( sig ) if( Wait( sig | SIGBREAKF_CTRL_C ) & SIGBREAKF_CTRL_C ) Done = TRUE; } MUI_DisposeObject( app ); } CloseLibrary( MUIMasterBase ); }
void CDPlusAuthenticator::stop() { m_killed = true; Wait(); }