void ProcessPacketLed (ARCPOPacket& pPacket) {
  switch (pPacket.SubType){
    case PACKET_SUBTYPE_LED1:
      pika(LED1_PIN, 100, 3);
      break;
    case PACKET_SUBTYPE_LED2:
      pika(LED2_PIN, 100, 5);
      break;
    default:
      //nothing
      break;
  }
}
void loop (){
  byte vButton1;
  ARCPOPacket vPacket;
  
  vButton1 = readButton(BUTTON_PIN);
  if (vButton1 == 0){
    ARCPOPacket vP;
    vP.Type = 98;
    vP.Content [0] = 'x';
    vP.Content [1] = 0;
    
    
    writePacket (vP);
    pika(LED1_PIN, 100);
  }
  
  
  vPacket = readPacket();
  
  if (readPacketSuccess()){
    delay(250);
    ProcessPacket (vPacket);
    //Serial.print ("Read a packet -->");
    //DEBUG_TRACE_ARCPOPACKET_TO_SERIAL (vPacket);
  }
  
  //system needs a small delay other keep on reading the same entries (COM problem?)
  delay(250);
}
Exemple #3
0
void Box::draw() {
    std::vector<Drawable*> elements;
    //Draw algorithm
    const int NUMBERROW = 5;
    const int NUMBERCOLUMN = 3;
    
    int j = (State::getIndexNumber()/(NUMBERROW*NUMBERCOLUMN) * (NUMBERROW*NUMBERCOLUMN));
    int k = (State::getIndexNumber()/(NUMBERROW*NUMBERCOLUMN));
    
    bool tick = State::getMultipleSelectionTick();
    for(int i = 0; i < NUMBERROW*NUMBERCOLUMN; i++) {
        const int XBOXSTART = posx;
        const int YBOXSTART = posy;
        const int YBOXDISTANCE = 5;
        const int XBOXDISTANCE = 5;
        
        std::string texturepath;
        
        if( State::getMode() == State::MULTIPLESELECTMODE || State::getMode() == State::MULTIPLECLONEMODE ) {
            if(tick)
                texturepath = ExtDataManager::getBasePath() + "/textures/boxslot_selected.png";
            
            else texturepath = ExtDataManager::getBasePath() + "/textures/boxslot.png";
        }
        
        else {
            if( State::getIndexNumber() == (i+(k*NUMBERROW*NUMBERCOLUMN)) )
                texturepath = ExtDataManager::getBasePath() + "/textures/boxslot_selected.png";

            else texturepath = ExtDataManager::getBasePath() + "/textures/boxslot.png";
        }
        
        int row = i / NUMBERCOLUMN;
        int column = i % NUMBERCOLUMN;
        const int XPOS = XBOXSTART + (XBOXDISTANCE*column) + (TextureManager::getTexture(texturepath)->width*column);
        const int YPOS = YBOXSTART + (YBOXDISTANCE*row) + (TextureManager::getTexture(texturepath)->height*row);
        
        Pokemon pika(State::getBoxNumber(), j, ExtDataManager::getSave());
        Drawable* box = new BoxSlot(TextureManager::getTexture(texturepath), XPOS, YPOS, pika);
        elements.push_back(box);
        j++;
    }
    
    for(unsigned int i = 0; i < elements.size(); i++)
        elements[i]->draw();
    
    for(unsigned int i = 0; i < elements.size(); i++)
        delete elements[i];
}
Exemple #4
0
int main(int argc, char** argv) {
//   cppipc::comm_client client({"localhost:2181"}, "test");
  //cppipc::comm_client client({}, "tcp://127.0.0.1:19000");
  cppipc::comm_client client({}, 
                             "ipc:///tmp/cppipc_server_test");
  if (argc >= 2) {
    client.add_auth_method(std::make_shared<cppipc::authentication_token_method>(argv[1]));
  }
  client.start();
  client.add_status_watch(WATCH_COMM_SERVER_INFO, 
                          [](std::string message) {
                          std::cout << message << "\n";
                          });

  for (size_t i = 0;i < 100; ++i) {
  try { 
    test_object_proxy test_object(client);
    std::cout << test_object.ping("hello world") << "\n";

    std::cout << "5 + 1 = " << test_object.add_one(5, "hello") << "\n";
    std::cout << "5 + 5 = " << test_object.add(5, 5) << "\n";
    std::cout << "5 - 5 = " << test_object.subtract(5, 5) << "\n";
    std::cout << "return_one = " << test_object.return_one() << "\n";
    ASSERT_EQ(test_object.add(5, 5), 10);
    ASSERT_EQ(test_object.subtract(5, 5), 0);
  } catch (cppipc::reply_status status) {
    std::cout << "Exception: " << cppipc::reply_status_to_string(status) << "\n";
  } catch (const char* s) {
    std::cout << "Exception: " << s << "\n";
  }
  }

  std::shared_ptr<test_object_proxy> pika(std::make_shared<test_object_proxy>(client));
  std::shared_ptr<test_object_proxy> chu(std::make_shared<test_object_proxy>(client));

  pika->set_value(10);
  chu->set_value(5);
  ASSERT_EQ(pika->get_value(), 10);
  ASSERT_EQ(chu->get_value(), 5);

  pika->subtract_from(std::static_pointer_cast<test_object_base>(chu));
  ASSERT_EQ(pika->get_value(), 5);
  ASSERT_EQ(chu->get_value(), 5);

  chu->subtract_from(std::static_pointer_cast<test_object_base>(pika));
  ASSERT_EQ(pika->get_value(), 5);
  ASSERT_EQ(chu->get_value(), 0);

  pika->swap(std::static_pointer_cast<test_object_base>(chu));
  ASSERT_EQ(pika->get_value(), 0);
  ASSERT_EQ(chu->get_value(), 5);

  chu->swap(std::static_pointer_cast<test_object_base>(pika));
  ASSERT_EQ(pika->get_value(), 5);
  ASSERT_EQ(chu->get_value(), 0);

  chu->set_value(2);
  std::shared_ptr<test_object_proxy> p = std::dynamic_pointer_cast<test_object_proxy>(*pika - chu);
  ASSERT_NE(p.get(), NULL);
  ASSERT_EQ(p->get_value(), 3);

  // Test objects with reference count greater than 1
  std::shared_ptr<test_object_proxy> q = std::dynamic_pointer_cast<test_object_proxy>(*pika + chu);
  ASSERT_EQ(q->get_value(), 7);
  ASSERT_EQ(chu->get_value(), 7);
  ASSERT_EQ(pika->get_value(), 5);

  bool exception_caught = false;
  try {
    chu->an_exception();
  } catch (cppipc::ipcexception& except) {
    std::cout << except.what() << "\n";
    exception_caught = true;
  }

  ASSERT_TRUE(exception_caught);

  // ping test with increasing lengths
  test_object_proxy test_object(client);
  for (size_t i = 0;i <= 25; ++i) {
    size_t j = ((size_t)1 << i) - 1;
    graphlab::timer ti;
    std::cout << "Sending ping of length " << j << std::endl;
    std::string ret = test_object.return_big_object(j);
    std::cout << "Ping of length " << j << " RTT = " << ti.current_time() << "s" << std::endl;
    ASSERT_EQ(ret.length(), j);
  }
  p.reset();
}
void setup (){
  Serial.begin(9600);
  
  pika(LED1_PIN, 50, 3);
}