diff --git a/indi_allsky/config.py b/indi_allsky/config.py index 59088b40..fd37d48e 100644 --- a/indi_allsky/config.py +++ b/indi_allsky/config.py @@ -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, diff --git a/indi_allsky/devices/sensors/lightSensorSi1145.py b/indi_allsky/devices/sensors/lightSensorSi1145.py index 6c235146..18f3f12c 100644 --- a/indi_allsky/devices/sensors/lightSensorSi1145.py +++ b/indi_allsky/devices/sensors/lightSensorSi1145.py @@ -1,4 +1,4 @@ -#import time +import time import logging from .sensorBase import SensorBase @@ -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 @@ -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 = { @@ -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) + diff --git a/indi_allsky/flask/forms.py b/indi_allsky/flask/forms.py index 00788273..f437bd73 100644 --- a/indi_allsky/flask/forms.py +++ b/indi_allsky/flask/forms.py @@ -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') @@ -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]) @@ -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]) diff --git a/indi_allsky/flask/templates/config.html b/indi_allsky/flask/templates/config.html index 256a8711..37ca07c7 100644 --- a/indi_allsky/flask/templates/config.html +++ b/indi_allsky/flask/templates/config.html @@ -4828,6 +4828,60 @@
+
+
+ {{ form_config.TEMP_SENSOR__SI1145_VIS_GAIN_NIGHT.label(class='col-form-label') }} +
+
+ {{ form_config.TEMP_SENSOR__SI1145_VIS_GAIN_NIGHT(class='form-select bg-secondary') }} + +
+
+
+
+
+ +
+
+ {{ form_config.TEMP_SENSOR__SI1145_VIS_GAIN_DAY.label(class='col-form-label') }} +
+
+ {{ form_config.TEMP_SENSOR__SI1145_VIS_GAIN_DAY(class='form-select bg-secondary') }} + +
+
+
+
+
+ +
+
+ {{ form_config.TEMP_SENSOR__SI1145_IR_GAIN_NIGHT.label(class='col-form-label') }} +
+
+ {{ form_config.TEMP_SENSOR__SI1145_IR_GAIN_NIGHT(class='form-select bg-secondary') }} + +
+
+
+
+
+ +
+
+ {{ form_config.TEMP_SENSOR__SI1145_IR_GAIN_DAY.label(class='col-form-label') }} +
+
+ {{ form_config.TEMP_SENSOR__SI1145_IR_GAIN_DAY(class='form-select bg-secondary') }} + +
+
+
+
+
+ +
+
{{ form_config.TEMP_SENSOR__MQTT_HOST.label(class='col-form-label') }} @@ -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', diff --git a/indi_allsky/flask/views.py b/indi_allsky/flask/views.py index ef10d082..a0ea1d15 100644 --- a/indi_allsky/flask/views.py +++ b/indi_allsky/flask/views.py @@ -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 @@ -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']) diff --git a/requirements/requirements_gpio.txt b/requirements/requirements_gpio.txt index 6ef08c8d..e1dae3cd 100644 --- a/requirements/requirements_gpio.txt +++ b/requirements/requirements_gpio.txt @@ -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