Update Class Variables during operation, attach interrupts to class pins/funcs

Hi everyone, let me first preface this with the fact that this is a high level concept question, and second let me give a brief description of what I am trying to accomplish.

What I want to do is to create a sensor class object that effectively has class variables pin, id, and value (not sensor value, just an int for the sensor set at construction). Then I want to create a sort of dataLink class which will be responsible for sending data packets via TCP/IP.

I want each to create 1x instance of the dataLink class and provide a handle/memory reference to each instance of the sensor class on construction. Then I want to register an interrupt for each sensor class so that when the pin goes high the sensor classes will call an internal function which will call a dataLink function to effectively queue data. (The dataLink class is just writing out data packets from the queue on a timer or at least that is the idea).

Now from what I have read, attaching interrupts to class functions IS technically possible but requires a little bit of hacky coding with a wrapper for the class due to the hidden object reference variable "this". (How to use attachInterrupt with a class member - Syntax & Programs - Arduino Forum)

But please correct me if I am wrong on this. Is there an easier way in setup() to just have myClassInstance.classFunction as the ISR/Callback function? Similarly I would like to use myClassInstance.myPin as the interrupt pin. Though I think that should be easy enough to just pull into a local variable in setup().

This ^ is effectively my first question, I just want to make sure I understand this.

My second question is how would I change class variables/properties during execution? Say I have 2 sensors class instances running with their ISR's waiting for a rising edge on the sensor pins. Sensor A is set with a value of 10 and sensor B is set with a value of 20, but now I want to change sensor A's value to 30. I am not sure how I would do that from a UI perspective. Programmatically it would be sensorA.val = 30; right, but once the setup() runs and the main loop() is running, I don't really have a live environment with access to the class instances.

From what I have read there are a few approaches. I could setup some sort of button system in the main code and have it increment vals up and down when pressed for example. I would prefer to do this via software though and I am not sure how or if I can do this at all. ( I read something about creating a serial command system to access variables but it was pretty non-specific)

For some perspective I am used to creating C++ classes and then creating dlls for them where all I do in my UI front end is create local handle to the memory address where the class lives. A good OOP example would be like Matlab with handles to C++ via mex functions. I am just not really sure what the process is for managing objects on a uController like Arduino.

Lastly, I don't really have any functional code for this (mainly because I am not sure how to do it) - just proof of concept things based on examples from the Arduino guides. Sorry about that, but this is sort of a high-level concept question.

Q1: You can not attach a class function to an interrupt because the compiler does not know the address of the function associated with that instance at compile time. If the function is static, then the compiler does know the address, but that makes the function a class function and will not get called for a specific instance of the class (sensorA and sensorB)

Q2: If the members of your class are public, you can change them any time, any where in the code you like. If they are private, the usual approach is to provide a get/set pair of functions that retrieve/set the value.

Personally, I would not try to translate over too much design from your dll/UI experience on a PC into the world of arduinos. They do not have gigabytes of ram, etc. and you are much closer to the hardware.

For Q1

So, to clarify, there is no way, even using some of the wrapper approaches discussed here How to use attachInterrupt with a class member - Syntax & Programs - Arduino Forum, to attach a class function to an interrupt? Or are you saying that there is no DIRECT way to do this, meaning that I MUST use one of these workarounds?

For Q2

Maybe I need to clarify myself, how exactly would I do this? The class is public but once I upload the sketch and run it, I don't see a software approach to go ahead and say SensorB.val = 10;. I would have to edit the sketch itself and re-upload it as far as I can tell.

Thanks for your time.

Correct. There is no direct method to do that. The topic you reference just shows an ordinary function that gets attached to an interrupt and that ordinary function then calls the the desired method of the desired object. This means that the interrupt is calling a function address known to the compiler.

If you want to change a value at runtime, there are many ways to do that. Buttons for up/down. Serial communication, having the arduino be a webserver, etc.