Skip to content

Commit b97f0fa

Browse files
committed
adds starting rotation to xpt2046 touch driver
1 parent da65146 commit b97f0fa

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

api_drivers/common_api_drivers/indev/xpt2046.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def __init__(
2323
self,
2424
spi_bus,
2525
touch_cal=None,
26+
startup_rotation=pointer_framework.lv.DISPLAY_ROTATION._0,
2627
debug=False
2728
):
2829
self._debug = debug
@@ -39,7 +40,11 @@ def __init__(
3940
self.__margin = margin * margin
4041

4142
self._spi = spi_bus
42-
super().__init__(touch_cal=touch_cal, debug=debug)
43+
super().__init__(
44+
touch_cal=touch_cal,
45+
startup_rotation=startup_rotation,
46+
debug=debug
47+
)
4348

4449
def _read_reg(self, reg):
4550
self._trans_buf[0] = reg

api_drivers/py_api_drivers/frozen/indev/pointer_framework.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class PointerDriver(_indev_base.IndevBase):
1010

11-
def __init__(self, touch_cal=None, debug=False): # NOQA
11+
def __init__(self, touch_cal=None, startup_rotation=lv.DISPLAY_ROTATION._0, debug=False): # NOQA
1212
self._last_x = -1
1313
self._last_y = -1
1414
self.__debug = debug
@@ -25,6 +25,7 @@ def __init__(self, touch_cal=None, debug=False): # NOQA
2525
self._orig_height = self._height
2626
self._set_type(lv.INDEV_TYPE.POINTER) # NOQA
2727
self.__cal_running = None
28+
self.__startup_rotation = startup_rotation
2829

2930
def __cal_callback(self, alphaX, betaX, deltaX, alphaY, betaY, deltaY):
3031
self._cal.alphaX = alphaX
@@ -77,9 +78,21 @@ def _get_coords(self):
7778
def _calc_coords(self, x, y):
7879
if self.is_calibrated:
7980
cal = self._cal
80-
xpos = int(round(x * cal.alphaX + y * cal.betaX + cal.deltaX))
81-
ypos = int(round(x * cal.alphaY + y * cal.betaY + cal.deltaY))
82-
return xpos, ypos
81+
x = int(round(x * cal.alphaX + y * cal.betaX + cal.deltaX))
82+
y = int(round(x * cal.alphaY + y * cal.betaY + cal.deltaY))
83+
84+
if (
85+
self.__startup_rotation == lv.DISPLAY_ROTATION._180 or # NOQA
86+
self.__startup_rotation == lv.DISPLAY_ROTATION._270 # NOQA
87+
):
88+
x = self._orig_width - x - 1
89+
y = self._orig_height - y - 1
90+
91+
if (
92+
self.__startup_rotation == lv.DISPLAY_ROTATION._90 or # NOQA
93+
self.__startup_rotation == lv.DISPLAY_ROTATION._270 # NOQA
94+
):
95+
x, y = self._orig_height - y - 1, x
8396

8497
return x, y
8598

0 commit comments

Comments
 (0)