Skip to content

Commit

Permalink
Add API to check if sensor is in trigger mode (#441)
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 authored Jun 14, 2024
1 parent 4d2ae18 commit feb4ea3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/gz/sensors/Sensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ namespace gz
/// trigger.
public: bool HasPendingTrigger() const;

/// \brief Whether the sensor trigger mode is enabled.
/// \return True if the sensor is in trigger mode, false otherwise
public: bool IsTriggered() const;

GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
/// \internal
/// \brief Data pointer for private data
Expand Down
9 changes: 8 additions & 1 deletion src/Sensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -653,10 +653,17 @@ void SensorPrivate::DisableTriggered() {
}

//////////////////////////////////////////////////
bool Sensor::HasPendingTrigger() const {
bool Sensor::HasPendingTrigger() const
{
if (!this->dataPtr->IsTriggered())
return false;

std::lock_guard<std::mutex> triggerLock(this->dataPtr->triggerMutex);
return this->dataPtr->pendingTrigger;
}

//////////////////////////////////////////////////
bool Sensor::IsTriggered() const
{
return this->dataPtr->IsTriggered();
}
2 changes: 2 additions & 0 deletions src/Sensor_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,10 @@ TEST(Sensor_TEST, Trigger)
sensor.SetUpdateRate(5);
EXPECT_DOUBLE_EQ(kUpdateRate, sensor.UpdateRate());

EXPECT_FALSE(sensor.IsTriggered());
constexpr char kTriggerTopic[] = "/trigger";
EXPECT_TRUE(sensor.SetTriggered(true, kTriggerTopic));
EXPECT_TRUE(sensor.IsTriggered());
EXPECT_FALSE(sensor.HasPendingTrigger());

transport::Node node;
Expand Down

0 comments on commit feb4ea3

Please sign in to comment.