From f47c4054c67f7f8b56b7485ea504b5d38ac46275 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 12 Jul 2024 17:09:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=90=AF=E7=B3=BB=E7=BB=9F=E5=85=88?= =?UTF-8?q?=E7=AD=89=E5=BE=851s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mpmaster/src/main/cpp/mpmaster.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/mpmaster/src/main/cpp/mpmaster.cpp b/mpmaster/src/main/cpp/mpmaster.cpp index e4cb8591..0c461972 100644 --- a/mpmaster/src/main/cpp/mpmaster.cpp +++ b/mpmaster/src/main/cpp/mpmaster.cpp @@ -17,6 +17,8 @@ // } #include #include +#include +#include #include #include #include @@ -57,8 +59,8 @@ Java_com_xypower_mpmaster_MpMasterService_getInt(JNIEnv* env, jclass cls, jint c return -1; } -extern "C" JNIEXPORT jint JNICALL -Java_com_xypower_mpmaster_MpMasterService_setInt(JNIEnv* env, jclass cls, jint cmd, jint val) { +int setGpioInt(int cmd, int val) +{ int fd = open("/dev/mtkgpioctrl", O_RDONLY); // LOGE("set_int fd=%d,cmd=%d,value=%d\r\n",fd, cmd, value); if( fd > 0 ) @@ -74,15 +76,25 @@ Java_com_xypower_mpmaster_MpMasterService_setInt(JNIEnv* env, jclass cls, jint c return -1; } +extern "C" JNIEXPORT jint JNICALL +Java_com_xypower_mpmaster_MpMasterService_setInt(JNIEnv* env, jclass cls, jint cmd, jint val) { + + return setGpioInt(cmd, val); +} + extern "C" JNIEXPORT void JNICALL Java_com_xypower_mpmaster_MpMasterService_rebootDevice(JNIEnv* env, jclass cls) { // setInt(CMD_SET_SYSTEM_RESET, 1); - for (int idx = 0; idx < 3; idx++) { - if (Java_com_xypower_mpmaster_MpMasterService_setInt(env, cls, 202, 1) == 0) { - break; - } - } - + std::thread t([]() + { + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + for (int idx = 0; idx < 3; idx++) { + if (setGpioInt(202, 1) == 0) { + break; + } + } + }); + t.detach(); } extern "C" JNIEXPORT jintArray JNICALL