In one of my diagnostic versions of the Python script I wrote:
ok = Bridge.provide("adc_data", on_adc)
print(f"Bridge.provide returned: {ok}", flush=True)This was actually unnecessary on my part.
Bridge.provide() simply registers the callback on the MPU side and does not return a meaningful value for the application logic. The assignment to ok was only a quick diagnostic check to see whether the framework exposed any status information.
In practice the correct usage is simply:
Bridge.provide("adc_data", on_adc)
So there is no real return value to consider on the MPU side for this function.
My tests also clarified the behavioral difference between the two mechanisms.
Bridge.notify()
Bridge.notify("adc_data", adc);This is a one-way event notification:
- MCU → MPU
- the Python callback is triggered
- no value is expected back
So the MCU simply sends the information and continues execution.
Bridge.call()
auto r = Bridge.call("adc_data", adc);This is a remote procedure call (RPC) between the MCU and the MPU.
Two pieces of information can be obtained on the MCU side.
First, the success status of the RPC transaction:
int pyValue;
bool ok = r.result(pyValue);ok indicates whether the Bridge transaction itself completed successfully.
Second, if the Python callback explicitly returns a value:
def on_adc(value):
print(f"ADC: {value:#x}", flush=True)
return valuethen the MCU can retrieve that value through pyValue.
Example output from my tests:
RPC success: 1 Python returned: 0x6A Sending data to MPU: 0x6A
This confirms that:
- the MCU successfully called the Python callback
- the callback executed on the MPU
- the returned value was correctly transferred back to the MCU.
Bridge.notify()→ asynchronous event, no return value expectedBridge.call()→ RPC mechanism, possible return value from Python
In your original example, notify() is actually the appropriate mechanism because
the Python side only prints the ADC value and does not need to return anything.
For completeness, here is the same example adapted from your original program but using Bridge.call() so that the Python callback explicitly returns a value to the MCU. In your original example, notify() remains the correct choice since the Python side only prints the ADC value and does not need to return anything.
RPC success: 1. Python returned: 0x6A. Sending data to MPU: 0x6A.