jz2440:QT控制LED灯点亮熄灭(11)

2023-05-16

1.LED灯的驱动:

首先要准备好在驱动文件,通过insmod led.ko来加载模块,然后在QT的代码里面配合调用open,write,read函数来点亮,关闭LED灯。这一步,做完,应该可以通过测试程序点亮关闭LED。

具体内容可参照:jz2440点亮LED

2.QT代码:

实现的功能:

  1. LED按键进入右图,Back键进入LED按键界面。
  2. LEDx open 与 LEDx close可以打开关闭3个LED灯。

 代码在这个位置:https://github.com/zion6135/QT/tree/main/4.LED/QT

LED页面:

这是LED按键的主要函数:比较关键的就是connect()函数:

4个参数是这样的,按键对象pushButtonLed 发送按下的信号SIGNAL(clicked())给this(也就是LED这个页面),然后执行回调函数ButtonToLed();

总之:点下LED按键就会执行ButtonToLed()函数。

#include "mainwindow.h"
#include <QList>
#include "Class/LedWindow.h"



MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    this->setGeometry(0, 0, 472, 300);  // set windows size
    pushButtonLed = new QPushButton("LED", this); //set button name
    pushButtonLed->setGeometry(50, 50, 100, 100); //set button size
    // button push callback exec ButtonToLed()
    connect(pushButtonLed, SIGNAL(clicked()), this, SLOT(ButtonToLed()));
}

void MainWindow::ButtonToLed() {
    LedWindow* mLed = new LedWindow();
    mLed->show();
    connect(mLed, SIGNAL(signaltomain()), this, SLOT(ButtonToMain()));

    this->hide();
    qDebug("To Led");
}

void MainWindow::ButtonToMain() {
    this->show();
    qDebug("To main");
}


MainWindow::~MainWindow()
{

}


6个按键的页面:

1.6个按键没有啥复杂的,主要是返回按键发送自定义的信号,然后需要在回调函数隐藏按键页面,显示LED页面。

#include "mainwindow.h"
#include <QList>
#include "Class/LedWindow.h"
#define upxxxxxxx 0

bool LedWindow::openLedDrv() {
#if upxxxxxxx
    fd = open("/dev/xyz", O_RDWR);
    if (fd < 0) {
        qDebug("open dev failed!!!");
        return false;
    }
#endif
    return true;
}

LedWindow::LedWindow(QWidget *parent)
    : QMainWindow(parent)
{
    if (true == openLedDrv()) {
        this->setGeometry(0, 0, 472, 300);

        pushButtonBack = new QPushButton("Back", this);
        pushButtonBack->setObjectName("btnBack");
        pushButtonBack ->setGeometry(10, 10, 60, 30);
        connect(pushButtonBack, SIGNAL(clicked()), this, SLOT(ButtonLedclicked()));

        pushButton[0] = new QPushButton("LED1 open", this);
        pushButton[0]->setObjectName("btn1");
        pushButton[0] ->setGeometry(50, 50, 100, 100);
        connect(pushButton[0], SIGNAL(clicked()), this, SLOT(ButtonLedclicked()));

        pushButton[1] = new QPushButton("LED2 open", this);
        pushButton[1]->setObjectName("btn2");
        pushButton[1] ->setGeometry(150, 50, 100, 100);
        connect(pushButton[1], SIGNAL(clicked()), this, SLOT(ButtonLedclicked()));

        pushButton[2] = new QPushButton("LED3 open", this);
        pushButton[2]->setObjectName("btn3");
        pushButton[2] ->setGeometry(250, 50, 100, 100);
        connect(pushButton[2], SIGNAL(clicked()), this, SLOT(ButtonLedclicked()));

        pushButton[3] = new QPushButton("LED4 close", this);
        pushButton[3]->setObjectName("btn4");
        pushButton[3] ->setGeometry(50, 150, 100, 100);
        connect(pushButton[3], SIGNAL(clicked()), this, SLOT(ButtonLedclicked()));

        pushButton[4] = new QPushButton("LED5 close", this);
        pushButton[4]->setObjectName("btn5");
        pushButton[4] ->setGeometry(150, 150, 100, 100);
        connect(pushButton[4], SIGNAL(clicked()), this, SLOT(ButtonLedclicked()));

        pushButton[5] = new QPushButton("LED6 close", this);
        pushButton[5]->setObjectName("btn6");
        pushButton[5] ->setGeometry(250, 150, 100, 100);
        connect(pushButton[5], SIGNAL(clicked()), this, SLOT(ButtonLedclicked()));
    } else {
        qDebug("open failed");
    }
}

