-
Notifications
You must be signed in to change notification settings - Fork 0
Description
It would make sense to know the correct number of bytes to read during spectral acquisition using the get line length function.
We do not want to call that from within get_spectrum for two reasons. (1) It's against one of the design principles of this module to have driver functions call each other (2) when get_spectrum is called repeatedly that would correspond to reading the EEPROM repeatedly, which may be slow or reduce the lifespan of the EEPROM (not sure).
Lines 129 to 130 in 03b0ecd
| # TODO do something smart wrt msg_bytes and get_line_length, do not overcook EEPROM | |
| def get_spectrum(device, msg_bytes=1024): |
Lines 117 to 124 in 03b0ecd
| def get_line_length(device): | |
| "get number of pixels reported by device" | |
| # TODO check if EEPROM is involved, if so: mention in docstring | |
| seq = device.ctrl_transfer(DEVICE_TO_HOST, 0xff, 0x03, 0, 64) | |
| return seq[1]<<8 + seq[0] | |
One option which fits into the rationale of this module is to leave that as a responsibility of the caller. So they would write a client program something along the lines of the following. Here it is the caller who keeps track of the EEPROM data and makes the decision to call it only once at the beginning. That keeps the module from being stateful. We can simplify the caller's work slightly be adding a get_line_bytes function which includes the factor of two.
# ...
bytes_to_read = 2*get_line_length(device) # OR bytes_to_read = get_line_bytes(device)
while True:
get_spectrum(device, bytes_to_read)
# ...It's also possible to use caching on eeprom reading operations so then statefulness is tucked into the language. With caching in place, it could be acceptable to call get_line_length from within get_spectrum.
In summary the options are:
- Responsibility of caller: add a
get_line_bytesfunction to simplify the client program determining and storing that data - Automatic Caching: let
get_spectrumbe an exception to the rule that driver functions do not call each other. Use an annotation for caching - Manual Caching: implement the contents of
get_line_lengthwithin get_spectrum (keeping the functions independent). Use a small amount of state to cache the byte_count value so that the USB command that determines the line length only need to be done on the first call ofget_spectrum