-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for MAX44009 ambient light sensor #4907
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can re-use HTTP_SNS_ILLUMINANCE - you do not need to define a new HTTP_SNS_ILLUMINANCE_S
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to not defining HTTP_SNS_ILLUMINANCE_S and re-using the existing HTTP_SNS_ILLUMINANCE please look at the unique values listed for default after reset/power-on and make your detection routine a little more robust using this to validate that you're actually finding a MAX44009 as opposed to just finding something on that particular I2C address.
In addition, I don't think missed readings would apply because although the chip is configured in continuous measurement mode it will only provide whatever it has in its register on the 1-second interval you're reading it at... so maybe skim off a few bytes by using it without that - unless there's some technical or fundamental reason why you would want that logged output (which I can't imagine, but then I do not have the sensor so I am only reliant on what I see in the datasheet) |
Hi, Any news on this? |
Yeah, I am working on it: changes prove to be not so simple as I thought and I am a bit short on time. Please give me a few more days |
- Added checks for improved MAX44009 detection - removed HTTP_SNS_ILLUMINANCE_S (show only integer in web-interface) - removed missed readings and repeated detection
I made the requested changes:
|
Please check if this works for detection instead of reading all the registers - My intention was not to have you check all the registers... just one unique enough to validate a positive detect.
If the above works you can replace the 0x05 with a #define MAX4409_REG_THRESHOLD 0x05 If the above works then you can proceed using the same method to read 16 bit registers and simplify functions such as this one which means using existing code that is in support.ino therefore bringing down the final binary size especially in cases where other I2C sensors are also compiled into the code (which is usually the case)
Another example of optimisation could be
^^ shaves off 64 bytes of flash :) If all the above works fine (remember I do not have a sensor so I have no way of testing these suggestions) you also don't need the Max4409Read_register function. So with this in mind it brings your flash requirement down to 0.6k |
- use functions from support.ino (had to split reading in Max4409Detect in 2 8 bits reads as the MAX44009 only supports 16 bits reads for luminance registers) - Used the << instead of pow() to save a lot of xompiled code - Improved float -> string conversion along the suggested lines - Code size is now +/- 750 bytes (without other I2C sensors compiled in I think
Changes implemented. In the detect function I had to split the 16 bit read into 2 8 bit reads as the MAX44009 supports 16bit reading only for luminance. |
Add support for MAX44009 Ambient Light sensor (#4907)
Add support for MAX44009 ambient light sensor
Add support for MAX44009 Ambient Light sensor (arendst#4907)
Here is a driver for the MAX44009 ambient light sensor. This is a very low power device, that outputs the light level as a float. In order to support that I had to add a new HTTP_SNS_ILLUMINANCE_S as I needed to output a float (is this the right way?).
I have used xsns_91 for now pending allocation of an own driver number.
The size of the driver is 5k7. mainly caused by the calculations on line 57 in the MAX44009 driver. Is there a way to do float calculations that do not use so much code space?
Thanks for considering to include this in tasmota!
BR, Louis