diff --git a/pioreactor/background_jobs/base.py b/pioreactor/background_jobs/base.py index 1f118265..49d385c4 100644 --- a/pioreactor/background_jobs/base.py +++ b/pioreactor/background_jobs/base.py @@ -895,7 +895,7 @@ def _confirm_state_in_broker(self, message: pt.MQTTMessage) -> None: self.logger.debug( f"Job is in state {self.state}, but in state {state_in_broker} in broker. Attempting fix by publishing {self.state}." ) - sleep(1) + sleep(5) self._publish_setting("state") def _clear_caches(self) -> None: diff --git a/pioreactor/background_jobs/monitor.py b/pioreactor/background_jobs/monitor.py index c2158b1b..363d75a3 100644 --- a/pioreactor/background_jobs/monitor.py +++ b/pioreactor/background_jobs/monitor.py @@ -532,6 +532,8 @@ def flicker_led_response_okay(self, *args) -> None: self.led_off() sleep(0.45) + self._republish_state() + self.led_in_use = False def flicker_led_with_error_code(self, error_code: int) -> None: diff --git a/pioreactor/utils/adcs.py b/pioreactor/utils/adcs.py index 01bdad27..22cfdd2d 100644 --- a/pioreactor/utils/adcs.py +++ b/pioreactor/utils/adcs.py @@ -94,6 +94,7 @@ class Pico_ADC(_ADC): def __init__(self) -> None: # set up i2c connection to hardware.ADC self.i2c = I2C(hardware.SCL, hardware.SDA) + assert self.get_firmware_version() == (0, 4), "Firmware version mismatch." def read_from_channel(self, channel: pt.AdcChannel) -> pt.AnalogValue: assert 0 <= channel <= 3 @@ -108,14 +109,19 @@ def read_from_channel(self, channel: pt.AdcChannel) -> pt.AnalogValue: f"Unable to find i2c channel {hardware.ADC}. Is the HAT attached? Is the firmware loaded?" ) + def get_firmware_version(self) -> tuple[int, int]: + result = bytearray(2) + self.i2c.writeto_then_readfrom(hardware.ADC, bytes([0x08]), result) + return (result[1], result[0]) + def from_voltage_to_raw(self, voltage: pt.Voltage) -> pt.AnalogValue: - return int((voltage / 3.3) * 4095 * 16) + return int((voltage / 3.3) * 4095 * 32) def from_voltage_to_raw_precise(self, voltage: pt.Voltage) -> float: - return (voltage / 3.3) * 4095 * 16 + return (voltage / 3.3) * 4095 * 32 def from_raw_to_voltage(self, raw: pt.AnalogValue) -> pt.Voltage: - return (raw / 4095 / 16) * 3.3 + return (raw / 4095 / 32) * 3.3 def check_on_gain(self, value: pt.Voltage, tol: float = 0.85) -> None: # pico has no gain. diff --git a/update_scripts/upcoming/update.sql b/update_scripts/upcoming/update.sql index ff1fe697..c98ec899 100644 --- a/update_scripts/upcoming/update.sql +++ b/update_scripts/upcoming/update.sql @@ -1,8 +1,10 @@ # update.sql +# Actually, I'm not going to do this. These can take a _long_ time to execute. -CREATE INDEX IF NOT EXISTS stirring_rates_ix -ON stirring_rates (experiment, pioreactor_unit); - -CREATE INDEX IF NOT EXISTS pwm_dcs_ix -ON pwm_dcs (experiment, pioreactor_unit); +# CREATE INDEX IF NOT EXISTS stirring_rates_ix +# ON stirring_rates (experiment, pioreactor_unit); +# +# CREATE INDEX IF NOT EXISTS pwm_dcs_ix +# ON pwm_dcs (experiment, pioreactor_unit); +#