Blame view

src/utils/plc/guitalens_observatory/driver_came.py 3.52 KB
ac31ddb1   Alain Klotz   New celme documen...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*-
import RPi.GPIO as io
import time

def do_open_roof(pin_cmd_open_bcm=27, debug_level=0):
   """Ouvre le toit avec un moteur de toit Came. 

Exemple:

import driver_came ; driver_came.do_open_roof(27,2)
"""

   io.setwarnings(False)
   io.setmode(io.BCM) #set up GPIO using BCM numbering
   io.setup(pin_cmd_open_bcm,io.OUT) # make pin an output (=arduino 27 open)

   io.output(pin_cmd_open_bcm,1)
   time.sleep(3)   
   io.output(pin_cmd_open_bcm,0)
    
   err=0
   return err

def do_stop_roof(pin_cmd_stop_bcm=4, debug_level=0):
   """Stope le toit avec un moteur de toit Came. 

Exemple:

import driver_came ; driver_came.do_stop_roof(4,2)
"""

   io.setwarnings(False)
   io.setmode(io.BCM) #set up GPIO using BCM numbering
   io.setup(pin_cmd_stop_bcm,io.OUT) # make pin an output (=arduino 25 stop)

   io.output(pin_cmd_stop_bcm,1)
   time.sleep(3)   
   io.output(pin_cmd_stop_bcm,0)
    
   err=0
   return err

def do_close_roof(pin_cmd_close_bcm=23, debug_level=0):
   """Ferme le toit avec un moteur de toit Came. 

Exemple:

import driver_came ; driver_came.do_close_roof(23,2)
"""

   io.setwarnings(False)
   io.setmode(io.BCM) #set up GPIO using BCM numbering
   io.setup(pin_cmd_close_bcm,io.OUT) # make pin an output (=arduino 29 close)

   io.output(pin_cmd_close_bcm,1)
   time.sleep(3)   
   io.output(pin_cmd_close_bcm,0)
    
   err=0
   return err
    
def get_data(pin_chk_power_bcm=26, pin_sw_manu_bcm=22, pin_sw_closed_bcm=5, pin_sw_opened_bcm=6, debug_level=0):
   """Lecture des etats des switchs du moteur de toit Came. 
Retourne un tuple, dans l'ordre: Un code de validité, 

Exemple:

import driver_came ; driver_came.get_data(26,22,5,6,2)
"""

   io.setwarnings(False)
   io.setmode(io.BCM) #set up GPIO using BCM numbering
   io.setup(pin_chk_power_bcm,io.IN, pull_up_down=io.PUD_DOWN) # make pin an input (=arduino 48 24V)
   io.setup(pin_sw_manu_bcm,io.IN, pull_up_down=io.PUD_DOWN) # make pin an input (=arduino 31 manu/auto)
   io.setup(pin_sw_closed_bcm,io.IN, pull_up_down=io.PUD_DOWN) # make pin an input (=arduino 39 closed)
   io.setup(pin_sw_opened_bcm,io.IN, pull_up_down=io.PUD_DOWN) # make pin an input (=arduino 41 opened)

   pin48  = io.input(pin_chk_power_bcm)
   pin31  = io.input(pin_sw_manu_bcm)
   pin39 = io.input(pin_sw_closed_bcm)
   pin41 = io.input(pin_sw_opened_bcm)
   if (debug_level==2):
      print("=== Bit states ===")
      disp ="pin48,gpio26,power24V ="+str(pin48)+"pin31,gpio22,auto/manu ="+str(pin31)+" pin39,gpio5,closed ="+str(pin39)+" pin41,gpio6,opened ="+str(pin41)
      print(disp)
    
   # === return
   err = 0
   power_came = 0
   if ( pin48==0 ):
      power_came_msg = "24Volts"
      power_came = 1
   else:
      power_came_msg = "0Volt"
      err = err +1
   if ( pin31==1 ):
      mode_came= 1
      mode_came_msg = "Auto"
   else:
      mode_came = 0
      mode_came_msg = "Manual"
   roof_state = -1
   roof_state_msg = "Unknown"
   if ( (pin39==1) and (pin41==1) ):
      err = err + 2
      roof_state_msg = "NoPower"
   elif ( (pin39==0) and (pin41==0) ):
      roof_state = 2
      roof_state_msg = "Intermediate"
   elif ( (pin39==1) and (pin41==0) ):
      roof_state = 0
      roof_state_msg = "Closed"
   elif ( (pin39==0) and (pin41==1) ):
      roof_state = 1
      roof_state_msg = "Opened"

   if (debug_level>=1):
      print("=== Came states ===")
      print("power={} mode={} state={}".format(power_came_msg, mode_came_msg, roof_state_msg));

   return err, power_came, mode_came, roof_state, power_came_msg, mode_came_msg, roof_state_msg, pin48, pin39, pin41,pin31