20180121
This commit is contained in:
parent
c32cc1ea99
commit
4bb08d9d33
95
raspberrypi_zero/gpio/info.sh
Normal file
95
raspberrypi_zero/gpio/info.sh
Normal file
@ -0,0 +1,95 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# reapberry zero w
|
||||
# GPIO module
|
||||
# Date: 20180118
|
||||
# Time: 17:17
|
||||
#
|
||||
# AUthor: aixiao@aixiao.me.
|
||||
#
|
||||
|
||||
|
||||
function DATE()
|
||||
{
|
||||
y=$(date "+%y");
|
||||
m=$(date "+%m");
|
||||
d=$(date "+%d");
|
||||
H=$(date "+%H");
|
||||
M=$(date "+%M");
|
||||
S=$(date "+%S");
|
||||
}
|
||||
|
||||
function get18b20data()
|
||||
{
|
||||
MODEL="28-04174019f0ff";
|
||||
if test -d "/sys/devices/w1_bus_master1/${MODEL}"; then
|
||||
temperature=$(cat /sys/devices/w1_bus_master1/28-04174019f0ff/w1_slave | grep 't=' | sed 's/^.*t=//g' | awk '{print $1/1000}');
|
||||
echo $y年$m月$d日$H时$M分$S秒
|
||||
echo -ne "当前室内温度: ";
|
||||
echo -e "\e[1;31m${temperature}℃ \e[0m";
|
||||
else
|
||||
return 1;
|
||||
fi
|
||||
}
|
||||
|
||||
function getcpudata()
|
||||
{
|
||||
MHZ=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq | awk '{print $1/1000}');
|
||||
temperature=$(cat /sys/class/thermal/thermal_zone0/temp | awk '{print $1/1000}');
|
||||
percentage=$(top -b -n 2 | grep ^%Cpu | sed -n "2p" | sed -e 's/^.*://g;s/..,//g;s/st//g' | awk '{print "scale=1; 100-" $4 }' | bc);
|
||||
echo "Cpu Frequencyi: ${MHZ}MHZ";
|
||||
echo -e "\e[1;31mCpu temperature: ${temperature}℃ \e[0m";
|
||||
echo "Cpu Percentage: ${percentage}%";
|
||||
}
|
||||
|
||||
function lightinfo()
|
||||
{
|
||||
bindir="/root/gpio"
|
||||
! test -d ${bindir} && exit 1;
|
||||
#时间范围
|
||||
high="1400";
|
||||
low="1430";
|
||||
#当前时间
|
||||
now=$(date +%H%M);
|
||||
bcm_lightpin="20";
|
||||
wiringpi_lightpin="28";
|
||||
|
||||
#判断手机是否在线
|
||||
phoneip="192.168.137.175";
|
||||
phonelogic="$(ping ${phoneip} -c 1 -S 1 &> /dev/null; echo $?)";
|
||||
|
||||
#读取灯pin值
|
||||
lightpinvalue="$(${bindir}/info_pin ${wiringpi_lightpin})";
|
||||
lightpinvalue="$(gpio -g read ${bcm_lightpin})";
|
||||
|
||||
#开灯&关灯
|
||||
start_light="${bindir}/info_light ${wiringpi_lightpin} 1";
|
||||
stop_light="${bindir}/info_light ${wiringpi_lightpin} 0";
|
||||
|
||||
}
|
||||
|
||||
DATE;
|
||||
#getcpudata;
|
||||
#get18b20data >> ~/temperature.txt;
|
||||
lightinfo;
|
||||
|
||||
while true; do
|
||||
if [ "${now}" -ge "${high}" -a "${now}" -le "${low}" ]; then #检测时间段
|
||||
if [ "${phonelogic}" == "0" ]; then #检测手机IP
|
||||
if test "${lightpinvalue}" = "0"; then #检测灯pin值
|
||||
${start_light};
|
||||
fi
|
||||
else
|
||||
if test "${lightpinvalue}" = "1"; then #如果开着就关闭
|
||||
${stop_light};
|
||||
fi
|
||||
fi
|
||||
else
|
||||
if test "${lightpinvalue}" = "1"; then #如果开着就关闭
|
||||
${stop_light};
|
||||
fi
|
||||
fi
|
||||
lightinfo; #再次获取信息
|
||||
sleep 9; #睡眠
|
||||
done
|
||||
|
BIN
raspberrypi_zero/gpio/info_light
Normal file
BIN
raspberrypi_zero/gpio/info_light
Normal file
Binary file not shown.
31
raspberrypi_zero/gpio/info_light.c
Normal file
31
raspberrypi_zero/gpio/info_light.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include <wiringPi.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
void pinMode (int pin, int mode) ;
|
||||
void pullUpDnControl (int pin, int pud) ;
|
||||
void digitalWrite (int pin, int value) ;
|
||||
void pwmWrite (int pin, int value) ;
|
||||
int digitalRead (int pin) ;
|
||||
analogRead (int pin) ;
|
||||
analogWrite (int pin, int value) ;
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if( argc != 3) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int pin = atol(argv[1]);
|
||||
wiringPiSetup();
|
||||
|
||||
pinMode(pin, OUTPUT);
|
||||
if(atol(argv[2]) == 1) {
|
||||
digitalWrite(pin, HIGH);
|
||||
}
|
||||
if(atol(argv[2]) == 0) {
|
||||
digitalWrite(pin, LOW);
|
||||
}
|
||||
|
||||
}
|
BIN
raspberrypi_zero/gpio/info_pin
Normal file
BIN
raspberrypi_zero/gpio/info_pin
Normal file
Binary file not shown.
32
raspberrypi_zero/gpio/info_pin.c
Normal file
32
raspberrypi_zero/gpio/info_pin.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include <wiringPi.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
void pinMode (int pin, int mode) ;
|
||||
void pullUpDnControl (int pin, int pud) ;
|
||||
void digitalWrite (int pin, int value) ;
|
||||
void pwmWrite (int pin, int value) ;
|
||||
int digitalRead (int pin) ;
|
||||
analogRead (int pin) ;
|
||||
analogWrite (int pin, int value) ;
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if( argc != 2) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int pin = atol(argv[1]);
|
||||
wiringPiSetup();
|
||||
pinMode(pin, OUTPUT);
|
||||
/*
|
||||
while(1) {
|
||||
digitalWrite(28, HIGH);
|
||||
digitalWrite(28, LOW);
|
||||
}
|
||||
|
||||
return digitalRead(28);
|
||||
*/
|
||||
printf("%d\n", digitalRead(pin));
|
||||
}
|
Loading…
Reference in New Issue
Block a user