当前位置:   article > 正文

嵌入式 LINUX 驱动开发 day03 学习USB 烧录扩展盘 的镜像,启动网络传输控制开发板的命令 , 使用网络传输在LINUX QT 运行代码传给开发板。_嵌入式linux驱动是开发完了过后如何导入板子

嵌入式linux驱动是开发完了过后如何导入板子

1.  开发板 USB  烧录扩展板的镜像  (没有资源  3.35 G 不能传)

1. 首先驱动板子  的模式   调到 USB烧录模式, (我的是 三个拨码 都是 数字的这边)


2.烧录镜像   到外存 emmc  里面  ( 烧录软件资源里面有)


3. 启动串口连接 驱动板子与电脑    启动内核, 调节模式,关闭模式的显示屏幕


4.  设置开发版的 地址  (串口调试的工具   自己下一个吧, 版权不能上架)(其他的串口调试也行)

SecureCRT.exe 

 命令:  ifconfig  eth0  192.168.100.200


5. 设置网络连接  在windows  系统下  (需要网线连接  电脑  和  驱动板子)

 

 


6. 网络调试工具   连接扩展板子  (网络调节软件  资源有,  文件传输软件  也有)


7. 网络传输文件  

1. 我们需要传输  自己喜欢的字体   (一般在 )

2. 传输测试的文件 。  (测试扩展板子的功能)

我的测试是 板子的蜂鸣器

指导文件!!

 网络调试:


 2. 网络传输在LINUX QT 运行代码传给开发板。 

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

  1. #ifndef WIDGET_H
  2. #define WIDGET_H
  3. #include <QWidget>
  4. #include <QFile>
  5. #include <linux/input.h>
  6. #include <unistd.h>
  7. QT_BEGIN_NAMESPACE
  8. namespace Ui { class Widget; }
  9. QT_END_NAMESPACE
  10. class Widget : public QWidget
  11. {
  12. Q_OBJECT
  13. public:
  14. Widget(QWidget *parent = nullptr);
  15. ~Widget();
  16. public slots:
  17. void slot_pushButton_LED1_ON();
  18. void slot_pushButton_LED1_OFF();
  19. void slot_pushButton_temp();
  20. void slot_pushButton_hum();
  21. private slots:
  22. void on_pushButton_LED1_ON_2_clicked();
  23. void on_pushButton_LED1_OFF_2_clicked();
  24. void on_pushButton_LED1_ON_3_clicked();
  25. void on_pushButton_LED1_OFF_3_clicked();
  26. void on_pushButton_open_beep_clicked();
  27. void on_pushButton_close_beep_clicked();
  28. private:
  29. Ui::Widget *ui;
  30. QFile *File_led1;//led1
  31. QFile *File_led2;//led2
  32. QFile *File_led3;//led3
  33. QFile *File_beep;//蜂鸣器
  34. struct input_event event;//蜂鸣器的结构体
  35. struct timeval time_beep;//蜂鸣器的时间
  36. QFile *File_punka;//电风扇
  37. };
  38. #endif // WIDGET_H

