赞
踩
1. 首先驱动板子 的模式 调到 USB烧录模式, (我的是 三个拨码 都是 数字的这边)
2.烧录镜像 到外存 emmc 里面 ( 烧录软件资源里面有)
3. 启动串口连接 驱动板子与电脑 启动内核, 调节模式,关闭模式的显示屏幕
4. 设置开发版的 地址 (串口调试的工具 自己下一个吧, 版权不能上架)(其他的串口调试也行)
SecureCRT.exe
命令: ifconfig eth0 192.168.100.200
5. 设置网络连接 在windows 系统下 (需要网线连接 电脑 和 驱动板子)
6. 网络调试工具 连接扩展板子 (网络调节软件 资源有, 文件传输软件 也有)
7. 网络传输文件
1. 我们需要传输 自己喜欢的字体 (一般在 )
2. 传输测试的文件 。 (测试扩展板子的功能)
我的测试是 板子的蜂鸣器
指导文件!!
网络调试:
1. 首先ping 一下
2. 配置 QT 的环境 (这个我不好写,看 文章 linux QT 运行程序, (之后补) )
3. 查看连接,(是否连接)
4.根据指导文件写代码,
指导文件,
打开LED1 命令: echo 0 > /sys/class/leds/led1/brightness
语句解说: linux 里面 所有的都是文件, 所以我们需要在 QT 里面打开文件 ( /sys/class/leds/led1/brightness) , 然后向里面写入 0 就可以了。。
5. 根据指导文件写 QT 代码: (打开蜂鸣器)
指导文件:
命令: ./beeper_test /dev/input/event0
命令解释: 运行可执行文件,(./beeper_test) 文件路径(/dev/input/event0)
./beeper_test 就是上面个的两张图片 beeper_test.c gcc 编译出来的!!
根据 命令和 beep 的内核代码我们知道, 怎么写QT 代码了!!!
1. 首先打开 路径: ( /dev/input/event0)
2. 创建 结构体:
struct input_event event;//蜂鸣器的结构体
struct timeval time_beep;//蜂鸣器的时间
3. 向文件里面写入 结构体
4.关于蜂鸣器的开关 配置参数就可以了。
代码:
代码:
widget .h
- #ifndef WIDGET_H
- #define WIDGET_H
-
- #include <QWidget>
- #include <QFile>
- #include <linux/input.h>
- #include <unistd.h>
- QT_BEGIN_NAMESPACE
- namespace Ui { class Widget; }
- QT_END_NAMESPACE
-
- class Widget : public QWidget
- {
- Q_OBJECT
-
- public:
- Widget(QWidget *parent = nullptr);
- ~Widget();
- public slots:
- void slot_pushButton_LED1_ON();
- void slot_pushButton_LED1_OFF();
-
- void slot_pushButton_temp();
- void slot_pushButton_hum();
- private slots:
- void on_pushButton_LED1_ON_2_clicked();
-
- void on_pushButton_LED1_OFF_2_clicked();
-
- void on_pushButton_LED1_ON_3_clicked();
-
- void on_pushButton_LED1_OFF_3_clicked();
-
- void on_pushButton_open_beep_clicked();
-
- void on_pushButton_close_beep_clicked();
-
- private:
- Ui::Widget *ui;
- QFile *File_led1;//led1
- QFile *File_led2;//led2
- QFile *File_led3;//led3
- QFile *File_beep;//蜂鸣器
- struct input_event event;//蜂鸣器的结构体
- struct timeval time_beep;//蜂鸣器的时间
- QFile *File_punka;//电风扇
-
- };
- #endif // WIDGET_H

