-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fomatter settings for .c file (#46)
- Loading branch information
Showing
7 changed files
with
186 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
BasedOnStyle: Google | ||
IndentWidth: 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,25 @@ | ||
#include "fcntl.h" | ||
|
||
void main(void) | ||
{ | ||
void main(void) { | ||
int led[4]; | ||
int i; | ||
|
||
led[0]=open("/dev/rtled0",O_WRONLY); | ||
led[1]=open("/dev/rtled1",O_WRONLY); | ||
led[2]=open("/dev/rtled2",O_WRONLY); | ||
led[3]=open("/dev/rtled3",O_WRONLY); | ||
led[0] = open("/dev/rtled0", O_WRONLY); | ||
led[1] = open("/dev/rtled1", O_WRONLY); | ||
led[2] = open("/dev/rtled2", O_WRONLY); | ||
led[3] = open("/dev/rtled3", O_WRONLY); | ||
|
||
while(1) | ||
{ | ||
for(i=0;i<4;i++) | ||
{ | ||
write(led[i],"1",1); | ||
while (1) { | ||
for (i = 0; i < 4; i++) { | ||
write(led[i], "1", 1); | ||
} | ||
usleep(500*1000); | ||
for(i=0;i<4;i++) | ||
{ | ||
write(led[i],"0",1); | ||
usleep(500 * 1000); | ||
for (i = 0; i < 4; i++) { | ||
write(led[i], "0", 1); | ||
} | ||
usleep(500*1000); | ||
usleep(500 * 1000); | ||
} | ||
for(i=0;i<4;i++) | ||
{ | ||
for (i = 0; i < 4; i++) { | ||
close(led[i]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,66 @@ | ||
#include "fcntl.h" | ||
|
||
int _Getch(void) | ||
{ | ||
int ch; | ||
system("stty -echo -icanon min 1 time 0"); | ||
ch = getchar(); | ||
system("stty echo icanon"); | ||
return ch; | ||
int _Getch(void) { | ||
int ch; | ||
system("stty -echo -icanon min 1 time 0"); | ||
ch = getchar(); | ||
system("stty echo icanon"); | ||
return ch; | ||
} | ||
|
||
void main(void){ | ||
int buzzer = open("/dev/rtbuzzer0",O_WRONLY); | ||
int c=1; | ||
void main(void) { | ||
int buzzer = open("/dev/rtbuzzer0", O_WRONLY); | ||
int c = 1; | ||
|
||
while(c){ | ||
switch(_Getch()){ | ||
case '0'://off | ||
write(buzzer,"0",2); | ||
break; | ||
case 'a'://do | ||
write(buzzer,"261",4); | ||
break; | ||
case 'w'://do# | ||
write(buzzer,"277",4); | ||
break; | ||
case 's'://re | ||
write(buzzer,"293",4); | ||
break; | ||
case 'e'://re# | ||
write(buzzer,"311",4); | ||
break; | ||
case 'd'://mi | ||
write(buzzer,"329",4); | ||
break; | ||
case 'f'://fa | ||
write(buzzer,"349",4); | ||
break; | ||
case 't'://fa# | ||
write(buzzer,"370",4); | ||
break; | ||
case 'g' ://so | ||
write(buzzer,"392",4); | ||
break; | ||
case 'y'://so# | ||
write(buzzer,"415",4); | ||
break; | ||
case 'h'://ra | ||
write(buzzer,"440",4); | ||
break; | ||
case 'u'://ra# | ||
write(buzzer,"446",4); | ||
break; | ||
case 'j'://shi | ||
write(buzzer,"493",4); | ||
break; | ||
case 'k'://do2 | ||
write(buzzer,"523",4); | ||
break; | ||
case 'c': | ||
write(buzzer,"0",2); | ||
c=0; | ||
break; | ||
} | ||
} | ||
close(buzzer); | ||
while (c) { | ||
switch (_Getch()) { | ||
case '0': // off | ||
write(buzzer, "0", 2); | ||
break; | ||
case 'a': // do | ||
write(buzzer, "261", 4); | ||
break; | ||
case 'w': // do# | ||
write(buzzer, "277", 4); | ||
break; | ||
case 's': // re | ||
write(buzzer, "293", 4); | ||
break; | ||
case 'e': // re# | ||
write(buzzer, "311", 4); | ||
break; | ||
case 'd': // mi | ||
write(buzzer, "329", 4); | ||
break; | ||
case 'f': // fa | ||
write(buzzer, "349", 4); | ||
break; | ||
case 't': // fa# | ||
write(buzzer, "370", 4); | ||
break; | ||
case 'g': // so | ||
write(buzzer, "392", 4); | ||
break; | ||
case 'y': // so# | ||
write(buzzer, "415", 4); | ||
break; | ||
case 'h': // ra | ||
write(buzzer, "440", 4); | ||
break; | ||
case 'u': // ra# | ||
write(buzzer, "446", 4); | ||
break; | ||
case 'j': // shi | ||
write(buzzer, "493", 4); | ||
break; | ||
case 'k': // do2 | ||
write(buzzer, "523", 4); | ||
break; | ||
case 'c': | ||
write(buzzer, "0", 2); | ||
c = 0; | ||
break; | ||
} | ||
} | ||
close(buzzer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,81 @@ | ||
#include "fcntl.h" | ||
|
||
char get_SW0(void){ | ||
char buf[2]; | ||
int SW0; | ||
SW0 = open("/dev/rtswitch0",O_RDONLY); | ||
read(SW0,buf,2); | ||
close(SW0); | ||
return buf[0]; | ||
char get_SW0(void) { | ||
char buf[2]; | ||
int SW0; | ||
SW0 = open("/dev/rtswitch0", O_RDONLY); | ||
read(SW0, buf, 2); | ||
close(SW0); | ||
return buf[0]; | ||
} | ||
|
||
char get_SW1(void){ | ||
char buf[2]; | ||
int SW1; | ||
SW1 = open("/dev/rtswitch1",O_RDONLY); | ||
read(SW1,buf,2); | ||
close(SW1); | ||
return buf[0]; | ||
char get_SW1(void) { | ||
char buf[2]; | ||
int SW1; | ||
SW1 = open("/dev/rtswitch1", O_RDONLY); | ||
read(SW1, buf, 2); | ||
close(SW1); | ||
return buf[0]; | ||
} | ||
|
||
char get_SW2(void){ | ||
char buf[2]; | ||
int SW2; | ||
SW2 = open("/dev/rtswitch2",O_RDONLY); | ||
read(SW2,buf,2); | ||
close(SW2); | ||
return buf[0]; | ||
char get_SW2(void) { | ||
char buf[2]; | ||
int SW2; | ||
SW2 = open("/dev/rtswitch2", O_RDONLY); | ||
read(SW2, buf, 2); | ||
close(SW2); | ||
return buf[0]; | ||
} | ||
|
||
void main(void) { | ||
int state0, state1, state2; | ||
int LED0, LED1, LED2, LED3; | ||
|
||
LED0 = open("/dev/rtled0", O_WRONLY); | ||
LED1 = open("/dev/rtled1", O_WRONLY); | ||
LED2 = open("/dev/rtled2", O_WRONLY); | ||
LED3 = open("/dev/rtled3", O_WRONLY); | ||
|
||
void main(void){ | ||
int state0,state1,state2; | ||
int LED0,LED1,LED2,LED3; | ||
state0 = state1 = state2 = 0; | ||
|
||
LED0 = open("/dev/rtled0",O_WRONLY); | ||
LED1 = open("/dev/rtled1",O_WRONLY); | ||
LED2 = open("/dev/rtled2",O_WRONLY); | ||
LED3 = open("/dev/rtled3",O_WRONLY); | ||
|
||
state0 = state1 = state2 = 0; | ||
|
||
while(1){ | ||
if (get_SW0() =='0'){ | ||
usleep(10000); | ||
while (get_SW0() == '0'); | ||
usleep(10000); | ||
state0=(state0+1)&0x01; | ||
if(state0==0){ | ||
write(LED3,"0",1); | ||
}else{ | ||
write(LED3,"1",1); | ||
} | ||
} | ||
if (get_SW1() =='0'){ | ||
usleep(10000); | ||
while (get_SW1() == '0'); | ||
usleep(10000); | ||
state1=(state1+1)&0x01; | ||
if(state1==0){ | ||
write(LED2,"0",1); | ||
write(LED1,"0",1); | ||
}else{ | ||
write(LED2,"1",1); | ||
write(LED1,"1",1); | ||
} | ||
} | ||
if (get_SW2() =='0'){ | ||
usleep(10000); | ||
while (get_SW2() == '0'); | ||
usleep(10000); | ||
state2=(state2+1)&0x01; | ||
if(state2==0){ | ||
write(LED0,"0",1); | ||
}else{ | ||
write(LED0,"1",1); | ||
} | ||
} | ||
} | ||
while (1) { | ||
if (get_SW0() == '0') { | ||
usleep(10000); | ||
while (get_SW0() == '0') | ||
; | ||
usleep(10000); | ||
state0 = (state0 + 1) & 0x01; | ||
if (state0 == 0) { | ||
write(LED3, "0", 1); | ||
} else { | ||
write(LED3, "1", 1); | ||
} | ||
} | ||
if (get_SW1() == '0') { | ||
usleep(10000); | ||
while (get_SW1() == '0') | ||
; | ||
usleep(10000); | ||
state1 = (state1 + 1) & 0x01; | ||
if (state1 == 0) { | ||
write(LED2, "0", 1); | ||
write(LED1, "0", 1); | ||
} else { | ||
write(LED2, "1", 1); | ||
write(LED1, "1", 1); | ||
} | ||
} | ||
if (get_SW2() == '0') { | ||
usleep(10000); | ||
while (get_SW2() == '0') | ||
; | ||
usleep(10000); | ||
state2 = (state2 + 1) & 0x01; | ||
if (state2 == 0) { | ||
write(LED0, "0", 1); | ||
} else { | ||
write(LED0, "1", 1); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
Oops, something went wrong.