bug修改
This commit is contained in:
parent
964760e69d
commit
f4f13c2ef8
|
|
@ -2,7 +2,7 @@
|
||||||
"formatVersion": 1,
|
"formatVersion": 1,
|
||||||
"database": {
|
"database": {
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"identityHash": "2cfc52157095ba7809e8f8e5ade25bac",
|
"identityHash": "579afa9522feaddfe81cdb2c30e2ab24",
|
||||||
"entities": [
|
"entities": [
|
||||||
{
|
{
|
||||||
"tableName": "user_info",
|
"tableName": "user_info",
|
||||||
|
|
@ -167,7 +167,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tableName": "device_info",
|
"tableName": "device_info",
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `deviceId` INTEGER, `deviceNo` TEXT, `canteenId` TEXT, `areaId` TEXT, `devicePwd` TEXT, `deviceType` TEXT, `deviceCategory` TEXT, `deviceSize` TEXT, `deviceName` TEXT, `deviceSn` TEXT, `subPlace` TEXT, `subPlaceName` TEXT, `deviceNetworkState` INTEGER, `deviceRepairPeriod` INTEGER, `deviceExtendInfo` TEXT, `delFlag` TEXT, `areaName` TEXT, `canteenName` TEXT, `ip` TEXT, `channel` TEXT)",
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `deviceId` TEXT, `deviceNo` TEXT, `canteenId` TEXT, `areaId` TEXT, `devicePwd` TEXT, `deviceType` TEXT, `deviceCategory` TEXT, `deviceSize` TEXT, `deviceName` TEXT, `deviceSn` TEXT, `subPlace` TEXT, `subPlaceName` TEXT, `deviceNetworkState` INTEGER, `deviceRepairPeriod` INTEGER, `deviceExtendInfo` TEXT, `delFlag` TEXT, `areaName` TEXT, `canteenName` TEXT, `ip` TEXT, `channel` TEXT)",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"fieldPath": "id",
|
"fieldPath": "id",
|
||||||
|
|
@ -178,7 +178,7 @@
|
||||||
{
|
{
|
||||||
"fieldPath": "deviceId",
|
"fieldPath": "deviceId",
|
||||||
"columnName": "deviceId",
|
"columnName": "deviceId",
|
||||||
"affinity": "INTEGER",
|
"affinity": "TEXT",
|
||||||
"notNull": false
|
"notNull": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -421,7 +421,7 @@
|
||||||
"views": [],
|
"views": [],
|
||||||
"setupQueries": [
|
"setupQueries": [
|
||||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '2cfc52157095ba7809e8f8e5ade25bac')"
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '579afa9522feaddfe81cdb2c30e2ab24')"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -17,10 +17,13 @@
|
||||||
|
|
||||||
package com.bonus.canteen.activity;
|
package com.bonus.canteen.activity;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
import android.serialport.SerialPort;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
@ -53,8 +56,15 @@ import com.xuexiang.xutil.common.ClickUtils;
|
||||||
import org.easydarwin.easypusher.R;
|
import org.easydarwin.easypusher.R;
|
||||||
import org.easydarwin.easypusher.databinding.ActivityMainBinding;
|
import org.easydarwin.easypusher.databinding.ActivityMainBinding;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
|
@ -65,6 +75,11 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> implements C
|
||||||
private final Handler mHandler = new Handler(Looper.getMainLooper());
|
private final Handler mHandler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
private final OkHttpService service = new OkHttpService();
|
private final OkHttpService service = new OkHttpService();
|
||||||
|
private SerialPort serialPort = null;
|
||||||
|
private OutputStream outputStream = null;
|
||||||
|
private InputStream inputStream = null;
|
||||||
|
private boolean isStopRead = false;
|
||||||
|
private static final String TAG = "MainActivity";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ActivityMainBinding viewBindingInflate(LayoutInflater inflater) {
|
protected ActivityMainBinding viewBindingInflate(LayoutInflater inflater) {
|
||||||
|
|
@ -78,7 +93,13 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> implements C
|
||||||
initView();
|
initView();
|
||||||
initTab();
|
initTab();
|
||||||
startUpdateTime();
|
startUpdateTime();
|
||||||
|
// 如果时间是00:00:00,更新日期和星期
|
||||||
|
binding.date.setText(DateTimeHelper.getNowDate());
|
||||||
|
//获取当前星期几
|
||||||
|
String week = DateTimeHelper.getWeekOfDate(new Date());
|
||||||
|
binding.week.setText(week);
|
||||||
binding.back.setOnClickListener(v -> updateView(1));
|
binding.back.setOnClickListener(v -> updateView(1));
|
||||||
|
initPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startUpdateTime() {
|
private void startUpdateTime() {
|
||||||
|
|
@ -213,7 +234,7 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> implements C
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
DeviceInfo deviceInfo = AppDatabase.getDatabase(this).deviceInfoDao().getDeviceInfoOne();
|
DeviceInfo deviceInfo = AppDatabase.getDatabase(this).deviceInfoDao().getDeviceInfoOne();
|
||||||
json.put("staffId", userInfo.getUserId());
|
json.put("staffId", userInfo.getUserId());
|
||||||
json.put("deviceId", deviceInfo.getDeviceId());
|
json.put("deviceId", deviceInfo != null ? deviceInfo.getDeviceId() : "-1");
|
||||||
json.put("temperatureValue", userInfo.getTemperature());
|
json.put("temperatureValue", userInfo.getTemperature());
|
||||||
json.put("recordTime", DateTimeHelper.getNowDate());
|
json.put("recordTime", DateTimeHelper.getNowDate());
|
||||||
json.put("faceCheckImg", userInfo.getFaceCheckImg());
|
json.put("faceCheckImg", userInfo.getFaceCheckImg());
|
||||||
|
|
@ -245,4 +266,104 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> implements C
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void initPort() {
|
||||||
|
try {
|
||||||
|
if (serialPort != null) {
|
||||||
|
serialPort.close();
|
||||||
|
}
|
||||||
|
serialPort = null;
|
||||||
|
outputStream = null;
|
||||||
|
inputStream = null;
|
||||||
|
serialPort = SerialPort.newBuilder(new File("/dev/ttyS2"), 115200)
|
||||||
|
.dataBits(8)
|
||||||
|
.stopBits(1)
|
||||||
|
.parity(0)
|
||||||
|
.build();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
outputStream = serialPort.getOutputStream();
|
||||||
|
inputStream = serialPort.getInputStream();
|
||||||
|
ThreadPoolManager.getExecutor().execute(this::readData);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void readData() {
|
||||||
|
isStopRead = false;
|
||||||
|
try {
|
||||||
|
if (inputStream != null) {
|
||||||
|
if (inputStream.available() > 0) {
|
||||||
|
inputStream.skip(inputStream.available());
|
||||||
|
}
|
||||||
|
while (!isStopRead) {
|
||||||
|
if (inputStream == null) {
|
||||||
|
Thread.sleep(200);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (inputStream.available() <= 0) {
|
||||||
|
Thread.sleep(200);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
byte[] tempBuffer = new byte[1024];
|
||||||
|
StringBuilder hexString = new StringBuilder();
|
||||||
|
int tempSize = inputStream.read(tempBuffer);
|
||||||
|
for (int i = 0; i < tempSize; i++) {
|
||||||
|
hexString.append(String.format("%02X ", tempBuffer[i]));
|
||||||
|
}
|
||||||
|
//开始为 5A 5AA
|
||||||
|
if (tempBuffer[0] != 0x5A && tempBuffer[1] != 0x5A) {
|
||||||
|
if (!isStopRead && !ThreadPoolManager.getExecutor().isShutdown()) {
|
||||||
|
ThreadPoolManager.getExecutor().execute(() -> parseTheData(hexString.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint({"SetTextI18n", "UseCompatLoadingForDrawables", "DefaultLocale"})
|
||||||
|
protected void parseTheData(String hex) {
|
||||||
|
byte[] byteArray = hexStringToByteArray(new StringBuilder(hex));
|
||||||
|
List<Integer> numList = new ArrayList<>();
|
||||||
|
for (int i = 0; i < byteArray.length / 2; i++) {
|
||||||
|
int value = byteArray[2 * i + 1] * 256 + (byteArray[2 * i] & 0xFF);
|
||||||
|
numList.add(value);
|
||||||
|
}
|
||||||
|
List<Double> pixelTempList = new ArrayList<>();
|
||||||
|
for (int i = 2; i < numList.size(); i++) {
|
||||||
|
pixelTempList.add(numList.get(i) / 100.0);
|
||||||
|
}
|
||||||
|
Double maxValue = pixelTempList.isEmpty() ? null : Collections.max(pixelTempList);
|
||||||
|
try {
|
||||||
|
pixelTempList.remove(0);
|
||||||
|
pixelTempList.remove(0);
|
||||||
|
if (maxValue < 36.5) {
|
||||||
|
maxValue = 36.5;
|
||||||
|
}
|
||||||
|
if (maxValue > 39.5) {
|
||||||
|
maxValue = 39.5;
|
||||||
|
}
|
||||||
|
Intent broad = new Intent();
|
||||||
|
broad.setAction("action.updateTemperatureUI");
|
||||||
|
broad.putExtra("temperature", maxValue + "");
|
||||||
|
sendBroadcast(broad);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "parseTheData: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public byte[] hexStringToByteArray(StringBuilder hexString) {
|
||||||
|
String[] hexArray = hexString.toString().trim().split("\\s+");
|
||||||
|
byte[] byteArray = new byte[hexArray.length];
|
||||||
|
for (int i = 0; i < hexArray.length; i++) {
|
||||||
|
byteArray[i] = (byte) Integer.parseInt(hexArray[i], 16);
|
||||||
|
}
|
||||||
|
return byteArray;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.viewbinding.ViewBinding;
|
import androidx.viewbinding.ViewBinding;
|
||||||
|
|
||||||
|
import com.bonus.canteen.fragment.StartFragment;
|
||||||
import com.xuexiang.xpage.base.XPageActivity;
|
import com.xuexiang.xpage.base.XPageActivity;
|
||||||
import com.xuexiang.xpage.base.XPageFragment;
|
import com.xuexiang.xpage.base.XPageFragment;
|
||||||
import com.xuexiang.xpage.core.CoreSwitchBean;
|
import com.xuexiang.xpage.core.CoreSwitchBean;
|
||||||
|
|
@ -141,6 +142,15 @@ public abstract class BaseActivity<Binding extends ViewBinding> extends XPageAct
|
||||||
public <T extends XPageFragment> T switchPage(Class<T> clazz) {
|
public <T extends XPageFragment> T switchPage(Class<T> clazz) {
|
||||||
return switchPage(clazz, null); // 重载到带Bundle的方法
|
return switchPage(clazz, null); // 重载到带Bundle的方法
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 切换fragment
|
||||||
|
*
|
||||||
|
* @param clazz 页面类
|
||||||
|
* @return 打开的fragment对象
|
||||||
|
*/
|
||||||
|
public <T extends XPageFragment> T switchPageNew(Class<T> clazz) {
|
||||||
|
return openPage(clazz, false);
|
||||||
|
}
|
||||||
public <T extends XPageFragment> T switchPage(Class<T> clazz, Bundle bundle) {
|
public <T extends XPageFragment> T switchPage(Class<T> clazz, Bundle bundle) {
|
||||||
// 1. 防抖检查
|
// 1. 防抖检查
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
|
|
@ -202,11 +212,6 @@ public abstract class BaseActivity<Binding extends ViewBinding> extends XPageAct
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// public <T extends XPageFragment> T switchPage(Class<T> clazz, Bundle bundle) {
|
|
||||||
// CoreSwitchBean page = new CoreSwitchBean(clazz)
|
|
||||||
// .setBundle(bundle);
|
|
||||||
// return (T) openPage(page);
|
|
||||||
// }
|
|
||||||
/**
|
/**
|
||||||
* 序列化对象
|
* 序列化对象
|
||||||
*
|
*
|
||||||
|
|
@ -253,4 +258,8 @@ public abstract class BaseActivity<Binding extends ViewBinding> extends XPageAct
|
||||||
return page == null || page.getBundle() == null || page.getBundle().getBoolean(KEY_SUPPORT_SLIDE_BACK, true);
|
return page == null || page.getBundle() == null || page.getBundle().getBoolean(KEY_SUPPORT_SLIDE_BACK, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void popToFragment(Class<StartFragment> startFragmentClass, boolean b) {
|
||||||
|
getSupportFragmentManager().popBackStackImmediate(startFragmentClass.getName(), b ? 0 : FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||||
|
switchPage(StartFragment.class,null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ public class DeviceInfo {
|
||||||
|
|
||||||
/** 设备id */
|
/** 设备id */
|
||||||
@ColumnInfo
|
@ColumnInfo
|
||||||
private Long deviceId;
|
private String deviceId;
|
||||||
|
|
||||||
/** 设备编号 */
|
/** 设备编号 */
|
||||||
@ColumnInfo
|
@ColumnInfo
|
||||||
|
|
@ -105,11 +105,11 @@ public class DeviceInfo {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getDeviceId() {
|
public String getDeviceId() {
|
||||||
return deviceId;
|
return deviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDeviceId(Long deviceId) {
|
public void setDeviceId(String deviceId) {
|
||||||
this.deviceId = deviceId;
|
this.deviceId = deviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,14 @@
|
||||||
package com.bonus.canteen.fragment;
|
package com.bonus.canteen.fragment;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.hardware.Camera;
|
import android.hardware.Camera;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.serialport.SerialPort;
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
@ -77,11 +81,7 @@ import org.easydarwin.easypusher.databinding.ActivityFaceBinding;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -101,11 +101,6 @@ import io.reactivex.schedulers.Schedulers;
|
||||||
public class FaceFragment extends BaseFragment<ActivityFaceBinding> {
|
public class FaceFragment extends BaseFragment<ActivityFaceBinding> {
|
||||||
private static final String TAG = "FaceFragment";
|
private static final String TAG = "FaceFragment";
|
||||||
private OkHttpService service = new OkHttpService();
|
private OkHttpService service = new OkHttpService();
|
||||||
private SerialPort serialPort = null;
|
|
||||||
private OutputStream outputStream = null;
|
|
||||||
private InputStream inputStream = null;
|
|
||||||
private boolean isStopRead = false;
|
|
||||||
|
|
||||||
private CameraHelper cameraHelper;
|
private CameraHelper cameraHelper;
|
||||||
private DrawHelper drawHelper;
|
private DrawHelper drawHelper;
|
||||||
private Camera.Size previewSize;
|
private Camera.Size previewSize;
|
||||||
|
|
@ -178,7 +173,7 @@ public class FaceFragment extends BaseFragment<ActivityFaceBinding> {
|
||||||
private FaceSearchResultAdapter adapter;
|
private FaceSearchResultAdapter adapter;
|
||||||
UserInfo userInfo = null;
|
UserInfo userInfo = null;
|
||||||
private boolean isStartUpload = false;
|
private boolean isStartUpload = false;
|
||||||
|
UpdateUIBroadcastReceiver broadcastReceiver;
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
protected ActivityFaceBinding viewBindingInflate(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, boolean attachToRoot) {
|
protected ActivityFaceBinding viewBindingInflate(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, boolean attachToRoot) {
|
||||||
|
|
@ -190,7 +185,7 @@ public class FaceFragment extends BaseFragment<ActivityFaceBinding> {
|
||||||
previewView = findViewById(R.id.texture_preview);
|
previewView = findViewById(R.id.texture_preview);
|
||||||
faceRectView = findViewById(R.id.face_rect_view);
|
faceRectView = findViewById(R.id.face_rect_view);
|
||||||
FrameLayout faceRectContainer = findViewById(R.id.face_rect_view_container);
|
FrameLayout faceRectContainer = findViewById(R.id.face_rect_view_container);
|
||||||
|
registerBroadcastReceiver();
|
||||||
// 设置为圆形
|
// 设置为圆形
|
||||||
faceRectContainer.setOutlineProvider(new ViewOutlineProvider() {
|
faceRectContainer.setOutlineProvider(new ViewOutlineProvider() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -211,15 +206,31 @@ public class FaceFragment extends BaseFragment<ActivityFaceBinding> {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "initView: 销毁失败 或者 无需销毁");
|
Log.e(TAG, "initView: 销毁失败 或者 无需销毁");
|
||||||
}
|
}
|
||||||
initPort();
|
|
||||||
initModular();
|
initModular();
|
||||||
initEngine();
|
new Handler().postDelayed(() -> {
|
||||||
initCamera();
|
initEngine();
|
||||||
|
initCamera();
|
||||||
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initModular() {
|
public void initModular() {
|
||||||
new Thread(this::activeFaceEngine).start();
|
new Thread(this::activeFaceEngine).start();
|
||||||
}
|
}
|
||||||
|
@SuppressLint("UnspecifiedRegisterReceiverFlag")
|
||||||
|
private void registerBroadcastReceiver() {
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction("action.updateTemperatureUI");
|
||||||
|
broadcastReceiver = new UpdateUIBroadcastReceiver();
|
||||||
|
getActivity().registerReceiver(broadcastReceiver, filter);
|
||||||
|
}
|
||||||
|
private class UpdateUIBroadcastReceiver extends BroadcastReceiver {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
Log.e(TAG, "接收到广播");
|
||||||
|
String temperature = intent.getStringExtra("temperature");
|
||||||
|
binding.celsius.setText(temperature);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String APP_ID;
|
public String APP_ID;
|
||||||
public String SDK_KEY;
|
public String SDK_KEY;
|
||||||
|
|
@ -470,88 +481,7 @@ public class FaceFragment extends BaseFragment<ActivityFaceBinding> {
|
||||||
cameraHelper.start();
|
cameraHelper.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initPort() {
|
|
||||||
try {
|
|
||||||
if (serialPort != null) {
|
|
||||||
serialPort.close();
|
|
||||||
}
|
|
||||||
serialPort = SerialPort.newBuilder(new File("/dev/ttyS2"), 115200)
|
|
||||||
.dataBits(8)
|
|
||||||
.stopBits(1)
|
|
||||||
.parity(0)
|
|
||||||
.build();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
outputStream = serialPort.getOutputStream();
|
|
||||||
inputStream = serialPort.getInputStream();
|
|
||||||
ThreadPoolManager.getExecutor().execute(this::readData);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void readData() {
|
|
||||||
isStopRead = false;
|
|
||||||
try {
|
|
||||||
if (inputStream != null) {
|
|
||||||
if (inputStream.available() > 0) {
|
|
||||||
inputStream.skip(inputStream.available());
|
|
||||||
}
|
|
||||||
while (!isStopRead) {
|
|
||||||
if (inputStream == null) {
|
|
||||||
Thread.sleep(200);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (inputStream.available() <= 0) {
|
|
||||||
Thread.sleep(200);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
byte[] tempBuffer = new byte[1024];
|
|
||||||
StringBuilder hexString = new StringBuilder();
|
|
||||||
int tempSize = inputStream.read(tempBuffer);
|
|
||||||
for (int i = 0; i < tempSize; i++) {
|
|
||||||
hexString.append(String.format("%02X ", tempBuffer[i]));
|
|
||||||
}
|
|
||||||
//开始为 5A 5AA
|
|
||||||
if (tempBuffer[0] != 0x5A && tempBuffer[1] != 0x5A) {
|
|
||||||
if (!isStopRead && !ThreadPoolManager.getExecutor().isShutdown()) {
|
|
||||||
ThreadPoolManager.getExecutor().execute(() -> parseTheData(hexString.toString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException | InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint({"SetTextI18n", "UseCompatLoadingForDrawables", "DefaultLocale"})
|
|
||||||
protected void parseTheData(String hex) {
|
|
||||||
byte[] byteArray = hexStringToByteArray(new StringBuilder(hex));
|
|
||||||
List<Integer> numList = new ArrayList<>();
|
|
||||||
for (int i = 0; i < byteArray.length / 2; i++) {
|
|
||||||
int value = byteArray[2 * i + 1] * 256 + (byteArray[2 * i] & 0xFF);
|
|
||||||
numList.add(value);
|
|
||||||
}
|
|
||||||
int sum = 0;
|
|
||||||
for (int num : numList) {
|
|
||||||
sum += num;
|
|
||||||
}
|
|
||||||
List<Double> pixelTempList = new ArrayList<>();
|
|
||||||
for (int i = 2; i < numList.size(); i++) {
|
|
||||||
pixelTempList.add(numList.get(i) / 100.0);
|
|
||||||
}
|
|
||||||
Double maxValue = pixelTempList.isEmpty() ? null : Collections.max((Collection<? extends Double>) pixelTempList);
|
|
||||||
try {
|
|
||||||
pixelTempList.remove(0);
|
|
||||||
pixelTempList.remove(0);
|
|
||||||
if (maxValue > 30.0 && maxValue < 42.0) {
|
|
||||||
binding.celsius.setText(String.format("%.1f", maxValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
}catch (Exception e) {
|
|
||||||
Log.e(TAG, "parseTheData: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将map中key对应的value增1回传
|
* 将map中key对应的value增1回传
|
||||||
|
|
@ -769,7 +699,7 @@ public class FaceFragment extends BaseFragment<ActivityFaceBinding> {
|
||||||
}
|
}
|
||||||
requestFeatureStatusMap.put(requestId, RequestFeatureStatus.SUCCEED);
|
requestFeatureStatusMap.put(requestId, RequestFeatureStatus.SUCCEED);
|
||||||
if (faceHelper != null) {
|
if (faceHelper != null) {
|
||||||
if (!isStartUpload){
|
if (!isStartUpload) {
|
||||||
isStartUpload = true;
|
isStartUpload = true;
|
||||||
ThreadPoolManager.getExecutor().execute(() -> {
|
ThreadPoolManager.getExecutor().execute(() -> {
|
||||||
userInfo = AppDatabase.getDatabase(requireContext()).userDao().getUserInfoById(compareResult.getCustId());
|
userInfo = AppDatabase.getDatabase(requireContext()).userDao().getUserInfoById(compareResult.getCustId());
|
||||||
|
|
@ -778,10 +708,9 @@ public class FaceFragment extends BaseFragment<ActivityFaceBinding> {
|
||||||
requireActivity().runOnUiThread(() -> {
|
requireActivity().runOnUiThread(() -> {
|
||||||
binding.code.setText(userInfo.getAccId());
|
binding.code.setText(userInfo.getAccId());
|
||||||
binding.name.setText(userInfo.getUserName());
|
binding.name.setText(userInfo.getUserName());
|
||||||
binding.sex.setText(userInfo.getLoginType());
|
binding.sex.setText(userInfo.getLoginType().equals("0") ? "男" : "女");
|
||||||
binding.phone.setText(userInfo.getPhone());
|
binding.phone.setText(userInfo.getPhone());
|
||||||
binding.postName.setText(userInfo.getNickName());
|
binding.postName.setText(userInfo.getNickName());
|
||||||
//上传脸部照片
|
|
||||||
uploadFaceImage();
|
uploadFaceImage();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -811,7 +740,7 @@ public class FaceFragment extends BaseFragment<ActivityFaceBinding> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void uploadFaceImage(){
|
private void uploadFaceImage() {
|
||||||
Log.e(TAG, "uploadFaceImage: 开始上传人脸照片");
|
Log.e(TAG, "uploadFaceImage: 开始上传人脸照片");
|
||||||
//执行拍照并上传
|
//执行拍照并上传
|
||||||
if (cameraHelper != null) {
|
if (cameraHelper != null) {
|
||||||
|
|
@ -836,6 +765,7 @@ public class FaceFragment extends BaseFragment<ActivityFaceBinding> {
|
||||||
// 拍照完成后,继续预览,保持相机活性
|
// 拍照完成后,继续预览,保持相机活性
|
||||||
cameraHelper.start();
|
cameraHelper.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTakePictureFailed(Exception e) {
|
public void onTakePictureFailed(Exception e) {
|
||||||
Log.e(TAG, "拍照失败: " + e.getMessage());
|
Log.e(TAG, "拍照失败: " + e.getMessage());
|
||||||
|
|
@ -844,10 +774,11 @@ public class FaceFragment extends BaseFragment<ActivityFaceBinding> {
|
||||||
cameraHelper.start();
|
cameraHelper.start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}else{
|
} else {
|
||||||
isStartUpload = false;
|
isStartUpload = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传照片
|
* 上传照片
|
||||||
* 使用OkHttpService上传图片到服务器
|
* 使用OkHttpService上传图片到服务器
|
||||||
|
|
@ -879,14 +810,14 @@ public class FaceFragment extends BaseFragment<ActivityFaceBinding> {
|
||||||
if (photoResponse == null) {
|
if (photoResponse == null) {
|
||||||
isStartUpload = false;
|
isStartUpload = false;
|
||||||
requireActivity().runOnUiThread(() -> XToastUtils.error("图片上传失败,请重试!"));
|
requireActivity().runOnUiThread(() -> XToastUtils.error("图片上传失败,请重试!"));
|
||||||
}else{
|
} else {
|
||||||
Log.e(TAG, "上传图片成功: " + photoResponse.getUrl());
|
Log.e(TAG, "上传图片成功: " + photoResponse.getUrl());
|
||||||
// 更新用户信息中的头像URL
|
// 更新用户信息中的头像URL
|
||||||
if (userInfo != null) {
|
if (userInfo != null) {
|
||||||
userInfo.setFaceCheckImg(photoResponse.getUrl());
|
userInfo.setFaceCheckImg(photoResponse.getUrl());
|
||||||
userInfo.setTemperature(binding.celsius.getText().toString());
|
userInfo.setTemperature(binding.celsius.getText().toString());
|
||||||
((MainActivity)getActivity()).updateUserInfo(userInfo);
|
((MainActivity) getActivity()).updateUserInfo(userInfo);
|
||||||
((MainActivity)getActivity()).updateView(3);
|
binding.getRoot().postDelayed(() -> ((MainActivity) getActivity()).updateView(3), 1000);
|
||||||
Log.e(TAG, "更新用户信息中的脸部照片: " + userInfo.getFaceCheckImg());
|
Log.e(TAG, "更新用户信息中的脸部照片: " + userInfo.getFaceCheckImg());
|
||||||
} else {
|
} else {
|
||||||
isStartUpload = false;
|
isStartUpload = false;
|
||||||
|
|
@ -903,14 +834,6 @@ public class FaceFragment extends BaseFragment<ActivityFaceBinding> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public byte[] hexStringToByteArray(StringBuilder hexString) {
|
|
||||||
String[] hexArray = hexString.toString().trim().split("\\s+");
|
|
||||||
byte[] byteArray = new byte[hexArray.length];
|
|
||||||
for (int i = 0; i < hexArray.length; i++) {
|
|
||||||
byteArray[i] = (byte) Integer.parseInt(hexArray[i], 16);
|
|
||||||
}
|
|
||||||
return byteArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initListeners() {
|
protected void initListeners() {
|
||||||
|
|
@ -919,7 +842,7 @@ public class FaceFragment extends BaseFragment<ActivityFaceBinding> {
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
isStopRead = true;
|
getActivity().unregisterReceiver(broadcastReceiver);
|
||||||
if (cameraHelper != null) {
|
if (cameraHelper != null) {
|
||||||
cameraHelper.release();
|
cameraHelper.release();
|
||||||
cameraHelper = null;
|
cameraHelper = null;
|
||||||
|
|
@ -936,26 +859,6 @@ public class FaceFragment extends BaseFragment<ActivityFaceBinding> {
|
||||||
flEngine.unInit();
|
flEngine.unInit();
|
||||||
flEngine = null;
|
flEngine = null;
|
||||||
}
|
}
|
||||||
// if (serialPort != null) {
|
|
||||||
// serialPort.close();
|
|
||||||
// serialPort = null;
|
|
||||||
// }
|
|
||||||
if (outputStream != null) {
|
|
||||||
try {
|
|
||||||
outputStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "Error closing output stream: " + e.getMessage());
|
|
||||||
}
|
|
||||||
outputStream = null;
|
|
||||||
}
|
|
||||||
if (inputStream != null) {
|
|
||||||
try {
|
|
||||||
inputStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "Error closing input stream: " + e.getMessage());
|
|
||||||
}
|
|
||||||
inputStream = null;
|
|
||||||
}
|
|
||||||
if (delayFaceTaskCompositeDisposable != null && !delayFaceTaskCompositeDisposable.isDisposed()) {
|
if (delayFaceTaskCompositeDisposable != null && !delayFaceTaskCompositeDisposable.isDisposed()) {
|
||||||
delayFaceTaskCompositeDisposable.clear();
|
delayFaceTaskCompositeDisposable.clear();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -170,6 +170,7 @@ public class UpdateBasicData {
|
||||||
public ResponseVo getDeviceBase() {
|
public ResponseVo getDeviceBase() {
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("deviceSn", AppUtil.getSn(context));
|
json.put("deviceSn", AppUtil.getSn(context));
|
||||||
|
Log.e(TAG, "getDeviceBase AppUtil.getSn(context): " + AppUtil.getSn(context));
|
||||||
String jsonString = json.toString();
|
String jsonString = json.toString();
|
||||||
MediaType mediaType = MediaType.parse(MEDIA_TYPE);
|
MediaType mediaType = MediaType.parse(MEDIA_TYPE);
|
||||||
// 创建 RequestBody
|
// 创建 RequestBody
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -152,18 +152,19 @@
|
||||||
android:id="@+id/celsius"
|
android:id="@+id/celsius"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="00.0"
|
android:text="30.0"
|
||||||
android:layout_gravity="end"
|
android:layout_gravity="end"
|
||||||
android:layout_marginEnd="25dp"
|
android:layout_marginEnd="25dp"
|
||||||
android:textColor="#4C81F4"
|
android:textColor="#4C81F4"
|
||||||
android:textFontWeight="1000"
|
android:textFontWeight="1000"
|
||||||
android:textSize="25sp" />
|
android:textSize="25sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="℃"
|
|
||||||
android:layout_gravity="end"
|
android:layout_gravity="end"
|
||||||
android:textColor="#606060"
|
android:text="℃"
|
||||||
|
android:textColor="#4C81F4"
|
||||||
android:textFontWeight="1000"
|
android:textFontWeight="1000"
|
||||||
android:textSize="25sp" />
|
android:textSize="25sp" />
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,16 +22,16 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="30dp"
|
android:layout_marginTop="20dp"
|
||||||
android:text="欢迎登录"
|
android:text="欢迎登录"
|
||||||
|
android:fontFamily="@font/source_han_sans_cn_bold"
|
||||||
android:textColor="#333333"
|
android:textColor="#333333"
|
||||||
android:textFontWeight="1000"
|
|
||||||
android:textSize="35sp" />
|
android:textSize="35sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="32dp"
|
android:layout_marginTop="22dp"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
android:text="welcome to login in"
|
android:text="welcome to login in"
|
||||||
android:textColor="#AFAFAF"
|
android:textColor="#AFAFAF"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue