-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
477 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
title: MaixPy/MaixCAM Application Auto-Start at Boot | ||
--- | ||
|
||
Packaged applications can be set to automatically start when the device boots up, bypassing the application menu and directly launching the specified application. | ||
|
||
## Method One for Setting Application Auto-Start | ||
|
||
First, package and install the application, then go to `Settings -> Auto-Start` on your device to select the application you want to auto-start. To cancel auto-start, you can also adjust it here. | ||
|
||
## Method Two for Setting Application Auto-Start | ||
|
||
You can also modify the `/maixapp/auto_start.txt` file in your device to set it up. For methods on file transfer, refer to the previous documentation. | ||
* First, determine the `id` of the application you want to set. This is set when you package the application; if it's not an application you packaged yourself, you can install it on the device and check the folder names under the device's `/maixapp/apps/` directory, which are the application names (or you can download and check the device's `/maixapp/apps/app.info` file, where the application `id` is indicated inside the `[]` brackets). | ||
* Then write the `id` into the `/maixapp/auto_start.txt` file. (You can create the file locally on your computer, and then transfer it to the device using `MaixVision`.) | ||
* To cancel, delete the `/maixapp/auto_start.txt` file on the device. | ||
|
||
## Other Methods | ||
|
||
For MaixCAM, since the underlying system is Linux, if you are familiar with Linux, you can edit the startup scripts in `/etc/rc.local` or `/etc/init.d`. | ||
|
||
However, it is important to note that this method may cause the application to continue running when MaixVision connects, thereby occupying resources (such as the screen and camera) which might prevent MaixVision from running programs normally. The first two methods allow MaixVision to terminate the program upon connection to run its own programs. | ||
|
||
Thus, this method is more suitable for running background processes that do not occupy screen and camera resources. Generally, if you are not familiar with Linux, it is not recommended to use this method. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
--- | ||
title: MaixPy / MaixCAM Touchscreen Usage Guide | ||
--- | ||
|
||
## Introduction | ||
|
||
MaixCAM comes equipped with a touchscreen, which, when used in conjunction with applications, can facilitate numerous engaging functionalities. We can utilize APIs to detect touch interactions on the touchscreen. | ||
|
||
## Reading Touch Input with MaixPy | ||
|
||
MaixPy offers a straightforward `maix.touchscreen.TouchScreen` class for reading touch inputs. Here's an example: | ||
|
||
```python | ||
from maix import touchscreen, app, time | ||
|
||
ts = touchscreen.TouchScreen() | ||
|
||
pressed_already = False | ||
last_x = 0 | ||
last_y = 0 | ||
last_pressed = False | ||
while not app.need_exit(): | ||
x, y, pressed = ts.read() | ||
if x != last_x or y != last_y or pressed != last_pressed: | ||
print(x, y, pressed) | ||
last_x = x | ||
last_y = y | ||
last_pressed = pressed | ||
if pressed: | ||
pressed_already = True | ||
else: | ||
if pressed_already: | ||
print(f"clicked, x: {x}, y: {y}") | ||
pressed_already = False | ||
time.sleep_ms(1) # sleep some time to free some CPU usage | ||
``` | ||
|
||
## Interactivity with the Screen | ||
|
||
Integrating the screen can enable various interactive user experiences. More examples can be found in the [MaixPy/examples/vision/touchscreen](https://github.com/sipeed/MaixPy) directory. | ||
|
||
As previously described, to display content on the screen, typically, a `maix.image.Image` object is created and displayed using `disp.show(img)`. Implementing a button is as simple as drawing one on the image and then detecting touches within its area, ensuring that the image's dimensions match those of the screen: | ||
|
||
```python | ||
from maix import touchscreen, app, time, display, image | ||
|
||
ts = touchscreen.TouchScreen() | ||
disp = display.Display() | ||
|
||
img = image.Image(disp.width(), disp.height()) | ||
|
||
# draw exit button | ||
exit_label = "< Exit" | ||
size = image.string_size(exit_label) | ||
exit_btn_pos = [0, 0, 8*2 + size.width(), 12 * 2 + size.height()] | ||
img.draw_string(8, 12, exit_label, image.COLOR_WHITE) | ||
img.draw_rect(exit_btn_pos[0], exit_btn_pos[1], exit_btn_pos[2], exit_btn_pos[3], image.COLOR_WHITE, 2) | ||
|
||
def is_in_button(x, y, btn_pos): | ||
return x > btn_pos[0] and x < btn_pos[0] + btn_pos[2] and y > btn_pos[1] and y < btn_pos[1] + btn_pos[3] | ||
|
||
while not app.need_exit(): | ||
x, y, pressed = ts.read() | ||
if is_in_button(x, y, exit_btn_pos): | ||
app.set_exit_flag(True) | ||
img.draw_circle(x, y, 1, image.Color.from_rgb(255, 255, 255), 2) | ||
disp.show(img) | ||
``` | ||
|
||
## Handling Different Screen and Image Sizes | ||
|
||
In the example above, the `img` matches the screen size. If your `img` and screen sizes differ (e.g., using `img = image.Image(240, 240)` on a `640x480` screen), the default behavior of `disp.show(img)` is `image.Fit.FIT_CONTAIN`, which scales the image to `480x480` and fills the sides with black. If a button is drawn on the `240x240` image, such as at coordinates `(0, 0, 60, 40)`, the button will also be scaled up. Thus, the coordinates for touch detection should be adjusted to `((640 - 480) / 2, 0, 480/240*60, 480/240*40)`, which translates to `(80, 0, 120, 80)`. | ||
|
||
For convenience in scaling images and quickly calculating the positions and sizes of points or rectangles in the scaled image, the `image.resize_map_pos` function is provided: | ||
|
||
```python | ||
from maix import touchscreen, app, time, display, image | ||
|
||
ts = touchscreen.TouchScreen() | ||
disp = display.Display() | ||
|
||
img = image.Image(240, 240) | ||
img.draw_rect(0, 0, img.width(), img.height(), image.COLOR_WHITE) | ||
|
||
# draw exit button | ||
exit_label = "< Exit" | ||
size = image.string_size(exit_label) | ||
exit_btn_pos = [0, 0, 8*2 + size.width(), 12 * 2 + size.height()] | ||
img.draw_string(8, 12, exit_label, image.COLOR_WHITE) | ||
img.draw_rect(exit_btn_pos[0], exit_btn_pos[1], exit_btn_pos[2], exit_btn_pos[3], image.COLOR_WHITE, 2) | ||
# 图像按键坐标映射到屏幕上的坐标 | ||
exit_btn_disp_pos = image.resize_map_pos(img.width(), img.height(), disp.width(), disp.height(), image.Fit.FIT_CONTAIN, exit_btn_pos[0], exit_btn_pos[1], exit_btn_pos[2], exit_btn_pos[3]) | ||
|
||
def is_in_button(x, y, btn_pos): | ||
return x > btn_pos[0] and x < btn_pos[0] + btn_pos[2] and y > btn_pos[1] and y < btn_pos[1] + btn_pos[3] | ||
|
||
while not app.need_exit(): | ||
x, y, pressed = ts.read() | ||
if is_in_button(x, y, exit_btn_disp_pos): | ||
app.set_exit_flag(True) | ||
# 屏幕的坐标映射回图像上对应的坐标,然后在图像上画点 | ||
x, y = image.resize_map_pos_reverse(img.width(), img.height(), disp.width(), disp.height(), image.Fit.FIT_CONTAIN, x, y) | ||
img.draw_circle(x, y, 1, image.Color.from_rgb(255, 255, 255), 2) | ||
disp.show(img, fit=image.Fit.FIT_CONTAIN) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
title: MaixPy/MaixCAM 应用开机自启 | ||
--- | ||
|
||
打包安装好的应用可以设置开机自动启动,这样开机就不会显示应用菜单,直接进入指定的应用。 | ||
|
||
## 设置应用开机自启方法一 | ||
|
||
先打包安装好应用,然后在设备`设置 -> 开机自启` 设置中选择需要自动启动的应用即可,取消开机自启也是在这里设置。 | ||
|
||
|
||
## 设置应用开机自启方法二 | ||
|
||
你也可以通过修改设备中的 `/maixapp/auto_start.txt` 文件来设置,和传输文件的方法请看前面的文档。 | ||
* 首先知道你需要设置的应用的 `id` 是什么。在你打包应用的时候设置的;如果不是你自己打包的应用,可以先安装到设备,查看设备`/maixapp/apps/` 目录下的文件夹名就是应用名,(也可以下载查看设备的`/maixapp/apps/app.info` 文件,`[]`中括号部分就是应用`id`)。 | ||
* 然后写入 `id` 到 `/maixapp/auto_start.txt` 文件即可。(可以在电脑本地创建文件,然后 `MaixVision` 传输到设备。) | ||
* 如果要取消,删除设备上的 `/maixapp/auto_start.txt` 文件即可。 | ||
|
||
|
||
## 其它方法 | ||
|
||
对于 MaixCAM, 因为底层是 Linux, 如果你熟悉 Linux, 编辑`/etc/rc.local` 或者 `/etc/init.d` 下的启动脚本也可以。 | ||
|
||
但是需要注意的是,这种方式会让 MaixVision 在连接的时候无法停止这个应用,从而造成资源占用(比如屏幕和摄像头) MaixVision 可能无法正常跑程序,而前两种方法 MaixVision 连接设备时是可以正常让程序退出以供 MaixVsion 跑程序的。 | ||
|
||
所以这种方法比较适合开机跑一些不会占用屏幕和摄像头等资源的后台进程,一般情况下如果你不熟悉 Linux 不建议这样操作。 | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
--- | ||
title: MaixPy / MaixCAM 触摸屏使用方法 | ||
--- | ||
|
||
## 简介 | ||
|
||
对于 MaixCAM 自带了一个触摸屏,写应用时配合触摸屏可以实现很多有趣应用,我们可以通过 API 读取到触摸屏的点按操作。 | ||
|
||
## MaixPy 读取触摸 | ||
|
||
MaixPy 提供了一个简单的`maix.touchscreen.TouchScreen` 类来读取,举例: | ||
|
||
```python | ||
from maix import touchscreen, app, time | ||
|
||
ts = touchscreen.TouchScreen() | ||
|
||
pressed_already = False | ||
last_x = 0 | ||
last_y = 0 | ||
last_pressed = False | ||
while not app.need_exit(): | ||
x, y, pressed = ts.read() | ||
if x != last_x or y != last_y or pressed != last_pressed: | ||
print(x, y, pressed) | ||
last_x = x | ||
last_y = y | ||
last_pressed = pressed | ||
if pressed: | ||
pressed_already = True | ||
else: | ||
if pressed_already: | ||
print(f"clicked, x: {x}, y: {y}") | ||
pressed_already = False | ||
time.sleep_ms(1) # sleep some time to free some CPU usage | ||
``` | ||
|
||
## 配合屏幕实现交互 | ||
|
||
配合屏幕可以做出一些用户交互的内容,更多可以看[MaixPy/examples/vision/touchscreen](https://github.com/sipeed/MaixPy) 目录下例程。 | ||
|
||
如前面的文章介绍的,我们要往屏幕显示内容,一般是得到一个`maix.image.Image`对象,然后调用`disp.show(img)`来显示这张图像。 | ||
实现一个按钮的最原始和简单的方法就是在这个图像上画一个按钮,然后判断用户触摸到这个区域就算是触发了按下事件,注意图像的大小要和屏幕的大小保持一致: | ||
```python | ||
from maix import touchscreen, app, time, display, image | ||
|
||
ts = touchscreen.TouchScreen() | ||
disp = display.Display() | ||
|
||
img = image.Image(disp.width(), disp.height()) | ||
|
||
# draw exit button | ||
exit_label = "< Exit" | ||
size = image.string_size(exit_label) | ||
exit_btn_pos = [0, 0, 8*2 + size.width(), 12 * 2 + size.height()] | ||
img.draw_string(8, 12, exit_label, image.COLOR_WHITE) | ||
img.draw_rect(exit_btn_pos[0], exit_btn_pos[1], exit_btn_pos[2], exit_btn_pos[3], image.COLOR_WHITE, 2) | ||
|
||
def is_in_button(x, y, btn_pos): | ||
return x > btn_pos[0] and x < btn_pos[0] + btn_pos[2] and y > btn_pos[1] and y < btn_pos[1] + btn_pos[3] | ||
|
||
while not app.need_exit(): | ||
x, y, pressed = ts.read() | ||
if is_in_button(x, y, exit_btn_pos): | ||
app.set_exit_flag(True) | ||
img.draw_circle(x, y, 1, image.Color.from_rgb(255, 255, 255), 2) | ||
disp.show(img) | ||
``` | ||
|
||
|
||
## 屏幕和图像大小不一样时如何处理 | ||
|
||
上面的例子可以看到 `img` 大小和屏幕大小一样,如果你的`img`和屏幕大小不一样怎么办(比如上面使用`img = image.Image(240, 240)`,比如屏幕是`640x480`, 图像是`240x240`,`disp.show(img)`的默认行为是`image.Fit.FIT_CONTAIN`, 即把图片放大到`480x480`然后边上填充黑色,如果你在`240x240`的图上画了按钮,比如坐标`(0, 0, 60, 40)`,那么按钮也会自动被放大,所以触摸判断的坐标就不能用`(0, 0, 60, 40)`,需要用`((640 - 480) / 2, 0, 480/240*60, 480/240*40)`, 即`(80, 0, 120, 80)`。 | ||
|
||
这里为了方便缩放图像时,快速计算源图像的点或者矩形框 在 缩放后的目标图像的位置和大小,提供了`image.resize_map_pos`函数来进行此计算过程。 | ||
|
||
```python | ||
from maix import touchscreen, app, time, display, image | ||
|
||
ts = touchscreen.TouchScreen() | ||
disp = display.Display() | ||
|
||
img = image.Image(240, 240) | ||
img.draw_rect(0, 0, img.width(), img.height(), image.COLOR_WHITE) | ||
|
||
# draw exit button | ||
exit_label = "< Exit" | ||
size = image.string_size(exit_label) | ||
exit_btn_pos = [0, 0, 8*2 + size.width(), 12 * 2 + size.height()] | ||
img.draw_string(8, 12, exit_label, image.COLOR_WHITE) | ||
img.draw_rect(exit_btn_pos[0], exit_btn_pos[1], exit_btn_pos[2], exit_btn_pos[3], image.COLOR_WHITE, 2) | ||
# 图像按键坐标映射到屏幕上的坐标 | ||
exit_btn_disp_pos = image.resize_map_pos(img.width(), img.height(), disp.width(), disp.height(), image.Fit.FIT_CONTAIN, exit_btn_pos[0], exit_btn_pos[1], exit_btn_pos[2], exit_btn_pos[3]) | ||
|
||
def is_in_button(x, y, btn_pos): | ||
return x > btn_pos[0] and x < btn_pos[0] + btn_pos[2] and y > btn_pos[1] and y < btn_pos[1] + btn_pos[3] | ||
|
||
while not app.need_exit(): | ||
x, y, pressed = ts.read() | ||
if is_in_button(x, y, exit_btn_disp_pos): | ||
app.set_exit_flag(True) | ||
# 屏幕的坐标映射回图像上对应的坐标,然后在图像上画点 | ||
x, y = image.resize_map_pos_reverse(img.width(), img.height(), disp.width(), disp.height(), image.Fit.FIT_CONTAIN, x, y) | ||
img.draw_circle(x, y, 1, image.Color.from_rgb(255, 255, 255), 2) | ||
disp.show(img, fit=image.Fit.FIT_CONTAIN) | ||
``` | ||
|
||
|
Oops, something went wrong.