代码拉取完成,页面将自动刷新
#include "tem_hum.h"
float tem;
float hum;
float light;
float proximity;
int turn_num;
int turn_flag=1;
float sound_db;
tem_hum::tem_hum()
{
}
void tem_hum::get_tem()
{
//创建文件对象
QFile *file_tem_raw = new QFile("/sys/bus/iio/devices/iio:device0/in_temp_raw");
QFile *file_hum_raw = new QFile("/sys/bus/iio/devices/iio:device0/in_humidityrelative_raw");
QFile *file_offset = new QFile("/sys/bus/iio/devices/iio:device0/in_temp_offset");
QFile *file_scale = new QFile("/sys/bus/iio/devices/iio:device0/in_temp_scale");
//打开设备文件
file_tem_raw->open(QIODevice::ReadOnly);
file_hum_raw->open(QIODevice::ReadOnly);
file_offset->open(QIODevice::ReadOnly);
file_scale->open(QIODevice::ReadOnly);
//以文件流的形式读取
QTextStream stream_tem_raw (file_tem_raw);
QString temp = stream_tem_raw.readLine();
QTextStream stream_hum_raw (file_hum_raw);
QString hum_ = stream_hum_raw.readLine();
QTextStream stream_offset (file_offset);
QString offset = stream_offset.readLine();
QTextStream stream_scale (file_scale);
QString scale = stream_scale.readLine();
//计算具体值
tem = (temp.toFloat()+offset.toFloat())*(scale.toFloat())/1000;
hum = (hum_.toFloat()+offset.toFloat())*(scale.toFloat())/1000;
//关闭文件
file_tem_raw->close();
file_hum_raw->close();
file_offset->close();
file_scale->close();
}
//获取光照强度
void tem_hum::get_light()
{
QFile *file_light= new QFile("/sys/bus/iio/devices/iio:device1/in_illuminance_input");
file_light->open(QIODevice::ReadOnly);
QTextStream stream_light (file_light);
QString light_ = stream_light.readLine();
light = light_.toFloat();
file_light->close();
}
//判断翻身
void tem_hum::get_proximity()
{
QFile *file_proximity= new QFile("/sys/bus/iio/devices/iio:device1/in_proximity_raw");
file_proximity->open(QIODevice::ReadOnly);
QTextStream stream_proximity (file_proximity);
QString proximity_ = stream_proximity.readLine();
proximity = proximity_.toFloat();
file_proximity->close();
if(turn_flag==0)
{
if(proximity<100)
{
turn_num++;
turn_flag=1;
}
}
if(proximity>150)
{
turn_flag=0;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。