Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fomatter settings for .c file #46

Merged
merged 1 commit into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions SampleProgram/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: Google
IndentWidth: 4
31 changes: 13 additions & 18 deletions SampleProgram/step1.c
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]);
}
}
121 changes: 60 additions & 61 deletions SampleProgram/step2.c
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);
}
140 changes: 69 additions & 71 deletions SampleProgram/step3.c
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);
}
}
}
}



Loading