- Added cleanup_old_logs() function to app_v3_simplified.py - Deletes log.txt if older than 15 days at app startup - Sends notification to monitoring server when cleanup occurs - Archived all legacy modules and documentation to oldcode/ - Updated device_info.txt with correct IP (192.168.1.104) - All changes validated and tested
112 lines
2.7 KiB
Python
112 lines
2.7 KiB
Python
"""
|
|
LED Control Module
|
|
Provides LED control functionality using gpiozero for visual feedback
|
|
|
|
Supports:
|
|
- LED blink patterns (single, double, triple)
|
|
- On/off control
|
|
- Graceful fallback if GPIO is not available
|
|
"""
|
|
|
|
import logging
|
|
import time
|
|
|
|
# Try to import gpiozero, fallback to dummy if not available
|
|
try:
|
|
from gpiozero import LED
|
|
GPIOZERO_AVAILABLE = True
|
|
logging.info("✓ gpiozero module available for LED control")
|
|
except ImportError:
|
|
GPIOZERO_AVAILABLE = False
|
|
logging.warning("✗ gpiozero not available - LED control disabled")
|
|
|
|
|
|
class DummyLED:
|
|
"""Dummy LED class for systems without GPIO"""
|
|
def __init__(self, pin):
|
|
self.pin = pin
|
|
|
|
def on(self):
|
|
logging.debug(f"[Dummy LED {self.pin}] ON")
|
|
|
|
def off(self):
|
|
logging.debug(f"[Dummy LED {self.pin}] OFF")
|
|
|
|
def blink(self, on_time=1, off_time=1, n=None, background=True):
|
|
logging.debug(f"[Dummy LED {self.pin}] BLINK")
|
|
|
|
|
|
# Initialize LED on GPIO pin 23 (or use dummy if not available)
|
|
try:
|
|
if GPIOZERO_AVAILABLE:
|
|
led = LED(23)
|
|
logging.info("✓ LED initialized on GPIO pin 23")
|
|
else:
|
|
led = DummyLED(23)
|
|
logging.info("Using dummy LED (GPIO not available)")
|
|
except Exception as e:
|
|
logging.warning(f"Could not initialize LED: {e}, using dummy")
|
|
led = DummyLED(23)
|
|
|
|
|
|
def led_on():
|
|
"""Turn LED on"""
|
|
try:
|
|
led.on()
|
|
logging.debug("LED turned ON")
|
|
except Exception as e:
|
|
logging.debug(f"Could not turn LED on: {e}")
|
|
|
|
|
|
def led_off():
|
|
"""Turn LED off"""
|
|
try:
|
|
led.off()
|
|
logging.debug("LED turned OFF")
|
|
except Exception as e:
|
|
logging.debug(f"Could not turn LED off: {e}")
|
|
|
|
|
|
def led_blink_pattern(blinks=3, duration=0.5):
|
|
"""
|
|
Blink LED in a pattern
|
|
|
|
Args:
|
|
blinks: Number of blinks
|
|
duration: On/off duration per blink in seconds
|
|
"""
|
|
try:
|
|
logging.info(f"LED blink pattern: {blinks} blinks, {duration}s each")
|
|
for i in range(blinks):
|
|
led.on()
|
|
time.sleep(duration)
|
|
led.off()
|
|
time.sleep(duration)
|
|
except Exception as e:
|
|
logging.debug(f"Could not execute LED blink pattern: {e}")
|
|
|
|
|
|
def led_blink_slow(blinks=3):
|
|
"""Slow blink (1 second on/off)"""
|
|
led_blink_pattern(blinks, 1)
|
|
|
|
|
|
def led_blink_fast(blinks=3):
|
|
"""Fast blink (0.25 second on/off)"""
|
|
led_blink_pattern(blinks, 0.25)
|
|
|
|
|
|
def led_startup_sequence():
|
|
"""LED sequence on startup - 3 short blinks"""
|
|
led_blink_pattern(3, 0.5)
|
|
|
|
|
|
def led_ready_sequence():
|
|
"""LED sequence when system is ready - 2 long blinks"""
|
|
led_blink_pattern(2, 1)
|
|
|
|
|
|
def led_error_sequence():
|
|
"""LED sequence on error - rapid blinks"""
|
|
led_blink_pattern(5, 0.2)
|