20180128
This commit is contained in:
parent
0e94cc6935
commit
28c5a00d19
@ -8,7 +8,6 @@
|
||||
# AUthor: aixiao@aixiao.me.
|
||||
#
|
||||
|
||||
|
||||
function DATE()
|
||||
{
|
||||
y=$(date "+%y");
|
||||
@ -47,20 +46,31 @@ function lightinfo()
|
||||
bindir="/root/gpio"
|
||||
! test -d ${bindir} && exit 1;
|
||||
#时间范围
|
||||
high="1400";
|
||||
low="1430";
|
||||
high="1900";
|
||||
low="2400";
|
||||
#当前时间
|
||||
now=$(date +%H%M);
|
||||
bcm_lightpin="20";
|
||||
wiringpi_lightpin="28";
|
||||
bcm_lightpin="21";
|
||||
wiringpi_lightpin="29";
|
||||
#wiringpi_infrared="20";
|
||||
|
||||
#判断手机是否在线
|
||||
phoneip="192.168.137.175";
|
||||
phoneip="192.168.137.27";
|
||||
phonelogic="$(ping ${phoneip} -c 1 -S 1 &> /dev/null; echo $?)";
|
||||
|
||||
#判断人体红外线传感器
|
||||
infrared=$(${bindir}/info_infrared ${wiringpi_infrared});
|
||||
|
||||
#距离传感器
|
||||
l="60";
|
||||
s="150";
|
||||
wiringpi_tring="8";
|
||||
wiringpi_echo="9";
|
||||
#distance="$(${bindir}/info_ultrasound ${wiringpi_tring} ${wiringpi_echo})";
|
||||
|
||||
#读取灯pin值
|
||||
lightpinvalue="$(${bindir}/info_pin ${wiringpi_lightpin})";
|
||||
lightpinvalue="$(gpio -g read ${bcm_lightpin})";
|
||||
#lightpinvalue="$(gpio -g read ${bcm_lightpin})";
|
||||
|
||||
#开灯&关灯
|
||||
start_light="${bindir}/info_light ${wiringpi_lightpin} 1";
|
||||
@ -73,9 +83,13 @@ DATE;
|
||||
#get18b20data >> ~/temperature.txt;
|
||||
lightinfo;
|
||||
|
||||
function main_()
|
||||
{
|
||||
while true; do
|
||||
if [ "${now}" -ge "${high}" -a "${now}" -le "${low}" ]; then #检测时间段
|
||||
if [ "${phonelogic}" == "0" ]; then #检测手机IP
|
||||
#if [ "${infrared}" = "1" ]; then #检测人体红外线
|
||||
#if [ "${distance}" -ge ${l} -a "${distance}" -le ${s} ]; then #检测距离范围
|
||||
if test "${lightpinvalue}" = "0"; then #检测灯pin值
|
||||
${start_light};
|
||||
fi
|
||||
@ -90,6 +104,20 @@ while true; do
|
||||
fi
|
||||
fi
|
||||
lightinfo; #再次获取信息
|
||||
sleep 9; #睡眠
|
||||
sleep 7; #睡眠
|
||||
done
|
||||
}
|
||||
|
||||
while getopts :d pi
|
||||
do
|
||||
case ${pi} in
|
||||
d)
|
||||
daemon='&';
|
||||
;;
|
||||
h|?)
|
||||
:
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
eval main_ ${daemon}
|
||||
|
BIN
raspberrypi_zero/gpio/info_infrared
Normal file
BIN
raspberrypi_zero/gpio/info_infrared
Normal file
Binary file not shown.
37
raspberrypi_zero/gpio/info_infrared.c
Normal file
37
raspberrypi_zero/gpio/info_infrared.c
Normal file
@ -0,0 +1,37 @@
|
||||
#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);
|
||||
|
||||
//很重要。控制默认情况下此PIN处于下拉低电平状态
|
||||
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);
|
||||
printf("%d\n", status);
|
||||
|
||||
}
|
BIN
raspberrypi_zero/gpio/info_ultrasound
Normal file
BIN
raspberrypi_zero/gpio/info_ultrasound
Normal file
Binary file not shown.
42
raspberrypi_zero/gpio/info_ultrasound.c
Normal file
42
raspberrypi_zero/gpio/info_ultrasound.c
Normal file
@ -0,0 +1,42 @@
|
||||
#include <wiringPi.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
int i;
|
||||
if( argc != 3) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int pin_tring = atol(argv[1]);
|
||||
int pin_echo = atol(argv[2]);
|
||||
struct timeval tv1;
|
||||
struct timeval tv2;
|
||||
long start_time, stop_time;
|
||||
float distance;
|
||||
|
||||
if(wiringPiSetup() == -1) {
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
digitalWrite(pin_tring, LOW);
|
||||
digitalWrite(pin_tring, HIGH);
|
||||
delayMicroseconds(10);
|
||||
digitalWrite(pin_tring, LOW);
|
||||
|
||||
while(!(digitalRead(pin_echo) == 1));
|
||||
gettimeofday(&tv1, NULL);
|
||||
|
||||
while(!(digitalRead(pin_echo) == 0));
|
||||
gettimeofday(&tv2, NULL);
|
||||
|
||||
start_time = tv1.tv_sec * 1000000 + tv1.tv_usec;
|
||||
stop_time = tv2.tv_sec * 1000000 + tv2.tv_usec;
|
||||
|
||||
distance = (float)(stop_time - start_time) / 1000000 * 34000 / 2;
|
||||
|
||||
printf("%0.0f\n", distance);
|
||||
return distance;
|
||||
}
|
Loading…
Reference in New Issue
Block a user