migrate callbacks from std::vector to std::map

This commit is contained in:
Siwat Sirichai 2023-12-31 13:29:11 +07:00
parent c635427d64
commit 5f6e586945
11 changed files with 143 additions and 178 deletions

View file

@ -2,7 +2,7 @@
#include <ExpansionCard.hpp>
#include <Adafruit_PWMServoDriver.h>
#include <FRAM.h>
#include <vector>
#include <map>
// Protocol for digital output card
// Note that pin is always 2 characters long and padded with 0 if necessary
@ -50,7 +50,7 @@ public:
// Register a callback function that will be called when the state of a pin changes
void registerChangeCallback(std::function<void(uint8_t, bool, uint16_t)> callback);
// Deregister the callback function
// void deregisterChangeCallback(std::function<void(uint8_t, bool, uint16_t)> callback);
void deregisterChangeCallback(uint8_t handler);
// Load a new pin map
void loadPinMap(uint8_t pinMap[16]);
// Bind the fram object to the card
@ -90,7 +90,8 @@ private:
// The pwm value of the card
uint16_t value_buffer[16];
// The callback function
std::vector<std::function<void(uint8_t, bool, uint16_t)>> change_callbacks;
uint8_t callbacks_handler_index = 0;
std::map<uint8_t, std::function<void(uint8_t, bool, uint16_t)>> change_callbacks;
// Physical pin to virtual pin map
uint8_t pinMap[16];
// Return 16 bit value representing all 16 channels