Skip to content
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 SI1145 gain settings #1489

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions indi_allsky/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ class IndiAllSkyConfigBase(object):
"VEML7700_GAIN_DAY" : "ALS_GAIN_1_8",
"VEML7700_INT_NIGHT" : "ALS_100MS",
"VEML7700_INT_DAY" : "ALS_100MS",
"SI1145_VIS_GAIN_NIGHT" : "GAIN_ADC_CLOCK_DIV_32",
"SI1145_VIS_GAIN_DAY" : "GAIN_ADC_CLOCK_DIV_1",
"SI1145_IR_GAIN_NIGHT" : "GAIN_ADC_CLOCK_DIV_32",
"SI1145_IR_GAIN_DAY" : "GAIN_ADC_CLOCK_DIV_1",
},
"CHARTS" : {
"CUSTOM_SLOT_1" : 10,
Expand Down
36 changes: 34 additions & 2 deletions indi_allsky/devices/sensors/lightSensorSi1145.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import time
import time
import logging

from .sensorBase import SensorBase
Expand All @@ -12,6 +12,15 @@
class LightSensorSi1145(SensorBase):

def update(self):
if self.night != bool(self.night_v.value):
self.night = bool(self.night_v.value)
self.update_sensor_settings()


#vis_gain = self.si1145.vis_gain
#ir_gain = self.si1145.ir_gain
#logger.info('[%s] SI1145 settings - Vis Gain: %d, IR Gain: %d', vis_gain, ir_gain)


try:
vis, ir = self.si1145.als
Expand Down Expand Up @@ -42,6 +51,19 @@ def update(self):
return data


def update_sensor_settings(self):
if self.night:
logger.info('[%s] Switching SI1145 to night mode - Visible Gain: %d, IR Gain: %d', self.name, self.vis_gain_night, self.ir_gain_night)
self.si1145.vis_gain = self.vis_gain_night
self.si1145.ir_gain = self.ir_gain_night
else:
logger.info('[%s] Switching SI1145 to day mode - Gain: %d, Integration: %d', self.name, self.vis_gain_day, self.ir_gain_day)
self.si1145.vis_gain = self.vis_gain_day
self.si1145.ir_gain = self.ir_gain_day

time.sleep(1.0)


class LightSensorSi1145_I2C(LightSensorSi1145):

METADATA = {
Expand Down Expand Up @@ -75,7 +97,17 @@ def __init__(self, *args, **kwargs):
i2c = board.I2C()
self.si1145 = adafruit_si1145.SI1145(i2c, address=i2c_address)


# enable UV index
self.si1145.uv_index_enabled = True


self.night = None # force update on first run


self.vis_gain_night = getattr(adafruit_si1145, self.config.get('TEMP_SENSOR', {}).get('SI1145_VIS_GAIN_NIGHT', 'GAIN_ADC_CLOCK_DIV_32'))
self.vis_gain_day = getattr(adafruit_si1145, self.config.get('TEMP_SENSOR', {}).get('SI1145_VIS_GAIN_DAY', 'GAIN_ADC_CLOCK_DIV_1'))
self.ir_gain_night = getattr(adafruit_si1145, self.config.get('TEMP_SENSOR', {}).get('SI1145_IR_GAIN_NIGHT', 'GAIN_ADC_CLOCK_DIV_32'))
self.ir_gain_day = getattr(adafruit_si1145, self.config.get('TEMP_SENSOR', {}).get('SI1145_IR_GAIN_DAY', 'GAIN_ADC_CLOCK_DIV_1'))

time.sleep(1.0)

22 changes: 22 additions & 0 deletions indi_allsky/flask/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2381,6 +2381,11 @@ def TEMP_SENSOR__VEML7700_INT_validator(form, field):
raise ValidationError('Invalid integration selection')


def TEMP_SENSOR__SI1145_GAIN_validator(form, field):
if field.data not in list(zip(*form.TEMP_SENSOR__SI1145_GAIN_choices))[0]:
raise ValidationError('Invalid gain selection')


def HEALTHCHECK__DISK_USAGE_validator(form, field):
if not isinstance(field.data, (int, float)):
raise ValidationError('Please enter a valid number')
Expand Down Expand Up @@ -2895,6 +2900,19 @@ class IndiAllskyConfigForm(FlaskForm):
)


TEMP_SENSOR__SI1145_GAIN_choices = (
('GAIN_ADC_CLOCK_DIV_1', '[0] - 1x (default)'),
('GAIN_ADC_CLOCK_DIV_2', '[1] - 2x'),
('GAIN_ADC_CLOCK_DIV_4', '[2] - 4x'),
('GAIN_ADC_CLOCK_DIV_8', '[3] - 8x'),
('GAIN_ADC_CLOCK_DIV_16', '[4] - 16x'),
('GAIN_ADC_CLOCK_DIV_32', '[5] - 32x'),
('GAIN_ADC_CLOCK_DIV_64', '[6] - 64x'),
('GAIN_ADC_CLOCK_DIV_128', '[7] - 128x'),
)



ENCRYPT_PASSWORDS = BooleanField('Encrypt Passwords')
CAMERA_INTERFACE = SelectField('Camera Interface', choices=CAMERA_INTERFACE_choices, validators=[DataRequired(), CAMERA_INTERFACE_validator])
INDI_SERVER = StringField('INDI Server', validators=[DataRequired(), INDI_SERVER_validator])
Expand Down Expand Up @@ -3298,6 +3316,10 @@ class IndiAllskyConfigForm(FlaskForm):
TEMP_SENSOR__VEML7700_GAIN_DAY = SelectField('VEML7700 Gain (Day)', choices=TEMP_SENSOR__VEML7700_GAIN_choices, validators=[TEMP_SENSOR__VEML7700_GAIN_validator])
TEMP_SENSOR__VEML7700_INT_NIGHT = SelectField('VEML7700 Integration (Night)', choices=TEMP_SENSOR__VEML7700_INT_choices, validators=[TEMP_SENSOR__VEML7700_INT_validator])
TEMP_SENSOR__VEML7700_INT_DAY = SelectField('VEML7700 Integration (Day)', choices=TEMP_SENSOR__VEML7700_INT_choices, validators=[TEMP_SENSOR__VEML7700_INT_validator])
TEMP_SENSOR__SI1145_VIS_GAIN_NIGHT = SelectField('SI1145 Visible Gain (Night)', choices=TEMP_SENSOR__SI1145_GAIN_choices, validators=[TEMP_SENSOR__SI1145_GAIN_validator])
TEMP_SENSOR__SI1145_VIS_GAIN_DAY = SelectField('SI1145 Visible Gain (Day)', choices=TEMP_SENSOR__SI1145_GAIN_choices, validators=[TEMP_SENSOR__SI1145_GAIN_validator])
TEMP_SENSOR__SI1145_IR_GAIN_NIGHT = SelectField('SI1145 IR Gain (Night)', choices=TEMP_SENSOR__SI1145_GAIN_choices, validators=[TEMP_SENSOR__SI1145_GAIN_validator])
TEMP_SENSOR__SI1145_IR_GAIN_DAY = SelectField('SI1145 IR Gain (Day)', choices=TEMP_SENSOR__SI1145_GAIN_choices, validators=[TEMP_SENSOR__SI1145_GAIN_validator])
CHARTS__CUSTOM_SLOT_1 = SelectField('Extra Chart Slot 1', choices=[], validators=[SENSOR_SLOT_validator])
CHARTS__CUSTOM_SLOT_2 = SelectField('Extra Chart Slot 2', choices=[], validators=[SENSOR_SLOT_validator])
CHARTS__CUSTOM_SLOT_3 = SelectField('Extra Chart Slot 3', choices=[], validators=[SENSOR_SLOT_validator])
Expand Down
58 changes: 58 additions & 0 deletions indi_allsky/flask/templates/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -4828,6 +4828,60 @@

<hr>

<div class="form-group row">
<div class="col-sm-2">
{{ form_config.TEMP_SENSOR__SI1145_VIS_GAIN_NIGHT.label(class='col-form-label') }}
</div>
<div class="col-sm-4">
{{ form_config.TEMP_SENSOR__SI1145_VIS_GAIN_NIGHT(class='form-select bg-secondary') }}
<div id="TEMP_SENSOR__SI1145_VIS_GAIN_NIGHT-error" class="invalid-feedback text-danger" style="display: none;"></div>
</div>
<div class="col-sm-6">
<div></div>
</div>
</div>

<div class="form-group row">
<div class="col-sm-2">
{{ form_config.TEMP_SENSOR__SI1145_VIS_GAIN_DAY.label(class='col-form-label') }}
</div>
<div class="col-sm-4">
{{ form_config.TEMP_SENSOR__SI1145_VIS_GAIN_DAY(class='form-select bg-secondary') }}
<div id="TEMP_SENSOR__SI1145_VIS_GAIN_DAY-error" class="invalid-feedback text-danger" style="display: none;"></div>
</div>
<div class="col-sm-6">
<div></div>
</div>
</div>

<div class="form-group row">
<div class="col-sm-2">
{{ form_config.TEMP_SENSOR__SI1145_IR_GAIN_NIGHT.label(class='col-form-label') }}
</div>
<div class="col-sm-4">
{{ form_config.TEMP_SENSOR__SI1145_IR_GAIN_NIGHT(class='form-select bg-secondary') }}
<div id="TEMP_SENSOR__SI1145_IR_GAIN_NIGHT-error" class="invalid-feedback text-danger" style="display: none;"></div>
</div>
<div class="col-sm-6">
<div></div>
</div>
</div>

<div class="form-group row">
<div class="col-sm-2">
{{ form_config.TEMP_SENSOR__SI1145_IR_GAIN_DAY.label(class='col-form-label') }}
</div>
<div class="col-sm-4">
{{ form_config.TEMP_SENSOR__SI1145_IR_GAIN_DAY(class='form-select bg-secondary') }}
<div id="TEMP_SENSOR__SI1145_IR_GAIN_DAY-error" class="invalid-feedback text-danger" style="display: none;"></div>
</div>
<div class="col-sm-6">
<div></div>
</div>
</div>

<hr>

<div class="form-group row">
<div class="col-sm-2">
{{ form_config.TEMP_SENSOR__MQTT_HOST.label(class='col-form-label') }}
Expand Down Expand Up @@ -5775,6 +5829,10 @@
'TEMP_SENSOR__VEML7700_GAIN_DAY',
'TEMP_SENSOR__VEML7700_INT_NIGHT',
'TEMP_SENSOR__VEML7700_INT_DAY',
'TEMP_SENSOR__SI1145_VIS_GAIN_NIGHT',
'TEMP_SENSOR__SI1145_VIS_GAIN_DAY',
'TEMP_SENSOR__SI1145_IR_GAIN_NIGHT',
'TEMP_SENSOR__SI1145_IR_GAIN_DAY',
'INDI_CONFIG_DEFAULTS',
'INDI_CONFIG_DAY',
'CONFIG_NOTE',
Expand Down
8 changes: 8 additions & 0 deletions indi_allsky/flask/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,10 @@ def get_context(self):
'TEMP_SENSOR__VEML7700_GAIN_DAY' : self.indi_allsky_config.get('TEMP_SENSOR', {}).get('VEML7700_GAIN_DAY', 'ALS_GAIN_1_8'),
'TEMP_SENSOR__VEML7700_INT_NIGHT': self.indi_allsky_config.get('TEMP_SENSOR', {}).get('VEML7700_INT_NIGHT', 'ALS_100MS'),
'TEMP_SENSOR__VEML7700_INT_DAY' : self.indi_allsky_config.get('TEMP_SENSOR', {}).get('VEML7700_INT_DAY', 'ALS_100MS'),
'TEMP_SENSOR__SI1145_VIS_GAIN_NIGHT' : self.indi_allsky_config.get('TEMP_SENSOR', {}).get('SI1145_VIS_GAIN_NIGHT', 'GAIN_ADC_CLOCK_DIV_32'),
'TEMP_SENSOR__SI1145_VIS_GAIN_DAY' : self.indi_allsky_config.get('TEMP_SENSOR', {}).get('SI1145_VIS_GAIN_DAY', 'GAIN_ADC_CLOCK_DIV_1'),
'TEMP_SENSOR__SI1145_IR_GAIN_NIGHT' : self.indi_allsky_config.get('TEMP_SENSOR', {}).get('SI1145_IR_GAIN_NIGHT', 'GAIN_ADC_CLOCK_DIV_32'),
'TEMP_SENSOR__SI1145_IR_GAIN_DAY' : self.indi_allsky_config.get('TEMP_SENSOR', {}).get('SI1145_IR_GAIN_DAY', 'GAIN_ADC_CLOCK_DIV_1'),
'CHARTS__CUSTOM_SLOT_1' : str(self.indi_allsky_config.get('CHARTS', {}).get('CUSTOM_SLOT_1', 10)), # string in form, int in config
'CHARTS__CUSTOM_SLOT_2' : str(self.indi_allsky_config.get('CHARTS', {}).get('CUSTOM_SLOT_2', 11)), # string in form, int in config
'CHARTS__CUSTOM_SLOT_3' : str(self.indi_allsky_config.get('CHARTS', {}).get('CUSTOM_SLOT_3', 12)), # string in form, int in config
Expand Down Expand Up @@ -2376,6 +2380,10 @@ def dispatch_request(self):
self.indi_allsky_config['TEMP_SENSOR']['VEML7700_GAIN_DAY'] = str(request.json['TEMP_SENSOR__VEML7700_GAIN_DAY'])
self.indi_allsky_config['TEMP_SENSOR']['VEML7700_INT_NIGHT'] = str(request.json['TEMP_SENSOR__VEML7700_INT_NIGHT'])
self.indi_allsky_config['TEMP_SENSOR']['VEML7700_INT_DAY'] = str(request.json['TEMP_SENSOR__VEML7700_INT_DAY'])
self.indi_allsky_config['TEMP_SENSOR']['SI1145_VIS_GAIN_NIGHT'] = str(request.json['TEMP_SENSOR__SI1145_VIS_GAIN_NIGHT'])
self.indi_allsky_config['TEMP_SENSOR']['SI1145_VIS_GAIN_DAY'] = str(request.json['TEMP_SENSOR__SI1145_VIS_GAIN_DAY'])
self.indi_allsky_config['TEMP_SENSOR']['SI1145_IR_GAIN_NIGHT'] = str(request.json['TEMP_SENSOR__SI1145_IR_GAIN_NIGHT'])
self.indi_allsky_config['TEMP_SENSOR']['SI1145_IR_GAIN_DAY'] = str(request.json['TEMP_SENSOR__SI1145_IR_GAIN_DAY'])
self.indi_allsky_config['CHARTS']['CUSTOM_SLOT_1'] = int(request.json['CHARTS__CUSTOM_SLOT_1'])
self.indi_allsky_config['CHARTS']['CUSTOM_SLOT_2'] = int(request.json['CHARTS__CUSTOM_SLOT_2'])
self.indi_allsky_config['CHARTS']['CUSTOM_SLOT_3'] = int(request.json['CHARTS__CUSTOM_SLOT_3'])
Expand Down
4 changes: 3 additions & 1 deletion requirements/requirements_gpio.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ adafruit-circuitpython-tsl2561
adafruit-circuitpython-veml7700
adafruit-circuitpython-bh1750
adafruit-circuitpython-ads1x15
adafruit-circuitpython-si1145

#adafruit-circuitpython-si1145
git+https://github.com/aaronwmorris/Adafruit_CircuitPython_SI1145.git#egg=adafruit-circuitpython-si1145

### does not work on raspi
#adafruit-circuitpython-ds18x20
Expand Down