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
原创粉丝点击