-
Notifications
You must be signed in to change notification settings - Fork 39
Driver and example for AMSYS 5915 pressure sensor #275
Driver and example for AMSYS 5915 pressure sensor #275
Conversation
// Full scale span is 13107, with offset 1638 | ||
uint16_t *rData = reinterpret_cast<uint16_t*>(data); | ||
uint16_t pressure = xpcc::fromBigEndian(*rData) - 1638; | ||
return float(pressure) / 13107; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static_cast<float>(pressure) / 13107.f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
float | ||
getTemperature() | ||
{ | ||
uint16_t temperatureRaw = (data[3] >> 5) | (data[2] << 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is data[2]
implicitly cast to uint16_t
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(before the shift?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is implicitly converted to int
which is fine for 16 bit operations. For 32 bit an explicit cast is necessary for architectures where int
is 16 bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification.
I was wondering why the following code did not exert undefined behavior:
uint8_t data = 255;
uint16_t shifted_data_0 = data << 8;
uint16_t shifted_data_1 = data << 16;
Since data
is implicitly casted to int
which is 32bit on my machine, you need to shift by 32
for it to be undefined behavior:
uint16_t shifted_data_2 = data << 32;
leads to:
runtime error: shift exponent 32 is too large for 32-bit type 'int'`
3c76457
to
efc1e32
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cosmetic changes, otherwise a-ok.
{ | ||
RF_BEGIN(); | ||
|
||
RF_END_RETURN_CALL( this->runTransaction() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just do return this->runTransaction();
and inline the function.
/** | ||
* @param data a amsys5915::Data object | ||
* @bug The address of the sensor is by factory default set to 0x28. | ||
* This means you cannot use two HCLA sensors on the same bus! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HCLA?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again copy&paste 😀
I'll fix it
08674c1
to
da1b22f
Compare
da1b22f
to
fc59fc0
Compare
Driver for the AMSYS 5915 pressure sensor series.
Based on the HCLAx pressure sensor driver.
Tested in hardware (AMS 5915-0050-D).