jfjlaros / simpleRPC

Simple RPC implementation for Arduino.
MIT License
50 stars 17 forks source link

Allow class functions #19

Closed chrisflesher closed 3 years ago

chrisflesher commented 3 years ago

It would make things a bit more convenient if it were possible to use class functions with the template system:

Adafruit_BME280 bme;

void setup(void)
{
  Serial.begin(9600);
  bme.begin();
}

void loop(void)
{
  interface(
    Serial,
    bme.readTemperature, F("get_temperature: @return: Temperature [C]"));
}

I'm not sure how difficult / if it is worth doing this with the current template system? It is not too much trouble to just wrap these in another function.

jfjlaros commented 3 years ago

This is already possible. The following line should work:

pack(&bme, &Adafruit_BME280::readTemperature), F("get_temperature: @return: Temperature [C]")
chrisflesher commented 3 years ago

Nice! Thanks.

slaff commented 2 years ago

And what is solution when this method is overloaded ? For example if Adafruit_BME280::readTemperature has the following:

void Adafruit_BME280::readTemperature(uint8_t& degrees);
uint8_t Adafruit_BME280::readTemperature(); 
jfjlaros commented 2 years ago

To select the first option, something like this should work:

(void(Adafruit_BME280::*)(uint8_t&))&Adafruit_BME280::readTemperature
slaff commented 2 years ago

Awesome! Thank you @jfjlaros