Commit c074517c by onuma

RT41 温度計の情報を格納するクラスを追加

parent 0e7bcc1e
package jp.agentec.abook.abv.bl.dto;
/**
* RT41 bluetooth 温度計デバイスの名前とアドレスを持つクラス
* @author onuma
*/
public class RT41DeviceDto {
public long serial ;
public String name ;
public String address;
//private BluetoothDevice bltDevice ;
public int ch1Data ;
public long dataTime ;
public long rssi;
// private DeviceInfo(long serial, String name, String address, BluetoothDevice bltDevice,
// int ch1Data, long dataTime, long rssi)
public RT41DeviceDto(long serial, String name, String address,
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;
}
/**
public long getSerial() {
return serial ;
}
public String getName() {
return (name) + " " + rssi ;
}
public String getAddress() {
return address ;
}
private BluetoothDevice getBluetoothDevice() {
return bltDevice ;
}
public int getCh1Data() {
return ch1Data ;
}
public long getDataTime() {
return dataTime ;
}
*/
}
......@@ -41,6 +41,7 @@ import java.util.TimerTask;
import jp.agentec.abook.abv.bl.common.log.Logger;
import static android.bluetooth.le.ScanSettings.SCAN_MODE_LOW_LATENCY;
import static org.chromium.base.ThreadUtils.runOnUiThread;
public class TR41BluetoothUtil {
......@@ -61,11 +62,11 @@ public class TR41BluetoothUtil {
*
*/
public interface TR41BluetoothUtilLeScanner {
void onGetDeviceInfo(String strTemperature); // ディバイスから渡す情報
void onGetDeviceInfoFailed(int status); // ディバイスと接続失敗時の情報渡す。
void onConnectionState(); // ディバイスと接続された時情報渡す。
void onDisConnectionState(); // ディバイスと切断時
void onConnectionError(int status); // ディバイス接続エラー
//void onGetDeviceInfo(String strTemperature); // ディバイスから渡す情報
//void onGetDeviceInfoFailed(int status); // ディバイスと接続失敗時の情報渡す。
//void onConnectionState(); // ディバイスと接続された時情報渡す。
//void onDisConnectionState(); // ディバイスと切断時
//void onConnectionError(int status); // ディバイス接続エラー
void onBatchScanResults(List<ScanResult> results);
void onScanFailed(int errorCode);
......@@ -87,30 +88,19 @@ public class TR41BluetoothUtil {
// ************************************************************************
private void Sb_Init_Ble_Scan()
{
if(mBluetoothAdapter != null)
return ;
if(mBluetoothAdapter != null){
return;
}
//BluetoothAdapter取得
BluetoothAdapter btAdpt = BluetoothAdapter.getDefaultAdapter() ;
if(!btAdpt.equals(null)) {
// Bluetooth対応端末の場合
}else {
// Bluetooth非対応端末の場合
//finish() ;
}
boolean btEnable = btAdpt.isEnabled() ;
if(btEnable == true) {
// boolean btEnable = btAdpt.isEnabled() ;
// if(btEnable == true) {
// Bluetoothアダプタ作成
mBluetoothManager = (BluetoothManager) mContext.getSystemService( Context.BLUETOOTH_SERVICE );
mBluetoothAdapter = mBluetoothManager.getAdapter() ;
mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner() ;
}
else {
// BluetoothがOFFだった場合、ONにすることを促すダイアログを表示
//Intent btOn = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE) ;
//startActivityForResult(btOn, 1) ;
}
// }
}
///////////////////////////////////////////////////////////////////////////////////////////////
......@@ -148,16 +138,29 @@ public class TR41BluetoothUtil {
return super.clone();
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
public void onBatchScanResults(final List<ScanResult> results) {
Logger.d(TAG, "onBatchScanResults");
runOnUiThread( new Runnable() {
@Override
public void run() {
mListener.onBatchScanResults(results);
}
});
};
@Override
public void onScanFailed(int errorCode) {
public void onScanFailed(final int errorCode) {
Logger.d(TAG, "onScanFailed");
runOnUiThread( new Runnable() {
@Override
public void run() {
mListener.onScanFailed(errorCode);
}
});
};
@Override
public void onScanResult(int callbackType, ScanResult result) {
public void onScanResult(final int callbackType, final ScanResult result) {
Logger.d(TAG, "onScanResult");
BluetoothDevice device = result.getDevice() ;
byte[] scanRecord = result.getScanRecord().getBytes() ;
......@@ -209,6 +212,12 @@ public class TR41BluetoothUtil {
//mBluetoothLeScanner.stopScan(mScanCallback) ;
}
*/
runOnUiThread( new Runnable() {
@Override
public void run() {
mListener.onScanResult(callbackType, result);
}
});
mBluetoothLeScanner.stopScan(mScanCallback) ;
}
}
......@@ -417,4 +426,51 @@ public class TR41BluetoothUtil {
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
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