void LedWindow::ButtonLedclicked() {

    QObject* obj = sender();
//    obj->dumpObjectInfo();
    int val = -1;
   if (obj->objectName() == "btn1") {
       qDebug("1");
#if upxxxxxxx
       val = 1;
       ::write(fd, &val, 4);
#endif
   } else if (obj->objectName() == "btn2") {
       qDebug("2");
#if upxxxxxxx
       val = 2;
       ::write(fd, &val, 4);
#endif
   } else if (obj->objectName() == "btn3") {
       qDebug("3");
#if upxxxxxxx
       val = 3;
       ::write(fd, &val, 4);
#endif
   } else if (obj->objectName() == "btn4") {
       qDebug("4");
#if upxxxxxxx
       val = 4;
       ::write(fd, &val, 4);
#endif
   } else if (obj->objectName() == "btn5") {
       qDebug("5");
#if upxxxxxxx
       val = 5;
       ::write(fd, &val, 4);
#endif
   } else if (obj->objectName() == "btn6") {
       qDebug("6");
#if upxxxxxxx
       val = 6;
       ::write(fd, &val, 4);
#endif
   } else if (obj->objectName() == "btnBack") {
       qDebug("7");
       emit signaltomain();
       this->close();
   }

}


 

 

 

 

 

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

jz2440:QT控制LED灯点亮熄灭(11) 的相关文章

