Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
florin-trutiu committed Dec 13, 2024
2 parents 0b62584 + d175093 commit 9ad1d7f
Showing 1 changed file with 65 additions and 40 deletions.
105 changes: 65 additions & 40 deletions source/brailleDisplayDrivers/nlseReaderZoomax.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
# -*- coding: UTF-8 -*-
#brailleDisplayDrivers/nlseReaderZoomax.py
#Description:
# NLS eReader Zoomax driver for NVDA.
# brailleDisplayDrivers/nlseReaderZoomax.py
# Description:
# NLS eReader Zoomax driver for NVDA.

import time
from io import BytesIO
from typing import Union, List, Optional

from collections import OrderedDict
import hwPortUtils
import braille
from hwIo import intToByte, boolToByte
import inputCore
from logHandler import log
import brailleInput
import hwIo
import bdDetect
from struct import unpack
import serial

TIMEOUT = 0.2
Expand All @@ -37,7 +33,7 @@
LOC_BRAILLE_KEYS = b"\x33"
LOC_JOYSTICK_KEYS = b"\x34"
LOC_DEVICE_ID = b"\x84"
LOC_SERIAL_NUMBER = b"\x8A"
LOC_SERIAL_NUMBER = b"\x8a"

LOC_RSP_LENGTHS = {
LOC_DISPLAY_DATA: 1,
Expand All @@ -53,11 +49,28 @@
LOC_ROUTING_KEYS: None,
LOC_ROUTING_KEY: None,
LOC_DISPLAY_KEYS: ("d1", "d2", "d3", "d4", "d5", "d6"),
LOC_BRAILLE_KEYS: ("bl", "br", "bs", None, "s1", "s2", "s3", "s4", # byte 1
"b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8"), # byte 2
LOC_BRAILLE_KEYS: (
"bl",
"br",
"bs",
None,
"s1",
"s2",
"s3",
"s4", # byte 1
"b1",
"b2",
"b3",
"b4",
"b5",
"b6",
"b7",
"b8",
), # byte 2
LOC_JOYSTICK_KEYS: ("up", "left", "down", "right", "select"),
}


class BrailleDisplayDriver(braille.BrailleDisplayDriver):
_dev: hwIo.IoBase
name = "nlseReaderZoomax"
Expand All @@ -68,10 +81,13 @@ class BrailleDisplayDriver(braille.BrailleDisplayDriver):

@classmethod
def registerAutomaticDetection(cls, driverRegistrar: bdDetect.DriverRegistrar):
driverRegistrar.addUsbDevices(bdDetect.DeviceType.SERIAL, {
"VID_1A86&PID_7523", # CH340
})

driverRegistrar.addUsbDevices(
bdDetect.DeviceType.SERIAL,
{
"VID_1A86&PID_7523", # CH340
},
)

driverRegistrar.addBluetoothDevices(lambda m: m.id.startswith("NLS eReader Z"))

@classmethod
Expand All @@ -89,7 +105,8 @@ def _connect(self, port):
stopbits=serial.STOPBITS_ONE,
timeout=TIMEOUT,
writeTimeout=TIMEOUT,
onReceive=self._onReceive)
onReceive=self._onReceive,
)
except EnvironmentError:
log.info("Port not yet available.")
log.debugWarning("", exc_info=True)
Expand All @@ -106,10 +123,14 @@ def _connect(self, port):
self._dev.waitForRead(TIMEOUT)
if self.numCells:
break

if self.numCells:
log.info("Device connected via {type} ({port})".format(
type=portType, port=port))
log.info(
"Device connected via {type} ({port})".format(
type=portType,
port=port,
),
)
return True
log.info("Device arrival timeout")
self._dev.close()
Expand Down Expand Up @@ -140,7 +161,7 @@ def terminate(self):
pass
finally:
self._dev.close()

def _sendRequest(self, command: bytes, arg: Union[bytes, bool, int] = b""):
"""
:type command: bytes
Expand All @@ -159,11 +180,13 @@ def _sendRequest(self, command: bytes, arg: Union[bytes, bool, int] = b""):
raise TypeError(typeErrorString.format("command", "bytes", type(command).__name__))

arg = arg.replace(ESCAPE, ESCAPE * 2)
data = b"".join([
ESCAPE,
command,
arg
])
data = b"".join(
[
ESCAPE,
command,
arg,
],
)
self._dev.write(data)

def _onReceive(self, data: bytes):
Expand Down Expand Up @@ -219,36 +242,38 @@ def display(self, cells: List[int]):
arg = bytes(cells)
self._sendRequest(LOC_DISPLAY_DATA, arg)

gestureMap = inputCore.GlobalGestureMap({
"globalCommands.GlobalCommands": {
"braille_scrollBack": ("br(nlseReaderZoomax):d2",),
"braille_scrollForward": ("br(nlseReaderZoomax):d5",),
"braille_previousLine": ("br(nlseReaderZoomax):d1",),
"braille_nextLine": ("br(nlseReaderZoomax):d3",),
"braille_routeTo": ("br(nlseReaderZoomax):routing",),
"kb:upArrow": ("br(nlseReaderZoomax):up",),
"kb:downArrow": ("br(nlseReaderZoomax):down",),
"kb:leftArrow": ("br(nlseReaderZoomax):left",),
"kb:rightArrow": ("br(nlseReaderZoomax):right",),
"kb:enter": ("br(nlseReaderZoomax):select",),
gestureMap = inputCore.GlobalGestureMap(
{
"globalCommands.GlobalCommands": {
"braille_scrollBack": ("br(nlseReaderZoomax):d2",),
"braille_scrollForward": ("br(nlseReaderZoomax):d5",),
"braille_previousLine": ("br(nlseReaderZoomax):d1",),
"braille_nextLine": ("br(nlseReaderZoomax):d3",),
"braille_routeTo": ("br(nlseReaderZoomax):routing",),
"kb:upArrow": ("br(nlseReaderZoomax):up",),
"kb:downArrow": ("br(nlseReaderZoomax):down",),
"kb:leftArrow": ("br(nlseReaderZoomax):left",),
"kb:rightArrow": ("br(nlseReaderZoomax):right",),
"kb:enter": ("br(nlseReaderZoomax):select",),
},
},
})
)

class InputGesture(braille.BrailleDisplayGesture, brailleInput.BrailleInputGesture):

class InputGesture(braille.BrailleDisplayGesture, brailleInput.BrailleInputGesture):
source = BrailleDisplayDriver.name

def __init__(self, model, keysDown):
super(InputGesture, self).__init__()
# Model identifiers should not contain spaces.
if model:
self.model = model.replace(" ", "")
assert(self.model.isalnum())
assert self.model.isalnum()
self.keysDown = dict(keysDown)

self.keyNames = names = []
for group, groupKeysDown in keysDown.items():
if group == LOC_BRAILLE_KEYS and len(keysDown) == 1 and not groupKeysDown & 0xf8:
if group == LOC_BRAILLE_KEYS and len(keysDown) == 1 and not groupKeysDown & 0xF8:
# This is braille input.
# 0xfc covers command keys. The space bars are covered by 0x7.
self.dots = groupKeysDown >> 8
Expand Down

0 comments on commit 9ad1d7f

Please sign in to comment.