优化代码

serial
BlueMatthew 1 year ago
parent 71418a7e27
commit 022c755b93

@ -191,6 +191,11 @@ int NdkCamera::open(const std::string& cameraId) {
}
}
{
ACameraMetadata_const_entry e = {0};
camera_status_t status = ACameraMetadata_getConstEntry(camera_metadata,ACAMERA_LENS_INFO_MINIMUM_FOCUS_DISTANCE, &e);
}
{
ACameraMetadata_const_entry e = {0};
camera_status_t status = ACameraMetadata_getConstEntry(camera_metadata,ACAMERA_CONTROL_AF_AVAILABLE_MODES, &e);
@ -288,7 +293,7 @@ int NdkCamera::open(const std::string& cameraId) {
// TODO: PATCH!!!!
if (camera_id == "0")
{
afSupported = true;
// afSupported = true;
}
if (camera_id == "1")
{
@ -366,11 +371,17 @@ int NdkCamera::open(const std::string& cameraId) {
if (afSupported && m_params.autoFocus) {
// uint8_t afMode = ACAMERA_CONTROL_AF_MODE_CONTINUOUS_VIDEO;
uint8_t afMode = ACAMERA_CONTROL_AF_MODE_CONTINUOUS_PICTURE;
// uint8_t afMode = ACAMERA_CONTROL_AF_MODE_CONTINUOUS_PICTURE;
uint8_t afMode = ACAMERA_CONTROL_AF_MODE_AUTO;
res = ACaptureRequest_setEntry_u8(capture_request, ACAMERA_CONTROL_AF_MODE, 1, &afMode);
uint8_t trig = ACAMERA_CONTROL_AF_TRIGGER_START;
res = ACaptureRequest_setEntry_u8(capture_request, ACAMERA_CONTROL_AF_TRIGGER, 1, &trig);
m_imagesCaptured = (res == ACAMERA_OK) ? ~0 : 0;
}
else
{
m_imagesCaptured = 0;
}
uint8_t awbMode = ACAMERA_CONTROL_AWB_MODE_AUTO;
@ -422,7 +433,7 @@ int NdkCamera::open(const std::string& cameraId) {
camera_capture_session_capture_callbacks.onCaptureSequenceAborted = onCaptureSequenceAborted;
camera_capture_session_capture_callbacks.onCaptureBufferLost = 0;
m_imagesCaptured = ~0;
ACameraCaptureSession_setRepeatingRequest(capture_session, &camera_capture_session_capture_callbacks, 1, &capture_request, nullptr);
// ACameraCaptureSession_capture(capture_session, &camera_capture_session_capture_callbacks, 1, &capture_request,nullptr);
}
@ -676,14 +687,23 @@ void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureReque
ACameraMetadata_const_entry val = { 0 };
camera_status_t status = ACAMERA_ERROR_BASE;
val = { 0 };
status = ACameraMetadata_getConstEntry(result, ACAMERA_CONTROL_AF_STATE, &val);
uint8_t afState = *(val.data.u8);
m_imagesCaptured = 0;
if (afState == ACAMERA_CONTROL_AF_STATE_PASSIVE_FOCUSED || afState == ACAMERA_CONTROL_AF_STATE_FOCUSED_LOCKED)
// if (afState != ACAMERA_CONTROL_AF_STATE_INACTIVE)
if (m_imagesCaptured == ~0)
{
m_imagesCaptured = 0;
if (afSupported && (m_params.autoFocus != 0))
{
val = { 0 };
status = ACameraMetadata_getConstEntry(result, ACAMERA_CONTROL_AF_STATE, &val);
uint8_t afState = *(val.data.u8);
if (afState == ACAMERA_CONTROL_AF_STATE_PASSIVE_FOCUSED || afState == ACAMERA_CONTROL_AF_STATE_FOCUSED_LOCKED)
// if (afState != ACAMERA_CONTROL_AF_STATE_INACTIVE)
{
m_imagesCaptured = 0;
}
}
else
{
m_imagesCaptured = 0;
}
}
val = { 0 };

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.DataSetObserver;
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.hardware.camera2.CameraCharacteristics;
@ -36,7 +37,9 @@ import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.SpinnerAdapter;
import android.widget.Toast;
import com.dev.devapi.api.SysApi;
@ -130,12 +133,9 @@ public class MainActivity extends AppCompatActivity {
binding.logs.setScrollbarFadingEnabled(false);
// binding.logs.setMaxLines(16);
// Context appContext = getApplicationContext();
CameraManager mCameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
CameraCharacteristics cameraCharacteristics = mCameraManager.getCameraCharacteristics("0");
cameraCharacteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES)
// binding.protocol.item
// Context appContext = getApplicationContext();
mHandler = new Handler(Looper.myLooper()) {
@Override

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="2dp"
android:textSize="12sp"
android:typeface="serif"
android:singleLine="true"
android:layout_marginLeft="2dip"
android:layout_marginRight="5dip"
android:ellipsize="marquee"
android:textColor="#000000">
</TextView>

@ -36,6 +36,13 @@ public class MicroPhotoContext {
public int packetSize;
}
public static class MasterConfig {
public String url;
public int mntnMode;
public int quickHbMode;
public int heartbeatDuration;
}
public static String buildAppDir(Context contxt) {
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
@ -259,6 +266,118 @@ public class MicroPhotoContext {
}
}
public static MasterConfig getMasterConfig(Context context) {
MasterConfig masterConfig = new MasterConfig();
String appPath = buildAppDir(context);
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader = null;
StringBuilder stringBuilder = null;
try {
File appCfgFile = new File(appPath + "data/Master.json");
if (appCfgFile.exists()) {
inputStreamReader = new InputStreamReader(new FileInputStream(appCfgFile), "UTF-8");
bufferedReader = new BufferedReader(inputStreamReader);
String line;
stringBuilder = new StringBuilder();
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line);
}
}
JSONObject jsonObject = stringBuilder == null ? new JSONObject() : new JSONObject(stringBuilder.toString());
masterConfig.url = jsonObject.optString("url", "");
masterConfig.mntnMode = jsonObject.optInt("mntnMode", 0);
masterConfig.quickHbMode = jsonObject.optInt("quickHbMode", 0);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (Exception ex) {
}
}
if (inputStreamReader != null) {
try {
inputStreamReader.close();
} catch (Exception ex) {
}
}
}
return masterConfig;
}
public static void saveMasterConfig(Context context, MasterConfig masterConfig) {
String appPath = buildAppDir(context);
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader = null;
OutputStreamWriter outputStreamWriter = null;
try {
File dataPath = new File(appPath + "data/");
if (!dataPath.exists()) {
dataPath.mkdirs();
}
StringBuilder stringBuilder = new StringBuilder();
File file = new File(dataPath, "Master.json");
if (file.exists()) {
inputStreamReader = new InputStreamReader(new FileInputStream(file), "UTF-8");
bufferedReader = new BufferedReader(inputStreamReader);
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line);
}
}
JSONObject jsonObject = stringBuilder.length() > 0 ? (new JSONObject(stringBuilder.toString())) : (new JSONObject());
jsonObject.put("url", masterConfig.url);
jsonObject.put("Server", masterConfig.mntnMode);
jsonObject.put("Port", masterConfig.quickHbMode);
outputStreamWriter = new OutputStreamWriter(new FileOutputStream(new File(appPath + "data/App.json")), "UTF-8");
outputStreamWriter.write(jsonObject.toString());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (Exception ex) {
}
}
if (inputStreamReader != null) {
try {
inputStreamReader.close();
} catch (Exception ex) {
}
}
if (outputStreamWriter != null) {
try {
outputStreamWriter.close();
} catch (Exception ex) {
}
}
}
}
public static void restartMpApp(Context context) {
/*
Context context = MicroPhotoService.this.getApplicationContext();

@ -34,6 +34,7 @@ import java.util.List;
public class AppMaster {
private MpMasterService mService;
private String mMasterUrl;
private String mCmdid;
private PowerManager.WakeLock mWakelock;
@ -49,13 +50,19 @@ public class AppMaster {
public static final String CMD_ENABLE_GPS = "yw_cmd_enable_gps";
public static final String CMD_ENABLE_OTG = "yw_cmd_enable_otg";
public AppMaster(MpMasterService service) {
PowerManager powerManager = (PowerManager) service.getSystemService(Context.POWER_SERVICE);
mWakelock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "com.xinyingpower.microphoto:Upgrader");
public AppMaster(MpMasterService service, String masterUrl, String cmdid) {
mService = service;
// mCmdid = cmdid;
mMasterUrl = masterUrl;
mCmdid = cmdid;
mWakelock = null;
try {
PowerManager powerManager = (PowerManager) service.getSystemService(Context.POWER_SERVICE);
mWakelock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "com.xypower.mpmaster:MpMaster");
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
@ -79,18 +86,7 @@ public class AppMaster {
@Override
public void run() {
String masterUrl = MicroPhotoContext.DEFAULT_MASTER_URL;
String path = mService.buildAppDir();
path += "data/Master.json";
JSONObject jsonObject = JSONUtils.loadJson(path);
if (jsonObject != null && jsonObject.has("url")) {
masterUrl = jsonObject.optString("url");
}
MicroPhotoContext.AppConfig appConfig = MicroPhotoContext.getMpAppConfig(mService.getApplicationContext());
mCmdid = appConfig.cmdid;
String masterUrl = mMasterUrl;
if (TextUtils.isEmpty(masterUrl)) {
return;
@ -151,6 +147,11 @@ public class AppMaster {
String url = jsonObject.optString("url", null);
String cmd = jsonObject.optString("cmd", "");
int mntnMode = jsonObject.optInt("yw", 0);
int quickHbMode = jsonObject.optInt("kxt", 0);
mService.setMntnMode(mntnMode != 0, quickHbMode != 0);
if (isUpgrade == 1 && !TextUtils.isEmpty(url)) {
upgradeApp(url);
} else if (TextUtils.equals(cmd, CMD_REBOOT_DEV)) {
@ -164,7 +165,10 @@ public class AppMaster {
} else if (TextUtils.equals(cmd, CMD_SET_MNTN)) {
String ip = jsonObject.optString("value_str", null);
int port = jsonObject.optInt("value_int", 0);
updateMntnServer(ip, port);
String newUrl = buildMntnServer(ip, port);
if (newUrl != null) {
mService.updateMntn(newUrl);
}
} else if (TextUtils.equals(cmd, CMD_UPDATE_CONFIG)) {
String path = jsonObject.optString("path", null);
String fileName = jsonObject.optString("fileName", null);
@ -230,9 +234,9 @@ public class AppMaster {
return JSONUtils.saveJson(configFile.getAbsolutePath(), jsonObject);
}
private boolean updateMntnServer(String server, int port) {
private String buildMntnServer(String server, int port) {
if (TextUtils.isEmpty(server) && port == 0) {
return false;
return null;
}
String url = null;
@ -244,13 +248,7 @@ public class AppMaster {
}
}
if (url == null) {
return false;
}
mService.updateMntn(url);
return true;
return url;
}
private boolean updateCma(String ip, int port) {

@ -93,6 +93,7 @@ public class MpMasterService extends Service {
private static int mStateService = STATE_SERVICE.NOT_CONNECTED;
private boolean mMntnMode = false;
private boolean mQuickHbMode = false;
private String mCmdid = "";
private NotificationManager mNotificationManager;
@ -199,14 +200,53 @@ public class MpMasterService extends Service {
return mMpMasterVersion;
}
public void setMntnMode(boolean mntnMode, boolean quickHbMode) {
boolean oldMntnMode = mMntnMode;
boolean oldQuickHbMode = mQuickHbMode;
mMntnMode = mntnMode;
mQuickHbMode = quickHbMode;
if (oldMntnMode != mntnMode || oldQuickHbMode != quickHbMode) {
MicroPhotoContext.MasterConfig masterConfig = MicroPhotoContext.getMasterConfig(getApplicationContext());
masterConfig.mntnMode = mntnMode ? 1 : 0;
masterConfig.quickHbMode = quickHbMode ? 1 : 0;
MicroPhotoContext.saveMasterConfig(getApplicationContext(), masterConfig);
}
if (oldQuickHbMode != quickHbMode) {
// Cancel cuurent job first
if (quickHbMode) {
}
}
}
public static void sendMessage(Context context, int what, int data) {
Intent intent = new Intent(ACTION_MSG_BROADCAST);
intent.putExtra("what", what);
intent.putExtra("data", data);
intent.setPackage(context.getPackageName());
String typeName = AlarmReceiver.class.getTypeName();
intent.setComponent( new ComponentName(context.getPackageName(), AlarmReceiver.class.getTypeName()) );
context.sendBroadcast(intent);
// String typeName = AlarmReceiver.class.getTypeName();
// intent.setComponent( new ComponentName(context.getPackageName(), AlarmReceiver.class.getTypeName()) );
// context.sendBroadcast(intent);
}
private void startMaster() {
String masterUrl = MicroPhotoContext.DEFAULT_MASTER_URL;
MicroPhotoContext.MasterConfig masterConfig = MicroPhotoContext.getMasterConfig(getApplicationContext());
if (!TextUtils.isEmpty(masterConfig.url)) {
masterUrl = masterConfig.url;
}
MicroPhotoContext.AppConfig appConfig = MicroPhotoContext.getMpAppConfig(getApplicationContext());
AppMaster appMaster = new AppMaster(this, masterUrl, appConfig.cmdid);
appMaster.start();
}
public static class AlarmReceiver extends BroadcastReceiver {
@ -224,8 +264,7 @@ public class MpMasterService extends Service {
mService.registerHeartbeatTimer();
AppMaster appMaster = new AppMaster(mService);
appMaster.start();
mService.startMaster();
} else if (TextUtils.equals(ACTION_MSG_BROADCAST, action)) {
@ -382,8 +421,8 @@ public class MpMasterService extends Service {
mCmdid = cmdid;
registerHeartbeatTimer();
AppMaster appMaster = new AppMaster(this);
appMaster.start();
startMaster();
break;
case ACTION_STOP:

Loading…
Cancel
Save