匿名
尚未登入
登入
flip the world
搜尋
檢視Application - Monitor GPIO interrupt in userspace的原始碼
出自flip the world
命名空間
頁面
討論
更多
更多
頁面操作
閱讀
檢視原始碼
歷史
←
Application - Monitor GPIO interrupt in userspace
您沒有權限執行編輯此頁面,由於以下原因:
您請求的操作只有這個群組的使用者能使用:
使用者
您可以檢視並複製此頁面的原始碼。
== Monitor GPIO 4 interrupt == === watch-button-glib.cpp === <pre> #include <glib.h> #include <fcntl.h> #include <iostream> using namespace std; #define buf_sz 10 static int onButtonEvent(GIOChannel *channel, GIOCondition condition, gpointer user_data) { static char buf[buf_sz]; cerr << "onButtonEvent" <<endl; GError *error = 0; gsize bytes_read = 0; g_io_channel_seek_position(channel, 0, G_SEEK_SET, 0); GIOStatus rc = g_io_channel_read_chars(channel, buf, buf_sz - 1, &bytes_read, &error); cerr << "rc:" << rc << " data:" << buf <<endl; return 1; } int main(int argc, char** argv) { GMainLoop* loop = g_main_loop_new(0,0); int fd = open("/sys/class/gpio/gpio4/value", O_RDONLY | O_NONBLOCK); GIOChannel* channel = g_io_channel_unix_new(fd); GIOCondition cond = GIOCondition( G_IO_PRI); guint id = g_io_add_watch(channel, cond, onButtonEvent, 0); g_main_loop_run(loop); } </pre> === Makefile === <pre> watch-button-glib: watch-button-glib.cpp Makefile g++ watch-button-glib.cpp -o watch-button-glib -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -lglib-2.0 </pre>
返回到「
Application - Monitor GPIO interrupt in userspace
」。
導覽
導覽
首頁
近期變更
隨機頁面
MediaWiki說明
wiki工具
wiki工具
特殊頁面
頁面工具
頁面工具
使用者頁面工具
更多
連結至此的頁面
相關變更
頁面資訊
頁面日誌