Coder Social home page Coder Social logo

joba_tsl2561's People

Contributors

ivankravets avatar joba-1 avatar joba1 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ivankravets

joba_tsl2561's Issues

Autogain stays in endless loop with high light level

When the sensor gets very high light level (direct sunlight) it will loops forever in the bool autoGain sub.

Did some debugging myself, but can't find the solution.

The problem is in this part of the code (I think):
if( (full < 1000 && ++curr < sizeof(sensitivity)/sizeof(sensitivity[0])) || (full > limit && curr-- > 0) ) { if( !tsl.setSensitivity(sensitivity[curr].gain, sensitivity[curr].exposure) ) { return false; } gain = sensitivity[curr].gain; exposure = sensitivity[curr].exposure; } else { if( ++curr > 0 && retryOnSaturated-- == 0 ) { return true; // saturated, but best we can do } }

With high light level the first if is not true, code will then jump to the else, the if here is also not true and the code will jump to the begin of the sub and starts over. There will no false returned.

Added some debugging in front of this part code.
Serial.printf("full=%u, curr=%u, limit=%u, sizeof=%u \n", full, curr, limit, sizeof(sensitivity)/sizeof(sensitivity[0]));
And that will print full=5047, curr=0, limit=3783, sizeof=6

If you need more data let me know.

Autogain delays crowd out other events and lead to connection losses

When it's dark, the autogain readout can take several seconds. During this time the system is busy mostly in the following section of code:

void waitNext( Tsl2561::exposure_t exposure ) {
  switch( exposure ) {
    case Tsl2561::EXP_14:  delay(Tsl2561Util::DELAY_EXP_14);  break;
    case Tsl2561::EXP_101: delay(Tsl2561Util::DELAY_EXP_101); break;
    default:               delay(Tsl2561Util::DELAY_EXP_402); break;
  }
}

The problem is that delay() is not very well-behaved, so that other code that depends on regular calls to maintain connections and event loops is being crowded out. While delay() does the basics such as feeding watchdogs, a typical problem example is MQTT using the PubSubClient library (as outlined in this article). I regularly see lost MQTT connections and missed messages when it's dark because the system cannot respond to them.

I see two main ways out of this:

  • for myself I have refactored the autoGain() routine into a state machine. I call it regularly from the main loop() and it maintains timers internally so that there is no use of delay()and no lockups at all. That's a rather heavyweight solution, though.
  • or as a more lightweight solution there could be a hook that makes it possible to add user-specified alternative delay() functions that makes the necessary callbacks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.