Skip to content

Commit 81934b5

Browse files
committed
feat: set display rotation
1 parent 74753e8 commit 81934b5

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ export HDC_SERVER_PORT=7035
6666

6767
3. 安装`hmdirver2` 基础库
6868
```bash
69-
pip3 install -U hmdriver
69+
pip3 install -U hmdriver2
7070
```
7171
如果需要使用[屏幕录屏](#屏幕录屏) 功能,则需要安装额外依赖`opencv-python`
7272
```bash
73-
pip3 install -U "hmdriver[opencv-python]"
73+
pip3 install -U "hmdriver2[opencv-python]"
7474
//由于`opencv-python`比较大,因此没有写入到主依赖中
7575
```
7676

@@ -217,14 +217,23 @@ from hmdriver2.proto import DisplayRotation
217217
rotation = d.display_rotation
218218
# ouput: DisplayRotation.ROTATION_0
219219
```
220+
220221
设备旋转状态包括:
221222
```python
222223
ROTATION_0 = 0 # 未旋转
223224
ROTATION_90 = 1 # 顺时针旋转90度
224225
ROTATION_180 = 2 # 顺时针旋转180度
225226
ROTATION_270 = 3 # 顺时针旋转270度
226227
```
227-
备注:目前旋转状态只能查看,不支持设置
228+
229+
### 设置设备旋转
230+
```python
231+
from hmdriver2.proto import DisplayRotation
232+
233+
# 旋转180度
234+
d.set_display_rotation(DisplayRotation.ROTATION_180)
235+
```
236+
228237

229238

230239
### Home

example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import time
44
from hmdriver2.driver import Driver
5-
from hmdriver2.proto import DeviceInfo, KeyCode, ComponentData
5+
from hmdriver2.proto import DeviceInfo, KeyCode, ComponentData, DisplayRotation
66

77

88
# New driver
@@ -14,6 +14,7 @@
1414

1515
d.display_size
1616
d.display_rotation
17+
d.set_display_rotation(DisplayRotation.ROTATION_180)
1718

1819
d.install_app("~/develop/harmony_prj/demo.hap")
1920
d.clear_app("com.samples.test.uitest")

hmdriver2/driver.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ def display_rotation(self) -> DisplayRotation:
156156
value = self._invoke(api).result
157157
return DisplayRotation.from_value(value)
158158

159+
def set_display_rotation(self, rotation: DisplayRotation):
160+
"""
161+
Sets the display rotation to the specified orientation.
162+
163+
Args:
164+
rotation (DisplayRotation): The desired display rotation. This should be an instance of the DisplayRotation enum.
165+
"""
166+
api = "Driver.setDisplayRotation"
167+
self._invoke(api, args=[rotation.value])
168+
159169
@cached_property
160170
def device_info(self) -> DeviceInfo:
161171
"""

0 commit comments

Comments
 (0)