mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
add test and example for event
This commit is contained in:
parent
b10faacfec
commit
dbeb9ab239
17
examples/TemplateDevice/gpio_cb.py
Normal file
17
examples/TemplateDevice/gpio_cb.py
Normal file
@ -0,0 +1,17 @@
|
||||
import TemplateDevice
|
||||
|
||||
io1 = TemplateDevice.GPIO()
|
||||
io1.setPin('PA8')
|
||||
io1.setMode('in')
|
||||
io1.enable()
|
||||
|
||||
EVENT_SIGAL_IO_RISING_EDGE = 0x01
|
||||
EVENT_SIGAL_IO_FALLING_EDGE = 0x02
|
||||
|
||||
def callBack1(signal):
|
||||
if signal == EVENT_SIGAL_IO_RISING_EDGE:
|
||||
print('get rising edge!')
|
||||
elif signal == EVENT_SIGAL_IO_FALLING_EDGE:
|
||||
print('get falling edge!')
|
||||
|
||||
io1.addEventCallBack(callBack1)
|
31
port/linux/test/event-test.cpp
Normal file
31
port/linux/test/event-test.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include "test_common.h"
|
||||
|
||||
|
||||
extern PikaEventListener* g_pika_device_event_listener;
|
||||
TEST(event, gpio) {
|
||||
/* init */
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
pks_eventLisener_init(&g_pika_device_event_listener);
|
||||
|
||||
/* run */
|
||||
pikaVM_runFile(pikaMain, "../../examples/TemplateDevice/gpio_cb.py");
|
||||
|
||||
#define EVENT_SIGAL_IO_RISING_EDGE 0x01
|
||||
#define EVENT_SIGAL_IO_FALLING_EDGE 0x02
|
||||
#define GPIO_PA8_EVENT_ID 0x08
|
||||
|
||||
/* simulate run in the call back */
|
||||
pks_eventLisener_sendSignal(g_pika_device_event_listener, GPIO_PA8_EVENT_ID,
|
||||
EVENT_SIGAL_IO_RISING_EDGE);
|
||||
pks_eventLisener_sendSignal(g_pika_device_event_listener, GPIO_PA8_EVENT_ID,
|
||||
EVENT_SIGAL_IO_FALLING_EDGE);
|
||||
/* collect */
|
||||
/* assert */
|
||||
EXPECT_STREQ(log_buff[1], "get rising edge!\r\n");
|
||||
EXPECT_STREQ(log_buff[0], "get falling edge!\r\n");
|
||||
/* deinit */
|
||||
obj_deinit(pikaMain);
|
||||
pks_eventLisener_deinit(&g_pika_device_event_listener);
|
||||
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user