-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupisStatus.py
73 lines (65 loc) · 1.87 KB
/
upisStatus.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
# /*******************************************************
# *
# * Copyright (C) 2015-2016 Kyriakos Naziris <[email protected]>
# * This is a thesis project of University of Portsmouth.
# *
# * This file is part of HomeSecPi.
# *
# * Feel free to use and modify the source code as long as
# * as you give credit to the original author of the
# * project (Kyriakos Naziris - [email protected]).
# *
# *******************************************************/
import smbus
i2c = smbus.SMBus(1)
#Reurns the mode of the UPiS power
def pwr_mode():
row = i2c.read_word_data(0x6a, 0x00)
row = "%02x "%(row,)
output = (row[-2:]).strip()
if (output == '1'):
return "External Cable Powering (EPR)"
elif (output == '2'):
return "USB Cable Powering"
elif (output == '3'):
return "Raspberry Pi Powering"
elif (output == '4'):
return "Battery Powering"
elif (output == '5'):
return "Battery Low Powering"
elif (output == '6'):
return "CPR Mode"
elif (output =='7'):
return "BPR Mode"
else:
return "Reading Error"
#Returns the battary voltage
def bat_level():
row = i2c.read_word_data(0x6a, 0x01)
row = "%02x "%(row,)
return (float(row) / 100)
#Returns the RPi voltage
def rpi_level():
row = i2c.read_word_data(0x6a, 0x03)
row = "%02x "%(row,)
return (float(row) / 100)
#Returns the USB voltage
def usb_level():
row = i2c.read_word_data(0x6a, 0x05)
row = "%02x "%(row,)
return (float(row) / 100)
#Returns the external EPR voltage
def epr_level():
row = i2c.read_word_data(0x6a, 0x07)
row = "%02x "%(row,)
return (float(row) / 100)
#Returns the UPiS currnet in mA
def crn_level():
row = i2c.read_word_data(0x6a, 0x09)
row = "%02x "%(row,)
return row
#Reurns the current version of the UPiS
def version():
row = i2c.read_word_data(0x6b, 0x00)
row = "%02x "%(row,)
return float(int(row, 16)) / 100 # int(row,16) is converting the hex string into an integer