Skip to content

Add UV Index, use adafruit_register #4

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

Merged
merged 0 commits into from
Aug 10, 2022
Merged

Add UV Index, use adafruit_register #4

merged 0 commits into from
Aug 10, 2022

Conversation

tekktrik
Copy link
Member

I don't have the hardware but did by best to resolve #1 by adding the UV index functionaliy. Some other changes happened along the way:

  • _i2c is now i2c_device, because that's what adafruit_register expects
  • Refactored the ALS to use adafruit_register while I was in there, as well as a few other things, but some things made more sense not to based on the way RAM+offset writes happen as well

@tekktrik tekktrik requested a review from caternuson July 27, 2022 04:40
@caternuson
Copy link
Collaborator

Is using register necessary? It's a simple sensor and bringing in register will make it potentially not usable on small boards.

@tekktrik
Copy link
Member Author

Probably not necessary, I really just noticed that some of the functionality here could be covered by using it. I think that was just my understanding of the design guide, but definitely understand the argument for avoiding it. This shouldn't be too difficult to refactor out if we go that route.

@caternuson caternuson requested a review from a team July 27, 2022 15:46
@caternuson
Copy link
Collaborator

Added @adafruit/circuitpythonlibrarians as reviewers so others can comments.

@tekktrik
Copy link
Member Author

Oh never mind, the design guide only specifies adafruit_bus_device, whoops! I can refactor it out if you think that's the best move.

@caternuson
Copy link
Collaborator

My two cents is to leave it out for now. I only consider using the register lib for a device if there are a lot of registers broken up into various smaller bits that control a guzillion internal settings. The SI1145 only has a few, like IRQ_ENABLE and IRQ_STATUS.

But the counter argument is the abstracting out of all the bit shifting / masking foo that the register lib provides for the sake of code safety.

@tekktrik
Copy link
Member Author

I'm out during the next meeting, but maybe this worth bringing up on the Monday meeting? I can add it and just listen to the meeting after the fact.

SI1145_PARAM_WR = const(0x17)
SI1145_COMMAND = const(0x18)
SI1145_RESPONSE = const(0x20)
SI1145_ALS_VIS_DATA0 = const(0x22)
SI1145_UV_INDEX_DATA0 = const(0x2C)
SI1145_PARAM_RD = const(0x2E)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We chatted about this in the meeting today. Basically, you should use register if its model matches the device's registers.

You can save space in this library by reducing these variables to, for example, _UV_INDEX_DATA0 = const(0x2c). For const to drop a variable name it must start with _, otherwise the whole variable name is kept around in case code outside this module references it. (_ prefix in Python implies that something should be private.) You can also drop the SI1145 bit because it duplicates the context of the file/module name that already includes si1145.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tekktrik Agree with above. OK to use register and please add the _. I just forgot about that being a requirement. Also the degree to which the const names need to be unique, i.e. having SI1145 in all of them.

@tekktrik tekktrik merged commit 744d15f into adafruit:main Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add UV index
3 participants