int main(void) { uint8_t opt = 0; /* Reset of all peripherals, Initializes the Flash interface and the SysTick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART2_UART_Init(); /* Enable USART2 interrupt */ HAL_NVIC_SetPriority(USART2_IRQn, 0, 0); HAL_NVIC_EnableIRQ(USART2_IRQn); printMessage: printWelcomeMessage(); while (1) { opt = readUserInput(); if(opt > 0) { processUserInput(opt); if(opt == 3) goto printMessage; } performCriticalTasks(); } }
bool VoxMain::initialize(int argc, char** argv) { if(!readUserInput(argc, argv)) return false; installSignalHandler(); if(!setToDaemon()) return false; if(!setupLog()) return false; if(!INIT_WIRING) { ERROR("INIT_WIRING failed!"); return false; } if(!VoxControl::getInstance().start()) { ERROR("(MAIN) failed to start controller thread"); return false; } if(!VoxSensor::getInstance().start()) { ERROR("(MAIN) failed to start sensor thread"); return false; } if(!VoxPlayer::getInstance().start()) { ERROR("(MAIN) failed to start player thread"); return false; } if(!VoxVision::getInstance().start()) { ERROR("(MAIN) failed to start vision thread"); return false; } if(!VoxVoice::getInstance().start()) { ERROR("(MAIN) failed to start voice thread"); return false; } if(!createPidFile()) { ERROR("(MAIN) pid file '%s' create failed", m_pidfile.c_str()); return false; } return true; }
int main(int argc, char* argv[]) { Graph<NodeMST>* G = new ConnectedGraph<NodeMST>(false, true, true, true); if (argc > 1) { if (strcmp(argv[1], "-r") == 0) { if (argc == 4) { // if random mode, read nVertices and density. // read number of nodes int nNodes = atoi(argv[2]); cout << "Number of Nodes: " << nNodes<<endl; // read density of edges float density = atoi(argv[3])/100.0; cout << "Density of Edges: " << density<<endl; // create random graph G->createRandomGraph(nNodes, density); } else if (argc == 2) { // create random graph G->createRandomGraph(1000, 0.4); } #ifdef DEBUG G->printGraph(); cout<<endl<<endl; #endif // comparison function randomComparisons(G); } else if(strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "-s") == 0) { // run user input mode with Fibonacci Scheme readUserInput(G, argv[2]); // MST class is a singleton, getting instance MinimumSpanningTree* mst = MinimumSpanningTree::getInstance(); if (strcmp(argv[1], "-f") == 0) { mst->setScheme(FHEAP); } else { mst->setScheme(SIMPLE); } cout<<mst->spanMinimumTree(G, G->getNodeByIndex(0))<<endl; mst->printMSTEdges(G); } } }
int main(void) { uint8_t opt = 0; /* Reset of all peripherals, Initializes the Flash interface and the SysTick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART2_UART_Init(); printMessage: printWelcomeMessage(); while (1) { opt = readUserInput(); processUserInput(opt); if(opt == 3) goto printMessage; } }
void SM_LED(State *state,int LED,int *Time) { static int currentTime[4] = {} ; static int counter = 0, triggered = 0 ; int UserInput = 0; switch(*state) { case START : turnOffLED(LED); if (LED == LED3) *state = LED_OFF ; //LED3 doesn;t have to care about button else *state = CHECK_BUTTON ; break ; case CHECK_BUTTON : UserInput = readUserInput(); //for LED4 and LED5 only if(UserInput == 1) { triggered = 1 ; //set triggered to 1 to remember that the user had already pressed the button *state = BUTTON_PRESSED ; // } else *state = BUTTON_NOT_PRESSED ; break ; case LED_ON : turnOnLED(LED); //if (getCurrentTime() - currentTime[LED] >= *Time) //{ // currentTime[LED] = getCurrentTime(); turnOffLED(LED); if (LED == LED3) *state = LED_OFF ; //LED3 doesn;t have to care about button else *state = CHECK_BUTTON ; if (LED == LED5) counter ++ ; //} break ; case LED_OFF: turnOffLED(LED); //if (getCurrentTime() - currentTime[LED] >= *Time) //{ // currentTime[LED] = getCurrentTime(); *state = LED_ON ; //} break ; case BUTTON_PRESSED: if (LED == LED4) *Time = _100ms; else if (LED == LED5) { if (counter == 5) // LED5 blinked 5 times { *state = START ; break ; } } *state = LED_OFF ; break ; case BUTTON_NOT_PRESSED : if (LED == LED4) //restore LED4 to original blinking rate *Time = _1s ; else if (LED == LED5) { if (triggered) // button was pressed { if (counter == 5 ) // check if LED5 had blinked 5 times { triggered = 0 ; counter = 0 ; } else //if not will force LED5 to blink till 5 times { *state = LED_OFF ; break; } } *state = CHECK_BUTTON ; // button was not pressed previously and go and check it again break ; } *state = LED_OFF ; break ; } }