widget .cpp
- #include "widget.h"
- #include "ui_widget.h"
- #include <QDebug>
- #include <stdint.h>
- #include <string.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <errno.h>
- #include <unistd.h>
- #include <linux/input.h>
-
- Widget::Widget(QWidget *parent)
- : QWidget(parent)
- , ui(new Ui::Widget)
- {
- ui->setupUi(this);
- File_led1 = new QFile("/sys/class/leds/led1/brightness");
- File_led2 = new QFile("/sys/class/leds/led2/brightness");
- File_led3 = new QFile("/sys/class/leds/led3/brightness");
- File_punka= new QFile("/sys/class/hwmon/hwmon1/pwm1");
- File_beep = new QFile("/dev/input/event0");
-
- //配置蜂鸣器的
- event.type= EV_SND;
- event.code=SND_TONE;
- event.value=1000;
- time_beep.tv_sec=1;
- time_beep.tv_usec=0;
- event.time=time_beep;
-
-
-
- if (!File_led1->open(QIODevice::WriteOnly | QIODevice::Text))
- return;
- if (!File_led2->open(QIODevice::WriteOnly | QIODevice::Text))
- return;
- if (!File_led3->open(QIODevice::WriteOnly | QIODevice::Text))
- return;
- if (!File_beep->open(QIODevice::WriteOnly | QIODevice::Text))
- return;
- if (!File_punka->open(QIODevice::WriteOnly | QIODevice::Text))
- return;
-
-
-
-
- connect(ui->pushButton_LED1_ON,SIGNAL(clicked(bool)),this,SLOT(slot_pushButton_LED1_ON()));
- connect(ui->pushButton_LED1_OFF,SIGNAL(clicked(bool)),this,SLOT(slot_pushButton_LED1_OFF()));
- connect(ui->pushButton_temp,SIGNAL(clicked(bool)),this,SLOT(slot_pushButton_temp()));
- connect(ui->pushButton_hum,SIGNAL(clicked(bool)),this,SLOT(slot_pushButton_hum()));
-
- }
-
- Widget::~Widget()
- {
- delete ui;
- }
-
- #include <stdlib.h>
- void Widget::slot_pushButton_LED1_ON()
- {
- //system("echo 1 > /sys/class/leds/led1/brightness");
- File_led1->write("1");
- File_led1->flush();
- }
-
- void Widget::slot_pushButton_LED1_OFF()
- {
- //system("echo 0 > /sys/class/leds/led1/brightness");
- File_led1->write("0");
- File_led1->flush();
- }
-
- void Widget::on_pushButton_LED1_ON_2_clicked()
- {
- //system("echo 1 > /sys/class/leds/led2/brightness");
- File_led2->write("1");
- File_led2->flush();
- }
-
- void Widget::on_pushButton_LED1_OFF_2_clicked()
- {
- //system("echo 0 > /sys/class/leds/led2/brightness");
- File_led2->write("0");
- File_led2->flush();
- }
-
- void Widget::on_pushButton_LED1_ON_3_clicked()
- {
- //system("echo 1 > /sys/class/leds/led3/brightness");
- File_led3->write("1");
- File_led3->flush();
- }
-
- void Widget::on_pushButton_LED1_OFF_3_clicked()
- {
- //system("echo 0 > /sys/class/leds/led3/brightness");
- File_led3->write("0");
- File_led3->flush();
- }
-
- void Widget::on_pushButton_open_beep_clicked()//电风扇打开
- {
- //File_punka->write("200");//电风扇打开 PWM 为 200/255
- // File_punka->flush();
- event.type= EV_SND;
- event.code=SND_TONE;
- event.value=1000;
- time_beep.tv_sec=1;
- time_beep.tv_usec=0;
- event.time=time_beep;
- char *a=(char* )&event;
- File_beep->write(a,sizeof(event));
- File_beep->flush();
-
- }
-
- void Widget::on_pushButton_close_beep_clicked()//电风扇关闭
- {
- // File_punka->write("0");//电风扇关闭
- //File_punka->flush();
- event.code = SND_BELL;
- event.value =0;
- char *a=(char* )&event;
- File_beep->write(a,sizeof(event));
- File_beep->flush();
- File_beep->flush();
- }
-
-
-
-
- int read_sysfs_float(const char *device, const char *filename, float *val)
- {
- int ret = 0;
- FILE *sysfsfp;
- char temp[128];
- memset(temp, '0', 128);
- ret = sprintf(temp, "/sys/bus/iio/devices/%s/%s", device, filename);
- if (ret < 0)
- goto error;
- sysfsfp = fopen(temp, "r");
- if (!sysfsfp) {
- ret = -errno;
- goto error;
- }
- errno = 0;
- if (fscanf(sysfsfp, "%f\n", val) != 1) {
- ret = errno ? -errno : -ENODATA;
- if (fclose(sysfsfp))
- perror("read_sysfs_float(): Failed to close dir");
- goto error;
- }
- if (fclose(sysfsfp))
- ret = -errno;
- error:
- return ret;
- }
-
- int read_sysfs_int(const char *device, const char *filename, int *val)
- {
- int ret = 0;
- FILE *sysfsfp;
- char temp[128];
- memset(temp, '0', 128);
- ret = sprintf(temp, "/sys/bus/iio/devices/%s/%s", device, filename);
- if (ret < 0)
- goto error;
- sysfsfp = fopen(temp, "r");
- if (!sysfsfp) {
- ret = -errno;
- goto error;
- }
- errno = 0;
- if (fscanf(sysfsfp, "%d\n", val) != 1) {
- ret = errno ? -errno : -ENODATA;
- if (fclose(sysfsfp))
- perror("read_sysfs_float(): Failed to close dir");
- goto error;
- }
- if (fclose(sysfsfp))
- ret = -errno;
- error:
- return ret;
- }
-
-
- void Widget::slot_pushButton_temp()
- {
- int temp_raw = 0;
- int temp_offset = 0;
- float temp_scale = 0;
- read_sysfs_int("iio:device0", "in_temp_raw", &temp_raw);
- read_sysfs_int("iio:device0", "in_temp_offset", &temp_offset);
- read_sysfs_float("iio:device0", "in_temp_scale", &temp_scale);
-
- //printf("temperature = %.2f\n", (temp_raw + temp_offset) * temp_scale / 1000);
- float temp = (temp_raw + temp_offset) * temp_scale / 1000;
- ui->lineEdit_temp_hum->setText(QString("温度:") + QString::number(temp));
- }
-
- void Widget::slot_pushButton_hum()
- {
- int hum_raw = 0;
- int hum_offset = 0;
- float hum_scale = 0;
-
- read_sysfs_int("iio:device0", "in_humidityrelative_raw", &hum_raw);
- read_sysfs_int("iio:device0", "in_humidityrelative_offset", &hum_offset);
- read_sysfs_float("iio:device0", "in_humidityrelative_scale", &hum_scale);
- //printf("humidity = %.2f%%\n", (hum_raw + hum_offset) * hum_scale / 1000);
-
- float hum = (hum_raw + hum_offset) * hum_scale / 1000;
- ui->lineEdit_temp_hum->setText(QString("湿度:") + QString::number(hum));
- }
-
-
-
-

