|
|
|
@ -31,20 +31,73 @@ typedef struct
|
|
|
|
|
char str[MAX_STRING_LEN];
|
|
|
|
|
}IOT_PARAM;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::mutex GpioControl::m_locker;
|
|
|
|
|
std::vector<std::pair<int, uint32_t>> GpioControl::m_references;
|
|
|
|
|
|
|
|
|
|
void GpioControl::setInt(int cmd, int value)
|
|
|
|
|
{
|
|
|
|
|
int fd = open(GPIO_NODE_MP, O_RDONLY);
|
|
|
|
|
int fd = -1;
|
|
|
|
|
IOT_PARAM param;
|
|
|
|
|
param.cmd = cmd;
|
|
|
|
|
param.value = value;
|
|
|
|
|
int res = 0;
|
|
|
|
|
// LOGE("set_int fd=%d,cmd=%d,value=%d\r\n",fd, cmd, value);
|
|
|
|
|
if( fd > 0 )
|
|
|
|
|
|
|
|
|
|
uint32_t references = (value != 0) ? 1 : 0;
|
|
|
|
|
std::vector<std::pair<int, uint32_t> >::iterator it;
|
|
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
|
{
|
|
|
|
|
int res = ioctl(fd, IOT_PARAM_WRITE, ¶m);
|
|
|
|
|
// LOGE("set_int22 cmd=%d,value=%d,result=%d\r\n",param.cmd, param.value, param.result);
|
|
|
|
|
close(fd);
|
|
|
|
|
m_locker.lock();
|
|
|
|
|
fd = open(GPIO_NODE_MP, O_RDONLY);
|
|
|
|
|
if( fd > 0 )
|
|
|
|
|
{
|
|
|
|
|
res = ioctl(fd, IOT_PARAM_WRITE, ¶m);
|
|
|
|
|
close(fd);
|
|
|
|
|
// check res???
|
|
|
|
|
for (it = m_references.begin(); it != m_references.end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if (it->first == cmd)
|
|
|
|
|
{
|
|
|
|
|
it->second++;
|
|
|
|
|
references = it->second;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (it == m_references.end())
|
|
|
|
|
{
|
|
|
|
|
m_references.push_back(std::pair<int, uint32_t >(cmd, references));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_locker.unlock();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_locker.lock();
|
|
|
|
|
for (it = m_references.begin(); it != m_references.end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if (it->first == cmd)
|
|
|
|
|
{
|
|
|
|
|
if (it->second > 0)
|
|
|
|
|
{
|
|
|
|
|
it->second--;
|
|
|
|
|
}
|
|
|
|
|
references = it->second;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (references == 0)
|
|
|
|
|
{
|
|
|
|
|
fd = open(GPIO_NODE_MP, O_RDONLY);
|
|
|
|
|
if (fd > 0) {
|
|
|
|
|
res = ioctl(fd, IOT_PARAM_WRITE, ¶m);
|
|
|
|
|
close(fd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_locker.unlock();
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GpioControl::getInt(int cmd)
|
|
|
|
|