Различия

Здесь показаны различия между двумя версиями данной страницы.

Ссылка на это сравнение

Предыдущая версия справа и слева Предыдущая версия
Следующая версия
Предыдущая версия
dev:pi:main [2016/09/20 17:47]
denis
dev:pi:main [2016/12/09 10:15] (текущий)
denis [shutdown]
Строка 96: Строка 96:
 <code bash> <code bash>
   sudo apt-get install python-smbus i2c-tools   sudo apt-get install python-smbus i2c-tools
-  sudo apt-get purge fake-hwclock +  sudo apt-get purge fake-hwclock ntp
-  sudo apt-get purge ntp+
   sudo apt-get install ntpdate # TODO: not found   sudo apt-get install ntpdate # TODO: not found
  
Строка 136: Строка 135:
  
 14. Other info commands: 14. Other info commands:
 +<code bash>
   sudo i2cdetect -y 1   sudo i2cdetect -y 1
   sudo dmesg | grep rtc   sudo dmesg | grep rtc
   sudo cat /​proc/​driver/​rtc   sudo cat /​proc/​driver/​rtc
 +</​code>​
   ​   ​
 Compiled from: [[https://​elementztechblog.wordpress.com/​2015/​08/​08/​real-time-clock-rtc-interfacing-with-raspberrypi/​|src1]] [[https://​trick77.com/​adding-ds3231-real-time-clock-raspberry-pi-3/​|src2]] Compiled from: [[https://​elementztechblog.wordpress.com/​2015/​08/​08/​real-time-clock-rtc-interfacing-with-raspberrypi/​|src1]] [[https://​trick77.com/​adding-ds3231-real-time-clock-raspberry-pi-3/​|src2]]
Строка 144: Строка 145:
  
  
 +===== shutdown =====
  
 +{{:​dev:​pi:​rpi_shutdown_scheme.png|}}
  
-  ​+''/​home/​pi/​softshut/​softshut.py'':​ 
 +<code python>​ 
 +#​!/​usr/​bin/​python 
 +import time 
 +from subprocess import call 
 +import RPi.GPIO as gpio
  
 +pinBt=19
 +pinAC=21
 +pinLed=23
  
 +dlyShutdownBt = 5
 +dlyShutdownAC = 10
 +
 +dlyLedOk = 1
 +dlyLedFast = 0.1
 +
 +
 +def loop():
 +  hasBt = False
 +  hasAC = False
 +  timeBt = 0
 +  timeAC = 0
 +  dlyLed = dlyLedOk
 +  terminated = False
 +
 +  while gpio.input(pinBt)>​0 or gpio.input(pinAC)>​0:​
 +    for i in range(0,3):
 +      gpio.output(pinLed,​ True)
 +      time.sleep(dlyLedFast)
 +      gpio.output(pinLed,​ False)
 +      time.sleep(dlyLedFast)
 +    time.sleep(dlyLedOk)
 +
 +  while not terminated:
 +
 +    if gpio.input(pinBt)==0:​
 +      if timeBt > 0:
 +        print "Bt OK"
 +        timeBt = 0
 +    else:
 +      if timeBt == 0:
 +        print "Bt failed"​
 +        timeBt = time.time()
 +      else:
 +        if time.time() - timeBt > dlyShutdownBt:​
 +          print "Bt shutdown"​
 +          doShutdown()
 +          terminated = True
 +
 +
 +    if gpio.input(pinAC)==0:​
 +      if timeAC > 0:
 +        print "AC OK"
 +        timeAC = 0
 +    else:
 +      if timeAC == 0:
 +        print "AC failed"​
 +        timeAC = time.time()
 +      else:
 +        if time.time() - timeAC > dlyShutdownAC:​
 +          print "AC shutdown"​
 +          doShutdown()
 +          terminated = True
 +
 +
 +
 +    if (timeAC > 0  or  timeBt > 0) and dlyLed == dlyLedOk:
 +      dlyLed = dlyLedFast
 +    elif timeAC == 0  and  timeBt == 0  and  dlyLed != dlyLedOk:
 +      dlyLed = dlyLedOk
 +
 +    gpio.output(pinLed,​ True)
 +    time.sleep(dlyLed)
 +    gpio.output(pinLed,​ False)
 +    time.sleep(dlyLed)
 +
 +
 +
 +def eventButton(pin):​
 +  print "​Button shutdown"​
 +  doShutdown()
 +
 +def doShutdown():​
 +#  call('​halt',​ shell=False)
 +  print "​SHUTDOWN!!!"​
 +
 +
 +gpio.setmode(gpio.BOARD)
 +gpio.setup(pinBt,​ gpio.IN)
 +gpio.setup(pinAC,​ gpio.IN)
 +gpio.setwarnings(False)
 +gpio.setup(pinLed,​ gpio.OUT)
 +loop()
 +gpio.cleanup()
 +</​code>​
 +
 +
 +''/​etc/​rc.local'':​
 +<code bash>
 +# add this line before "exit 0"
 +python /​home/​pi/​softshut/​softshut.py &
 +</​code>​
  
  
dev/pi/main.1474382871.txt.gz · Последние изменения: 2016/09/20 17:47 — denis
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0