From d3d3b3b33c0271a4eb3e827d522e17ca11e91b25 Mon Sep 17 00:00:00 2001 From: Krish Date: Mon, 24 Apr 2023 21:05:52 +0530 Subject: [PATCH] fetching 6 axis sensor data --- .../beacondemo/Activity/DetailActivity.java | 102 +++++++++++------- app/src/main/res/drawable/mybutton.xml | 5 + 2 files changed, 71 insertions(+), 36 deletions(-) create mode 100644 app/src/main/res/drawable/mybutton.xml diff --git a/app/src/main/java/com/example/beacondemo/Activity/DetailActivity.java b/app/src/main/java/com/example/beacondemo/Activity/DetailActivity.java index 0018877..30a95e8 100644 --- a/app/src/main/java/com/example/beacondemo/Activity/DetailActivity.java +++ b/app/src/main/java/com/example/beacondemo/Activity/DetailActivity.java @@ -29,6 +29,7 @@ import com.minew.beaconplus.sdk.MTConnectionFeature; import com.minew.beaconplus.sdk.MTConnectionHandler; import com.minew.beaconplus.sdk.MTFrameHandler; import com.minew.beaconplus.sdk.MTPeripheral; +import com.minew.beaconplus.sdk.Utils.Tools; import com.minew.beaconplus.sdk.enums.ConnectState; import com.minew.beaconplus.sdk.enums.FeatureSupported; import com.minew.beaconplus.sdk.enums.FrameType; @@ -52,7 +53,12 @@ import com.minew.beaconplus.sdk.frames.TvocFrame; import com.minew.beaconplus.sdk.frames.UidFrame; import com.minew.beaconplus.sdk.frames.UrlFrame; import com.minew.beaconplus.sdk.interfaces.MTCentralManagerListener; +import com.minew.beaconplus.sdk.interfaces.MTSensorOperateCallback; import com.minew.beaconplus.sdk.interfaces.SetTriggerListener; +import com.minew.beaconplus.sdk.model.SensorAPModel; +import com.minew.beaconplus.sdk.model.SensorHTModel; +import com.minew.beaconplus.sdk.model.SensorMAGModel; +import com.minew.beaconplus.sdk.model.SensorSixAxisModel; import com.minew.beaconplus.sdk.model.Trigger; import java.util.ArrayList; @@ -97,13 +103,10 @@ public class DetailActivity extends AppCompatActivity implements View.OnClickLis sharedPreferences = getSharedPreferences(SHARED_PREF_NAME,MODE_PRIVATE); - - initView(); initData(); initListener(); - tv_resetPass.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -207,6 +210,9 @@ public class DetailActivity extends AppCompatActivity implements View.OnClickLis mRecycle.setAdapter(mAdapter); } + long longtime = System.currentTimeMillis(); + int time = (int) (longtime / 1000); + byte[] curTime = Tools.intToBytes(time); private void initData() { mtPeripheral = MainActivity.mtPeripheral; @@ -376,40 +382,63 @@ public class DetailActivity extends AppCompatActivity implements View.OnClickLis } }); - /*MTConnectionHandler mtConnectionHandler = mtPeripheral.mMTConnectionHandler; - ConnectState connectState = mtConnectionHandler.getConnectState(); - // password require or not. None, Require - PasswordState passwordState = mMTConnectionHandler.getPasswordState(); - // device info, such as:(Firmware Version: 0.9.1); - HashMap systeminfos = (HashMap) mMTConnectionHandler.systeminfos; - String manufacturer = systeminfos.get(SyncStateContract.Constants.manufacturer); - String modlenumber = systeminfos.get(Constants.modlenumber); - String macAddress = systeminfos.get(Constants.serialnumber); - String hardware = systeminfos.get(Constants.hardware); - String firmware = systeminfos.get(Constants.firmware); - String software = systeminfos.get(Constants.software);*/ - - // device features - /*MTConnectionFeature mtConnectionFeature = mMTConnectionHandler.mTConnectionFeature; - // atitude of slot(s), - int slotAtitude = mtConnectionFeature.getSlotAtitude(); - Log.d("slotAtitude", String.valueOf(slotAtitude)); - // parameters can be modified:none,adv,txpower,adv/txpower - FeatureSupported featureSupported = mtConnectionFeature.getFeatureSupported(); - Log.d("featureSupported", String.valueOf(featureSupported)); - // // frames supported(multiple) - List supportedSlots = mtConnectionFeature.getSupportedSlots(); - Log.d("supportedSlots", String.valueOf(supportedSlots)); - // Txpower supported(multiple) - byte[] supportedTxpowers = mtConnectionFeature.getSupportedTxpowers(); - Log.d("supportedTxpowers", String.valueOf(supportedTxpowers)); - // trigger supported(multiple) - ArrayList supportTriggers = (ArrayList) mtConnectionFeature.supportTriggers; - Log.d("supportTriggers", String.valueOf(supportTriggers)); - // Version of firmware; - Version version = mtConnectionFeature.getVersion(); - Log.d("version", String.valueOf(version));*/ + + + + + // Six-axis sensor data from the device + + // Sensor data from the magnetometer on the device + magnetometer(); + // From the atmospheric pressure sensor data on the device + atmosphesricPressure(); + } + + public void sensorData(){ + mMTConnectionHandler.getMtSensorHandler().readLSMHistory(Tools.intToBytes(time), + (MTSensorOperateCallback) sensorSixAxisModel -> { + int date = sensorSixAxisModel.getDate();// Unix timestamp of this data; + System.out.println("Date: " + date); + double A_XAxis = sensorSixAxisModel.getA_XAxis(); + double A_YAxis = sensorSixAxisModel.getA_YAxis(); + double A_ZAxis = sensorSixAxisModel.getA_ZAxis(); + double D_XAxis = sensorSixAxisModel.getD_XAxis(); + double D_YAxis = sensorSixAxisModel.getD_YAxis(); + double D_ZAxis = sensorSixAxisModel.getD_ZAxis(); + + System.out.println("Six axis sensor data: " + A_XAxis + " " + A_YAxis + " " + A_ZAxis + " " + D_XAxis + " " + D_YAxis + " " + D_ZAxis); + + }); + } + public void magnetometer(){ + mMTConnectionHandler.getMtSensorHandler().readLISHistory(Tools.intToBytes(time), + new MTSensorOperateCallback() { + @Override + public void onResult(SensorMAGModel sensorMAGModel) { + int date = sensorMAGModel.getDate();// Unix timestamp of this data; + double A_XAxis = sensorMAGModel.getXAxis(); + double A_YAxis = sensorMAGModel.getYAxis(); + double A_ZAxis = sensorMAGModel.getZAxis(); + System.out.println("Data from magnetometer: " + A_XAxis + " " + A_YAxis + " " + A_ZAxis) ; + } + }); + } + public void atmosphesricPressure(){ + + mMTConnectionHandler.getMtSensorHandler().readDPSHistory(Tools.intToBytes(time), + new MTSensorOperateCallback() { + @Override + public void onResult(SensorAPModel sensorAPModel) { + int date = sensorAPModel.getDate();// Unix timestamp of this data; + double pressure = sensorAPModel.getPressure(); + System.out.println("Pressure: " +pressure) ; + } + }); + + } + + private void initListener() { ivBack.setOnClickListener(this); @@ -473,6 +502,7 @@ public class DetailActivity extends AppCompatActivity implements View.OnClickLis finish(); break; case R.id.tv_set: + sensorData(); //saveTrigger(); break; default: diff --git a/app/src/main/res/drawable/mybutton.xml b/app/src/main/res/drawable/mybutton.xml new file mode 100644 index 0000000..578de4d --- /dev/null +++ b/app/src/main/res/drawable/mybutton.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file