在driver文件中添加sysfs节点供debug用
来源:互联网 发布:国内经济数据 编辑:程序博客网 时间:2024/04/28 15:21
首先
static ssize_t switch_glove_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%d \n", ftxxxx_ts->glove_mode_eable);
}
static ssize_t switch_dclick_mode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
int tmp = 0;
tmp = buf[0] - 48;
if (tmp == 0) {
ftxxxx_ts->dclick_mode_eable = false;
printk("[Focal][Touch] dclick_mode_disable ! \n");
} else if (tmp == 1) {
ftxxxx_ts->dclick_mode_eable = true;
printk("[Focal][Touch] dclick_mode_enable ! \n");
}
return count;
}
static DEVICE_ATTR(glove_mode, Focal_RW_ATTR, switch_glove_mode_show, switch_glove_mode_store);
static struct attribute *ftxxxx_attributes[] = {
......
&dev_attr_glove_mode.attr,
......
NULL
}
static struct attribute_group ftxxxx_attribute_group = {
.attrs = ftxxxx_attributes
};
static struct kobject *android_touch_kobj; /* Sys kobject variable*/
int ftxxxx_create_sysfs(struct i2c_client * client) //这个函数被probe函数调用,这个client参数是从probe中传入的
{
int err;
G_Client = client;
err = sysfs_create_group(&client->dev.kobj, &ftxxxx_attribute_group);
if (0 != err) {
sysfs_remove_group(&client->dev.kobj, &ftxxxx_attribute_group);
return -EIO;
}
android_touch_kobj = kobject_create_and_add("android_touch", NULL);
if (sysfs_create_file(android_touch_kobj, &dev_attr_ftsfwupgradeapp.attr)) {
printk("[Focal][TOUCH_ERR] : create_file ftsfwupgradeapp failed\n");
return -1;
}
HidI2c_To_StdI2c(client);
return err;
}
int ftxxxx_remove_sysfs(struct i2c_client * client)
{
sysfs_remove_group(&client->dev.kobj, &ftxxxx_attribute_group);
return 0;
static ssize_t switch_glove_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%d \n", ftxxxx_ts->glove_mode_eable);
}
static ssize_t switch_dclick_mode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
int tmp = 0;
tmp = buf[0] - 48;
if (tmp == 0) {
ftxxxx_ts->dclick_mode_eable = false;
printk("[Focal][Touch] dclick_mode_disable ! \n");
} else if (tmp == 1) {
ftxxxx_ts->dclick_mode_eable = true;
printk("[Focal][Touch] dclick_mode_enable ! \n");
}
return count;
}
static DEVICE_ATTR(glove_mode, Focal_RW_ATTR, switch_glove_mode_show, switch_glove_mode_store);
static struct attribute *ftxxxx_attributes[] = {
......
&dev_attr_glove_mode.attr,
......
NULL
}
static struct attribute_group ftxxxx_attribute_group = {
.attrs = ftxxxx_attributes
};
static struct kobject *android_touch_kobj; /* Sys kobject variable*/
int ftxxxx_create_sysfs(struct i2c_client * client) //这个函数被probe函数调用,这个client参数是从probe中传入的
{
int err;
G_Client = client;
err = sysfs_create_group(&client->dev.kobj, &ftxxxx_attribute_group);
if (0 != err) {
sysfs_remove_group(&client->dev.kobj, &ftxxxx_attribute_group);
return -EIO;
}
android_touch_kobj = kobject_create_and_add("android_touch", NULL);
if (sysfs_create_file(android_touch_kobj, &dev_attr_ftsfwupgradeapp.attr)) {
printk("[Focal][TOUCH_ERR] : create_file ftsfwupgradeapp failed\n");
return -1;
}
HidI2c_To_StdI2c(client);
return err;
}
int ftxxxx_remove_sysfs(struct i2c_client * client)
{
sysfs_remove_group(&client->dev.kobj, &ftxxxx_attribute_group);
return 0;
}
使用DEVICE_ATTR,可以在sys fs中添加“文件”,通过修改该文件内容,可以实现在运行过程中动态控制device的目的。
类似的还有DRIVER_ATTR,BUS_ATTR,CLASS_ATTR。
这几个东东的区别就是,DEVICE_ATTR对应的文件在/sys/devices/目录中对应的device下面。
而其他几个分别在driver,bus,class中对应的目录下。
0 0
- 在driver文件中添加sysfs节点供debug用
- 在sysfs中添加文件--添加设备非默认属性
- 在/sysfs文件系统中添加和删除文件
- 在device driver中给device快速添加属性文件
- 在XML中增加节点 . 在原有的XML文件中,根据节点,添加数据
- 在Linux DeviceTree添加dtsi文件并在驱动中读取节点信息写入sys文件系统
- cocos studio 中 添加了动画节点, 在程序中直接用该节点播放动画
- 如何在SolrCloud中添加删除节点
- 在xml中添加<!DOCTYPE >节点
- 在ASP.NET中实现多文件上传(以及添加节点的问题)(setAttribute())
- Linux driver model & sysfs
- dom4j解析xml文件,添加新节点,添加节点内容,读取文件中节点内容作为新增节点内容
- linux sysfs中目录和文件节点的创建
- linux中sysfs 创建设备节点的方法sysfs_create_group DEVICE_ATTR
- 在末尾添加节点
- android怎么在已有的xml文件添加节点
- 创建sysfs节点
- 创建sysfs节点
- iOS字符串截取字符
- 新时代来临——工业4.0时代有感
- 什么是句柄
- js 对html的基本操作
- lhgdialog基本使用方法,附验证数字的jquery方法
- 在driver文件中添加sysfs节点供debug用
- JavaScript 数组字符互转
- QStringList类常用方法总结|QStringList 遍历
- STL之next()函数和iota函数
- COCOS2DX-游戏开发之 坐标系
- ubuntu安装64位谷歌浏览器
- JS开发HTML5游戏《神奇的六边形》(三)
- oracle命令之oracle用户
- Applet程序特点及其的运行步骤