Skip to content

Commit

Permalink
Adding support for RM2
Browse files Browse the repository at this point in the history
  • Loading branch information
bordaigorl committed Jan 2, 2021
1 parent ac56d4e commit 693e709
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
24 changes: 11 additions & 13 deletions src/rmview/rmview.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,24 @@ def connected(self, ssh):
# cat /sys/devices/soc0/machine -> reMarkable 1.x
_,out,_ = ssh.exec_command("cat /sys/devices/soc0/machine")
rmv = out.read().decode("utf-8")
ver = re.fullmatch(r"reMarkable (\d+)\..*\n", rmv)
if ver is None or ver[1] != "1":
log.error("Device is unsupported: '%s' [%s]", rmv, ver[1] if ver else "unknown device")
version = re.fullmatch(r"reMarkable (\d+)\..*\n", rmv)
if version is None or version[1] not in ["1", "2"]:
log.error("Device is unsupported: '%s' [%s]", rmv, version[1] if version else "unknown device")
QMessageBox.critical(None, "Unsupported device", 'The detected device is %s.\nrmView currently only supports reMarkable 1.' % rmv)
self.quit()
return

version = int(version[1])

# check needed files are in place
_,out,_ = ssh.exec_command("[ -x $HOME/rM-vnc-server ] && [ -e $HOME/mxc_epdc_fb_damage.ko ]")
_,out,_ = ssh.exec_command("[ -x $HOME/rM-vnc-server-standalone ]")
if out.channel.recv_exit_status() != 0:
mbox = QMessageBox(QMessageBox.NoIcon, 'Missing components', 'Your reMarkable is missing some needed components.')
icon = QPixmap(":/assets/problem.svg")
icon.setDevicePixelRatio(self.devicePixelRatio())
mbox.setIconPixmap(icon)
mbox.setInformativeText(
"To work properly, rmView needs the rM-vnc-server and mxc_epdc_fb_damage.ko files "\
"To work properly, rmView needs the rM-vnc-server-standalone program "\
"to be installed on your tablet.\n"\
"You can install them manually, or let rmView do the work for you by pressing 'Auto Install' below.\n\n"\
"If you are unsure, please consult the documentation.")
Expand All @@ -232,15 +234,11 @@ def connected(self, ssh):
try:
sftp = ssh.open_sftp()
from stat import S_IXUSR
fo = QFile(':bin/rM-vnc-server')
fo.open(QIODevice.ReadOnly)
sftp.putfo(fo, 'rM-vnc-server')
fo.close()
sftp.chmod('rM-vnc-server', S_IXUSR)
fo = QFile(':bin/mxc_epdc_fb_damage.ko')
fo = QFile(':bin/rM%d-vnc-server-standalone' % version)
fo.open(QIODevice.ReadOnly)
sftp.putfo(fo, 'mxc_epdc_fb_damage.ko')
sftp.putfo(fo, 'rM-vnc-server-standalone')
fo.close()
sftp.chmod('rM-vnc-server-standalone', S_IXUSR)
log.info("Installation successful!")
except Exception as e:
log.error('%s %s', type(e), e)
Expand All @@ -263,7 +261,7 @@ def connected(self, ssh):
self.fbworker.signals.onFatalError.connect(self.frameError)
self.threadpool.start(self.fbworker)

self.penworker = PointerWorker(ssh)
self.penworker = PointerWorker(ssh, path="/dev/input/event%d" % (version-1))
self.threadpool.start(self.penworker)
self.pen = self.viewer.scene.addEllipse(0,0,self.pen_size,self.pen_size,
pen=QPen(QColor('white')),
Expand Down
13 changes: 8 additions & 5 deletions src/rmview/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ def vncConnectionMade(self):
self.setEncodings([
HEXTILE_ENCODING,
CORRE_ENCODING,
PSEUDO_CURSOR_ENCODING,
RRE_ENCODING,
RAW_ENCODING ])
time.sleep(.1) # get first image without artifacts
self.framebufferUpdateRequest()

def sendPassword(self, password):
Expand Down Expand Up @@ -89,11 +91,11 @@ def stop(self):
log.info("Stopping framebuffer thread...")
reactor.callFromThread(reactor.stop)
try:
self.ssh.exec_command("killall rM-vnc-server", timeout=3)
self.ssh.exec_command("killall rM-vnc-server-standalone", timeout=3)
except Exception as e:
log.warning("VNC could not be stopped on the reMarkable.")
log.warning("Although this is not a big problem, it may consume some resources until you restart the tablet.")
log.warning("You can manually terminate it by running `ssh %s killall rM-vnc-server`.", self.ssh.hostname)
log.warning("You can manually terminate it by running `ssh %s killall rM-vnc-server-standalone`.", self.ssh.hostname)
log.error(e)
log.info("Framebuffer thread stopped")

Expand All @@ -102,7 +104,7 @@ def run(self):
try:
_,out,_ = self.ssh.exec_command("/sbin/insmod $HOME/mxc_epdc_fb_damage.ko")
log.debug("Insmod returned %d", out.channel.recv_exit_status())
_,_,out = self.ssh.exec_command("$HOME/rM-vnc-server")
_,_,out = self.ssh.exec_command("$HOME/rM-vnc-server-standalone")
log.info(next(out))
except Exception as e:
self.signals.onFatalError.emit(e)
Expand Down Expand Up @@ -133,8 +135,9 @@ class PointerWorker(QRunnable):

_stop = False

def __init__(self, ssh, threshold=1000):
def __init__(self, ssh, path="/dev/input/event0", threshold=1000):
super(PointerWorker, self).__init__()
self.event = path
self.ssh = ssh
self.threshold = threshold
self.signals = PWSignals()
Expand All @@ -145,7 +148,7 @@ def stop(self):

@pyqtSlot()
def run(self):
penkill, penstream, _ = self.ssh.exec_command('cat /dev/input/event0 & { read ; kill %1; }')
penkill, penstream, _ = self.ssh.exec_command('cat %s & { read ; kill %%1; }' % self.event)
self._penkill = penkill
new_x = new_y = False
state = LIFTED
Expand Down

0 comments on commit 693e709

Please sign in to comment.