|
|
@ -15,8 +15,10 @@ import android.bluetooth.BluetoothManager; |
|
|
|
import android.content.Context; |
|
|
|
import android.content.Intent; |
|
|
|
import android.content.pm.PackageManager; |
|
|
|
import android.graphics.Color; |
|
|
|
import android.os.Build; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.text.Html; |
|
|
|
import android.util.Log; |
|
|
|
import android.view.View; |
|
|
|
import android.widget.TextView; |
|
|
@ -29,6 +31,7 @@ import com.example.beacondemo.adapter.RecycleViewDivider; |
|
|
|
import com.minew.beaconplus.sdk.MTCentralManager; |
|
|
|
import com.minew.beaconplus.sdk.MTFrameHandler; |
|
|
|
import com.minew.beaconplus.sdk.MTPeripheral; |
|
|
|
import com.minew.beaconplus.sdk.Utils.LogUtils; |
|
|
|
import com.minew.beaconplus.sdk.enums.BluetoothState; |
|
|
|
import com.minew.beaconplus.sdk.enums.ConnectionStatus; |
|
|
|
import com.minew.beaconplus.sdk.enums.FrameType; |
|
|
@ -76,7 +79,7 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
ArrayList<MinewFrame> advFrames; |
|
|
|
|
|
|
|
TextView txt_name,txt_mac,txt_battery,txt_rssi,txt_device,txt_xaxis,txt_yaxis,txt_zaxis; |
|
|
|
String mac,name; |
|
|
|
String mac,name,xaxis,yaxis,zaxis; |
|
|
|
int battery,rssi; |
|
|
|
|
|
|
|
@Override |
|
|
@ -116,6 +119,7 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
|
|
|
|
@SuppressLint("MissingPermission") |
|
|
|
private void showBLEDialog() { |
|
|
|
System.out.println("Hitting the dialog box"); |
|
|
|
final Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); |
|
|
|
startActivityForResult(enableIntent, REQUEST_ENABLE_BT); |
|
|
|
} |
|
|
@ -134,11 +138,14 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
|
|
|
|
private void initData() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mMtCentralManager.startScan(); |
|
|
|
mMtCentralManager.setMTCentralManagerListener(new MTCentralManagerListener() { |
|
|
|
@Override |
|
|
|
public void onScanedPeripheral(final List<MTPeripheral> peripherals) { |
|
|
|
Log.e("Peripherals : ", String.valueOf(peripherals.size())); |
|
|
|
mAdapter.setData(peripherals); |
|
|
|
for (MTPeripheral mtPeripheral : peripherals) { |
|
|
|
// get FrameHandler of a device. |
|
|
|
MTFrameHandler mtFrameHandler = mtPeripheral.mMTFrameHandler; |
|
|
@ -146,10 +153,16 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
name = mtFrameHandler.getName(); // name of device |
|
|
|
battery = mtFrameHandler.getBattery(); //battery |
|
|
|
rssi = mtFrameHandler.getRssi(); //rssi |
|
|
|
txt_device.setText("Device in range. "); |
|
|
|
txt_device.setText("Device in range. "); |
|
|
|
txt_device.setTextColor(Color.BLUE); |
|
|
|
|
|
|
|
String html1 = "<font color=" + Color.BLACK |
|
|
|
+ ">Mac Address : </font><font color=" |
|
|
|
+ Color.BLACK + ">"+ mac+"</font>"; |
|
|
|
|
|
|
|
txt_mac.setText(Html.fromHtml(html1)); |
|
|
|
|
|
|
|
|
|
|
|
txt_mac.setText("Mac Address : "+mac); |
|
|
|
txt_name.setText("Device Name : "+name); |
|
|
|
txt_battery.setText("Battery Status : "+battery); |
|
|
|
txt_rssi.setText(" Rssi : "+rssi); |
|
|
@ -171,9 +184,23 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
break; |
|
|
|
case FrameAccSensor: |
|
|
|
AccFrame accFrame = (AccFrame) minewFrame;//acc |
|
|
|
txt_xaxis.setText("X axis: " + accFrame.getXAxis()); |
|
|
|
txt_yaxis.setText("Y axis: " + accFrame.getYAxis()); |
|
|
|
txt_zaxis.setText("Z axis: " + accFrame.getZAxis()); |
|
|
|
xaxis = String.valueOf(accFrame.getXAxis()); |
|
|
|
yaxis = String.valueOf(accFrame.getYAxis()); |
|
|
|
zaxis = String.valueOf(accFrame.getZAxis()); |
|
|
|
|
|
|
|
txt_xaxis.setText("X axis: " + xaxis); |
|
|
|
txt_yaxis.setText("Y axis: " + yaxis); |
|
|
|
txt_zaxis.setText("Z axis: " + zaxis); |
|
|
|
|
|
|
|
if (accFrame.getXAxis() == Double.MIN_VALUE) { |
|
|
|
Log.v("tag","this value is not available."); |
|
|
|
} |
|
|
|
if (accFrame.getYAxis() == Double.MIN_VALUE) { |
|
|
|
Log.v("tag","this value is not available."); |
|
|
|
} |
|
|
|
if (accFrame.getZAxis() == Double.MIN_VALUE) { |
|
|
|
Log.v("tag","this value is not available."); |
|
|
|
} |
|
|
|
Log.v("beaconplus3", String.valueOf(accFrame.getXAxis() + " "+ accFrame.getYAxis() +" "+ accFrame.getZAxis())); |
|
|
|
break; |
|
|
|
case FrameHTSensor: |
|
|
@ -206,7 +233,7 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
break; |
|
|
|
case FrameTVOCSensor://tvoc |
|
|
|
TvocFrame tvocFrame = (TvocFrame) minewFrame; |
|
|
|
Log.v("beaconplus11", "battery:" + tvocFrame.getBattery() + " "+ ",TVOC:"+ tvocFrame.getValue() + " "+ "ppb," + "battery:" " "+ +tvocFrame.getBattery() + "mV"); |
|
|
|
Log.v("beaconplus11", "battery:" + tvocFrame.getBattery() + " "+ ",TVOC:"+ tvocFrame.getValue() + " "+ "ppb," + "battery:"+ " "+ +tvocFrame.getBattery() + "mV"); |
|
|
|
break; |
|
|
|
case FrameLineBeacon://FrameLineBeacon |
|
|
|
LineBeaconFrame lineBeacon = ((LineBeaconFrame) minewFrame); |
|
|
@ -272,15 +299,76 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
/*mMtCentralManager.connect(mtPeripheral,connectionStatueListener); |
|
|
|
ConnectionStatueListener connectionStatueListener = new ConnectionStatueListener(){ |
|
|
|
@Override |
|
|
|
public void onUpdateConnectionStatus(final ConnectionStatus connectionStatus,final GetPasswordListener getPasswordListener) { |
|
|
|
runOnUiThread(new Runnable() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
switch (connectionStatus){ |
|
|
|
case PASSWORDVALIDATING: |
|
|
|
String password = "minew123"; |
|
|
|
getPasswordListener.getPassword(password); |
|
|
|
break; |
|
|
|
} |
|
|
|
switch (connectionStatus) { |
|
|
|
case CONNECTING: |
|
|
|
Log.e("minew_tag", ": CONNECTING"); |
|
|
|
break; |
|
|
|
case CONNECTED: |
|
|
|
Log.e("minew_tag", ": CONNECTED"); |
|
|
|
break; |
|
|
|
case READINGINFO: |
|
|
|
//Advanced exercise can be notified when reading firmware information |
|
|
|
Log.e("minew_tag", ": Read device firmware information"); |
|
|
|
break; |
|
|
|
case DEVICEVALIDATING://After successfully verifying the device, write the verification key to the device |
|
|
|
LogUtils.e("DEVICEVALIDATING"); |
|
|
|
break; |
|
|
|
case PASSWORDVALIDATING: |
|
|
|
String password = "minew123"; |
|
|
|
getPasswordListener.getPassword(password); |
|
|
|
break; |
|
|
|
case SYNCHRONIZINGTIME://Password verification completed |
|
|
|
Log.e("minew_tag", ": SYNCHRONIZINGTIME"); |
|
|
|
break; |
|
|
|
case READINGCONNECTABLE: |
|
|
|
Log.e("minew_tag", ": Read device firmware information"); |
|
|
|
LogUtils.e("READINGCONNECTABLE"); |
|
|
|
break; |
|
|
|
case READINGFEATURE: |
|
|
|
LogUtils.e("READINGFEATURE"); |
|
|
|
break; |
|
|
|
case READINGFRAMES: |
|
|
|
LogUtils.e("READINGFRAMES"); |
|
|
|
break; |
|
|
|
case READINGTRIGGERS: |
|
|
|
LogUtils.e("READINGTRIGGERS"); |
|
|
|
break; |
|
|
|
case READINGSENSORS: |
|
|
|
LogUtils.e("READINGSENSORS"); |
|
|
|
break; |
|
|
|
case COMPLETED: |
|
|
|
//At this point the connection is successful and the parameters are written to the device |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onError(MTException e) { |
|
|
|
|
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
mMtCentralManager.disconnect(mtPeripheral);*/ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void initView() { |
|
|
|
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this); |
|
|
|
txt_battery=findViewById(R.id.txt_battery); |
|
|
|
txt_mac=findViewById(R.id.txt_mac); |
|
|
|
txt_name=findViewById(R.id.txt_name); |
|
|
@ -289,9 +377,11 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
txt_xaxis=findViewById(R.id.txt_xaxis); |
|
|
|
txt_yaxis=findViewById(R.id.txt_yaxis); |
|
|
|
txt_zaxis=findViewById(R.id.txt_zaxis); |
|
|
|
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this); |
|
|
|
mRecycle.setLayoutManager(layoutManager); |
|
|
|
mAdapter = new RecycleAdapter(); |
|
|
|
mRecycle.setAdapter(mAdapter); |
|
|
|
System.out.println("Data is set in recyclerview through the adapter"); |
|
|
|
/*mRecycle.addItemDecoration(new RecycleViewDivider(this, LinearLayoutManager |
|
|
|
.HORIZONTAL));*/ |
|
|
|
|
|
|
@ -358,17 +448,21 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
} |
|
|
|
|
|
|
|
private void initListener() { |
|
|
|
|
|
|
|
mMtCentralManager.startScan(); |
|
|
|
mMtCentralManager.setMTCentralManagerListener(new MTCentralManagerListener() { |
|
|
|
@Override |
|
|
|
public void onScanedPeripheral(final List<MTPeripheral> peripherals) { |
|
|
|
Log.e("demo11", " " + peripherals.size()); |
|
|
|
mAdapter.setData(peripherals); |
|
|
|
System.out.println("Data set in the adapter"); |
|
|
|
} |
|
|
|
}); |
|
|
|
mAdapter.setOnItemClickListener(new RecycleAdapter.OnItemClickListener() { |
|
|
|
@Override |
|
|
|
public void onItemClick(View view, int position) { |
|
|
|
mtPeripheral = mAdapter.getData(position); |
|
|
|
System.out.println("Inside click listener of the adapter"); |
|
|
|
mMtCentralManager.connect(mtPeripheral, connectionStatueListener); |
|
|
|
} |
|
|
|
|
|
|
@ -432,9 +526,16 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
Log.e("tag", "COMPLETED"); |
|
|
|
Toast.makeText(MainActivity.this, "COMPLETED", Toast.LENGTH_SHORT).show(); |
|
|
|
mMtCentralManager.disconnect(mtPeripheral); |
|
|
|
// Intent intent = new Intent(); |
|
|
|
// intent.setClass(MainActivity.this, DetailActivity.class); |
|
|
|
// startActivity(intent); |
|
|
|
Intent intent = new Intent(); |
|
|
|
intent.setClass(MainActivity.this, DetailActivity.class); |
|
|
|
intent.putExtra("mac", mac); |
|
|
|
intent.putExtra("name", name); |
|
|
|
intent.putExtra("battery", battery); |
|
|
|
intent.putExtra("rssi", rssi); |
|
|
|
intent.putExtra("xaxis", xaxis); |
|
|
|
intent.putExtra("yaxis", yaxis); |
|
|
|
intent.putExtra("zaxis", zaxis); |
|
|
|
startActivity(intent); |
|
|
|
break; |
|
|
|
case CONNECTFAILED: |
|
|
|
case DISCONNECTED: |
|
|
|