随机推荐

  • 激光啄木鸟使用教程

    软件下载地址 1 红色方框内的按钮长按开机 2 红色方框内的按钮轻触自动对焦 3 打开手机APP选择要雕刻的素材 4 设置要雕刻区域的大小 xff0c 开始预览可以查看雕刻的位置 5 打开蓝牙 xff0c 点击连接设备 6 选择被雕刻物件的
  • STM32 HAL库

    STM32 HAL库 第三章 MDK5 软件入门bug解决关键文件介绍程序仿真User Keywords语法提示代码编辑 查看技巧 第四章 STM32F1 基础知识入门MDK 下 C 语言基础复习STM32F103 时钟系统STM32F10
  • LWIP网络-基于STM32平台

    LWIP P1无操作系统移植RAW UDP实验RAW TCP实验Webserver实验 P1无操作系统移植 MAC 43 PHY 通过符合 IEEE802 3的MII和RMII接口与外接快速以太网PHY进行通信 MII和RMII实现数据交换
  • 树莓派学习

    树莓派学习教程 系统安装数据源的更新与配置命令设定固定IP网络地址 xff1a 法一法二 给树莓派安装中文环境和中文输入法远程控制树莓派SSH方式 xff1a 通过putty软件实现 xff08 不需要屏幕 xff09 VNC方式 xff0
  • C++学习教程

    C 43 43 学习教程 C 43 43 内存分区模型数据类型循环语句for循环语句 跳转语句指针指针 数组 函数 结构体指针 内存分区模型 工具vs codeDEV C 43 43 C 43 43 内存分区模型 程序运行前 全局区和代码区
  • core dumped ?完了?

    微信公众号 xff1a linux码头 core dumped xff1a 当程序在运行过程中发生异常 xff0c 这时linux系统可以把程序出错的内存 内容存储在一个core文件中 xff0c 又叫核心转存 应用程序在运行过程汇总经常会
  • Ubuntu18.04安装网络调试助手 NetAssist

    下载地址 链接 xff1a https pan baidu com s 1DUqZBtxFh pGTsRR2kXaPA 提取码 xff1a fp32 安装步骤 1 xff09 建立依赖关系 sudo apt get install f 2
  • C语言中左移(<<)和右移(>>)的理解

    lt lt 左移 xff1a 相当于乘法 a lt lt b 61 a 2 b 举例 xff1a 1 lt lt 5 xff0c 相当于1 2 5 61 32 1 lt lt 0 xff0c 相当于1 2 0 61 1 gt gt 右移 x
  • 《Linux运维总结:firewalld防火墙使用教程》

    文章目录 一 firewalld基础知识1 1 firewalld基本介绍1 2 firewalld与iptables关系与区别1 3 firewalld默认策略1 4 firewalld配置模式1 5 firewalld配置方法1 6 f
  • ROS常用的功能包

    坐标系 坐标变换 xff08 tf xff09 tf功能包提供了一个基于ROS的分布式框架 xff0c 可以随着时间的推移计算多个坐标系的位置 3D可视化工具 xff08 rviz xff09 机器人模型的可视化 图像数据的可视化 地图数据
  • 树莓派4B+Ubuntu 18.04 LTS + 桌面desktop + ros安装@树莓派4B、Ubuntu、desktop、ros

    树莓派4B 43 Ubuntu 18 04 LTS 43 桌面desktop 43 ros安装 64 树莓派4B Ubuntu desktop ros 久违的一篇博客 xff0c 说实话CSDN的编辑器还是用不太习惯 xff0c 记录一下树
  • 云台控制协议总结(VISCA/PELCOD/PELCOP)

  • error: #20: identifier "TIM_TimeBaseInitTypeDef" is undefined

    如果出现多句错误 xff1a identifier 34 34 is undefined 解决问题方法一 xff1a C C 43 43 include paths 把文件路径添加进去 解决问题方法二 xff1a 在stm32f10x co
  • 使用pyqt5实现键盘(含组合键)鼠标事件响应

    使用pyqt5实现键盘 xff08 含组合键 xff09 鼠标事件响应 使用python3 6 xff0c pyqt5 xff0c 在macOS上测试有效 span class hljs keyword import span sys sp
  • 递归思想刷题总结

    核心思想 我们在调用递归函数的时候 xff0c 把递归函数当做普通函数 xff08 黑箱 xff09 来调用 xff0c 即明白该函数的输入输出是什么 xff0c 而不用管此函数内部在做什么 xff08 千万不要跳进去了 xff0c 你脑袋
  • anonymous unions are only supported in --gnu mode, or when enabled with #pragma anon_unions

    在keil工程下移植代码 xff0c 编译出现了这个问题 xff0c 字面上解决办法有 xff1a 1 打开GNU模式 option gt GNU extensions 2 在代码前加上 pragma anon union 就是代表支持匿名
  • 串口的深入理解

    1 串口是如何发送数据的 xff1f 一般说来 xff0c 串口发送数据是往数据寄存器sbuf填写数据 xff0c 一个字节一个字节的写入 xff0c 如果有串口中断 xff0c 那么发送完一个字节的数据 xff0c 就会进入串口中断一次
  • CMakeLists.txt的简单使用

    Makefile和CMakeLists的关系 环境准备 xff1a 需要安装gcc xff0c g 43 43 xff0c make sudo apt get install gcc g 43 43 sudo apt get isntall
  • .so文件的基本理解,使用。

    一 基本概念 Linux下的 so是基于Linux下的动态链接 其功能和作用类似与windows下 dll文件 代码编译 xff0c 链接 xff0c 最后生成可执行文件 xff1b 这个可执行文件就可看作是一个静态链接 xff0c 因为代
  • jz2440:QT控制LED灯点亮熄灭(11)

    1 LED灯的驱动 xff1a 首先要准备好在驱动文件 xff0c 通过insmod led ko来加载模块 xff0c 然后在QT的代码里面配合调用open xff0c write read函数来点亮 xff0c 关闭LED灯 这一步 x