Skip to content

Commit

Permalink
Merge pull request #22 from mcci-catena/issue21
Browse files Browse the repository at this point in the history
update feature of dynamic gain change of LTR329 light sensor
  • Loading branch information
dhineshkumarmcci authored Sep 27, 2023
2 parents 6f9769a + a589f22 commit 2770771
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Catena4430_Sensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static_assert(
"This sketch requires Catena-Arduino-Platform v0.21.0-5 or later"
);

constexpr std::uint32_t kAppVersion = McciCatena4430::makeVersion(2,2,0,0);
constexpr std::uint32_t kAppVersion = McciCatena4430::makeVersion(2,2,1,0);
constexpr std::uint32_t kDoubleResetWaitMs = 3000;
constexpr std::uint32_t kSetDoubleResetMagic = 0xCA44301;
constexpr std::uint32_t kClearDoubleResetMagic = 0xCA44300;
Expand Down
2 changes: 1 addition & 1 deletion Catena4430_cMeasurementLoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class cMeasurementLoop : public McciCatena::cPollableObject
// version parameters
static constexpr std::uint8_t kMajor = 2;
static constexpr std::uint8_t kMinor = 2;
static constexpr std::uint8_t kPatch = 0;
static constexpr std::uint8_t kPatch = 1;
static constexpr std::uint8_t kLocal = 0;

// some parameters
Expand Down
23 changes: 14 additions & 9 deletions Catena4430_cMeasurementLoopV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,37 @@ bool cMeasurementLoopV2::takeMeasurements(void)
{
this->m_fHardError = true;
if (gLog.isEnabled(gLog.DebugFlags::kError))
{
gLog.printf(
gLog.kAlways,
"LTR329 queryReady failed: status %s(%u)\n",
this->m_Ltr.getLastErrorName(),
unsigned(this->m_Ltr.getLastError())
);

this->m_Ltr.begin();
}
}
else
{
currentLux = this->m_Ltr.getLux();

this->m_data.flags |= FlagsV2::Light;
this->m_data.light.Lux = currentLux;

if (currentLux <= kMax_Gain_96)
m_AlsCtrl.setGain(96);
this->m_Ltr.setGain(96);
else if (currentLux <= kMax_Gain_48)
m_AlsCtrl.setGain(48);
this->m_Ltr.setGain(48);
else if (currentLux <= kMax_Gain_8)
m_AlsCtrl.setGain(8);
this->m_Ltr.setGain(8);
else if (currentLux <= kMax_Gain_4)
m_AlsCtrl.setGain(4);
this->m_Ltr.setGain(4);
else if (currentLux <= kMax_Gain_2)
m_AlsCtrl.setGain(2);
this->m_Ltr.setGain(2);
else
m_AlsCtrl.setGain(1);
this->m_Ltr.setGain(1);

currentLux = this->m_Ltr.getLux();
this->m_data.flags |= FlagsV2::Light;
this->m_data.light.Lux = currentLux;

if (currentLux <= 100)
gpMeasurementLoopConcrete->m_fLowLight = true;
Expand Down

0 comments on commit 2770771

Please sign in to comment.