-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecwrite.py
More file actions
71 lines (60 loc) · 2.18 KB
/
ecwrite.py
File metadata and controls
71 lines (60 loc) · 2.18 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
# EC_IO_FILE = '/sys/kernel/debug/ec/ec0/io'
EC_IO_FILE = '/dev/ec' if os.system('ls /sys/kernel/debug/ec/ec0/io 2> /dev/null > /dev/null') else '/sys/kernel/debug/ec/ec0/io'
##------------------------------##
##----Class to read/write EC----##
class ECWrite:
def __init__(self):
self.ec_path = EC_IO_FILE
print("Setting up EC access..." + self.ec_path)
self.buffer = b''
self.ec_file = None
self.setupEC()
def setupEC(self):
try:
self.ec_file = open(self.ec_path, 'rb+')#, buffering=0)
except PermissionError:
print('Run with sudo')
exit(1)
except FileNotFoundError:
print(self.ec_path, 'not found. Check acpi_ec')
exit(1)
# from subprocess import Popen
# Popen(['modprobe', 'ec_sys', 'write_support=1'])
# print('EC Changed. Restarting the application may help if it is not working.')
except Exception as e:
print("Error: " + str(e))
def ec_write(self, address, value):
try:
self.ec_file.seek(address)
self.ec_file.write(bytearray([value]))
except Exception as e:
print("Error: " + str(e))
exit(1)
## Copy EC contents to buffer
def ec_refresh(self):
try:
self.ec_file.seek(0)
self.buffer = self.ec_file.read()
# print(self.buffer)
if self.buffer == b'':
print("BAD BUFFER EXITING!")
exit(1)
except Exception as e:
print("Error: " + str(e))
exit(1)
## Read EC contents from buffer instead of going to disk
def ec_read(self, address):
try:
# self.ec_file.seek(address)
# return ord(self.ec_file.read(1))
if self.buffer == b'':
print("BUFFER EMPTY!")
exit(1)
return self.buffer[address]
# return ord(self.buffer[int(address)])
except Exception as e:
print("Error: " + str(e))
exit(1)
def shutdownEC(self):
self.ec_file.close()