乘着5.1假期弄下4月主题月。4月主题月是GUI主题,我使用IMX6ULL进行测试,主要还是跑下QT GUI,在嵌入式Linux端部署这个还是很方便的。
板子还是原子的,使用板子在一个ap3216c一款集成光传感器,距离传感器,红外LED的芯片。驱动只需要使用原子的历程编译下。然后加载即可。
- void MainWindow::ap3216c_INIT()
- {
-
-
- fd = open("/dev/ap3216c",O_RDWR);
- if(fd<0)
- {
- qDebug() << "App:Open dev failed.";
- }
- }
-
- void MainWindow::timerTimeOut()
- {
- unsigned short databuf[3];
- unsigned short ir, als, ps;
- int ret = 0;
- static int now = 0;
-
- ret = read(fd, databuf, sizeof(databuf));
- if(ret == 0) { /* 数据读取成功 */
- ir = databuf[0]; /* ir 传感器数据 */
- als = databuf[1]; /* als 传感器数据 */
- ps = databuf[2]; /* ps 传感器数据 */
- printf("ir = %d, als = %d, ps = %d\r\n", ir, als, ps);
-
- ui->label_4->setText(QString::number(ir));
- ui->label_5->setText(QString::number(als));
- ui->label_6->setText(QString::number(ps));
- now++;
- dataCustomPlot->graph(0)->addData(now, ir); //addData(double key, double value);原型
- dataCustomPlot->graph(1)->addData(now, als); //addData(double key, double value);原型
- dataCustomPlot->graph(2)->addData(now, ps);
- dataCustomPlot->replot();
- }
-
-
- }
- //曲线显示
- void MainWindow::on_pushButton_2_clicked()
- {
- ui->stackedWidget->setCurrentIndex(1);
- }
-
- void MainWindow::on_pushButton_clicked()
- {
- ui->stackedWidget->setCurrentIndex(0);
- }
-
-
- void MainWindow::dataCustomPlotInit()
- {
- QFont font;
- // font.setPointSize(12);
- /* 实例化,设置位置、背景颜色 */
- QBrush brush(QColor(255, 255, 255));
- dataCustomPlot = new QCustomPlot(ui->widget);
- dataCustomPlot->setGeometry(0, 0, 550, 300);
- dataCustomPlot->setBackground(brush);
- dataCustomPlot->installEventFilter(this);
-
- /* x轴、Y轴相关配置 */
- QPen pen(Qt::black);
-
- font.setPointSize(8);
- dataCustomPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); //可拖拽+可滚轮缩放
- dataCustomPlot->xAxis->setLabelColor(QColor(Qt::black)); // X轴上标识label字体颜色
- dataCustomPlot->yAxis->setLabelColor(QColor(Qt::black));
- dataCustomPlot->xAxis->setTickPen(pen); // 设置x轴上坐标点上对应的刻度线的颜色
- dataCustomPlot->xAxis->setTickLabelRotation(60);//设置标签角度旋转
- dataCustomPlot->yAxis->setTickPen(pen);
- dataCustomPlot->xAxis->setBasePen(pen); // 设置x轴 轴线本身的颜色
- dataCustomPlot->yAxis->setBasePen(pen);
- dataCustomPlot->xAxis->setTickLabelColor(QColor(Qt::black)); // 设置x轴刻度值文本的颜色
- dataCustomPlot->yAxis->setTickLabelColor(QColor(Qt::black));
- dataCustomPlot->xAxis->setSubTicks(false); // 隐藏x轴刻度线
- dataCustomPlot->yAxis->setSubTicks(false); // 隐藏y轴刻度线
- dataCustomPlot->xAxis->setLabelFont(font); // 设置x轴标识label文本字体大小
- dataCustomPlot->yAxis->setLabelFont(font); // 设置y轴标识label文本字体大小
- font.setPointSize(10);
- dataCustomPlot->xAxis->setTickLabelFont(font);
- dataCustomPlot->yAxis->setTickLabelFont(font);
- dataCustomPlot->xAxis->setLabel("时间");
- dataCustomPlot->yAxis->setLabel("数值");
-
-
- dataCustomPlot->legend->setVisible(true);
-
- /* 增加一个数据曲线 */
- pen.setColor(Qt::yellow); // 设置画笔的颜色
- dataCustomPlot->addGraph(); // 增加曲线图
- dataCustomPlot->graph(0)->setName("ir"); // 设置曲线的名字
- dataCustomPlot->graph(0)->setPen(pen); // 设置曲线画笔的颜色
- dataCustomPlot->graph(0)->setLineStyle(QCPGraph::lsLine); // 设置连接线的类型 两点直线连接
-
-
-
- pen.setColor(Qt::red); // 设置画笔的颜色
- dataCustomPlot->addGraph(); // 增加曲线图
- dataCustomPlot->graph(1)->setName("als"); // 设置曲线的名字
- dataCustomPlot->graph(1)->setPen(pen); // 设置曲线画笔的颜色
- dataCustomPlot->graph(1)->setLineStyle(QCPGraph::lsLine); // 设置连接线的类型 两点直线连接
-
-
- pen.setColor(Qt::black); // 设置画笔的颜色
- dataCustomPlot->addGraph(); // 增加曲线图
- dataCustomPlot->graph(2)->setName("ps"); // 设置曲线的名字
- dataCustomPlot->graph(2)->setPen(pen); // 设置曲线画笔的颜色
- dataCustomPlot->graph(2)->setLineStyle(QCPGraph::lsLine); // 设置连接线的类型 两点直线连接
-
-
- }
复制代码
QT端主要是对传感器初始化,然后是曲线界面初始化,网上也都有历程。
之后通过定时器一直读取就可以完成操作。QT端可以操作的很多,后续还可以修改成系统时间为标准的。
目前先搭建一个框架,后续接着弄往后更新。
|