OK335xS tmp75 Qt 温度读取
/*******************************************************************
* OK335xS tmp75 Qt 温度读取
* 说明:
* 简单的Qt显示tmp75温度值,其驱动已经在Linux驱动中存在,只需要
* 注册一下I2C设备就行了。
*
* 2016-3-26 深圳 南山平山村 曾剑锋
******************************************************************/ \\\\\\\\\\\-*- 目录 -*-///////////
| 一、cat main.c
| 二、cat mainwindow.h
| 三、cat mainwindow.cpp
| 四、cat temperaturethread.h
| 五、cat temperaturethread.cpp
|||||||||||||||||||||||||||||||||| 一、cat main.c
#include "mainwindow.h"
#include <QApplication> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.setWindowFlags(w.windowFlags()& ~Qt::WindowMaximizeButtonHint& ~Qt::WindowMinimizeButtonHint);
w.show(); return a.exec();
} 二、cat mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H #include <QMainWindow>
#include <temperaturethread.h>
#include <QString> namespace Ui {
class MainWindow;
} class MainWindow : public QMainWindow
{
Q_OBJECT public:
explicit MainWindow(QWidget *parent = );
~MainWindow();
TemperatureThread tempThread; public slots:
void dealWithData(QString); protected:
void moveEvent(QMoveEvent *);
void resizeEvent(QResizeEvent *);
void closeEvent(QCloseEvent *); private:
Ui::MainWindow *ui;
}; #endif // MAINWINDOW_H 三、cat mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox> MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this); connect(&tempThread, SIGNAL(msg(QString)),this, SLOT(dealWithData(QString))); tempThread.threadRunning = true;
tempThread.start();
} void MainWindow::dealWithData(QString data) { if( data.trimmed().length() == ) {
QMessageBox::about(this, "About", "Please check your temperature modle.");
exit(-);
} ui->temp->setText(QString("Temperature: ").append(QString::number(data.toFloat()/)).append(" C"));
} MainWindow::~MainWindow()
{
delete ui;
} void MainWindow::moveEvent(QMoveEvent *)
{
this->move(QPoint(,));
} void MainWindow::resizeEvent(QResizeEvent *)
{
this->showMaximized();
} void MainWindow::closeEvent(QCloseEvent *)
{
exit();
} 四、cat temperaturethread.h
#ifndef TEMPERATURETHREAD_H
#define TEMPERATURETHREAD_H #include <QThread>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <QFileInfo>
#include <QMessageBox>
#include <QTreeView>
#include <QDir>
#include <QFile>
#include <QDebug>
#include <QMessageBox> class TemperatureThread : public QThread
{
Q_OBJECT
public:
explicit TemperatureThread(QObject *parent = );
QString readTempFile(void); bool threadRunning; signals:
void msg(QString str); public slots:
void run(); }; #endif // TEMPERATURETHREAD_H 五、cat temperaturethread.cpp
#include "temperaturethread.h" #define tmp75Path "/sys/bus/i2c/devices/3-004c/temp1_input" TemperatureThread::TemperatureThread(QObject *parent) :
QThread(parent)
{
} void TemperatureThread::run(){ while(threadRunning) { emit msg(readTempFile()); msleep(); } } QString TemperatureThread::readTempFile(){ QFile *file=new QFile(tmp75Path); if ( file->exists() ) {
file->open(QIODevice::ReadOnly|QIODevice::Text);
QString data = QString(file->readAll());
file->close();
return data;
} else {
return "";
}
}
OK335xS tmp75 Qt 温度读取的更多相关文章
- OK335xS Linux Qt make: icpc: Command not found
OK335xS Linux Qt make: icpc: Command not found 一.出错现象: make: icpc: Command not found make: *** [main ...
- Qt QtXml读取xml文件内容
Qt QtXml读取xml文件内容 xml文件内容 <?xml version="1.0" encoding="UTF-8"?> <YG_RT ...
- Qt之读取配置文件
一.读取配置文件增删功能与修改参数数据 #ifndef CONFIG_H #define CONFIG_H #define QS_FILEPATH "E:\\woo\\Code\\Qt\\A ...
- Qt XML读取写入操作
XML(eXtensible Markup Language,可扩展标记语言)是普通用于数据交换和数据存储的一种多用途文本文件格式: SVG(可标量矢量图形)XML格式,QtSvg模块提供了可用于载入 ...
- QT+OpenGL读取显示图片,OpenGL在QT里的刷新问题(好几篇)
GLuint readImage(char *filename){ GLuint tex_id; GLint alignment; QImage tex, buf; buf.load ...
- QT中读取文本数据(txt)
下面的代码实现读取txt文档中的数据,并且是一行一行的读取. void MainWindow::on_pushButton_clicked() { QFile file("abcd.txt& ...
- QT 读取txt文件的几种方法
废话不说直接上代码 1. QString displayString; QFile file("/home/alvin/text.txt"); if(!file.open(QIOD ...
- Qt qtextstream读取文件
今天发现一个很有用的类:qtextstream 这个类可以以文件句柄为构造函数 然后用readAll函数返回一个QString的字符串
- Qt如何读取ico文件中的image(使用QImageReader和QIcon)
ico文件是一个容器,内部可以装载许多个image,我们可以通过QIcon的pixmap方法来获取需要的image QPixmap pixmap ( const QSize & size, M ...
随机推荐
- 《WPF程序设计指南》读书笔记——第5章 Stack与Wrap
1.StackPanel面板 using System; using System.Windows; using System.Windows.Input; using System.Windows. ...
- touches获得手指点击的坐标
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObjec ...
- SQL优化之索引
最近碰到一个问题,因数据量越来越大,然后存储过程查询过慢!后来发现没有加索引列导致的!从这里让我开始慢慢去了解索引的原理及作用!以下是我的总结,个人理解只供参考: SQL SERVER提供了两种索引: ...
- shell复习笔记----入门知识
Unix 简史 UNIX 最初是由贝尔实验室(Bell Telephone Laborataries)的计算机科学研究中心开发的,第一版诞生于1970年--也就是在贝尔实验室退出Multics项目不久 ...
- 【高斯消元】BZOJ 1013: [JSOI2008]球形空间产生器sphere
Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧毁 ...
- 深入js的面向对象学习篇——温故知新(一)
在学习设计模式前必须要知道和掌握的***. 为类添加新方法: Function.prototype.method = function(name,fn) { this.prototype[name] ...
- spoj 1437
自己暴了一下不过 转一个 bfs... #include <cstdio> #include <vector> #include <queue> #incl ...
- 如果Java 失宠于Oracle,那么未来会怎么样?
[编者按]对于前不久 Oracle 裁掉了一部分 Java 布道师,近日一位 Oracle 前高管称其为该机构对Java的「计划报废」.如果这个计划是属实的,那么对于寻常的开发者.已经采用了 Java ...
- 【C++基础】关键字static 局部变量
1.局部变量 static局部变量和普通局部变量有什么区别:static局部变量只被初始化一次,下一次依据上一次结果值: int test(int j){ static int i=10; i=i+j ...
- ***总结:在linux下连接redis并进行命令行操作(设置redis密码)
[root@iZ254lfyd6nZ ~]# cd / [root@iZ254lfyd6nZ /]# ls bin boot dev etc home lib lib64 lost+found med ...