Skip to content

Commit

Permalink
Bump version to 0.7.5
Browse files Browse the repository at this point in the history
  • Loading branch information
GlassOnTin committed Nov 17, 2024
1 parent 2e566ca commit 1fe6898
Show file tree
Hide file tree
Showing 5 changed files with 936 additions and 29 deletions.
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
gecko-controller (0.7.5) stable; urgency=medium

* Bump version to 0.7.5

-- GlassOnTin <[email protected]> Sun, 17 Nov 2024 16:32:24 +0000

gecko-controller (0.7.4) stable; urgency=medium

* Bump version to 0.7.4
Expand Down
61 changes: 36 additions & 25 deletions gecko_controller/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from typing import Tuple, Optional
from pathlib import Path


# Constants for logging
LOG_DIR = "/var/log/gecko-controller"
LOG_FILE = "readings.csv"
Expand Down Expand Up @@ -126,16 +125,6 @@ def write_data(self, data: int):

class GeckoController:
def __init__(self):
# Convert time settings from config to datetime.time objects
self.light_on_time = self.parse_time_setting(LIGHT_ON_TIME)
self.light_off_time = self.parse_time_setting(LIGHT_OFF_TIME)
print(f"Light on @ {self.light_on_time}, Light off @ {self.light_off_time}\n")

# Use thresholds from config
self.UVA_THRESHOLDS = UVA_THRESHOLDS
self.UVB_THRESHOLDS = UVB_THRESHOLDS
print(f"UVA Thresholds = {self.UVA_THRESHOLDS}, UVB Thresholds = {self.UVB_THRESHOLDS}\n")

# GPIO Setup
GPIO.setmode(GPIO.BCM)
GPIO.setup(LIGHT_RELAY, GPIO.OUT)
Expand All @@ -149,38 +138,55 @@ def __init__(self):
self.setup_logging()
self.last_log_time = 0
self.bus = smbus2.SMBus(1)

# Convert time settings from config to datetime.time objects
self.light_on_time = self.parse_time_setting(LIGHT_ON_TIME)
self.light_off_time = self.parse_time_setting(LIGHT_OFF_TIME)
print(f"Light on @ {self.light_on_time}, Light off @ {self.light_off_time}\n")

# Use thresholds from config
self.UVA_THRESHOLDS = UVA_THRESHOLDS
self.UVB_THRESHOLDS = UVB_THRESHOLDS
print(f"UVA Thresholds = {self.UVA_THRESHOLDS}, UVB Thresholds = {self.UVB_THRESHOLDS}\n")

# Calculate UV correction factor
self.uv_correction_factor = self.calculate_uv_correction()
print(f"\nUV Correction Factor: {self.uv_correction_factor:.3f}")
print(f"Sensor Position: {SENSOR_HEIGHT}m height, {LAMP_DIST_FROM_BACK}m from back")
print(f"Lamp Height: {ENCLOSURE_HEIGHT}m, Sensor Angle: {SENSOR_ANGLE}°\n")

# UV sensor configuration with fallback paths
try:
# First try relative import (when installed as package)
from .as7331 import AS7331, INTEGRATION_TIME_256MS, GAIN_16X
from .as7331 import AS7331, INTEGRATION_TIME_256MS, GAIN_16X, MEASUREMENT_MODE_CONTINUOUS
except ImportError:
try:
# Try importing from the same directory as this script
import os
import sys
script_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(script_dir)
from as7331 import AS7331, INTEGRATION_TIME_256MS, GAIN_16X
from as7331 import AS7331, INTEGRATION_TIME_256MS, GAIN_16X, MEASUREMENT_MODE_CONTINUOUS
print("Imported UV sensor (as7331) module ok")
except ImportError:
print("Warning: AS7331 module not found, UV sensing disabled")
print("Warning: UV sensor module (AS7331) not found. UV sensing disabled")
print(f"Looked in: {script_dir}")
print("Make sure as7331.py is in the same directory as this script")
self.uv_sensor = None
else:
self.uv_sensor = AS7331(1)
self.uv_sensor = AS7331(1)
self.uv_sensor.integration_time = INTEGRATION_TIME_256MS
self.uv_sensor.gain = GAIN_16X
self.uv_sensor.measurement_mode = MEASUREMENT_MODE_CONTINUOUS
else:
self.uv_sensor = AS7331(1)
self.uv_sensor.integration_time = INTEGRATION_TIME_256MS
self.uv_sensor.gain = GAIN_16X

