forked from snowyoneill/Linux-PredatorSense
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathecwrite.py
More file actions
47 lines (40 loc) · 1.53 KB
/
Copy pathecwrite.py
File metadata and controls
47 lines (40 loc) · 1.53 KB
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
EC_IO_FILE = '/sys/kernel/debug/ec/ec0/io'
##------------------------------##
##----Class to read/write EC----##
class ECWrite:
def __init__(self):
print("Setting up EC access...")
self.ec_path = EC_IO_FILE
self.setupEC()
def setupEC(self):
try:
self.ec_file = open(self.ec_path, 'rb+')
except PermissionError:
print('Run with sudo')
exit(1)
except FileNotFoundError:
print(ec_path, 'not found. Creating the EC IO file...')
# from subprocess import Popen
# Popen(['modprobe', 'ec_sys', 'write_support=1'])
# print('EC Changed. Restarting the application may help if it is not working.')
def ec_write(self, address, value):
try:
self.ec_file.read()
self.ec_file.seek(address)
old_value = ord(self.ec_file.read(1))
if value != old_value:
# print("Before: %3d\tAfter: %3d" % (old_value, value))
self.ec_file.seek(address)
self.ec_file.write(bytearray([value]))
else:
print("Value was not changed: %s, %3d" % (hex(address), value))
print("Before: %3d\tAfter: %3d" % (old_value, value))
except Exception as e:
print("Error" + str(e))
def ec_refresh(self):
self.ec_file.read()
def ec_read(self, address):
self.ec_file.seek(address)
return ord(self.ec_file.read(1))
def shutdownEC(self):
self.ec_file.close()