byte Radioino::receiveCommand() { // Check the setup mode command if (digitalRead(_setupButtonPin)==HIGH && !_setupMode) { _setupMode = true; _previousTime = 0; _setupModeCount = 0; } if (_setupMode) { // check to see if it's time to blink the LED; that is, if the // difference between the current time and last time you blinked // the LED is bigger than the interval at which you want to // blink the LED. unsigned long currentTime = millis(); if(currentTime - _previousTime > RADIOINO_SETUP_LED_BLINK_MS) { // save the last time you blinked the LED _previousTime = currentTime; setActivityLedState(!_activityLedState); _setupModeCount++; } // Exit the setup mode if (_setupModeCount > RADIOINO_SETUP_ATTEMPTS) { _setupMode = false; setActivityLedState(LOW); } } //Wait for a new command _commandResult = RADIOINO_NO_COMMAND; if (Serial.available() > 0) { if (receive()) { if (execute()) { // Build the response message beginResponse(true); // Add the sensors status sendSensorsStatus(); _commandResult = RADIOINO_COMMAND_OK; } else { // Build the error response message beginResponse(false); _commandResult = RADIOINO_COMMAND_ERROR; } // wait for another command resetCommand(); } } // end activity setActivityLedState(LOW); return _commandResult; }
void runCmd(struct Node* node, const char *fPath) { //Run the commands for each node in parallel pthread_t pt; if (node->child != NULL) runCmd(node->child, fPath); if (node->command != NULL) { char buf[2048]; memset(buf, 0, sizeof(buf)); if (node->statusFlag == 0) { if (treeSearchDups(node, node->nodeName, node->statusFlag, node->command)) return 0; } if (node->statusFlag == 0) { char *sourceExt = strchr(node->nodeName, '.'); if (sourceExt != NULL) { if ((strcmp(sourceExt, ".cpp") == 0) || (strcmp(sourceExt, ".o") == 0)) resetCommand(node, fPath); } else { //Need to fix other string and remove "" const char *src = strrchr(node->command, 'g'); int endl = 0; if (src != NULL) { //src--; const char *dsc = strrchr(src, '"'); endl = dsc - src; char* iptr = (char*) malloc(endl + 1); memset(iptr, 0, endl); memcpy(iptr, src, endl); iptr[endl] = 0; node->command = iptr; } } sprintf(buf, "%s", node->command); if (createThread(buf, &pt)) return NULL; node->statusFlag = 1; if (node->next != NULL) runCmd(node->next, fPath); } } }
bool ONScripter::executeSystemReset() { if ( executeSystemYesNo( SYSTEM_RESET ) ){ resetCommand(); leaveSystemCall( false ); return true; } leaveSystemCall(); return false; }
// Build the incoming command in a ascii-string boolean Radioino::receive() { while (Serial.available() > 0) { int value = Serial.read(); // show activity setActivityLedState(!_activityLedState); switch (value) { case RADIOINO_COMMAND_END : // Command arrived. Check if we can accept this command command address if (_command.startsWith(_startHeader) || _command.startsWith(RADIOINO_SETUP_HEADER) && _setupMode) { // Check if is not message to send the latest result again if (_command == _startHeader+"C") { // Send the latest response again Serial.println(_response); resetCommand(); return false; } // It's a regular command. execute-it return true; } else { resetCommand(); return false; } case 'R' : resetCommand(); _command = _command + char(value); return false; default: _command = _command + char(value); return false; } } return false; }
byte IOToaster::receiveCommand() { if (_setupMode) { // check to see if it's time to blink the LED; that is, if the // difference between the current time and last time you blinked // the LED is bigger than the interval at which you want to // blink the LED. unsigned long currentTime = millis(); if (currentTime - _previousTime > IOTOASTER_SETUP_LED_BLINK_MS) { // save the last time you blinked the LED _previousTime = currentTime; // if the LED is off turn it on and vice-versa: if (_activityLedState == LOW) setActivityLedState(HIGH); else setActivityLedState(LOW); } } //Wait for a new command _commandResult = IOTOASTER_NO_COMMAND; if (Serial.available() > 0) { if (receive()) { if (_command.startsWith("+IPD")) // Check for data sent from the server { _command = _command.substring(_command.lastIndexOf(':') + 1); _customResponse = ""; if (execute()) { // Build the response message beginResponse(true); // Add the sensors status send(getInputSensorsStatus()); _commandResult = IOTOASTER_COMMAND_OK; } else { // Build the error response message beginResponse(false); _commandResult = IOTOASTER_COMMAND_ERROR; } } // wait for another command resetCommand(); } } return _commandResult; }
MainApplication::MainApplication(int argc, char *argv[]) : QApplication(argc, argv), simulator(12345), engine(), history(), communication(), robot(history, communication), handler(robot, *engine.rootContext(), history) { // Szimulátor indítása simulator.start(0.3F); // Csatlakozás a szimulátorhoz. communication.connect(QStringLiteral("localhost"),12345); // Szimulálunk egy history változást, mert attól kezdve léteznek a QML oldalon // a C++ oldalról származó változók. (Különben referencia hibákat kapnánk a QML oldalon // egészen addig, amíg az első üzenet meg nem jönne a szimulátortól. //handler.historyChanged(); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); // A QML gyökérelemre szükségünk van ahhoz, hogy tudjunk hivatkozni a QML-es elemekre. auto rootObjects = engine.rootObjects(); if (rootObjects.size() == 0) { qDebug() << "HIBA: Nem sikerült létrehozni a QML környezetet."; return; } // A QML környezet is felállt, bekötjük a signalokat a QML és C++ oldal között. QObject *rootObject = rootObjects[0]; // A handler beköti a saját signaljait. handler.ConnectQmlSignals(rootObject); // Bekötjük a nyomógombok signaljait. QObject::connect(rootObject, SIGNAL(resetCommandCpp()), &handler, SLOT(resetCommand())); QObject::connect(rootObject, SIGNAL(accelerateXCommandCpp()), &handler, SLOT(accelerateXCommand())); QObject::connect(rootObject, SIGNAL(accelerateYCommandCpp()), &handler, SLOT(accelerateYCommand())); QObject::connect(rootObject, SIGNAL(slowDownXCommandCpp()), &handler, SLOT(slowDownXCommand())); QObject::connect(rootObject, SIGNAL(slowDownYCommandCpp()), &handler, SLOT(slowDownYCommand())); QObject::connect(rootObject, SIGNAL(stopCommandCpp()), &handler, SLOT(stopCommand())); QObject::connect(rootObject, SIGNAL(testCommandCpp()), &handler, SLOT(testCommand())); QObject::connect(rootObject, SIGNAL(defaultCommandCpp()), &handler, SLOT(defaultCommand())); }
void PonscripterLabel::executeSystemYesNo() { current_font = &menu_font; if (event_mode & WAIT_BUTTON_MODE) { if (current_button_state.button == 0) return; event_mode = IDLE_EVENT_MODE; deleteButtons(); if (current_button_state.button == 1) { // yes is selected playSound(menuselectvoice_file_name[MENUSELECTVOICE_YES], SOUND_WAVE | SOUND_OGG, false, MIX_WAVE_CHANNEL); if (yesno_caller == SYSTEM_SAVE) { saveSaveFile(yesno_selected_file_no); leaveSystemCall(); } else if (yesno_caller == SYSTEM_LOAD) { current_font = &sentence_font; if (loadSaveFile(yesno_selected_file_no)) { system_menu_mode = yesno_caller; advancePhase(); return; } leaveSystemCall(false); saveon_flag = true; internal_saveon_flag = true; text_on_flag = false; indent_offset = 0; line_enter_status = 0; string_buffer_offset = 0; string_buffer_restore = -1; break_flag = false; if (loadgosub_label) gosubReal(loadgosub_label, script_h.getCurrent()); readToken(); } else if (yesno_caller == SYSTEM_RESET) { resetCommand("reset"); readToken(); event_mode = IDLE_EVENT_MODE; leaveSystemCall(false); } else if (yesno_caller == SYSTEM_END) { endCommand("end"); } } else { playSound(menuselectvoice_file_name[MENUSELECTVOICE_NO], SOUND_WAVE | SOUND_OGG, false, MIX_WAVE_CHANNEL); system_menu_mode = yesno_caller & 0xf; if (yesno_caller == SYSTEM_RESET) leaveSystemCall(); advancePhase(); } } else { text_info.fill(0, 0, 0, 0); pstring name; if (yesno_caller == SYSTEM_SAVE) { SaveFileInfo save_file_info; searchSaveFile(save_file_info, yesno_selected_file_no); processMessage(name, locale.message_save_confirm, save_file_info); } else if (yesno_caller == SYSTEM_LOAD) { SaveFileInfo save_file_info; searchSaveFile(save_file_info, yesno_selected_file_no); processMessage(name, locale.message_load_confirm, save_file_info); } else if (yesno_caller == SYSTEM_RESET) name = locale.message_reset_confirm; else if (yesno_caller == SYSTEM_END) name = locale.message_end_confirm; current_font->area_x = int (ceil(current_font->StringAdvance(name))); current_font->area_y = current_font->line_top(4); current_font->top_x = (screen_width * screen_ratio2 / screen_ratio1 - current_font->area_x) / 2; current_font->top_y = (screen_height * screen_ratio2 / screen_ratio1 - current_font->area_y) / 2; current_font->SetXY(0, 0); buttons[0] = getSelectableSentence(name, current_font, false); flush(refreshMode()); float yes_len = current_font->StringAdvance(locale.message_yes), no_len = current_font->StringAdvance(locale.message_no); name = locale.message_yes; current_font->SetXY(float (current_font->area_x) / 4 - yes_len / 2, current_font->line_top(2)); buttons[1] = getSelectableSentence(name, current_font, false); name = locale.message_no; current_font->SetXY(float (current_font->area_x) * 3 / 4 - no_len / 2, current_font->line_top(2)); buttons[2] = getSelectableSentence(name, current_font, false); flush(refreshMode()); event_mode = WAIT_BUTTON_MODE; refreshMouseOverButton(); } }
void Keyboard::releaseAll() { // set pressure to zero for every key memset(m_keyState, 0, sizeof(m_keyState)); resetCommand(); }
/* Enter the main loop. Read and parse input from the serial port and run any valid commands. Run a PID calculation at the target interval and check for auto-stop conditions. */ void loop() { while (Serial.available() > 0) { // Read the next character chr = Serial.read(); // Terminate a command with a CR if (chr == 13) { if (arg == 1) argv1[index] = NULL; else if (arg == 2) argv2[index] = NULL; runCommand(); resetCommand(); } // Use spaces to delimit parts of the command else if (chr == ' ') { // Step through the arguments if (arg == 0) arg = 1; else if (arg == 1) { argv1[index] = NULL; arg = 2; index = 0; } continue; } else { if (arg == 0) { // The first arg is the single-letter command cmd = chr; } else if (arg == 1) { // Subsequent arguments can be more than one character argv1[index] = chr; index++; } else if (arg == 2) { argv2[index] = chr; index++; } } } // If we are using base control, run a PID calculation at the appropriate intervals #ifdef USE_BASE if (millis() > nextPID) { updatePID(); nextPID += PID_INTERVAL; } // Check to see if we have exceeded the auto-stop interval if ((millis() - lastMotorCommand) > AUTO_STOP_INTERVAL) {; setMotorSpeeds(0, 0); moving = 0; resetPID(); } #endif if (millis() > nextTick) { ticks += 1; nextTick += TICK_INTERVAL; } }