# Calculate UV correction factor
self.uv_correction_factor = self.calculate_uv_correction()
print(f"\nUV Correction Factor: {self.uv_correction_factor:.3f}")
print(f"Sensor Position: {SENSOR_HEIGHT}m height, {LAMP_DIST_FROM_BACK}m from back")
print(f"Lamp Height: {ENCLOSURE_HEIGHT}m, Sensor Angle: {SENSOR_ANGLE}°\n")

if self.uv_sensor:
print("UV Sensor (AS7331) ready")
print(f" measurement mode: {self.uv_sensor.measurement_mode_as_string}")
print(f" standby state: {self.uv_sensor.standby_state}")

# Create an image buffer
self.image = Image.new('1', (128, 64), 255) # 255 = white background
Expand Down Expand Up @@ -421,12 +427,16 @@ def read_uv(self) -> Tuple[Optional[float], Optional[float], Optional[float]]:
"""Read UV values from the sensor and apply geometric correction"""
try:
if self.uv_sensor is None:
print(f"UV sensor is None")
return None, None, None
uva, uvb, uvc, temp = self.uv_sensor.values
uva, uvb, uvc, temp = self.uv_sensor.values

# Apply correction factor
if uva is not None:
uva = uva * self.uv_correction_factor
else:
print(f"UV sensor read error")

if uvb is not None:
uvb = uvb * self.uv_correction_factor
if uvc is not None:
Expand Down Expand Up @@ -476,15 +486,16 @@ def run(self):
while True:
temp, humidity = self.read_sensor()
uva, uvb, uvc = self.read_uv()
light_status = self.control_light()
heat_status = self.control_heat(temp)
#print(temp,humidity,uva, uvb, uvc, light_status, heat_status)

if temp is not None and humidity is not None:
light_status = self.control_light()
heat_status = self.control_heat(temp)
self.update_display(temp, humidity, uva, uvb, uvc,
light_status, heat_status)
self.log_readings(temp, humidity, uva, uvb, uvc,
light_status, heat_status)
time.sleep(2)
time.sleep(10)

except KeyboardInterrupt:
print("\nShutting down...")
Expand Down
10 changes: 7 additions & 3 deletions gecko_controller/web/static/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,14 @@ document.addEventListener('DOMContentLoaded', function() {
data: []
},
{
label: 'UVB (μW/cm²)',
label: 'UVB (mW/cm²)',
borderColor: 'rgb(75, 192, 192)',
yAxisID: 'y1',
tension: 0.1,
data: []
},
{
label: 'UVC (μW/cm²)',
label: 'UVC (mW/cm²)',
borderColor: 'rgb(153, 102, 255)',
yAxisID: 'y1',
tension: 0.1,
Expand Down Expand Up @@ -508,16 +508,20 @@ document.addEventListener('DOMContentLoaded', function() {
text: 'UVA (mW/cm²)'
},
beginAtZero: true,
min:0,
suggestedMax: 200
},
y1: {
type: 'linear',
display: true,
position: 'right',
title: {
display: true,
text: 'UVB/UVC (μW/cm²)'
text: 'UVB/UVC (mW/cm²)'
},
beginAtZero: true,
min:0,
suggestedMax: 10,
grid: {
drawOnChartArea: false,
},
Expand Down
Loading

0 comments on commit 1fe6898

Please sign in to comment.