Commit 39e4fbdc by onuma

Bluetooth未接続時に、フォームから作業一覧に戻る時にスキャンを停止するように修正した

parent c074517c
...@@ -1438,5 +1438,6 @@ ...@@ -1438,5 +1438,6 @@
<string name="msg_no_nfc_setting">端末の設定からNFCを有効にする必要があります。\n端末の設定画面へ遷移しますか?</string> <string name="msg_no_nfc_setting">端末の設定からNFCを有効にする必要があります。\n端末の設定画面へ遷移しますか?</string>
<string name="select_spp_device_title">シリアル通信機器選択</string> <string name="select_spp_device_title">シリアル通信機器選択</string>
<string name="msg_bluetooth_connect_timeout_error">%1$s with the central thermometer has been lost. Check the power and distance of %1$s and try again.(%2$s)</string> <string name="msg_bluetooth_connect_timeout_error">%1$s with the central thermometer has been lost. Check the power and distance of %1$s and try again.(%2$s)</string>
<string name="tr41_thermometer">TR41温度センサー</string>
</resources> </resources>
\ No newline at end of file
...@@ -326,6 +326,18 @@ public class BleManagerUtil { ...@@ -326,6 +326,18 @@ public class BleManagerUtil {
// 切断 // 切断
public void disconnect(boolean listenerFlg) { public void disconnect(boolean listenerFlg) {
// 接続されていない。検索中の場合はスキャン停止
if (listenerFlg) {
runOnUiThread( new Runnable() {
@Override
public void run() {
// スキャン停止
mHandler.removeCallbacksAndMessages(null);
mBluetoothAdapter.getBluetoothLeScanner().stopScan(mScanCallback);
}
});
}
if(mBluetoothGatt == null) { if(mBluetoothGatt == null) {
return; return;
} }
...@@ -339,6 +351,7 @@ public class BleManagerUtil { ...@@ -339,6 +351,7 @@ public class BleManagerUtil {
mBluetoothGatt.disconnect(); mBluetoothGatt.disconnect();
// mBluetoothGatt.close(); // mBluetoothGatt.close();
mBluetoothGatt = null; mBluetoothGatt = null;
/**
if (listenerFlg) { if (listenerFlg) {
runOnUiThread( new Runnable() { runOnUiThread( new Runnable() {
@Override @Override
...@@ -348,6 +361,7 @@ public class BleManagerUtil { ...@@ -348,6 +361,7 @@ public class BleManagerUtil {
} }
}); });
} }
*/
} }
// キャラクタリスティックの読み込み // キャラクタリスティックの読み込み
......
...@@ -62,15 +62,10 @@ public class TR41BluetoothUtil { ...@@ -62,15 +62,10 @@ public class TR41BluetoothUtil {
* *
*/ */
public interface TR41BluetoothUtilLeScanner { public interface TR41BluetoothUtilLeScanner {
//void onGetDeviceInfo(String strTemperature); // ディバイスから渡す情報 //void onBatchScanResults(List<ScanResult> results);
//void onGetDeviceInfoFailed(int status); // ディバイスと接続失敗時の情報渡す。
//void onConnectionState(); // ディバイスと接続された時情報渡す。
//void onDisConnectionState(); // ディバイスと切断時
//void onConnectionError(int status); // ディバイス接続エラー
void onBatchScanResults(List<ScanResult> results);
void onScanFailed(int errorCode); void onScanFailed(int errorCode);
void onScanResult(int callbackType, ScanResult result); //void onScanResult(int callbackType, ScanResult result);
void onScanResult(String strTemperature); // デバイスから温度を渡す
} }
public TR41BluetoothUtil(Context context, TR41BluetoothUtilLeScanner listener) public TR41BluetoothUtil(Context context, TR41BluetoothUtilLeScanner listener)
...@@ -108,7 +103,7 @@ public class TR41BluetoothUtil { ...@@ -108,7 +103,7 @@ public class TR41BluetoothUtil {
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
/** BLE機器を検索する */ /** BLE機器を検索する */
private void Sb_Scan() public void Sb_StartScan()
{ {
Sb_Init_Ble_Scan() ; Sb_Init_Ble_Scan() ;
...@@ -131,6 +126,11 @@ public class TR41BluetoothUtil { ...@@ -131,6 +126,11 @@ public class TR41BluetoothUtil {
}, SCAN_PERIOD ); }, SCAN_PERIOD );
} }
public void Sb_StopScan()
{
mBluetoothLeScanner.stopScan(mScanCallback) ;
}
private ScanCallback mScanCallback = new ScanCallback() private ScanCallback mScanCallback = new ScanCallback()
{ {
@Override @Override
...@@ -140,12 +140,14 @@ public class TR41BluetoothUtil { ...@@ -140,12 +140,14 @@ public class TR41BluetoothUtil {
@Override @Override
public void onBatchScanResults(final List<ScanResult> results) { public void onBatchScanResults(final List<ScanResult> results) {
Logger.d(TAG, "onBatchScanResults"); Logger.d(TAG, "onBatchScanResults");
/**
runOnUiThread( new Runnable() { runOnUiThread( new Runnable() {
@Override @Override
public void run() { public void run() {
mListener.onBatchScanResults(results); mListener.onBatchScanResults(results);
} }
}); });
*/
}; };
@Override @Override
...@@ -160,12 +162,10 @@ public class TR41BluetoothUtil { ...@@ -160,12 +162,10 @@ public class TR41BluetoothUtil {
}; };
@Override @Override
public void onScanResult(final int callbackType, final ScanResult result) { public void onScanResult(int callbackType, ScanResult result) {
Logger.d(TAG, "onScanResult");
BluetoothDevice device = result.getDevice() ; BluetoothDevice device = result.getDevice() ;
byte[] scanRecord = result.getScanRecord().getBytes() ; byte[] scanRecord = result.getScanRecord().getBytes() ;
Logger.d("","getBoundState = " + device.getBondState());
if (device.getBondState() != BluetoothDevice.BOND_BONDED) { if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
long serial[] = new long[1] ; long serial[] = new long[1] ;
int security[] = new int[1] ; int security[] = new int[1] ;
...@@ -173,7 +173,6 @@ public class TR41BluetoothUtil { ...@@ -173,7 +173,6 @@ public class TR41BluetoothUtil {
int ch2Data[] = new int[1] ; int ch2Data[] = new int[1] ;
int batLevel[] = new int[1] ; int batLevel[] = new int[1] ;
StringBuffer localName = new StringBuffer() ; StringBuffer localName = new StringBuffer() ;
//int found ;
int rtn ; int rtn ;
String devName = device.getName() ; String devName = device.getName() ;
...@@ -182,43 +181,29 @@ public class TR41BluetoothUtil { ...@@ -182,43 +181,29 @@ public class TR41BluetoothUtil {
return; return;
} }
// 近くにあるTR4だけを検索したい場合 // 近くにあるTR4だけを検索したい場合( getRssiは、電波強度を返す。dBm マイナスが小さいほど電波が強い)
//if(result.getRssi() < -50) //if(result.getRssi() < -50)
// return ; // return ;
rtn = Sb_Parse_ScanRecord(scanRecord, serial, localName, security, ch1Data, ch2Data, batLevel) ; rtn = Sb_Parse_ScanRecord(scanRecord, serial, localName, security, ch1Data, ch2Data, batLevel) ;
if(rtn == 0) { if(rtn == 0) {
devName = localName.toString().trim() ; devName = localName.toString().trim() ;
// すでに登録されたシリアル番号を調べる
//found = 0 ;
/**
for(int i=0; i< mDeviceList.getCount(); i++) {
Logger.d("","" + mDeviceList.infoList.get(i).getSerial());
if(mDeviceList.infoList.get(i).getSerial() == serial[0]) {
found = 1 ;
break ;
}
}
if(found == 0) {
mDeviceList.addDeviceInfo(serial[0], devName, device.getAddress(),
device, ch1Data[0], mScanTime/1000);
mListView.setAdapter(mDeviceList) ; final String ch1Str ;
mDeviceList.notifyDataSetChanged() ; if(ch1Data[0] == 0xEEEE)
ch1Str = "----" ;
else if(ch1Data[0] == 0xEEE0)
ch1Str = "" ;
else
ch1Str = String.format("%.1f", (double)(ch1Data[0]-1000)/10.0) ;
//mScanStop.cancel();
//mScanStop = null;
//mBluetoothLeScanner.stopScan(mScanCallback) ;
}
*/
runOnUiThread( new Runnable() { runOnUiThread( new Runnable() {
@Override @Override
public void run() { public void run() {
mListener.onScanResult(callbackType, result); mListener.onScanResult(ch1Str);
} }
}); });
mBluetoothLeScanner.stopScan(mScanCallback) ; //mBluetoothLeScanner.stopScan(mScanCallback) ;
} }
} }
}; };
...@@ -426,51 +411,4 @@ public class TR41BluetoothUtil { ...@@ -426,51 +411,4 @@ public class TR41BluetoothUtil {
return retStr ; return retStr ;
} }
//デバイスの名前とアドレスを持つクラス
private class DeviceInfo {
private long serial ;
private String name ;
private String address;
private BluetoothDevice bltDevice ;
private int ch1Data ;
private long dataTime ;
private long rssi;
private DeviceInfo(long serial, String name, String address, BluetoothDevice bltDevice,
int ch1Data, long dataTime, long rssi)
{
this.serial = serial ;
this.name = name ;
this.address = address ;
this.bltDevice = bltDevice ;
this.ch1Data = ch1Data ;
this.dataTime = dataTime ;
this.rssi = rssi;
}
private long getSerial() {
return serial ;
}
private String getName() {
return (name) + " " + rssi ;
}
private String getAddress() {
return address ;
}
private BluetoothDevice getBluetoothDevice() {
return bltDevice ;
}
private int getCh1Data() {
return ch1Data ;
}
private long getDataTime() {
return dataTime ;
}
}
} }
\ No newline at end of file
...@@ -991,6 +991,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -991,6 +991,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
if (StringUtil.equalsAny(mCmd,ABookKeys.CMD_INSERT_TASK_REPORT, ABookKeys.CMD_UPDATE_TASK_REPORT, if (StringUtil.equalsAny(mCmd,ABookKeys.CMD_INSERT_TASK_REPORT, ABookKeys.CMD_UPDATE_TASK_REPORT,
ABookKeys.CMD_DELETE_TASK_REPORT , ABookKeys.CMD_CANCEL_TASK_REPORT) ABookKeys.CMD_DELETE_TASK_REPORT , ABookKeys.CMD_CANCEL_TASK_REPORT)
){ ){
// 作業一覧に戻る時
disconnectBluetoothDevice(); disconnectBluetoothDevice();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment