Skip to content
Snippets Groups Projects
Commit b5aaaee6 authored by Lee TaeKyung's avatar Lee TaeKyung
Browse files

add

parent c1a164b1
Branches
Tags
No related merge requests found
Pipeline #1776 failed
Showing with 564 additions and 0 deletions
# SYS_teamproject
File added
simpleMain : buzzer.o flame.o gas.o led.o pir.o main.o
gcc -o simpleMain buzzer.o flame.o gas.o led.o pir.o main.o -lwiringPi -lpthread
buzzer.o : buzzer.c
gcc -c buzzer.c -lwiringPi -lpthread
flame.o : flame.c
gcc -c flame.c -lwiringPi -lpthread
gas.o : gas.c
gcc -c gas.c -lwiringPi -lpthread
led.o : led.c
gcc -c led.c -lwiringPi -lpthread
pir.o : pir.c
gcc -c pir.c -lwiringPi -lpthread
main.o : main.c
gcc -c main.c -lwiringPi -lpthread
clean :
rm *.o simpleMain
/*
** buzzer.c
** written by KSH, LTK in 19/06/02
** based on buzzer_test.c
*/
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/ioctl.h>
#include<fcntl.h>
#include "buzzer.h"
#define NUM 100
#define WRITE _IOW(NUM, 1, int)
int buzzer_fd;
/*
** setup function to use buzzer's device driver
** in success case it will return 0
*/
int init_buzzer()
{
buzzer_fd = open("/dev/buzzer_device", O_RDWR); // for _IOW
if (buzzer_fd < 0) {
printf("buzzer init error\n");
return 1;
}
return 0;
}
/*
** write '0' make buzzer on
** using ioctl function
*/
void on_buzzer()
{
char buf[10] ="0";
ioctl(buzzer_fd, WRITE, buf);
}
/*
** write '1' make buzzer on
** using ioctl function
*/
void off_buzzer()
{
char buf[10] ="1";
ioctl(buzzer_fd, WRITE, buf);
}
#ifndef _BUZZER_H_
#define _BUZZER_H_
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/ioctl.h>
#include<fcntl.h>
#include "buzzer.h"
#define NUM 100
#define WRITE _IOW(NUM, 1, int)
int buzzer_fd;
int init_buzzer();
void on_buzzer();
void off_buzzer();
#endif
File added
/*
** flame.c
** wrtten by KSH in 19/05/31
** based on flame_test.c
*/
#include <stdio.h>
#include <unistd.h>
#include <wiringPi.h>
#include <wiringPiSPI.h>
#include "flame.h"
#define CS_MCP3008 10 // wPi 10
#define SPI_CHANNEL 0
#define SPI_SPEED 1000000
/*
** setup function to use wiringPi and wiringPISPI
** in success case it will return 0
*/
int init_MCP3008 (void)
{
if(wiringPiSetup() == -1) return 1;
if(wiringPiSPISetup(SPI_CHANNEL, SPI_SPEED) == -1) return 1;
pinMode(CS_MCP3008, OUTPUT);
return 0;
}
/*
** read flame sensor's analog signal using 'read_MCP3008' function
** return 'flame_adcValue' which is calculated digital signal
** 1 = flame NOT exist , 0 = flame exist
** use this function will be used in main program with while(1) to check flame signal consistently
*/
int read_flame()
{
int adcValue = 0;
int adcChannel = 0;
adcValue = read_MCP3008((unsigned char)adcChannel)*3.3/1024;
// printf("adc0 Value = %u\n", adcValue);
sleep(1);
return adcValue;
/*
unsigned char buff[3];
buff[0] = 1;
buff[1] = (8+(unsigned char)adcChannel)<<4;
buff[2] = 0;
digitalWrite(CS_MCP3008, 0);
wiringPiSPIDataRW(SPI_CHANNEL, buff, 3);
adcValue = ((buff[1]&3 << 8) + buff[2]);
digitalWrite(CS_MCP3008,1);
return adcValue*3.3/1024;
*/
}
/*
** convert flame module's analog signal to digital using MCP3008 module
** return 'adcValue' digital siganl conveted by MCP3008 module
** this function will be used in 'read_flame' function
*/
int read_MCP3008(unsigned char adcChannel)
{
unsigned char buff[3];
int adcValue = 0;
buff[0] = 1;
buff[1] = (8+adcChannel)<<4;
buff[2] = 0;
digitalWrite(CS_MCP3008, 0);
wiringPiSPIDataRW(SPI_CHANNEL, buff, 3);
//buff[1] = 0x0F & buff[1];
adcValue = ((buff[1]&3) << 8) + buff[2];
digitalWrite(CS_MCP3008, 1);
return adcValue;
}
#ifndef _FLAME_H_
#define _FLAME_H_
#include <stdio.h>
#include <unistd.h>
#include <wiringPi.h>
#include <wiringPiSPI.h>
#include "flame.h"
#define CS_MCP3008 10
#define SPI_CHANNEL 0
#define SPI_SPEED 1000000
int init_MCP3008 (void);
int read_flame();
int read_MCP3008(unsigned char adcChannel);
#endif
File added
/*
** gas_app.c
** wrtten by KimSeongHeon in 19/06/01
** based on gasTest.c
*/
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include "gas.h"
#define IOCTL_MAGIC_NUMBER 'H'
#define IOCTL_GAS_READ _IOR(IOCTL_MAGIC_NUMBER, 0, unsigned int)
#define GAS_IDLE 0
#define GAS_RELEASE 1
int gas_fd;
/*
** setup function to use 'gas_device' ReadOnly
** in NOT success case it will return 1
*/
int init_gas(void)
{
gas_fd = open("/dev/gas_device", O_RDONLY);
if(gas_fd < 0)
{
perror("failed open because ");
return 1;
}
return 0;
}
/*
** read gas sensor's digital signal
** return 'gas_value'
** 1 = NO gas , 0 = YES gas
** use this function will be used in main program with while(1) to check gas signal consistently
*/
int read_gas(void)
{
int gas_value;
ioctl(gas_fd, IOCTL_GAS_READ, &gas_value);
//printf("gas : %d\n", gas_status);
return gas_value;
}
/*
** close 'gas_device'
*/
void close_gas(void)
{
close(gas_fd);
}
#ifndef _GAS_H_
#define _GAS_H_
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include "gas.h"
#define IOCTL_MAGIC_NUMBER 'H'
#define IOCTL_GAS_READ _IOR(IOCTL_MAGIC_NUMBER, 0, unsigned int)
#define GAS_IDLE 0
#define GAS_RELEASE 1
int gas_fd;
int init_gas(void);
int read_gas(void);
void close_gas(void);
#endif
File added
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#define IOCTL_MAGIC_NUMBER 'H'
#define IOCTL_LED_ON _IO(IOCTL_MAGIC_NUMBER, 0)
#define IOCTL_LED_OFF _IO(IOCTL_MAGIC_NUMBER, 1)
int led_fd;
void init_led ()
{
led_fd = open("/dev/led_device", O_RDWR);
}
void close_led()
{
close(led_fd);
}
void on_led()
{
ioctl(led_fd, IOCTL_LED_ON, 0);
}
void off_led()
{
ioctl(led_fd, IOCTL_LED_OFF, 0);
}
#ifndef _PARSE_H_
#define _PARSE_H_
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include "led.h"
#define IOCTL_MAGIC_NUMBER 'H'
#define IOCTL_LED_ON _IO(IOCTL_MAGIC_NUMBER, 0)
#define IOCTL_LED_OFF _IO(IOCTL_MAGIC_NUMBER, 1)
int led_fd;
void init_led ();
void close_led();
void on_led();
void off_led();
#endif
File added
File added
#include <stdio.h>
#include "buzzer.h"
#include "flame.h"
#include "gas.h"
#include "led.h"
#include "pir.h"
int main ()
{
// check buzzer
printf("check buzzer\n");
printf("init_buzzer\n");
int check = init_buzzer();
if(check != 0)
{
printf("end program(ERR)\n");
return 0;
}
while(1)
{
int n;
printf("input : ");
scanf("%d", &n);
if(n == 0)
{
printf("on_buzzer");
on_buzzer();
}
else if (n == 1)
{
printf("off_buzzer\n");
off_buzzer();
}
else
{
printf("end check buzzer\n");
break;
}
}
//check flame
printf("check flame\n");
printf("init_MCP3008\n");
check = init_MCP3008();
if(check != 0)
{
printf("end program(ERR)\n");
return 0;
}
for(int i = 0; i < 25; i++)
{
int result = read_flame();
printf("flame result : %d\n", result);
}
/*
//check gas
printf("check gas\n");
printf("init_gas\n");
check = init_gas();
if(check != 0)
{
printf("end program(ERR)\n");
return 0;
}
for(int i = 0; i < 20; i++)
{
int result = read_gas();
printf("gas result : %d\n", result);
}
close_gas();
*/
//check led
printf("check led\n");
printf("init_led");
init_led();
if(check != 0)
{
printf("end program(ERR)\n");
return 0;
}
on_led();
sleep(2);
off_led();
sleep(2);
on_led();
sleep(2);
off_led();
sleep(2);
//check pir
printf("check pir\n");
printf("init pir\n");
check=init_pir();
if(check!=0)
{
printf("end error\n");
return 0;
}
int n=0,t=0,f=0;
while(1){
sleep(1);
int flag=read_pir();
if(flag==0)
t++;
else if(flag==1)
f++;
n++;
if(n>=30)
{
printf("%d%%\n",f*3);
n=0;
t=0;
f=0;
}
}
return 0;
}
File added
#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/ioctl.h>
#include<stdlib.h>
#include<string.h>
#define MY_S 100
#define READ _IOR( MY_S, 0, int )
#define WRITE _IOW( MY_S, 1, int )
int pir_fd;
int init_pir(){
pir_fd = open("/dev/pir_device", O_RDWR);
if (pir_fd < 0) {
printf("file not open\n");
return 1;
}
return 0;
}
int read_pir(){
char buf[100]={0,};
ioctl(pir_fd,READ,buf);
return atoi(buf);
}
/* int n=0,t=0,f=0;
while(1){
sleep(1);
ioctl(fd, READ, buf);
int flag=atoi(buf);
if(flag==0)
t++;
else if(flag==1)
f++;
n++;
if(n>=30)
{
printf("%d%%\n",f*3);
n=0;
t=0;
f=0;
}
}*/
#ifndef _PIR_H_
#define _PIR_H_
#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/ioctl.h>
#include<stdlib.h>
#include<string.h>
#include "pir.h"
#define MY_S 100
#define READ _IOR( MY_S, 0, int )
#define WRITE _IOW( MY_S, 1, int )
int pir_fd;
int init_pir();
int read_pir();
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment