jfloresmu92@yahoo.com [nuttx]
2018-02-15 10:00:23 UTC
Hi!
After solve my problem with I2C bus, I felt secure enough to develop a driver for NuttX. So I'm developing the driver for the HIH-6130 humidity/sensor which it's a I2C sensor, but it's pretty simple to use it.
At the moment it's working perfectly all the functions (I can open, close and read the device data) except the IOCTL.
And here comes my questions.
I would like to have the possibility to configure with IOCTL which measure I want to show (If you want to choose the humidity measure or the temperature measure).
To implement this functions I've done the next things:
- This is my function IOCTL function:
static int hih6130_ioctl(FAR struct file *filep,int cmd,unsigned long arg){
FAR struct hih6130_dev_s *priv;
switch (cmd)
{
//You can choose between temperature measure or humidity measure
case SNIOC_TEMPERATURE:
{
sninfo("Set temperature measure\n");
priv->opt=true;
sninfo("priv value %i\n",priv->opt);
}
break;
case SNIOC_HUMIDITY:
{
sninfo("Set humidity measure\n");
priv->opt=false;
sninfo("priv value %i\n",priv->opt);
}
break;
}
}
As you can see it's pretty simple, depending the argument you change the value of opt and then in the read function, you check the value of "opt" and it call to the humidity measure function or temperature measure function.
Also I initialize the function in register function giving a true value.
But the problem comes in the read function. And it doesn't matter if I change or not that it always the initialization value.
I check the value like this:
if(priv->opt){
*data=temperature();
}
else{
*data=humidity();
}
Everything compile correctly, initialization fine and also when I use the ioctl function in my example, the debug info returns me the correct value, but it looks like it only save the data in the function.
Any idea?
Thank you for the help!!
After solve my problem with I2C bus, I felt secure enough to develop a driver for NuttX. So I'm developing the driver for the HIH-6130 humidity/sensor which it's a I2C sensor, but it's pretty simple to use it.
At the moment it's working perfectly all the functions (I can open, close and read the device data) except the IOCTL.
And here comes my questions.
I would like to have the possibility to configure with IOCTL which measure I want to show (If you want to choose the humidity measure or the temperature measure).
To implement this functions I've done the next things:
- This is my function IOCTL function:
static int hih6130_ioctl(FAR struct file *filep,int cmd,unsigned long arg){
FAR struct hih6130_dev_s *priv;
switch (cmd)
{
//You can choose between temperature measure or humidity measure
case SNIOC_TEMPERATURE:
{
sninfo("Set temperature measure\n");
priv->opt=true;
sninfo("priv value %i\n",priv->opt);
}
break;
case SNIOC_HUMIDITY:
{
sninfo("Set humidity measure\n");
priv->opt=false;
sninfo("priv value %i\n",priv->opt);
}
break;
}
}
As you can see it's pretty simple, depending the argument you change the value of opt and then in the read function, you check the value of "opt" and it call to the humidity measure function or temperature measure function.
Also I initialize the function in register function giving a true value.
But the problem comes in the read function. And it doesn't matter if I change or not that it always the initialization value.
I check the value like this:
if(priv->opt){
*data=temperature();
}
else{
*data=humidity();
}
Everything compile correctly, initialization fine and also when I use the ioctl function in my example, the debug info returns me the correct value, but it looks like it only save the data in the function.
Any idea?
Thank you for the help!!