您的位置:首页 > 运维架构 > Linux

linux/Android LED deamon

2015-06-26 11:09 656 查看
/*
* author:          chwenj@gmail.com.
* Agreement:       GPL.
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
#include <errno.h>
#include <pthread.h>
#include <time.h>
#include<signal.h>

#define DEVICE_FILE "/dev/gpio_cdev"

typedef struct {
unsigned char count;  //GPIO序列
unsigned char data;   //GPIO电平状态
} gpio_userspace_t;

int fd;

void init_deamon()
{
int pid;
int i;

if (pid < 0)
exit(0);
else if (pid < 0)
exit(1);

setsid();

if (pid = fork())
exit(0);
else if (pid < 0)
exit(1);

chdir("/system");
umask(0);

return;
}

int main(int argc, char **argv)
{
int fd;
gpio_userspace_t gpio;

signal(SIGCHLD, SIG_IGN);

init_deamon();

while (1) {
fd = open(DEVICE_FILE, O_RDWR);

//#PH23: LED off
gpio.count = 6;   //GPIO序列号
gpio.data = 1;    //GPIO电平值
write(fd, &gpio, sizeof(gpio_userspace_t));

sleep(4);

//#PH23: LED on
gpio.count = 6;   //GPIO序列号
gpio.data = 0;    //GPIO电平值
write(fd, &gpio, sizeof(gpio_userspace_t));

sleep(4);

close(fd);

}

return 0;
}
<pre name="code" class="html">LOCAL_PATH:= $(call my-dir)ifeq (a, a) 
include $(CLEAR_VARS)LOCAL_SRC_FILES:= led-service.cLOCAL_MODULE := led-serviceLOCAL_SHARED_LIBRARIES:= libcutils libutilsLOCAL_MODULE_TAGS := optionalinclude $(BUILD_EXECUTABLE)endif
<pre name="code" class="html">service led-service /system/bin/led-serviceclass mainuser rootgroup rootoneshot

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: