|
|
|
@ -20,86 +20,122 @@
|
|
|
|
|
|
|
|
|
|
#define IOT_PARAM_WRITE 0xAE
|
|
|
|
|
#define IOT_PARAM_READ 0xAF
|
|
|
|
|
#define MAX_STRING_LEN 32
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
int cmd;
|
|
|
|
|
int value;
|
|
|
|
|
int result;
|
|
|
|
|
long value2;
|
|
|
|
|
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 GpioControl::turnOnImpl(const IOT_PARAM& param)
|
|
|
|
|
{
|
|
|
|
|
int fd = -1;
|
|
|
|
|
IOT_PARAM param = { cmd, value, 0 };
|
|
|
|
|
// param.cmd = cmd;
|
|
|
|
|
// param.value = value;
|
|
|
|
|
uint32_t references = 1;
|
|
|
|
|
std::vector<std::pair<int, uint32_t> >::iterator it;
|
|
|
|
|
int res = 0;
|
|
|
|
|
int fd = -1;
|
|
|
|
|
|
|
|
|
|
uint32_t references = (value != 0) ? 1 : 0;
|
|
|
|
|
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 == param.cmd)
|
|
|
|
|
{
|
|
|
|
|
it->second++;
|
|
|
|
|
references = it->second;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (it == m_references.end())
|
|
|
|
|
{
|
|
|
|
|
m_references.push_back(std::pair<int, uint32_t >(cmd, references));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return references;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GpioControl::turnOffImpl(const IOT_PARAM& param)
|
|
|
|
|
{
|
|
|
|
|
uint32_t references = 0;
|
|
|
|
|
std::vector<std::pair<int, uint32_t> >::iterator it;
|
|
|
|
|
int res = 0;
|
|
|
|
|
int fd = -1;
|
|
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
|
for (it = m_references.begin(); it != m_references.end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if (it->first == param.cmd)
|
|
|
|
|
{
|
|
|
|
|
if (it->second > 0)
|
|
|
|
|
{
|
|
|
|
|
it->second--;
|
|
|
|
|
}
|
|
|
|
|
references = it->second;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (references == 0)
|
|
|
|
|
{
|
|
|
|
|
m_locker.lock();
|
|
|
|
|
fd = open(GPIO_NODE_MP, O_RDONLY);
|
|
|
|
|
if( fd > 0 )
|
|
|
|
|
if (fd > 0)
|
|
|
|
|
{
|
|
|
|
|
res = ioctl(fd, IOT_PARAM_WRITE, ¶m);
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
ALOGI("setInt cmd=%d,value=%d,result=%d\r\n",param.cmd, param.value, param.result);
|
|
|
|
|
#endif
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return references;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GpioControl::setInt(int cmd, int value)
|
|
|
|
|
{
|
|
|
|
|
IOT_PARAM param = { cmd, value, 0 };
|
|
|
|
|
// param.cmd = cmd;
|
|
|
|
|
// param.value = value;
|
|
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
|
{
|
|
|
|
|
m_locker.lock();
|
|
|
|
|
turnOnImpl(param);
|
|
|
|
|
m_locker.unlock();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_locker.lock();
|
|
|
|
|
for (it = m_references.begin(); it != m_references.end(); ++it)
|
|
|
|
|
turnOffImpl(param);
|
|
|
|
|
m_locker.unlock();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void GpioControl::setInt(const std::vector<int>& cmds, int value)
|
|
|
|
|
{
|
|
|
|
|
IOT_PARAM param = { 0, value, 0 };
|
|
|
|
|
// param.cmd = cmd;
|
|
|
|
|
// param.value = value;
|
|
|
|
|
|
|
|
|
|
std::vector<int>::const_iterator it;
|
|
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
|
{
|
|
|
|
|
m_locker.lock();
|
|
|
|
|
for (it = cmds.cbegin(); it != cmds.cend(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if (it->first == cmd)
|
|
|
|
|
{
|
|
|
|
|
if (it->second > 0)
|
|
|
|
|
{
|
|
|
|
|
it->second--;
|
|
|
|
|
}
|
|
|
|
|
references = it->second;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
param.cmd = *it;
|
|
|
|
|
turnOnImpl(param);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (references == 0)
|
|
|
|
|
m_locker.unlock();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_locker.lock();
|
|
|
|
|
for (it = cmds.cbegin(); it != cmds.cend(); ++it)
|
|
|
|
|
{
|
|
|
|
|
fd = open(GPIO_NODE_MP, O_RDONLY);
|
|
|
|
|
if (fd > 0) {
|
|
|
|
|
res = ioctl(fd, IOT_PARAM_WRITE, ¶m);
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
ALOGI("setInt cmd=%d,value=%d,result=%d\r\n",param.cmd, param.value, param.result);
|
|
|
|
|
#endif
|
|
|
|
|
close(fd);
|
|
|
|
|
}
|
|
|
|
|
param.cmd = *it;
|
|
|
|
|
turnOffImpl(param);
|
|
|
|
|
}
|
|
|
|
|
m_locker.unlock();
|
|
|
|
|
}
|
|
|
|
|