display.py

# هذا العمل مرخص بموجب ترخيص MIT.
# حقوق النشر (c) 2013-2023 OpenMV LLC. جميع الحقوق محفوظة.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# مثال على شاشة LCD ولوحة اللمس والكاميرا.

import csi
import time
import image
import display
from gt911 import GT911
from machine import I2C

IMG_OFFSET = 80
touch_detected = False
points_colors = ((255, 0, 0), (0, 255, 0), (0, 0, 255), (0, 255, 255), (255, 255, 0))

csi0 = csi.CSI()
csi0.reset()  # إعادة ضبط المستشعر وتهيئته.
csi0.pixformat(csi.RGB565)  # تعيين تنسيق البكسل إلى RGB565 (أو GRAYSCALE)
csi0.framesize(csi.VGA)  # تعيين حجم الإطار إلى QVGA (320x240)

lcd = display.DSIDisplay(
    framesize=display.FWVGA, portrait=True, refresh=60, controller=display.ST7701()
)

# لاحظ استخدام أرقام أو أسماء الأطراف وليس كائنات Pin لأن
# المشغل (driver) يحتاج إلى تغيير اتجاهات الأطراف لإعادة تعيين المتحكم (controller).
touch = GT911(
    I2C(4, freq=400_000),
    reset_pin="PI2",
    irq_pin="PI1",
    touch_points=5,
    refresh_rate=240,
    reverse_x=True,
    touch_callback=lambda pin: globals().update(touch_detected=True),
)

# أنشئ كائن ساعة (clock) لتتبع معدل الإطارات (FPS).
clock = time.clock()

while True:
    clock.tick()  # تحديث ساعة معدل الإطارات (FPS).

    # التقاط إطار جديد
    img = csi0.snapshot()

    # رسم نقاط اللمس في حال تم اكتشاف لمس.
    if touch_detected:
        n, points = touch.read_points()
        for i in range(0, n):
            img.draw_circle(
                (points[i][0] - IMG_OFFSET, points[i][1], points[i][2] * 3),
                color=points_colors[points[i][3]],
                thickness=2,
            )
        touch_detected = False

    # رسم الصورة على الشاشة.
    lcd.write(img, y=IMG_OFFSET, hint=image.TRANSPOSE | image.VFLIP)

    print(clock.fps())

results matching ""

    No results matching ""