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 @@