widget .cpp

  1. #include "widget.h"
  2. #include "ui_widget.h"
  3. #include <QDebug>
  4. #include <stdint.h>
  5. #include <string.h>
  6. #include <fcntl.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <unistd.h>
  10. #include <errno.h>
  11. #include <unistd.h>
  12. #include <linux/input.h>
  13. Widget::Widget(QWidget *parent)
  14. : QWidget(parent)
  15. , ui(new Ui::Widget)
  16. {
  17. ui->setupUi(this);
  18. File_led1 = new QFile("/sys/class/leds/led1/brightness");
  19. File_led2 = new QFile("/sys/class/leds/led2/brightness");
  20. File_led3 = new QFile("/sys/class/leds/led3/brightness");
  21. File_punka= new QFile("/sys/class/hwmon/hwmon1/pwm1");
  22. File_beep = new QFile("/dev/input/event0");
  23. //配置蜂鸣器的
  24. event.type= EV_SND;
  25. event.code=SND_TONE;
  26. event.value=1000;
  27. time_beep.tv_sec=1;
  28. time_beep.tv_usec=0;
  29. event.time=time_beep;
  30. if (!File_led1->open(QIODevice::WriteOnly | QIODevice::Text))
  31. return;
  32. if (!File_led2->open(QIODevice::WriteOnly | QIODevice::Text))
  33. return;
  34. if (!File_led3->open(QIODevice::WriteOnly | QIODevice::Text))
  35. return;
  36. if (!File_beep->open(QIODevice::WriteOnly | QIODevice::Text))
  37. return;
  38. if (!File_punka->open(QIODevice::WriteOnly | QIODevice::Text))
  39. return;
  40. connect(ui->pushButton_LED1_ON,SIGNAL(clicked(bool)),this,SLOT(slot_pushButton_LED1_ON()));
  41. connect(ui->pushButton_LED1_OFF,SIGNAL(clicked(bool)),this,SLOT(slot_pushButton_LED1_OFF()));
  42. connect(ui->pushButton_temp,SIGNAL(clicked(bool)),this,SLOT(slot_pushButton_temp()));
  43. connect(ui->pushButton_hum,SIGNAL(clicked(bool)),this,SLOT(slot_pushButton_hum()));
  44. }
  45. Widget::~Widget()
  46. {
  47. delete ui;
  48. }
  49. #include <stdlib.h>
  50. void Widget::slot_pushButton_LED1_ON()
  51. {
  52. //system("echo 1 > /sys/class/leds/led1/brightness");
  53. File_led1->write("1");
  54. File_led1->flush();
  55. }
  56. void Widget::slot_pushButton_LED1_OFF()
  57. {
  58. //system("echo 0 > /sys/class/leds/led1/brightness");
  59. File_led1->write("0");
  60. File_led1->flush();
  61. }
  62. void Widget::on_pushButton_LED1_ON_2_clicked()
  63. {
  64. //system("echo 1 > /sys/class/leds/led2/brightness");
  65. File_led2->write("1");
  66. File_led2->flush();
  67. }
  68. void Widget::on_pushButton_LED1_OFF_2_clicked()
  69. {
  70. //system("echo 0 > /sys/class/leds/led2/brightness");
  71. File_led2->write("0");
  72. File_led2->flush();
  73. }
  74. void Widget::on_pushButton_LED1_ON_3_clicked()
  75. {
  76. //system("echo 1 > /sys/class/leds/led3/brightness");
  77. File_led3->write("1");
  78. File_led3->flush();
  79. }
  80. void Widget::on_pushButton_LED1_OFF_3_clicked()
  81. {
  82. //system("echo 0 > /sys/class/leds/led3/brightness");
  83. File_led3->write("0");
  84. File_led3->flush();
  85. }
  86. void Widget::on_pushButton_open_beep_clicked()//电风扇打开
  87. {
  88. //File_punka->write("200");//电风扇打开 PWM 为 200/255
  89. // File_punka->flush();
  90. event.type= EV_SND;
  91. event.code=SND_TONE;
  92. event.value=1000;
  93. time_beep.tv_sec=1;
  94. time_beep.tv_usec=0;
  95. event.time=time_beep;
  96. char *a=(char* )&event;
  97. File_beep->write(a,sizeof(event));
  98. File_beep->flush();
  99. }
  100. void Widget::on_pushButton_close_beep_clicked()//电风扇关闭
  101. {
  102. // File_punka->write("0");//电风扇关闭
  103. //File_punka->flush();
  104. event.code = SND_BELL;
  105. event.value =0;
  106. char *a=(char* )&event;
  107. File_beep->write(a,sizeof(event));
  108. File_beep->flush();
  109. File_beep->flush();
  110. }
  111. int read_sysfs_float(const char *device, const char *filename, float *val)
  112. {
  113. int ret = 0;
  114. FILE *sysfsfp;
  115. char temp[128];
  116. memset(temp, '0', 128);
  117. ret = sprintf(temp, "/sys/bus/iio/devices/%s/%s", device, filename);
  118. if (ret < 0)
  119. goto error;
  120. sysfsfp = fopen(temp, "r");
  121. if (!sysfsfp) {
  122. ret = -errno;
  123. goto error;
  124. }
  125. errno = 0;
  126. if (fscanf(sysfsfp, "%f\n", val) != 1) {
  127. ret = errno ? -errno : -ENODATA;
  128. if (fclose(sysfsfp))
  129. perror("read_sysfs_float(): Failed to close dir");
  130. goto error;
  131. }
  132. if (fclose(sysfsfp))
  133. ret = -errno;
  134. error:
  135. return ret;
  136. }
  137. int read_sysfs_int(const char *device, const char *filename, int *val)
  138. {
  139. int ret = 0;
  140. FILE *sysfsfp;
  141. char temp[128];
  142. memset(temp, '0', 128);
  143. ret = sprintf(temp, "/sys/bus/iio/devices/%s/%s", device, filename);
  144. if (ret < 0)
  145. goto error;
  146. sysfsfp = fopen(temp, "r");
  147. if (!sysfsfp) {
  148. ret = -errno;
  149. goto error;
  150. }
  151. errno = 0;
  152. if (fscanf(sysfsfp, "%d\n", val) != 1) {
  153. ret = errno ? -errno : -ENODATA;
  154. if (fclose(sysfsfp))
  155. perror("read_sysfs_float(): Failed to close dir");
  156. goto error;
  157. }
  158. if (fclose(sysfsfp))
  159. ret = -errno;
  160. error:
  161. return ret;
  162. }
  163. void Widget::slot_pushButton_temp()
  164. {
  165. int temp_raw = 0;
  166. int temp_offset = 0;
  167. float temp_scale = 0;
  168. read_sysfs_int("iio:device0", "in_temp_raw", &temp_raw);
  169. read_sysfs_int("iio:device0", "in_temp_offset", &temp_offset);
  170. read_sysfs_float("iio:device0", "in_temp_scale", &temp_scale);
  171. //printf("temperature = %.2f\n", (temp_raw + temp_offset) * temp_scale / 1000);
  172. float temp = (temp_raw + temp_offset) * temp_scale / 1000;
  173. ui->lineEdit_temp_hum->setText(QString("温度:") + QString::number(temp));
  174. }
  175. void Widget::slot_pushButton_hum()
  176. {
  177. int hum_raw = 0;
  178. int hum_offset = 0;
  179. float hum_scale = 0;
  180. read_sysfs_int("iio:device0", "in_humidityrelative_raw", &hum_raw);
  181. read_sysfs_int("iio:device0", "in_humidityrelative_offset", &hum_offset);
  182. read_sysfs_float("iio:device0", "in_humidityrelative_scale", &hum_scale);
  183. //printf("humidity = %.2f%%\n", (hum_raw + hum_offset) * hum_scale / 1000);
  184. float hum = (hum_raw + hum_offset) * hum_scale / 1000;
  185. ui->lineEdit_temp_hum->setText(QString("湿度:") + QString::number(hum));
  186. }

