查看: 891|回复: 0

SIN210学习笔记__QT 操作 LED

[复制链接]
  • TA的每日心情
    慵懒
    2016-10-17 12:07
  • 签到天数: 306 天

    连续签到: 1 天

    [LV.8]以坛为家I

    发表于 2015-2-27 09:32:20 | 显示全部楼层 |阅读模式
    分享到:
    首先新建一个Qt工程文件(可参考前几篇帖子)。
    首先新建一个led.c和led.h文件,添加到工程中去。
    //led.h文件   #ifndef LED_H   #define LED_H   #ifdef __cplusplus   extern "C" {   #endif   extern int led_open(const char *devname);   extern int led_ioctl(const int no,const int sw);   extern int led_close(void);   extern int led_fd;   #ifdef __cplusplus   }   #endif   #endif // LED_H  //led.c文件   #include "led.h"   #include <fcntl.h>   #include <stdio.h>   #include <unistd.h>   #include <string.h>   #include <stdlib.h>     #define IOCTL_LED_ON    0   #define IOCTL_LED_OFF   1     int led_fd=0;   int led_open(const char*devname){    led_fd=open(devname,O_RDWR);    printf("LED driver is ok\n");    if(led_fd<0){     printf("open device %s failed.\n",devname);     return -1;    }    return 0;   }   int led_ioctl(const int no,const int sw){    //led_fd=open("/dev/led",O_RDWR);    int num=no;    ioctl(led_fd,sw,num);    printf("LED%dis open\n",num);    return 0;   }   int led_close(void){    if(led_fd)     close(led_fd);   }  添加一个pushbutton,如下图所示:

    将鼠标放在pushbutton上面,点击右键,选择转到槽( goto  slot。。。)。选择pressed()和 release()按键函数。
    修改mainwindow.cpp代码如下:
    #include "mainwindow.h"   #include "ui_mainwindow.h"   #include "led.h"     #define LED1    0   #define LED2    1   #define LED3    2   #define LED4    3     #define LED_ON  0   #define LED_OFF 1     MainWindow::MainWindow(QWidget *parent) :       QMainWindow(parent),       ui(new Ui::MainWindow)   {       ui->setupUi(this);       led_open("/dev/led");       printf("C++ /dev/led\n");   }     MainWindow::~MainWindow()   {       delete ui;       led_close();   }     void MainWindow:n_pushButton_pressed()   {       led_ioctl(LED1,LED_ON);   }     void MainWindow:n_pushButton_released()   {       led_ioctl(LED1,LED_OFF);   }  发布运行。。。

    点击pushbutton之后,LED1点亮。松开pushbutton之后LED1熄灭。
    好吧,今天为止Qt也配置出来了,Qt调用驱动也完成了,剩下的就是搬转了。。。
    珍爱生命,远离编程。。。
    最后,非常感谢sinlinx公司提供的SIN210开发板。
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-4-20 01:45 , Processed in 0.110608 second(s), 17 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.