#include
#include
#include
#include
#include
#include
#include
#include
#include
/*--------------------------*/ //具体开发板相关
#define LED_ON _IO('k', 0)
#define LED_OFF _IO('k', 1)
#define LED1 2
#define LED2 3
#define LED3 4
#define LED4 1
int ledfd;
int led_init(){
ledfd = open("/dev/led",O_RDWR | O_NONBLOCK);
if (ledfd< 0) {
perror("open led");
return -1;
}
return 0;
}
int led_exit(){
led_off(LED1);
led_off(LED2);
led_off(LED3);
led_off(LED4);
close(ledfd);
return 0;
}
int led_on(int num ){
ioctl(ledfd,LED_ON,num);
return 0;
}
int led_off(int num ){
ioctl(ledfd,LED_OFF,num);
return 0;
}
int led_Flicke(int num,long time){
int flag = 1;
while(flag >0){
ioctl(ledfd,LED_ON,num);
usleep(time );
ioctl(ledfd,LED_OFF,num);
usleep(time );
flag--;
}
return 0;
}
/*-------------------*/
void show_list(){
puts(" *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-");
puts(" push any key mentioned as follow");
puts(" led1 on/off:------1");
puts(" led2 on/off:------2");
puts(" led3 on/off:------3");
puts(" led4 on/off:------4");
puts(" Print the list:---5");
puts(" Cp file A to B:---6");
puts(" Special:----------7");
puts(" Quit:-------------8");
puts(" *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-");
}
void fun(char *aa,char *bb){
int fd1,fd2;
int ret;
fd1=open(aa,O_RDONLY);
fd2=open(bb,O_CREAT|O_RDWR);
while(1){
int buf[1024];
memset(buf,0,1024);
ret=read(fd1,buf,1024);
write(fd2,buf,ret);
if(ret<1024)
break;
}
close(fd1);
close(fd2);
return;
}
int main(){
int l;
int flag1=0,flag2=0,flag3=0,flag4=0;
led_init();
show_list();
while(1){
puts("input your choice:");
scanf("%d",&l);
//getchar();
switch(l){
case 1: {
flag1=~flag1;
if(flag1) led_on(LED1);
else led_off(LED1);
}break;
case 2: {
flag2=~flag2;
if(flag2) led_on(LED2);
else led_off(LED2);
}break;
case 3: {
flag3=~flag3;
if(flag3) led_on(LED3);
else led_off(LED3);
}break;
case 4: {
flag4=~flag4;
if(flag4) led_on(LED4);
else led_off(LED4);
}break;
case 5: {
show_list();
}break;
case 6: {
puts("input two file names");
char a[10],b[10];
puts("which file you want to copy?");
scanf("%s",a);
puts("copy to what?");
scanf("%s",b);
fun(a,b);
}break;
case 7: {
int i;
for(i=0;i<10;i++){
led_off(LED1);
led_off(LED2);
led_off(LED3);
led_off(LED4);
usleep(10000);
led_on(LED1);
led_on(LED2);
led_on(LED3);
led_on(LED4);
usleep(10000);
}
}break;
case 8: {
exit(0);
}break;
default :{
puts("--------input erro! try others----------");
}break;
}
}
return 0;
}
阅读(358) | 评论(0) | 转发(0) |