main.cpp

  1. #include "widget.h"
  2. #include <QApplication>
  3. int main(int argc, char *argv[])
  4. {
  5. QApplication a(argc, argv);
  6. Widget w;
  7. w.show();
  8. return a.exec();
  9. }

 ui设计界面

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <ui version="4.0">
  3. <class>Widget</class>
  4. <widget class="QWidget" name="Widget">
  5. <property name="geometry">
  6. <rect>
  7. <x>0</x>
  8. <y>0</y>
  9. <width>480</width>
  10. <height>640</height>
  11. </rect>
  12. </property>
  13. <property name="windowTitle">
  14. <string>Widget</string>
  15. </property>
  16. <widget class="QGroupBox" name="groupBox">
  17. <property name="geometry">
  18. <rect>
  19. <x>10</x>
  20. <y>10</y>
  21. <width>201</width>
  22. <height>141</height>
  23. </rect>
  24. </property>
  25. <property name="font">
  26. <font>
  27. <pointsize>24</pointsize>
  28. </font>
  29. </property>
  30. <property name="title">
  31. <string>LED1</string>
  32. </property>
  33. <layout class="QHBoxLayout" name="horizontalLayout">
  34. <item>
  35. <widget class="QPushButton" name="pushButton_LED1_ON">
  36. <property name="text">
  37. <string>开灯</string>
  38. </property>
  39. </widget>
  40. </item>
  41. <item>
  42. <widget class="QPushButton" name="pushButton_LED1_OFF">
  43. <property name="text">
  44. <string>关灯</string>
  45. </property>
  46. </widget>
  47. </item>
  48. </layout>
  49. </widget>
  50. <widget class="QGroupBox" name="groupBox_2">
  51. <property name="geometry">
  52. <rect>
  53. <x>10</x>
  54. <y>320</y>
  55. <width>381</width>
  56. <height>151</height>
  57. </rect>
  58. </property>
  59. <property name="font">
  60. <font>
  61. <pointsize>19</pointsize>
  62. </font>
  63. </property>
  64. <property name="title">
  65. <string>温度湿度获取</string>
  66. </property>
  67. <layout class="QVBoxLayout" name="verticalLayout">
  68. <item>
  69. <widget class="QLineEdit" name="lineEdit_temp_hum"/>
  70. </item>
  71. <item>
  72. <layout class="QHBoxLayout" name="horizontalLayout_2">
  73. <item>
  74. <widget class="QPushButton" name="pushButton_temp">
  75. <property name="text">
  76. <string>获取温度</string>
  77. </property>
  78. </widget>
  79. </item>
  80. <item>
  81. <widget class="QPushButton" name="pushButton_hum">
  82. <property name="text">
  83. <string>获取湿度</string>
  84. </property>
  85. </widget>
  86. </item>
  87. </layout>
  88. </item>
  89. </layout>
  90. </widget>
  91. <widget class="QGroupBox" name="groupBox_3">
  92. <property name="geometry">
  93. <rect>
  94. <x>220</x>
  95. <y>10</y>
  96. <width>231</width>
  97. <height>141</height>
  98. </rect>
  99. </property>
  100. <property name="font">
  101. <font>
  102. <pointsize>24</pointsize>
  103. </font>
  104. </property>
  105. <property name="title">
  106. <string>LED2</string>
  107. </property>
  108. <layout class="QHBoxLayout" name="horizontalLayout_3">
  109. <item>
  110. <widget class="QPushButton" name="pushButton_LED1_ON_2">
  111. <property name="text">
  112. <string>开灯</string>
  113. </property>
  114. </widget>
  115. </item>
  116. <item>
  117. <widget class="QPushButton" name="pushButton_LED1_OFF_2">
  118. <property name="text">
  119. <string>关灯</string>
  120. </property>
  121. </widget>
  122. </item>
  123. </layout>
  124. </widget>
  125. <widget class="QGroupBox" name="groupBox_4">
  126. <property name="geometry">
  127. <rect>
  128. <x>10</x>
  129. <y>160</y>
  130. <width>201</width>
  131. <height>141</height>
  132. </rect>
  133. </property>
  134. <property name="font">
  135. <font>
  136. <pointsize>24</pointsize>
  137. </font>
  138. </property>
  139. <property name="title">
  140. <string>LED3</string>
  141. </property>
  142. <layout class="QHBoxLayout" name="horizontalLayout_4">
  143. <item>
  144. <widget class="QPushButton" name="pushButton_LED1_ON_3">
  145. <property name="text">
  146. <string>开灯</string>
  147. </property>
  148. </widget>
  149. </item>
  150. <item>
  151. <widget class="QPushButton" name="pushButton_LED1_OFF_3">
  152. <property name="text">
  153. <string>关灯</string>
  154. </property>
  155. </widget>
  156. </item>
  157. </layout>
  158. </widget>
  159. <widget class="QPushButton" name="pushButton_open_beep">
  160. <property name="geometry">
  161. <rect>
  162. <x>10</x>
  163. <y>490</y>
  164. <width>111</width>
  165. <height>51</height>
  166. </rect>
  167. </property>
  168. <property name="text">
  169. <string>打开蜂鸣器</string>
  170. </property>
  171. </widget>
  172. <widget class="QPushButton" name="pushButton_close_beep">
  173. <property name="geometry">
  174. <rect>
  175. <x>150</x>
  176. <y>490</y>
  177. <width>111</width>
  178. <height>51</height>
  179. </rect>
  180. </property>
  181. <property name="text">
  182. <string>关闭蜂鸣器</string>
  183. </property>
  184. </widget>
  185. </widget>
  186. <resources/>
  187. <connections/>
  188. </ui>

效果图:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/246846
推荐阅读
相关标签
  

闽ICP备14008679号