Skip to content

Commit f0980c7

Browse files
committed
Add support for pressure readings from 1Wire-devices by EDS.
1 parent 095f3d5 commit f0980c7

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

hardware/1Wire.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ void C1Wire::GetDeviceDetails()
263263
{
264264
ReportTemperatureHumidity(device.devid, temperature, m_system->GetHumidity(device));
265265
}
266+
ReportPressure(device.devid,m_system->GetPressure(device));
266267
break;
267268
}
268269

hardware/1Wire/1WireByOWFS.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ float C1WireByOWFS::GetHumidity(const _t1WireDevice& device) const
229229

230230
float C1WireByOWFS::GetPressure(const _t1WireDevice& device) const
231231
{
232-
std::string readValue=readRawData(std::string(device.filename+"/B1-R1-A/pressure"));
232+
std::string readValue=readRawData(std::string(device.filename+"/pressure"));
233233
if (readValue.empty())
234234
return -1000.0;
235235
return static_cast<float>(atof(readValue.c_str()));
@@ -412,8 +412,35 @@ void C1WireByOWFS::GetDevice(const std::string &inDir, const std::string &dirnam
412412
}
413413
device.devid=id;
414414

415-
// Filename (full path)
416415
device.filename=inDir;
417-
device.filename+="/" + dirname;
416+
if (device.family == Environmental_Monitors || device.family == smart_battery_monitor) {
417+
device.filename+="/" + dirname + "/" + nameHelper(dirname);;
418+
} else {
419+
device.filename+="/" + dirname;
420+
}
421+
}
422+
423+
std::string C1WireByOWFS::nameHelper(const std::string& dirname) const {
424+
std::string name;
425+
DIR *d=NULL;
426+
427+
d=opendir(std::string(std::string(OWFS_Base_Dir) + "/" + dirname.c_str()).c_str());
428+
if (d != NULL)
429+
{
430+
struct dirent *de=NULL;
431+
while ((de = readdir(d)))
432+
{
433+
name = de->d_name;
434+
if (de->d_type==DT_DIR)
435+
{
436+
if (name.compare(0,3, "EDS") == 0 || name.compare(0,7, "B1-R1-A") == 0) {
437+
closedir(d);
438+
return name;
439+
}
440+
}
441+
}
442+
closedir(d);
443+
}
444+
return "";
418445
}
419446

hardware/1Wire/1WireByOWFS.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ class C1WireByOWFS : public I_1WireSystem
3030
void GetDevices(const std::string &inDir, /*out*/std::vector<_t1WireDevice>& devices) const;
3131
std::string readRawData(const std::string& filename) const;
3232
void writeData(const _t1WireDevice& device,std::string propertyName,const std::string &value) const;
33+
std::string nameHelper(const std::string& dirname) const;
3334
};

0 commit comments

Comments
 (0)