aggiunta commenti

This commit is contained in:
2026-05-12 16:30:43 +02:00
parent 1c1344ea63
commit 328a5fe540
+23 -1
View File
@@ -17,7 +17,7 @@
# - (2.6.0) Aggiunto gestione Redis x code salvate ogni minuto e ricaricate all'avvio 2025.04.17
# - (2.6.1) Cleanup generale vecchia queue post test vari
# - (2.6.2) Fix in global di to_retry in send_coda per evitare problemi
# - (3.0.0) Fix in global di to_retry in send_coda per evitare problemi
# - (3.0.0) Prima versione code-assisted: riformulazione e ottimizzazione globale programma
import time
@@ -125,6 +125,9 @@ class ReadParallelaIOB:
self.MAX_COUNTER_FILTER = config.getint('filter', 'MAX_COUNTER_FILTER')
def setup_logging(self):
"""
Configures the logging system.
"""
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s %(name)-8s %(levelname)-8s %(message)s',
@@ -137,6 +140,9 @@ class ReadParallelaIOB:
self.logPro = logging.getLogger('program')
def setup_gpio(self):
"""
Initializes the GPIO pins for input.
"""
if GPIO is None:
self.logPro.error("GPIO library not found. Are you on a Raspberry Pi?")
sys.exit(1)
@@ -151,13 +157,22 @@ class ReadParallelaIOB:
sys.exit(1)
def rqEnqueue(self, item):
"""
Adds an item to the Redis queue.
"""
self.CodaR.rpush(self.queue_name, item)
def rqDequeue(self):
"""
Removes and returns an item from the Redis queue.
"""
item = self.CodaR.lpop(self.queue_name)
return item.decode('utf-8') if item else None
def rqLen(self):
"""
Returns the current length of the Redis queue.
"""
return self.CodaR.llen(self.queue_name)
def readParallelaFiltrata(self):
@@ -302,6 +317,12 @@ class ReadParallelaIOB:
self.timer_busy = False
def run(self):
"""
Starts the main execution loop:
1. Initializes GPIO.
2. Spawns a background daemon thread to empty the Redis queue.
3. Enters a loop to sample GPIO inputs, apply filters/blinking, and queue changes.
"""
self.setup_gpio()
# Start background thread for queue emptying
@@ -348,6 +369,7 @@ class ReadParallelaIOB:
self.to_long = self.TIMEOUTLONG
except KeyboardInterrupt:
self.logPro.info("Keyboard interrupt received. Exiting...")
break
except Exception as e:
self.logPro.error(f"Main loop error: {e}")