/*******************************************************************
* 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 温度读取的更多相关文章

  1. OK335xS Linux Qt make: icpc: Command not found

    OK335xS Linux Qt make: icpc: Command not found 一.出错现象: make: icpc: Command not found make: *** [main ...

  2. Qt QtXml读取xml文件内容

    Qt QtXml读取xml文件内容 xml文件内容 <?xml version="1.0" encoding="UTF-8"?> <YG_RT ...

  3. Qt之读取配置文件

    一.读取配置文件增删功能与修改参数数据 #ifndef CONFIG_H #define CONFIG_H #define QS_FILEPATH "E:\\woo\\Code\\Qt\\A ...

  4. Qt XML读取写入操作

    XML(eXtensible Markup Language,可扩展标记语言)是普通用于数据交换和数据存储的一种多用途文本文件格式: SVG(可标量矢量图形)XML格式,QtSvg模块提供了可用于载入 ...

  5. QT+OpenGL读取显示图片,OpenGL在QT里的刷新问题(好几篇)

    GLuint readImage(char *filename){    GLuint tex_id;    GLint alignment; QImage tex, buf;    buf.load ...

  6. QT中读取文本数据(txt)

    下面的代码实现读取txt文档中的数据,并且是一行一行的读取. void MainWindow::on_pushButton_clicked() { QFile file("abcd.txt& ...

  7. QT 读取txt文件的几种方法

    废话不说直接上代码 1. QString displayString; QFile file("/home/alvin/text.txt"); if(!file.open(QIOD ...

  8. Qt qtextstream读取文件

    今天发现一个很有用的类:qtextstream 这个类可以以文件句柄为构造函数 然后用readAll函数返回一个QString的字符串

  9. Qt如何读取ico文件中的image(使用QImageReader和QIcon)

    ico文件是一个容器,内部可以装载许多个image,我们可以通过QIcon的pixmap方法来获取需要的image QPixmap pixmap ( const QSize & size, M ...

随机推荐

  1. Linux进程间通信IPC学习笔记之同步二(SVR4 信号量)

    Linux进程间通信IPC学习笔记之同步二(SVR4 信号量)

  2. wpf鼠标捕获与控件交互——UIElement.CaptureMouse

    应用场景是这样的,我需要拖动一个元素在屏幕上移动,注册了被移动元素的MouseMove事件,但是当鼠标移到被移动元素的外面时,移动失效,且鼠标的手势变成了普通的箭头形状,于是就找到了以下的解决方案. ...

  3. 种子填充找连通块 floodfill

    Description Due to recent rains, water has pooled in various places in Farmer John's field, which is ...

  4. The connection to adb is down

    有一周时间没有打开ADT了,最近想为我的APP增加下些新的功能,但是在编译的时候出现了一个奇怪问题 [2013-10-18 14:43:50 - zzbus] Android Launch![2013 ...

  5. Java 多线程 简单实例 (Runnable)

    1.多线程实例 package second; public class A implements Runnable { public char stat = '*'; public void run ...

  6. java开发命名规范总结

    一 包名的书写规范 (Package)推荐使用公司或机构的顶级域名为包名的前缀,目的是保证各公司/机构内所使用的包名的唯一性.包名全部为小写字母,且具有实际的区分意义. 1.1 一般要求1.选择有意义 ...

  7. 快捷设置IE代理小工具

    时间:2015-02-06 起因: 公司新装了PLM系统,用这个系统必须使用指定IP段的IP才能访问.所以为了还能愉快的继续使用代理进行特定网站的访问,我们必须要频繁的去设置IE代理,这也太麻烦了吧. ...

  8. 如何让VS根据编译环境选择相应的配置文件

    其实微软还是蛮有创造力的,一个配置文件居然弄了这么多的形式,从原来的ini到现在的xml,总而言之让我们这些在微软殿堂里的程序员翘着屁股追赶. 微软最新的配置文件实际上就是个xml文件,以后缀名.co ...

  9. Visual Leak Detector 2.2.3 Visual C++内存检测工具

      Visual Leak Detector是一款免费的.健全的.开源的Visual C++内存泄露检测系统.相比Visual C++自带的内存检测机制,Visual Leak Detector可以显 ...

  10. Deployment of VC2008 apps without installing anything

    If you create a default CRT/MFC application with VS2008, this application will not run on other comp ...