-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathROOF.py
80 lines (69 loc) · 2.89 KB
/
ROOF.py
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
#importing libraries
import smbus
import time
import IO
bus = smbus.SMBus(1)
# Device address
adress_20 = 0x20
adress_21 = 0x21
adress_22 = 0x22
adress_23 = 0x23
adress_24 = 0x24
adress_25 = 0x25
# Pin direction register
IO_DIR_A = 0x00
IO_DIR_B = 0x01
# Register for outputs
OLATA = 0x14
OLATB = 0x15
# Register for inputs
GPIOA = 0x12
GPIOB = 0x13
LR_write = [89,81,83,90,84,86,82]
LR_read = [49,50,51,52,53,54,55]
LR_in = [1,2,4,8,16,32,64]
ROOF_result = [0,0,0,0,0,0,0]
#check if cable is OK
def check():
for out in range(0,7):
#setting pins as outputs
bus.write_byte_data(adress_24,IO_DIR_A,0x00)
bus.write_byte_data(adress_24,IO_DIR_B,0x00)
bus.write_byte_data(adress_25,IO_DIR_A,0x00)
bus.write_byte_data(adress_25,IO_DIR_B,0x00)
#setting pins as pull-up inputs
bus.write_byte_data(adress_20,IO_DIR_A,0xff)
bus.write_byte_data(adress_20,IO_DIR_B,0xff)
bus.write_byte_data(adress_21,IO_DIR_A,0xff)
bus.write_byte_data(adress_21,IO_DIR_B,0xff)
bus.write_byte_data(adress_22,IO_DIR_A,0xff)
bus.write_byte_data(adress_22,IO_DIR_B,0xff)
bus.write_byte_data(adress_23,IO_DIR_A,0xff)
bus.write_byte_data(adress_23,IO_DIR_B,0xff)
bus.write_byte_data(adress_20,0x0d,0xff)
bus.write_byte_data(adress_20,0x0c,0xff)
bus.write_byte_data(adress_21,0x0d,0xff)
bus.write_byte_data(adress_21,0x0c,0xff)
bus.write_byte_data(adress_22,0x0d,0xff)
bus.write_byte_data(adress_22,0x0c,0xff)
bus.write_byte_data(adress_23,0x0d,0xff)
bus.write_byte_data(adress_23,0x0c,0xff)
bus.write_byte_data(adress_25,OLATA,0xff)
bus.write_byte_data(adress_25,OLATB,0xff)
adress_in,port_in,pin_in = IO.read_pin(LR_read[out])
adress_out,port_out,pin_out = IO.write_pin(LR_write[out])
bus.write_byte_data(adress_out,port_out,pin_out)
time.sleep(0.01)
read = bus.read_byte_data(adress_in,port_in)
time.sleep(0.01)
bus.write_byte_data(adress_out,port_out,0)
read = ~read
read = read & 0xff
if read == LR_in[out]:
ROOF_result[out] = 1
if read != LR_in[out]:
ROOF_result[out] = 0
#print ("LR_write-->", LR_write[out], "LR_read-->", LR_read[out], "read-->", read, "result-->", ROOF_result[out])
out = out + 1
return(ROOF_result)
#check()