This commit is contained in:
aixiao 2018-02-10 22:45:55 +08:00
parent 9254fb43b9
commit 25688c3437
8 changed files with 110 additions and 57 deletions

Binary file not shown.

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
0

View File

@ -26,14 +26,16 @@ function SLEEP()
function get18b20data() function get18b20data()
{ {
MODEL="28-04174019f0ff"; MODEL="28-04174019f0ff";
if test -d "/sys/devices/w1_bus_master1/${MODEL}"; then while true; do
temperature=$(cat /sys/devices/w1_bus_master1/28-04174019f0ff/w1_slave | grep 't=' | sed 's/^.*t=//g' | awk '{print $1/1000}'); if test -d "/sys/devices/w1_bus_master1/${MODEL}"; then
#echo $y年$m月$d日$H时$M分$S秒 temperature=$(cat /sys/devices/w1_bus_master1/28-04174019f0ff/w1_slave | grep 't=' | sed 's/^.*t=//g' | awk '{print $1/1000}');
echo -ne "当前室内温度: "; #echo $y年$m月$d日$H时$M分$S秒
echo -e "\e[1;31m${temperature}℃ \e[0m"; #echo -ne "当前室内温度: ";
else #echo -e "\e[1;31m${temperature}℃ \e[0m";
return 1; echo "${temperature}" >> data/temperature.data;
fi fi
SLEEP 60;
done
} }
function getcpudata() function getcpudata()
@ -46,9 +48,10 @@ function getcpudata()
echo "Cpu Percentage: ${percentage}%"; echo "Cpu Percentage: ${percentage}%";
} }
function lightinfo() function INIT()
{ {
bindir="/root/gpio" null="/dev/null";
bindir="/root/gpio";
! test -d ${bindir} && exit 1; ! test -d ${bindir} && exit 1;
#时间范围 #时间范围
high="1500"; high="1500";
@ -67,7 +70,11 @@ function lightinfo()
#判断人体红外线传感器 #判断人体红外线传感器
#infrared=$(${bindir}/info_infrared ${wiringpi_infrared}); #infrared=$(${bindir}/info_infrared ${wiringpi_infrared});
infrared=$(cat ${bindir}/infrared.log 2> /dev/null); infrared=$(cat ${bindir}/data/infrared.data 2> /dev/null);
#声音传感器
wiringpi_sound=25;
sound=$(cat ${bindir}/data/sound.data 2> /dev/null);
#距离传感器 #距离传感器
l="60"; l="60";
@ -86,21 +93,15 @@ function lightinfo()
} }
#DATE;
#getcpudata;
#get18b20data >> ~/temperature.txt;
lightinfo;
function WHILE() function WHILE()
{ {
while true; do while true; do
${bindir}/info_infrared ${wiringpi_infrared} > infrared.log ${bindir}/info_infrared ${wiringpi_infrared} > data/infrared.data;
SLEEP 1 SLEEP 1;
done done
} }
function main_() function light()
{ {
while true; do while true; do
if [ "${now}" -ge "${high}" -a "${now}" -le "${low}" ]; then #检测时间段 if [ "${now}" -ge "${high}" -a "${now}" -le "${low}" ]; then #检测时间段
@ -122,14 +123,37 @@ while true; do
${stop_light}; ${stop_light};
fi fi
fi fi
lightinfo; #再次获取信息 INIT; #再次获取信息
SLEEP 1; #睡眠 SLEEP 1; #睡眠
done done
} }
while getopts :ds: pi function light_daemon()
{
while true; do
${bindir}/info_infrared ${wiringpi_infrared} > data/infrared.data;
SLEEP 1;
done
}
function sound_daemon()
{
while :; do
${bindir}/info_sound ${wiringpi_sound} > data/sound.data
SLEEP 0.3;
done
}
function sound()
{
:
}
INIT;
while getopts :ds:x ai
do do
case ${pi} in case ${ai} in
d) d)
daemon='&'; daemon='&';
;; ;;
@ -138,7 +162,8 @@ case ${pi} in
"stop") "stop")
array=$(ls ${bindir}/log/) array=$(ls ${bindir}/log/)
for arr in ${array[@]}; do for arr in ${array[@]}; do
kill $(cat ${bindir}/log/${arr}) kill $(cat ${bindir}/log/${arr}) &> ${null}
rm ${bindir}/log/${arr} 2> ${null}
done done
exit 0 exit 0
;; ;;
@ -148,12 +173,19 @@ case ${pi} in
esac esac
exit 0 exit 0
;; ;;
x)
set -x
;;
h|?) h|?)
echo " echo -ne "
raspberrypi zero w 智能灯控 \e[1;31mraspberrypi zero w 智能家居\e[0m
$0 Usage: $0 [-?|h] [-d] [-s] $0 Usage: $0 [-?|h] [-d] [-s] [-x] [light|temperature]
-d Daemon. -d : Daemon.
-s kill Daemon, signal: stop. -s : kill Daemon, signal: stop.
-x : Print commands and their arguments as they are executed.
light : light Modular.
temperature : temperature Modular.
by aixiao. by aixiao.
" "
@ -162,8 +194,26 @@ exit 0
esac esac
done done
WHILE & shift $((OPTIND-1))
WHILEID="$(echo $!)" case ${1} in
echo ${WHILEID} > log/infrared.pid 2> /dev/null light)
eval main_ ${daemon} light_daemon &
echo $! > log/main.pid 2> /dev/null light_daemon_id="$(echo $!)"
echo ${light_daemon_id} > log/infrared.pid 2> ${null}
eval light ${daemon}
echo $! > log/light.pid 2> ${null}
;;
temperature)
#get18b20data &
#echo $! > log/temperature.pid 2> ${null}
:
;;
sound)
sound_daemon &
echo $! > log/sound.pid 2> ${null};
eval sound ${daemon};
;;
*)
exit 1;
;;
esac

View File

@ -10,27 +10,13 @@ int main(int argc, char *argv[])
} }
int pin = atol(argv[1]); int pin = atol(argv[1]);
int status = 0; int status = 0;
wiringPiSetup(); wiringPiSetup();
//设置为输入模式
pinMode(pin, INPUT); pinMode(pin, INPUT);
//很重要。控制默认情况下此PIN处于下拉低电平状态
pullUpDnControl(pin, PUD_DOWN); pullUpDnControl(pin, PUD_DOWN);
/*
while(true)
{
delay(1000);
//读取当前pin的输入状态
if(digitalRead(pin) == 1) {
printf("There is somebody here\n");
}
else {
printf("There is no one here\n");
}
}
*/
status = digitalRead(pin); status = digitalRead(pin);
printf("%d\n", status); printf("%d\n", status);

View File

@ -20,13 +20,5 @@ int main(int argc, char *argv[])
int pin = atol(argv[1]); int pin = atol(argv[1]);
wiringPiSetup(); wiringPiSetup();
pinMode(pin, OUTPUT); pinMode(pin, OUTPUT);
/*
while(1) {
digitalWrite(28, HIGH);
digitalWrite(28, LOW);
}
return digitalRead(28);
*/
printf("%d\n", digitalRead(pin)); printf("%d\n", digitalRead(pin));
} }

Binary file not shown.

View File

@ -0,0 +1,23 @@
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main(int argc, char *argv[])
{
if(argc != 2) {
exit(0);
}
int pin = atol(argv[1]);
int status = 0;
wiringPiSetup();
pinMode(pin, INPUT);
pullUpDnControl(pin, PUD_DOWN);
status = digitalRead(pin);
printf("%d\n", status);
}