Skip to content

Instantly share code, notes, and snippets.

@Harakan
Created March 10, 2016 17:49
Show Gist options
  • Save Harakan/908f0e434fb14cf7f8c7 to your computer and use it in GitHub Desktop.
Save Harakan/908f0e434fb14cf7f8c7 to your computer and use it in GitHub Desktop.
julian... callback.... wats?
class Wrap
{
public:
virtual void printerStatusHandler(void* newMessage);
virtual void moveToDripCountHandler(void* newMessage);
};
struct Handler {
uint8_t typeId;
void (*handler)(void* message);
};
struct WrapHandler {
uint8_t typeId;
void (Wrap::*handler)(void* message);
Wrap* ctx;
};
@Harakan
Copy link
Author

Harakan commented Mar 10, 2016

`class PeachDuino
{
public:
PeachDuino(HardwareSerial &hw_serial)
{
serial = &hw_serial;
};

void addHandler(unsigned int typeId, void (Wrap::* handler)(void* message), Wrap* ctx)
{
  w_handlers[w_handler_count].typeId = typeId;
  w_handlers[w_handler_count].handler = handler;
  w_handlers[w_handler_count].ctx = ctx;
  w_handler_count++;
};

void addHandler(unsigned int typeId, void (*handler)(void* message))
{
  g_handlers[g_handler_count].typeId = typeId;
  g_handlers[g_handler_count].handler = handler;
  g_handler_count++;
};`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment