Различия

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

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

Предыдущая версия справа и слева Предыдущая версия
Следующая версия
Предыдущая версия
dev:pi:main [2016/10/06 09:38]
denis [shutdown]
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
  
Строка 157: Строка 156:
 import RPi.GPIO as gpio import RPi.GPIO as gpio
  
-acShutdownDelay ​60 # delay before shutdown in seconds after AC failed+pinBt=19 
 +pinAC=21 
 +pinLed=23
  
-ledDelayNormal ​1 +dlyShutdownBt ​5 
-ledDelayFast ​0.1+dlyShutdownAC ​10
  
-stateAC ​True +dlyLedOk ​1 
-timeACfailed ​= 0 +dlyLedFast ​= 0.1
-ledDelay = ledDelayNormal +
-shutdownCompleted = False+
  
-pinButton=19 
-pinAC=21 
-pinLed=23 
  
 def loop(): def loop():
-  ​global ledDelay +  ​hasBt = False 
-  ​global stateAC +  ​hasAC = False 
-  ​global timeACfailed+  ​timeBt = 0 
 +  timeAC = 0 
 +  dlyLed = dlyLedOk 
 +  terminated = False
  
-  while not shutdownCompleted:​ +  while gpio.input(pinBt)>​0 or gpio.input(pinAC)>0
-    if gpio.input(pinAC)== ​and ​ stateAC==False+    for i in range(0,3)
-      ​print "AC OK" +      ​gpio.output(pinLed,​ True) 
-      ​stateAC = 1 +      ​time.sleep(dlyLedFast) 
-      ​ledDelay = ledDelayNormal+      ​gpio.output(pinLed,​ False) 
 +      time.sleep(dlyLedFast) 
 +    time.sleep(dlyLedOk)
  
-    ​if gpio.input(pinAC)>0: +  while not terminated:​ 
-      if stateAC==True:+ 
 +    ​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"​         print "AC failed"​
-        ​stateAC = 0 +        ​timeAC ​= time.time()
-        ledDelay = ledDelayFast +
-        timeACfailed ​= time.time()+
       else:       else:
-        if time.time() - timeACfailed ​acShutdownDelay:+        if time.time() - timeAC ​dlyShutdownAC:
           print "AC shutdown"​           print "AC shutdown"​
           doShutdown()           doShutdown()
-          ​break+          ​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)     gpio.output(pinLed,​ True)
-    time.sleep(ledDelay)+    time.sleep(dlyLed)
     gpio.output(pinLed,​ False)     gpio.output(pinLed,​ False)
-    time.sleep(ledDelay)+    time.sleep(dlyLed) 
 + 
  
 def eventButton(pin):​ def eventButton(pin):​
Строка 204: Строка 233:
  
 def doShutdown():​ def doShutdown():​
-  ​call('​halt',​ shell=False) +#  ​call('​halt',​ shell=False) 
-  ​global shutdownCompleted +  ​print "​SHUTDOWN!!!"​ 
-  ​shutdownCompleted = True+
  
 gpio.setmode(gpio.BOARD) gpio.setmode(gpio.BOARD)
-gpio.setup(pinButton, gpio.IN)+gpio.setup(pinBt, gpio.IN)
 gpio.setup(pinAC,​ gpio.IN) gpio.setup(pinAC,​ gpio.IN)
-gpio.add_event_detect(pinButton,​ gpio.RISING,​ callback=eventButton,​ bouncetime=200) 
 gpio.setwarnings(False) gpio.setwarnings(False)
 gpio.setup(pinLed,​ gpio.OUT) gpio.setup(pinLed,​ gpio.OUT)
 loop() loop()
 gpio.cleanup() gpio.cleanup()
- 
 </​code>​ </​code>​
  
Строка 223: Строка 250:
 <code bash> <code bash>
 # add this line before "exit 0" # add this line before "exit 0"
-/​home/​pi/​softshut/​softshut.py+python ​/​home/​pi/​softshut/​softshut.py ​&
 </​code>​ </​code>​
  
  
dev/pi/main.1475735895.txt.gz · Последние изменения: 2016/10/06 09:38 — denis
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0