Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Handling interrupts in OOP
#1
This is a project in process control. Originally a software simulator to keep my busy during long winter nights (two years ago). Over time the project has moved to real hardware to control and has kind of gotten out of hand. Top level looks like this.

[Image: TopLevel.png]

My current focus is on the Raspberry Pi, Debian (Linux), python 3.7, . The Arduino runs a working application in C++ and currently the laptop application is written in Java. These two JMRI programs work fine, but don’t do exactly what I want. Also I ran out of I/O pins on the Arduino for sensors and want to control 56 servos. So I added the Raspberry in the middle.
My (current) problem is checking the status of hardware sensor. I want to be able inquire the current state of a single sensor and have changes reported by interrupt when a change occurs. No problem doing one or the other but my OO structure, who imports who, prevents me from doing both.
[Image: Softwar-3.png]
The problem is with the path from Traffic -> Command ->Sensor -> WabbitFB -> (the real hardware).
TT3 just starts an instance of Traffic and Fan.
The Traffic Class handles all the communication between the three processors and “knows” only that an instructions from the laptop ends with a “>”. Traffic ask Command what to do with a received instruction – process locally, send to the Arduino or both.
The Command Class processes instructions from the laptop. Some instructions I have added, some are subset of original instruction. All instruction format and validity is checked then passed to Sensor or Signals.
The Sensor Class handles instructions related to the sensors used to report the current state of the hardware available from class WabbitFB. Following the original sensor instructions between the laptop and the Arduino this class receives instructions to map from sensor ID (used by the laptop) and GPIO pins (used by the hardware/WabbitFB class). Command/hardware status is returned to the laptop.
Class WabbitFB sets up the hardware GPIO pins, interrupts.
So Traffic imports Command, Command imports Sensor, Sensor imports WabbitFB. Sensor can see into WabbitFB to call a function to retrieve the current status of a sensor. The problem is WabbitFB can not see into Sensor to report a change in status flagged by an interrupt. OR I don’t know how to code the circular reference. If I try to also import Sensor into WabbitFB I get an error.
Trying to turn things around, importing Sensor into WabbitFB, just moves the problem between Command and Sensor.
The Arduino package avoids this problem by scanning each sensor and not using interrupts. I am thinking that interrupts have elegances.
Creating a new path from the hardware (WabbitFB) back to Traffic seems to require a copy of the GPIO-to-sensor ID mapping. This at some point also results in a circular reference.
Is there a way to program both 1) an inquiry of status on demand and 2) reporting status change triggered by interrupt?
Say what you will about Sisyphus. He always has work.
Reply


Messages In This Thread
Handling interrupts in OOP - by Lou - Aug-27-2021, 10:50 PM
RE: Handling interrupts in OOP - by Lou - Sep-02-2021, 03:52 AM
RE: Handling interrupts in OOP - by Larz60+ - Sep-02-2021, 02:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Star python exception handling handling .... with traceback mg24 3 1,411 Nov-09-2022, 07:29 PM
Last Post: Gribouillis
  Problems with Interrupts/ callback functions in Python for an Alarm Clock project Henry1 1 4,970 Dec-16-2016, 10:17 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020