/** * @brief startInteractiveMode : starts the interactive mode * (blocks until it is exited) * @param s : The sphero to control */ void InteractiveController::startInteractiveMode(Sphero *s) { this->s = s; if(!isConnected()) return; ja->startListener(); commandMode = mode::CLASSIC; cout << "************************************" << endl; cout << "* welcome to interactive mode *" <<endl; classicHelp(); BufferToggle bt; bt.off(); int input; timeval lastInput, now; double elapsedTime; // start timer gettimeofday(&lastInput, NULL); do { input = getchar(); switch (commandMode) { case mode::CLASSIC: handleKeysClassic(input, lastInput); break; case mode::CALIBRATE: handleKeysCalibrate(input, lastInput); break; case mode::JOYSTICK: handleKeysJoystick(lastInput); break; } #ifdef MAP if(input != -1) cout << "You pressed key ID: " << input << endl; #endif gettimeofday(&now, NULL); elapsedTime = (now.tv_sec - lastInput.tv_sec) * 1000.0; // sec to ms elapsedTime += (now.tv_usec - lastInput.tv_usec) / 1000.0; //cout << elapsedTime << endl; if(elapsedTime >= 120) s->roll((uint8_t) 0 % 256, (uint16_t) lastAngle % 0x10000); usleep(8000); }while(input != global::_KEY_QUIT); bt.on(); ja->stop(); }
int main(int argc, const char * argv[]) { if (argc < 2) { cout << "Usage: " << argv[0] << " assembly_file_name.asm" << endl; return 0; } SourceReader sourceReader(argv[1]); sourceReader.findLabelAddresses(); sourceReader.constructInstructionList(); vector<Instruction> originalInstructionList = sourceReader.getInstructionList(); vector<SimulatedInstruction> simulatedInstructionList = vector<SimulatedInstruction>(); cout << "-------------Start Simulation-------------" << endl; cout << "Original number of instructions : " << originalInstructionList.size() << endl; cout << string(OUTPUT_WIDTH, '-') << endl; for (Instruction instruction: originalInstructionList) { simulatedInstructionList.push_back(SimulatedInstruction(instruction)); } // Inserts an end instruction followed by 3 'NOPs' to terminate the instruction list // An end NOP instruction is used to indicate the end of the instruction list SimulatedInstruction end = SimulatedInstruction(); end.originalString = "end"; end.opcodeString = "end"; simulatedInstructionList.push_back(end); fill_n(back_inserter(simulatedInstructionList), 3, SimulatedInstruction()); for (int i = 0; i < simulatedInstructionList.size(); i++) { simulatedInstructionList[i].instructionLocation = i; } Simulator simulator(simulatedInstructionList); cout << "Press enter to run the entire simulation without pauses" << endl; cout << "Or press space to step through the simulation" << endl; BufferToggle bt; while (simulator.memoryStage.currentInstructionList.front().originalString != "end") { bt.off(); char input = getchar(); bt.on(); if (input == ' ') { cout << endl; simulator.stepProcess(); } else if (input == '\n' || input == '\r') { simulator.process(); } } simulator.printFinalOutput(); return 0; }