Class_file&&Android应用调用方法
来源:互联网 发布:数据库是什么软件 编辑:程序博客网 时间:2024/06/07 05:13
java代码调用 fos.write这里面是byte类型的
+ private static final String LEDBLPATH="/sys/class/hdyrodent_charger_led/brightness";+ private final void SetChargerLedBrightness(String path,int brightness)+ {+ try{+ java.io.FileOutputStream fos = new+ java.io.FileOutputStream(new java.io.File(path));+ fos.write(String.valueOf(brightness).getBytes());+ fos.flush();+ fos.close();+ Slog.e(TAG, "--------->SetChargerLedBrightness"+LEDBLPATH+"brightness"+brightness);+ }catch(Exception e){+ e.printStackTrace();+ }+ }+ private static final String LEDFEPATH="/sys/class/hdyrodent_charger_led/frequency";+ private final void SetChargerLedfrequency(String path,int frequency)+ {+ try{+ java.io.FileOutputStream fos = new+ java.io.FileOutputStream(new java.io.File(path));+ fos.write(String.valueOf(frequency).getBytes());+ fos.flush();+ fos.close();+ Slog.e(TAG, "--------->SetChargerLedfrequency"+LEDFEPATH+"frequency"+frequency);+ }catch(Exception e){+ e.printStackTrace();+ }+ }
驱动
/* * drivers/leds/leds-mt65xx.c * * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive for * more details. * * Hydrodent weiqifa modify add * */#include <linux/module.h>#include <linux/platform_device.h>#include <linux/delay.h>#include <linux/string.h>#include <linux/ctype.h>#include <linux/leds.h>#include <linux/leds-mt65xx.h>#include <linux/workqueue.h>#include <linux/wakelock.h>#include <linux/slab.h>#include <linux/spinlock.h>//#include <cust_leds.h>//#include <cust_leds_def.h>#include <mach/mt_pwm.h>//#include <mach/mt_pwm_hal.h>//#include <mach/mt_gpio.h>#include <mach/pmic_mt6329_hw_bank1.h> #include <mach/pmic_mt6329_sw_bank1.h> #include <mach/pmic_mt6329_hw.h>#include <mach/pmic_mt6329_sw.h>#include <mach/upmu_common_sw.h>#include <mach/upmu_hw.h>//#include <mach/mt_pmic_feature_api.h>//#include <mach/mt_boot.h>#include <leds_hal.h>//#include <linux/leds_hal.h>#include "leds_drv.h"static struct class *hdyrodent_pwm_class=NULL;int show_value=123;/**************************************************************************** * scnprintf是linux下面一个函数,这个函数把后面 的值格式话转化成字符串 * 并在adb 下面显示出来 ***************************************************************************/static ssize_t hdyrodent_pwm_show(struct device *dev,struct device_attribute *attr, char *buf){ printk("%s\n", __FUNCTION__); return scnprintf(buf, PAGE_SIZE, "%d\n", show_value);}/**************************************************************************** * echo pwm这个节点的时候就会调用下面这个函数,echo "12" > pwm * 那么value的值就是12 可以通过这样设置pwm的数值 ***************************************************************************/static ssize_t hdyrodent_pwm_store(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count){ int value=0; sscanf(_buf, "%d", &value); sscanf(_buf, "%d", &show_value);//把值传给show_value这样 cat的值就是echo 进去的值了 printk("%s: value: %d _count:%d\n", __FUNCTION__, value,_count); return _count;}/**************************************************************************** * __ATTR的第一个参数是在sys文件系统里面显示的名字 * 0666是这个节点的属性,0666表示是可读可写 * hdyrodent_pwm_show 是cat 这个文件的时候调用的函数 * hdyrodent_pwm_store 是echo的时候调用的函数 ***************************************************************************/static struct class_attribute hdyrodent_attr[] = {__ATTR(pwm,0666, hdyrodent_pwm_show, hdyrodent_pwm_store),__ATTR_NULL,};static int __init hdyrodent_pwm_init(void){ int ret; int i = 0; printk("%s start\n", __FUNCTION__); //用class_create在sys/class/下面生成sys文件系统 hdyrodent_pwm_class=class_create(THIS_MODULE,"hdyrodent"); if(IS_ERR(hdyrodent_pwm_class)) { printk("create hdyrodent module fail \n"); return PTR_ERR(hdyrodent_pwm_class);; } for (i = 0 ; NULL != attr_name(hdyrodent_attr[i]);i++) { ret = class_create_file(hdyrodent_pwm_class, &hdyrodent_attr[i]); if (0 != ret) { printk("creat %s class file fail\n",attr_name(hdyrodent_attr[i])); break; } } printk("%s end\n", __FUNCTION__); return 0;}static void __exit hdyrodent_pwm_exit(void){ int i = 0; printk("hdyrodent module cleanup start.\n"); for (i = 0 ; NULL != attr_name(hdyrodent_attr[i]);i++) { class_remove_file(hdyrodent_pwm_class, &hdyrodent_attr[i]); } class_destroy(hdyrodent_pwm_class); printk("hdyrodent module cleanup OK!\n");}MODULE_AUTHOR("329410527@qq.com");MODULE_DESCRIPTION("HDYRODENT PWM MODULE");MODULE_LICENSE("GPL");MODULE_VERSION("ver0.1");module_init(hdyrodent_pwm_init);module_exit(hdyrodent_pwm_exit);
0 0
- Class_file&&Android应用调用方法
- 浏览器 调用ios/android应用的方法
- android 调用应用的两种方法
- android如何调用其他应用的方法或属性
- Android Webkit内核应用层函数调用方法
- Android中通过Intent调用其他应用的方法
- Android调用系统邮件类应用的正确实现方法
- Android中通过Intent调用其他应用的方法
- android 调用系统其他已经安装的应用的方法
- Android中通过Intent调用其他应用的方法
- Android 通过反射调用隐蔽方法forceStopPackage结束应用
- android应用调用系统相关设置的方法
- android应用调用系统相关设置的方法
- Android Jni层调用应用层(Java)的方法
- Android中通过Intent调用其他应用的方法
- Android应用中clearFocus方法调用无效的问题解决
- Android调用系统邮件类应用的正确实现方法
- android制作sdk,通过SDK调用另一个应用的方法
- Java基本知识(连载)-面向对象入门
- 本机上多个cocos2dx版本下怎么创建自己想要的版本?
- ios_obj-c KVC,谓词,KVO和通知
- elasticsearch java query API
- Android 换肤方案(2种)
- Class_file&&Android应用调用方法
- Android关于创建Message
- iOS 线程的基本介绍
- 安卓模拟器 com.android.phone已停止运行的解决办法
- 数字图像处理:第十一章基于特征向量的变换
- 【iOS】plist无法写入的原因
- Zookeeper命令行以及java API简单使用
- 14.9.2 File Space Management
- 好博客