예제 #1
0
uint8_t StaticGame::loadGame(int timeout) {

  long startTime = millis();

  this->readExisting();
  _dataReceived = "";
  this->writeMessage("GET_GAMEID");
  do {
    delay(5);
    if (this->available()){
      String reply = this->readMessage();
#ifdef DEBUG
      Serial.println("Game reply: " + reply);
#endif
      String command = getCommand(reply);
      if (command.equals("GAMEID")) {
        String parameters = getParameters(reply);
        if (numberOfParameters(parameters) == 1){
          uint8_t temp = getParameter(parameters, 1).toInt();
          if (temp != NO_GAME) {
            this->_gameId = temp;
#ifdef DEBUG
            Serial.print("Game ID: ");
            Serial.println(_gameId, DEC);
#endif
            return this->_gameId;
          }
        }
      }
      break;
    }
  } 
  while ((millis() - startTime) < timeout);
  return NO_GAME;
}
예제 #2
0
  // 2d case
  double   PythonFunction::value2D(double x, double y) const {  
        /* Time to call the callback */
    PyObject * result; 
    // assume only one dim (for the moment) and max 5  params
    PyObject * arglist = 0; 

    //   std::cout << numberOfParameters() << " argDescr = " << m_argDescr << std::endl;
    if ( numberOfParameters() == 0) 
      arglist = Py_BuildValue(const_cast<char *> (m_argDescr.c_str() ), x, y);
    else if ( numberOfParameters() == 1 ) 
      arglist = Py_BuildValue(const_cast<char *> ( m_argDescr.c_str() ), x, y, parameters()[0] );
    else if ( numberOfParameters() == 2 ) 
      arglist = Py_BuildValue(const_cast<char *> ( m_argDescr.c_str() ), x, y, parameters()[0], parameters()[1] );
    else if ( numberOfParameters() == 3 ) 
      arglist = Py_BuildValue(const_cast<char *> ( m_argDescr.c_str() ), x, y, parameters()[0], parameters()[1], parameters()[2] );
    else if ( numberOfParameters() == 4 ) 
      arglist = Py_BuildValue(const_cast<char *> ( m_argDescr.c_str() ), x, y, parameters()[0], parameters()[1], parameters()[2] , parameters()[3] );
    else if ( numberOfParameters() == 5 ) 
      arglist = Py_BuildValue(const_cast<char *> ( m_argDescr.c_str() ), x, y, parameters()[0], parameters()[1], parameters()[2] , parameters()[3], parameters()[4] );

    result = PyEval_CallObject(m_func, arglist);
    Py_DECREF(arglist);
    if (result == NULL) 
        return 0; /* Pass error back */
    //...use result...
    double v = PyFloat_AsDouble(result); 
    Py_DECREF(result);
    return v; 
  }
예제 #3
0
파일: Xbee.cpp 프로젝트: joruiz/PFG-Robot
String Xbee::executeShake() {
  
  String dataReceived = "";
  
  Serial.begin(9600);
  Serial3.begin(9600);
  Serial.flush();
  Serial3.flush();
  
  while (Serial3.available()) {
    char data = Serial3.read();
    dataReceived += data;
    }
  //check if there is any message (it must be finish with END_COMMAND)
  int index = dataReceived.indexOf(END_COMMAND);
  if (index != -1) {
    //get message, execute it and remove from receive bytes
    String message = dataReceived.substring(0, index);
    dataReceived = dataReceived.substring(index + 1);
    Serial.println("Msg. Received: " + message);
    String command = getCommand(message);
    Serial.println("Command: " + command);
    if (command.equals("SHAKE_ON")) {
      String parameters = getParameters(message);
      if (numberOfParameters(parameters) == 1)
        byte shake_id = getParameter(parameters, 0).toInt();
      Serial.println("Parameters: " + parameters);
      Serial.write(END_COMMAND);
	  return "";
      }
	}	

  else
	return "";
  //Serial3.end();
}