7 Star 2 Fork 1

NKEO2333/sleepHelper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
tem_hum.cpp 2.26 KB
一键复制 编辑 原始数据 按行查看 历史
NKEO2333 提交于 2024-08-22 23:20 . 添加心率界面
#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;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/NEKO12580/sleephelper.git
git@gitee.com:NEKO12580/sleephelper.git
NEKO12580
sleephelper
sleepHelper
master

搜索帮助