...
 
......@@ -116,7 +116,7 @@ VL53l1x::VL53L1Status VL53l1x::getBootState(uint8_t &state)
bootStateStatus = MsgStatus::inUse;
return VL53L1Status::Sent;
return VL53l1x::VL53L1Status::Sent;
}
if (bootStateStatus == MsgStatus::dataValid)
......@@ -124,24 +124,34 @@ VL53l1x::VL53L1Status VL53l1x::getBootState(uint8_t &state)
state = bootStateBuf[0];
bootStateStatus = MsgStatus::dataUsed;
return VL53L1Status::Received;
return VL53l1x::VL53L1Status::Received;
}
if (bootStateStatus == MsgStatus::timedOut)
{
return VL53L1Status::Error;
return VL53l1x::VL53L1Status::Error;
}
return VL53L1Status::Waiting;
return VL53l1x::VL53L1Status::Waiting;
}
void VL53l1x::init()
{
i2c_message_t initMsg {VL53L1X_default_conf, 93, _address, MsgType::Write, nullptr};
i2c_message_t initMsg {VL53L1X_default_conf, 93, _address, MsgType::Write, &initStatus};
_i2c->sendMessage(initMsg);
}
VL53l1x::VL53L1Status VL53l1x::checkInit()
{
if (initStatus == MsgStatus::dataTransmitted)
return VL53l1x::VL53L1Status::Sent;
else if (initStatus == MsgStatus::timedOut)
return VL53l1x::VL53L1Status::Error;
return VL53l1x::VL53L1Status::Waiting;
}
void VL53l1x::setI2CAddress(uint8_t newAddress)
{
// VL53L1X_ERROR status = 0;
......@@ -306,15 +316,16 @@ VL53l1x::VL53L1Status VL53l1x::getTimingBudget(uint16_t &timingInMs)
void VL53l1x::setDistanceMode(VL53L1DistanceMode distanceMode)
{
i2c_message_t dmPhaseMsg {nullptr, 2, _address, MsgType::Write, nullptr};
i2c_message_t dmRangePeriodAMsg {nullptr, 2, _address, MsgType::Write, nullptr};
i2c_message_t dmRangePeriodBMsg {nullptr, 2, _address, MsgType::Write, nullptr};
i2c_message_t dmRangePhaseMsg {nullptr, 2, _address, MsgType::Write, nullptr};
i2c_message_t dmWOISD0Msg {nullptr, 4, _address, MsgType::Write, nullptr};
i2c_message_t dmPhaseSD0Msg {nullptr, 4, _address, MsgType::Write, nullptr};
i2c_message_t dmPhaseMsg {nullptr, 2, _address, MsgType::Write, &dmPhaseStatus};
i2c_message_t dmRangePeriodAMsg {nullptr, 2, _address, MsgType::Write, &dmRangePeriodAStatus};
i2c_message_t dmRangePeriodBMsg {nullptr, 2, _address, MsgType::Write, &dmRangePeriodBStatus};
i2c_message_t dmRangePhaseMsg {nullptr, 2, _address, MsgType::Write, &dmRangePhaseStatus};
i2c_message_t dmWOISD0Msg {nullptr, 4, _address, MsgType::Write, &dmShortWOISD0Status};
i2c_message_t dmPhaseSD0Msg {nullptr, 4, _address, MsgType::Write, &dmShortPhaseSD0Status};
switch (distanceMode)
{
case VL53L1DistanceMode::ShortMode:
dmPhaseMsg.messageBuffer = dmShortPhase;
dmRangePeriodAMsg.messageBuffer = dmShortRangePeriodA;
......@@ -323,6 +334,7 @@ void VL53l1x::setDistanceMode(VL53L1DistanceMode distanceMode)
dmWOISD0Msg.messageBuffer = dmShortWOISD0;
dmPhaseSD0Msg.messageBuffer = dmShortPhaseSD0;
break;
case VL53L1DistanceMode::LongMode:
dmPhaseMsg.messageBuffer = dmLongPhase;
dmRangePeriodAMsg.messageBuffer = dmLongRangePeriodA;
......@@ -331,6 +343,7 @@ void VL53l1x::setDistanceMode(VL53L1DistanceMode distanceMode)
dmWOISD0Msg.messageBuffer = dmLongWOISD0;
dmPhaseSD0Msg.messageBuffer = dmLongPhaseSD0;
break;
default:
break;
}
......@@ -345,6 +358,20 @@ void VL53l1x::setDistanceMode(VL53L1DistanceMode distanceMode)
setTimingBudget(timingBudget);
}
VL53l1x::VL53L1Status VL53l1x::checkSetDistanceMode()
{
if ((dmPhaseStatus == MsgStatus::dataTransmitted) && (dmRangePeriodAStatus == MsgStatus::dataTransmitted) &&
(dmRangePeriodBStatus == MsgStatus::dataTransmitted) && (dmRangePhaseStatus == MsgStatus::dataTransmitted) &&
(dmShortWOISD0Status == MsgStatus::dataTransmitted) && (dmShortPhaseSD0Status == MsgStatus::dataTransmitted))
return VL53l1x::VL53L1Status::Sent;
else if ((dmPhaseStatus == MsgStatus::timedOut) || (dmRangePeriodAStatus == MsgStatus::timedOut) ||
(dmRangePeriodBStatus == MsgStatus::timedOut) || (dmRangePhaseStatus == MsgStatus::timedOut) ||
(dmShortWOISD0Status == MsgStatus::timedOut) || (dmShortPhaseSD0Status == MsgStatus::timedOut))
return VL53l1x::VL53L1Status::Error;
return VL53l1x::VL53L1Status::Waiting;
}
VL53l1x::VL53L1Status VL53l1x::getDistanceMode(VL53L1DistanceMode &distanceMode)
{
// uint8_t TempDM, status=0;
......@@ -396,7 +423,7 @@ VL53l1x::VL53L1Status VL53l1x::getDistance(uint16_t &distance)
distanceStatus = MsgStatus::inUse;
return VL53L1Status::Sent;
return VL53l1x::VL53L1Status::Sent;
}
if (distanceStatus == MsgStatus::dataValid) {
......@@ -404,15 +431,15 @@ VL53l1x::VL53L1Status VL53l1x::getDistance(uint16_t &distance)
distance = (distanceBuf[1]) | (tmp << 8);
distanceStatus = MsgStatus::dataUsed;
return VL53L1Status::Received;
return VL53l1x::VL53L1Status::Received;
}
if (distanceStatus == MsgStatus::timedOut)
{
return VL53L1Status::Error;
return VL53l1x::VL53L1Status::Error;
}
return VL53L1Status::Waiting;
return VL53l1x::VL53L1Status::Waiting;
}
VL53l1x::VL53L1Status VL53l1x::getRangeStatus(uint8_t &status)
......@@ -427,7 +454,7 @@ VL53l1x::VL53L1Status VL53l1x::getRangeStatus(uint8_t &status)
rangeStatus = MsgStatus::inUse;
return VL53L1Status::Sent;
return VL53l1x::VL53L1Status::Sent;
}
if (rangeStatus == MsgStatus::dataValid)
......@@ -435,15 +462,15 @@ VL53l1x::VL53L1Status VL53l1x::getRangeStatus(uint8_t &status)
status = rangeBuf[0];
rangeStatus = MsgStatus::dataUsed;
return VL53L1Status::Received;
return VL53l1x::VL53L1Status::Received;
}
if (rangeStatus == MsgStatus::timedOut)
{
return VL53L1Status::Error;
return VL53l1x::VL53L1Status::Error;
}
return VL53L1Status::Waiting;
return VL53l1x::VL53L1Status::Waiting;
// VL53L1X_ERROR status = 0;
// uint8_t RgSt;
......@@ -473,5 +500,5 @@ VL53l1x::VL53L1Status VL53l1x::getResult(VL53L1X_Result_t &result)
// pResult->Distance = Temp[13] << 8 | Temp[14];
//
// return status;
return VL53L1Status::Error;
return VL53l1x::VL53L1Status::Error;
}
......@@ -125,6 +125,11 @@ public:
*/
void init();
/**
* @brief This method check if the init was successfully transfered.
*/
VL53L1Status checkInit();
/**
* @brief This method sets the sensor I2C address used in case multiple devices application, default address 0x52
* @param[in] newAddress Addresse to be used by the component
......@@ -179,6 +184,11 @@ public:
*/
void setDistanceMode(VL53L1DistanceMode distanceMode);
/**
* @brief This method check if the setDistanceMode was successfully transfered.
*/
VL53L1Status checkSetDistanceMode();
/**
* @brief This method returns the current distance mode (1=short, 2=long).
*
......@@ -234,6 +244,8 @@ private:
uint8_t _address {0x52};
I2C* _i2c {nullptr};
MsgStatus initStatus {MsgStatus::dataUsed};
uint8_t startRangingBuf[3] {0x00, 0x87, 0x40};
uint8_t stopRangingBuf[3] {0x00, 0x87, 0x00};
......@@ -265,6 +277,13 @@ private:
uint8_t dmLongWOISD0[4] {0x00, 0x78, 0x0F, 0x0D};
uint8_t dmLongPhaseSD0[4] {0x00, 0x7A, 0x0E, 0x0E};
MsgStatus dmPhaseStatus {MsgStatus::dataUsed};
MsgStatus dmRangePeriodAStatus {MsgStatus::dataUsed};
MsgStatus dmRangePeriodBStatus {MsgStatus::dataUsed};
MsgStatus dmRangePhaseStatus {MsgStatus::dataUsed};
MsgStatus dmShortWOISD0Status {MsgStatus::dataUsed};
MsgStatus dmShortPhaseSD0Status {MsgStatus::dataUsed};
uint16_t timingBudget {100};
};
......