From 856c1a8b102beb6efe5625f199ea4e97718f6087 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 25 Feb 2025 18:16:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=BC=80=E7=94=B5=E6=BA=90=E7=9A=84?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E4=B9=9F=E4=BB=85=E5=9C=A8=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E7=94=B5=E6=BA=90=E6=97=B6=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/GPIOControl.cpp | 66 ++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/app/src/main/cpp/GPIOControl.cpp b/app/src/main/cpp/GPIOControl.cpp index b4fffbab..def8f3e9 100644 --- a/app/src/main/cpp/GPIOControl.cpp +++ b/app/src/main/cpp/GPIOControl.cpp @@ -32,42 +32,57 @@ bool GpioControl::m_cameraPowerStatus = false; size_t GpioControl::turnOnImpl(const IOT_PARAM& param) { + size_t oldRef = 0; size_t references = 1; std::vector::iterator it; int res = 0; int fd = -1; time_t now = time(NULL); - fd = open(GPIO_NODE_MP, O_RDONLY); - if( fd > 0 ) + m_locker.lock(); + +// check res??? + for (it = m_items.begin(); it != m_items.end(); ++it) { - res = ioctl(fd, IOT_PARAM_WRITE, ¶m); - close(fd); - // check res??? - for (it = m_items.begin(); it != m_items.end(); ++it) + if (it->cmd == param.cmd) { - if (it->cmd == param.cmd) - { - it->references++; - // it->closeTime = 0; - references = it->references; - if(it->openTime == 0) - it->openTime = now; - SetCamerastatus(it->cmd, true); - break; - } + oldRef = it->references; + it->references++; + // it->closeTime = 0; + references = it->references; + if(it->openTime == 0) + it->openTime = now; + SetCamerastatus(it->cmd, true); + break; } - if (it == m_items.end()) + } + if (it == m_items.end()) + { + oldRef = 0; + ITEM item = {param.cmd, references, 0, 0, now}; + m_items.push_back(item); + SetCamerastatus(param.cmd, true); + } + m_locker.unlock(); + + if (oldRef == 0) + { + fd = open(GPIO_NODE_MP, O_RDONLY); + if( fd > 0 ) { - ITEM item = {param.cmd, references, 0, 0, now}; - m_items.push_back(item); - SetCamerastatus(param.cmd, true); + res = ioctl(fd, IOT_PARAM_WRITE, ¶m); + close(fd); +#ifdef OUTPUT_DBG_INFO + XYLOG(XYLOG_SEVERITY_INFO, "setInt cmd=%d,value=%d,result=%d\r\n",param.cmd, param.value, param.result); +#endif + } - } #ifdef _DEBUG - ALOGI("PWR TurnOn cmd=%d,result=%d ref=%u\r\n",param.cmd, param.result, (uint32_t)references); + ALOGI("PWR TurnOn cmd=%d,result=%d ref=%u\r\n",param.cmd, param.result, (uint32_t)references); #endif - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + return references; } @@ -81,10 +96,11 @@ void GpioControl::setInt(int cmd, int value) if (fd > 0) { int res = ioctl(fd, IOT_PARAM_WRITE, ¶m); + close(fd); #ifdef OUTPUT_DBG_INFO - XYLOG(XYLOG_SEVERITY_DEBUG, "setInt cmd=%d,value=%d,result=%d\r\n",param.cmd, param.value, param.result); + int realVal = getInt(param.cmd); + XYLOG(XYLOG_SEVERITY_INFO, "setInt cmd=%d,value=%d,result=%d RealVal=%d",param.cmd, param.value, param.result, realVal); #endif - close(fd); } }