main.cpp
- #include "widget.h"
-
- #include <QApplication>
-
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- Widget w;
- w.show();
- return a.exec();
- }
ui设计界面
- <?xml version="1.0" encoding="UTF-8"?>
- <ui version="4.0">
- <class>Widget</class>
- <widget class="QWidget" name="Widget">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>480</width>
- <height>640</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Widget</string>
- </property>
- <widget class="QGroupBox" name="groupBox">
- <property name="geometry">
- <rect>
- <x>10</x>
- <y>10</y>
- <width>201</width>
- <height>141</height>
- </rect>
- </property>
- <property name="font">
- <font>
- <pointsize>24</pointsize>
- </font>
- </property>
- <property name="title">
- <string>LED1</string>
- </property>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QPushButton" name="pushButton_LED1_ON">
- <property name="text">
- <string>开灯</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="pushButton_LED1_OFF">
- <property name="text">
- <string>关灯</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <widget class="QGroupBox" name="groupBox_2">
- <property name="geometry">
- <rect>
- <x>10</x>
- <y>320</y>
- <width>381</width>
- <height>151</height>
- </rect>
- </property>
- <property name="font">
- <font>
- <pointsize>19</pointsize>
- </font>
- </property>
- <property name="title">
- <string>温度湿度获取</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QLineEdit" name="lineEdit_temp_hum"/>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_2">
- <item>
- <widget class="QPushButton" name="pushButton_temp">
- <property name="text">
- <string>获取温度</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="pushButton_hum">
- <property name="text">
- <string>获取湿度</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- <widget class="QGroupBox" name="groupBox_3">
- <property name="geometry">
- <rect>
- <x>220</x>
- <y>10</y>
- <width>231</width>
- <height>141</height>
- </rect>
- </property>
- <property name="font">
- <font>
- <pointsize>24</pointsize>
- </font>
- </property>
- <property name="title">
- <string>LED2</string>
- </property>
- <layout class="QHBoxLayout" name="horizontalLayout_3">
- <item>
- <widget class="QPushButton" name="pushButton_LED1_ON_2">
- <property name="text">
- <string>开灯</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="pushButton_LED1_OFF_2">
- <property name="text">
- <string>关灯</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <widget class="QGroupBox" name="groupBox_4">
- <property name="geometry">
- <rect>
- <x>10</x>
- <y>160</y>
- <width>201</width>
- <height>141</height>
- </rect>
- </property>
- <property name="font">
- <font>
- <pointsize>24</pointsize>
- </font>
- </property>
- <property name="title">
- <string>LED3</string>
- </property>
- <layout class="QHBoxLayout" name="horizontalLayout_4">
- <item>
- <widget class="QPushButton" name="pushButton_LED1_ON_3">
- <property name="text">
- <string>开灯</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="pushButton_LED1_OFF_3">
- <property name="text">
- <string>关灯</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <widget class="QPushButton" name="pushButton_open_beep">
- <property name="geometry">
- <rect>
- <x>10</x>
- <y>490</y>
- <width>111</width>
- <height>51</height>
- </rect>
- </property>
- <property name="text">
- <string>打开蜂鸣器</string>
- </property>
- </widget>
- <widget class="QPushButton" name="pushButton_close_beep">
- <property name="geometry">
- <rect>
- <x>150</x>
- <y>490</y>
- <width>111</width>
- <height>51</height>
- </rect>
- </property>
- <property name="text">
- <string>关闭蜂鸣器</string>
- </property>
- </widget>
- </widget>
- <resources/>
- <connections/>
- </ui>

效果图:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。