Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

Commit

Permalink
[driver] AMSYS5915: Expose raw measurement value
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durand committed Jan 28, 2018
1 parent 25fe296 commit 4656fd4
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/xpcc/driver/pressure/amsys5915.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ struct amsys5915
friend class Amsys5915;

public:
uint16_t
getPressureRaw()
{
// mask undefined bits
data[0] &= 0b00111111;

auto rData = reinterpret_cast<const uint16_t*>(data);
const uint16_t pressureRaw{xpcc::fromBigEndian(*rData)};

return pressureRaw;
}

/**
* This method returns the pressure as a normalized float from 0-1.
* You have to scale and offset this according to the specific sensor
Expand All @@ -42,17 +54,13 @@ struct amsys5915
float
getPressure()
{
// mask undefined bits
data[0] &= 0b00111111;
const uint16_t pressureRaw{getPressureRaw()};

// Full scale span is typically 13107, with offset 1638
// Caution: sensors may output values slightly exceeding the expected range!
const uint16_t offset{1638};
const uint16_t span{13107};

auto rData = reinterpret_cast<const uint16_t*>(data);
const uint16_t pressureRaw{xpcc::fromBigEndian(*rData)};

if(pressureRaw <= offset) {
return 0.f;
} else if (pressureRaw >= offset + span) {
Expand Down

0 comments on commit 4656fd4

Please sign in to comment.