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

Driver and example for AMSYS 5915 pressure sensor #275

Merged

Conversation

rleh
Copy link
Member

@rleh rleh commented Aug 11, 2017

Driver for the AMSYS 5915 pressure sensor series.
Based on the HCLAx pressure sensor driver.

Tested in hardware (AMS 5915-0050-D).

// 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;
Copy link
Member

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

Copy link
Member Author

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);
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(before the shift?)

Copy link
Member

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.

Copy link
Member

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'`

@salkinium salkinium self-assigned this Aug 11, 2017
@salkinium salkinium added this to the 2017q3 milestone Aug 11, 2017
@rleh rleh force-pushed the feature/driver-pressure-amsys5915 branch from 3c76457 to efc1e32 Compare August 11, 2017 18:12
Copy link
Member

@salkinium salkinium left a 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() );
Copy link
Member

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!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HCLA?

Copy link
Member Author

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

@rleh rleh force-pushed the feature/driver-pressure-amsys5915 branch 2 times, most recently from 08674c1 to da1b22f Compare August 11, 2017 18:31
salkinium
salkinium previously approved these changes Aug 11, 2017
@salkinium salkinium force-pushed the feature/driver-pressure-amsys5915 branch from da1b22f to fc59fc0 Compare August 12, 2017 15:15
@salkinium salkinium merged commit fc59fc0 into roboterclubaachen:develop Aug 12, 2017
@rleh rleh deleted the feature/driver-pressure-amsys5915 branch September 21, 2017 23:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants