需要之前看过 “SinlinxA33搭建Qt App开发环境编写helloworld” “芯灵思Sinlinx A33实现linux led驱动” 这两篇帖子,了解QT编程
主要代码:
#include "widget.h" #include "led.h" #include <qpushbutton.h> Widget::Widget(QWidget *parent) : QWidget(parent) { Led *led = new Led(); //led对象 QPushButton *led_off = new QPushButton("LED_OFF",this); QPushButton *led_on = new QPushButton("LED ON",this); led_on->setGeometry(75, 50, 75, 40); //设置按钮位置 led_off->setGeometry(300, 50, 75, 40); connect(led_off,SIGNAL(clicked(bool)),led,SLOT(led_off()));//消息函数 connect(led_on,SIGNAL(clicked(bool)),led,SLOT(led_on())); }
#include "led.h" Led::Led() { } int Led::led_on(void) { int fd; int val = 1; fd = open("/dev/ledzzzzzzzz", O_RDWR); if (fd < 0) { return -1; } else write(fd, &val, 1); return 0; } int Led::led_off(void) { int fd; int val = 0; fd = open("/dev/ledzzzzzzzz", O_RDWR); if (fd < 0) { return -1; } else write(fd, &val, 1); return 0; } Led::~Led(void) { }