java - Connecting arduino to an android app which uses libgdx (using Bluetooth) -


so i'm trying little unusual, it's fun. have game created using libgdx, consists of ship can shoot. want use external push buttons move it. push buttons send signals arduino, in turn sends them hc-05 bluetooth module. i'm doubtful android side of things. did following:

because i'm working on libgdx created interface called bluetoothdude, 3 methods setbluetooth() (which set bluetooth particular platform),string whatisthemessage() (which tell what's been sent phone), , boolean isactive(), know if bluetooth active of course.

the maingame receive bluetoothdude particular classes ship have access message , able react it.

then did particular implementation of bluetooth android, in setbluetooth() followed guide closely: https://developer.android.com/guide/topics/connectivity/bluetooth.html

i'm sure connecting properly, because when creates socket can print "connection success hc-05" (it print if method creates sockets, called btconnect() returns true).

the problem seems in reading data, code i'm using

   private class connectedthread extends thread {     private final bluetoothsocket mmsocket;     private final inputstream mminstream;     private final outputstream mmoutstream;     private handler handler;      public connectedthread(bluetoothsocket socket,handler mhandler) {         mmsocket = socket;         inputstream tmpin = null;         outputstream tmpout = null;         handler = mhandler;          try {             tmpin = socket.getinputstream();             tmpout = socket.getoutputstream();         } catch (ioexception e) {         }          mminstream = tmpin;         mmoutstream = tmpout;     }      public void run() {         byte[] buffer = new byte[1024];         int bytes;         while (true) {             try {                 bytes = mminstream.read(buffer);                 handler.obtainmessage(message_read, bytes, -1, buffer).sendtotarget();              } catch (ioexception e) {                 break;             }         }     } 

i made object of class in setbluetooth

 if (device != null) {         if (btconnect()) {             isactive = true;             connectedthread = new connectedthread(socket,handler);             system.out.println("connection success with" + device.getname() + " message: " + message );          } 

i have lot of doubts first target here, mhandler created in bluetoothdude, target?, second i'm quite sure thread isn't running because if put line system.out.println("run") inside run() doesn't show me line trillion times in logcat when app executed. wrong it, hope can me, i'm not experienced @ of this, , it's driving me crazy.

i cannot see if case code if calling platform specific methods, should done in platform specific project subproject.

for more information on how can check out page : https://github.com/libgdx/libgdx/wiki/interfacing-with-platform-specific-code

so if libgdx game has function say, "setbluetooth" each platform have own implementation of said method. differ when compile android or ios.

if try call platform specific code in core game won't work.

hope helps, maybe have done in case can ignore comment.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -