Skip to content

Commit

Permalink
don't create those indexes - takes too long during an update; we need…
Browse files Browse the repository at this point in the history
…ed to change the scale value with the new firmware code v0.4
  • Loading branch information
CamDavidsonPilon committed Feb 5, 2025
1 parent ed14127 commit 9e02589
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pioreactor/background_jobs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions pioreactor/background_jobs/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 9 additions & 3 deletions pioreactor/utils/adcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
12 changes: 7 additions & 5 deletions update_scripts/upcoming/update.sql
Original file line number Diff line number Diff line change
@@ -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);
#

0 comments on commit 9e02589

Please sign in to comment.