Skip to content

Commit

Permalink
feat: set display rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
codematrixer committed Sep 25, 2024
1 parent 74753e8 commit 81934b5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ export HDC_SERVER_PORT=7035

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

Expand Down Expand Up @@ -217,14 +217,23 @@ from hmdriver2.proto import DisplayRotation
rotation = d.display_rotation
# ouput: DisplayRotation.ROTATION_0
```

设备旋转状态包括:
```python
ROTATION_0 = 0 # 未旋转
ROTATION_90 = 1 # 顺时针旋转90度
ROTATION_180 = 2 # 顺时针旋转180度
ROTATION_270 = 3 # 顺时针旋转270度
```
备注:目前旋转状态只能查看,不支持设置

### 设置设备旋转
```python
from hmdriver2.proto import DisplayRotation

# 旋转180度
d.set_display_rotation(DisplayRotation.ROTATION_180)
```



### Home
Expand Down
3 changes: 2 additions & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import time
from hmdriver2.driver import Driver
from hmdriver2.proto import DeviceInfo, KeyCode, ComponentData
from hmdriver2.proto import DeviceInfo, KeyCode, ComponentData, DisplayRotation


# New driver
Expand All @@ -14,6 +14,7 @@

d.display_size
d.display_rotation
d.set_display_rotation(DisplayRotation.ROTATION_180)

d.install_app("~/develop/harmony_prj/demo.hap")
d.clear_app("com.samples.test.uitest")
Expand Down
10 changes: 10 additions & 0 deletions hmdriver2/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ def display_rotation(self) -> DisplayRotation:
value = self._invoke(api).result
return DisplayRotation.from_value(value)

def set_display_rotation(self, rotation: DisplayRotation):
"""
Sets the display rotation to the specified orientation.
Args:
rotation (DisplayRotation): The desired display rotation. This should be an instance of the DisplayRotation enum.
"""
api = "Driver.setDisplayRotation"
self._invoke(api, args=[rotation.value])

@cached_property
def device_info(self) -> DeviceInfo:
"""
Expand Down

0 comments on commit 81934b5

Please sign in to comment.