diff --git a/GPN_BadgeLasertag.ino b/GPN_BadgeLasertag.ino index 1cabf39b4f5d6bd01607db1521439d0f009c8ed0..0ff4d8f1a076587ee380ef4490a6f3323b6b7fb8 100644 --- a/GPN_BadgeLasertag.ino +++ b/GPN_BadgeLasertag.ino @@ -139,7 +139,6 @@ String recv_ir() { pixels.setPixelColor(1, pixels.Color(0, 0, 0)); pixels.show(); } - uint8_t checksum = 'X'; if (stringCompleted) { uint8_t checksum = buf[1]; dataCompleted = true; @@ -159,6 +158,7 @@ String recv_ir() { checksumRec += buf[0] + buf[1] + buf[2] + buf[3]; Serial.printf("->:\n\t0: %c\n\t1: %c\n\t2: %c\n\t3: %c\n", buf[0], buf[1], buf[2], buf[3]); if (buf[0] == '\n' || buf[1] == '\n' || buf[2] == '\n' || buf[3] == '\n') { + stringCompleted = true; Serial.printf("string complete %s\n", received.c_str()); //done = true; //isValidIp(received.substring(1, received.length() - 2)); @@ -167,34 +167,34 @@ String recv_ir() { irrecv.resume(); // Prepare for the next value } delay(0); - ui->dispatchInput(badge.getJoystickState()); //Allow canceling + // } - badge.setGPIO(IR_EN, HIGH); + badge.setGPIO(IR_EN, LOW); return received; } void joinGame() { ui->closeCurrent(); ui->draw(); + #ifdef DEBUG Serial.printf("Join Otter\n"); #endif String irinput = recv_ir(); -#ifdef DEBUG - Serial.printf("-->\n\t%s\n<--", irinput.c_str()); -#endif - String ip; - ip = irinput.substring(1, irinput.length() - 2); - Serial.printf("Received ip: %s", ip.c_str()); - + ip = irinput.substring(1, irinput.length() - 1); + unsigned short firstA = ip.indexOf('a'); + Serial.printf("firstA: %d\n", firstA); + ip = ip.substring(firstA, ip.length()); + Serial.printf("Received ip: >%s<\n", ip.c_str()); client = new GameClient(ui, &badge, player); client->joinGame(ip); #ifdef DEBUG Serial.printf("Join - Ende\n"); #endif + } void loop() { diff --git a/GameClient.cpp b/GameClient.cpp index 7dc1da0fd6d42e48050e0e5e499f75e64b5d0658..8b85eba131a6f9ebd0ce0ae5a138921239c595fc 100644 --- a/GameClient.cpp +++ b/GameClient.cpp @@ -41,12 +41,28 @@ void GameClient::joinGame(String ip) { badge->setVibrator(true); delay(200); badge->setVibrator(false); + playerList->addMenuItem(new MenuItem(player->getNickname(), []() {})); + + ui->dispatchInput(badge->getJoystickState()); ui->open(playerList); - client->connect(ip.c_str(), SERVER_PORT); + ui->draw(); + + + Serial.printf("Conn data:\n\tip: %s\n\tport: %d\n", ip.c_str(), SERVER_PORT); + + //client->connect(ip.c_str(), SERVER_PORT); + Serial.printf("Trying to conncet!\n"); + if (!client->connect("192.168.42.175", 4803)){ + Serial.printf("Connect failed!\n"); + } + Serial.printf("client->connect\n"); client->print(player->getNickname()); + Serial.printf("client->print nickname\n"); client->flush(); + Serial.printf("client->flush"); + Serial.printf("Receiving"); String recv = client->readStringUntil('\n'); Serial.printf("RECV: %s", recv.c_str()); }