Exemplo n.º 1
0
    def __init__(self, i2c, w, h, cycle=1000, irq_pin=33):
        self.cycle = cycle
        self.last_time = 0
        self.points = [(0, 0, 0), (0, 0, 0)]
        self.state = Touch.idle
        self.width, self.height = w, h

        # touch dirver init
        if i2c == None:
            i2c = I2C(I2C.I2C3, freq=100*1000, scl=24, sda=27)  # amigo
        TouchLow.config(i2c=i2c)

        # 按压检测(中断)
        self.events = []
        setattr(self, "press_check_", self.press_check)
        fm.register(irq_pin, fm.fpioa.GPIOHS28, force=True)
        key = GPIO(GPIO.GPIOHS28, GPIO.IN, GPIO.PULL_DOWN)
        key.irq(self.press_check_, GPIO.IRQ_FALLING, GPIO.WAKEUP_NOT_SUPPORT, 7)

        # 添加松手检测(轮询)
        system.event(20, self.release_check)
Exemplo n.º 2
0
from Maix import GPIO
import time

btn_time = 0

def btn_function(pin_num):
    current_time = time.ticks()
    global btn_time
    # print(current_time - btn_time)
    if (current_time - btn_time) >= 500:
        print("버튼이 눌렸습니다.")
        btn_time = time.ticks()

fm.register(8, fm.fpioa.GPIOHS0)
btn = GPIO(GPIO.GPIOHS0, GPIO.IN)

btn.irq(btn_function, GPIO.IRQ_RISING)
Exemplo n.º 3
0
import utime
from Maix import GPIO
from board import board_info
from fpioa_manager import *

board_info = board_info()


def test_irq(GPIO, pin_num):
    print("key", pin_num)


fm.register(board_info.BOOT_KEY, fm.fpioa.GPIOHS0)
key = GPIO(GPIO.GPIOHS0, GPIO.IN, GPIO.PULL_NONE)
key.irq(test_irq, GPIO.IRQ_BOTH, GPIO.WAKEUP_NOT_SUPPORT, 7)

i = 0
while i < 20:
    key.value()
    utime.sleep_ms(500)
    i += 1
key.disirq()
fm.unregister(board_info.BOOT_KEY, fm.fpioa.GPIOHS0)
Exemplo n.º 4
0
clock = time.clock()

fm.register(board_info.BOOT_KEY, fm.fpioa.GPIOHS0)
key_gpio = GPIO(GPIO.GPIOHS0, GPIO.IN)
start_processing = False

BOUNCE_PROTECTION = 50


def set_key_state(*_):
    global start_processing
    start_processing = True
    utime.sleep_ms(BOUNCE_PROTECTION)


key_gpio.irq(set_key_state, GPIO.IRQ_RISING, GPIO.WAKEUP_NOT_SUPPORT)

lcd.init()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_hmirror(1)
sensor.set_vflip(1)
sensor.run(1)
anchor = (1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658, 5.155437, 6.92275,
          6.718375, 9.01025)  # anchor for face detect
dst_point = [(44, 59), (84, 59), (64, 82), (47, 105),
             (81, 105)]  # standard face key point position
a = kpu.init_yolo2(task_fd, 0.5, 0.3, 5, anchor)
img_lcd = image.Image()
img_face = image.Image(size=(128, 128))
Exemplo n.º 5
0
save_data = False

if record == True:
    key_word_record = False
    tim2 = time.ticks_ms()

    def pins_irq(pin_num):
        global key_word_record
        global tim2
        if (time.ticks_ms() - tim2) > 800:
            key_word_record = not key_word_record
            tim2 = time.ticks_ms()

    fm.register(16, fm.fpioa.GPIOHS0)
    key_boot = GPIO(GPIO.GPIOHS0, GPIO.IN)
    key_boot.irq(pins_irq, GPIO.IRQ_FALLING, GPIO.WAKEUP_NOT_SUPPORT, 7)
    keyword_num = 3
    model_num = 3
    # Currently supports a maximum of 10 keywords, each recording a maximum of 4 templates
    for i in range(keyword_num):
        # Record three keywords, three times each
        for j in range(model_num):
            print("Press the button to record the {} keyword, the {}".format(
                i + 1, j + 1))
            while True:
                if key_word_record == True:
                    break
                else:
                    print('.', end="")
                    utime.sleep_ms(500)
            key_word_record = False
Exemplo n.º 6
0
说明:通过按键改变 LED 的亮灭状态(外部中断方式)
'''

from Maix import GPIO
from fpioa_manager import fm
import utime

#注册IO,注意高速GPIO口才有中断
fm.register(12, fm.fpioa.GPIO0)
fm.register(16, fm.fpioa.GPIOHS0)

#构建lED和KEY对象
LED_B = GPIO(GPIO.GPIO0, GPIO.OUT, value=1)
KEY = GPIO(GPIO.GPIOHS0, GPIO.IN, GPIO.PULL_UP)

#LED状态表示
state = 1


#中断回调函数
def fun(KEY):
    global state
    utime.sleep_ms(10)  #消除抖动
    if KEY.value() == 0:  #确认按键被按下
        state = not state
        LED_B.value(state)


#开启中断,下降沿触发
KEY.irq(fun, GPIO.IRQ_FALLING)
Exemplo n.º 7
0
fm.register(BACKLIGHT_PIN_NUM, BACKLIGHT_FPIOA)
bl = GPIO(BACKLIGHT_GPIO, GPIO.OUT)
bl.value(1)

fm.register(LED_PIN_NUM, LED_FPIOA)
led = GPIO(LED_GPIO, GPIO.OUT)


def irqHande(x):
    led.value(not led.value())


# pir
fm.register(PIR_PIN_NUM, PIR_FPIOA)
pir = GPIO(PIR_GPIO, GPIO.IN)
pir.irq(irqHande, GPIO.IRQ_RISING, GPIO.WAKEUP_NOT_SUPPORT, 7)

# button
fm.register(BOOT_PIN_NUM, BOOT_FPIOA)
button = GPIO(BOOT_GPIO, GPIO.IN)

i2c = I2C(I2C.I2C0, freq=400000, scl=30, sda=31)

addr = 0x68
img = image.Image()


def bytes_toint(firstbyte, secondbyte):
    if not firstbyte & 0x80:
        return firstbyte << 8 | secondbyte
    return -(((firstbyte ^ 255) << 8) | (secondbyte ^ 255) + 1)