Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #47 from 107-systems/add-polling-code
Browse files Browse the repository at this point in the history
Add function for polled data retrieval in order to support non-int-containing ESLOV connector.
  • Loading branch information
aentinger authored Mar 8, 2023
2 parents a700c27 + df0b3ec commit e7efaf2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/107-Arduino-TMF8801.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ArduinoTMF8801::ArduinoTMF8801(TMF8801::I2cWriteFunc write,
, _calib_data{calib_data}
, _algo_state{algo_state}
, _gpio_control{0}
, _old_tid{0}
{
}

Expand Down Expand Up @@ -186,6 +187,32 @@ void ArduinoTMF8801::get(unit::Length & distance)
distance = _distance;
}

bool ArduinoTMF8801::isDataReady()
{
uint8_t const tid = _io.read(TMF8801::Register::TID);

if ((tid >_old_tid) || ((tid == 0) && (_old_tid == 255)))
{
if(_api.getRegisterContent() != TMF8801::RegisterContent::CommandResult)
return false;

_old_tid = tid;
return true;
}
return false;
}

unit::Length ArduinoTMF8801::getDistance()
{
/* Clear the interrupt flag. */
_api.clearInterrupt(TMF8801::InterruptSource::ObjectDectectionAvailable);

/* Obtain distance data. */
TMF8801::ObjectDetectionData data;
_api.application_readObjectDetectionResult(data);
return (data.field.distance_peak_0_mm / 1000.0) * unit::meter;
}

void ArduinoTMF8801::clearerr()
{
_error = TMF8801::Error::None;
Expand Down
3 changes: 3 additions & 0 deletions src/107-Arduino-TMF8801.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class ArduinoTMF8801 : public LengthSensorBase
void onExternalEventHandler();


bool isDataReady();
unit::Length getDistance();
virtual void get(unit::Length & distance) override;


Expand All @@ -81,6 +83,7 @@ class ArduinoTMF8801 : public LengthSensorBase
TMF8801::AlgoState const & _algo_state;
unit::Length _distance;
uint8_t _gpio_control;
uint8_t _old_tid;

bool update_available();
bool perform_update(uint8_t const * ram_firmware, size_t const ram_firmware_bytes);
Expand Down

0 comments on commit e7efaf2

Please sign in to comment.