Skip to content

Commit

Permalink
init commit for new calibration code in pioreactor 25.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jan 20, 2025
1 parent 344f5b2 commit 334ec13
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 396 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: Checkout source
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v2
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ This plugin offers the ability to calibrate your LEDs using an **external light
Install from the command line.

```
pio install-plugin led-calibration-plugin ## to install on a single Pioreactor
pio plugins install led-calibration-plugin ## to install on a single Pioreactor
## OR, on the command line of the leader Pioreactor
pios install-plugin led-calibration-plugin ## to install on all Pioreactors in a cluster
pios plugins install led-calibration-plugin ## to install on all Pioreactors in a cluster
```

This plugin is also available on the Pioreactor web interface, in the _Plugins_ tab. Downloading from the web interface will install on all Pioreactors in a cluster.
Expand Down
1 change: 0 additions & 1 deletion led_calibration_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
from led_calibration_plugin.calibrated_light_dark_cycle import (
CalibratedLightDarkCycle,
) # noqa: F401
from led_calibration_plugin.led_calibration import click_led_calibration # noqa: F401
15 changes: 10 additions & 5 deletions led_calibration_plugin/calibrated_light_dark_cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pioreactor.exc import CalibrationError
from pioreactor.types import LedChannel
from pioreactor.utils import clamp
from pioreactor.utils import local_persistant_storage
from pioreactor.utils import local_persistent_storage

from .led_calibration import LEDCalibration

Expand Down Expand Up @@ -44,18 +44,23 @@ def __init__(
self.light_duration_hours = float(light_duration_hours)
self.dark_duration_hours = float(dark_duration_hours)

with local_persistant_storage("current_led_calibration") as cache:
with local_persistent_storage("active_calibrations") as cache:
for channel in self.channels:
if channel not in cache:
if self.channel_to_led_device(channel) not in cache:
raise CalibrationError(f"Calibration for {channel} does not exist.")

def channel_to_led_device(self, channel: LedChannel) -> str:
return f"led_{channel}"

def execute(self) -> events.AutomationEvent:
self.hours_online += 1
return self.trigger_leds(self.hours_online)

def calculate_intensity_percent(self, channel):
with local_persistant_storage("current_led_calibration") as cache:
led_calibration = decode(cache[channel], type=LEDCalibration)
with local_persistent_storage("current_led_calibration") as cache:
led_calibration = decode(
cache[self.channel_to_led_device(channel)], type=LEDCalibration
)

intensity_percent = (
self.light_intensity - led_calibration.curve_data_[1]
Expand Down
Loading

0 comments on commit 334ec13

Please sign in to comment.