论坛元老
- 积分
- 3571
- 金钱
- 3571
- 注册时间
- 2014-12-2
- 在线时间
- 365 小时
|
发表于 2020-12-27 20:51:58
|
显示全部楼层
开机qt桌面启动是由/etc/rc.local脚本完成的:
- #!/bin/sh -e
- #
- # rc.local
- #
- # This script is executed at the end of each multiuser runlevel.
- # Make sure that the script will "exit 0" on success or any other
- # value on error.
- #
- # In order to enable or disable this script just change the execution
- # bits.
- #
- # By default this script does nothing.
- echo 30000 > /proc/sys/vm/min_free_kbytes
- source /etc/profile
- /opt/QDesktop >/dev/null 2>&1 &
- exit 0
复制代码
QDesktop是一个程序,里面包含了各个子页面,源码位于:
【正点原子】阿尔法Linux开发板(A盘)-基础资料\1、例程源码\9、Qt综合例程源码\QDesktop
涉及到外设验证的程序(界面),里面确实是直接调用设备文件操作的,比如icm20608传感器程序:
首先调用了外部命令insmod安装内核模块,然后再对"/dev/icm20608"这个设备文件进行普通的open/read/close操作获取传感器数据。
- Icm20608::Icm20608(QObject *parent) : QObject (parent)
- {
- timer = new QTimer();
- #if __arm__
- system("insmod /home/root/driver/icm20608/icm20608.ko");
- #endif
- connect(timer,SIGNAL(timeout()),this,SLOT(timer_timeout()));
- }
- Icm20608::~Icm20608()
- {
- }
- void Icm20608::icm20608ReadData()
- {
- int fd;
- char const *filename = "/dev/icm20608";
- signed int databuf[7];
- unsigned char data[14];
- signed int gyro_x_adc, gyro_y_adc, gyro_z_adc;
- signed int accel_x_adc, accel_y_adc, accel_z_adc;
- signed int temp_adc;
- float gyro_x_act, gyro_y_act, gyro_z_act;
- float accel_x_act, accel_y_act, accel_z_act;
- float temp_act;
- int ret = 0;
- fd = open(filename, O_RDWR);
- if(fd < 0) {
- printf("can't open file %s\r\n", filename);
- return;
- }
- ret = read(fd, databuf, sizeof(databuf));
- if(ret == 0) { // read ok
- gyro_x_adc = databuf[0];
- gyro_y_adc = databuf[1];
- gyro_z_adc = databuf[2];
- accel_x_adc = databuf[3];
- accel_y_adc = databuf[4];
- accel_z_adc = databuf[5];
- temp_adc = databuf[6];
- // actal value
- gyro_x_act = (float)(gyro_x_adc) / 16.4;
- gyro_y_act = (float)(gyro_y_adc) / 16.4;
- gyro_z_act = (float)(gyro_z_adc) / 16.4;
- accel_x_act = (float)(accel_x_adc) / 2048;
- accel_y_act = (float)(accel_y_adc) / 2048;
- accel_z_act = (float)(accel_z_adc) / 2048;
- temp_act = ((float)(temp_adc) - 25 ) / 326.8 + 25;
- gxdata = QString::number(gyro_x_act, 'f', 2);
- gydata = QString::number(gyro_y_act, 'f', 2);
- gzdata = QString::number(gyro_z_act, 'f', 2);
- axdata = QString::number(accel_x_act, 'f', 2);
- aydata = QString::number(accel_y_act, 'f', 2);
- azdata = QString::number(accel_z_act, 'f', 2);
- tempdata = QString::number(temp_act, 'f', 2);
- }
- close(fd);
- emit icm20608DataChanged();
- }
复制代码
更有甚者,有的页面(程序)是完全通过调用外部第三方命令实现的,比如摄像头:
- void CameraMedia::setCameraState(bool str)
- {
- #ifdef __arm__
- if (str)
- process->start("gst-launch-1.0 -v imxv4l2src device=/dev/video1 ! "video/x-raw, format=(string)YUY2, width=(int)1024, height=(int)768, framerate=(fraction)30/1" ! imxv4l2sink ");
- else {
- process->kill();
- process->start("killall gst-launch-1.0");
- }
- #endif
- }
- void CameraMedia::setMediaState(bool str)
- {
- #ifdef __arm__
- if (str)
- process->start("gst-play-1.0 /media/test_movie.avi");
- else {
- process->kill();
- process->start("killall gst-play-1.0");
- }
- #endif
- }
复制代码
|
|