Skip to content

Commit

Permalink
Merge pull request #54 from martincizek/fix-callback-docs
Browse files Browse the repository at this point in the history
Make callbacks const-qualified. Fix invalid memory usage in callback examples.
  • Loading branch information
PowerBroker2 authored Feb 1, 2021
2 parents 950e752 + b0eb300 commit d2112da
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
5 changes: 3 additions & 2 deletions examples/i2c_rx_data/i2c_rx_data.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ void hi()
recSize = myTransfer.rxObj(arr, recSize);
Serial.println(arr);
}

// supplied as a reference - persistent allocation required
const functionPtr callbackArr[] = { hi };
///////////////////////////////////////////////////////////////////


Expand All @@ -34,8 +37,6 @@ void setup()
Serial.begin(115200);
Wire.begin(0);

functionPtr callbackArr[] = { hi };

///////////////////////////////////////////////////////////////// Config Parameters
configST myConfig;
myConfig.debug = true;
Expand Down
5 changes: 3 additions & 2 deletions examples/i2c_rx_datum/i2c_rx_datum.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ void hi()
Serial.print(testStruct.z);
Serial.println(testStruct.y);
}

// supplied as a reference - persistent allocation required
const functionPtr callbackArr[] = { hi };
///////////////////////////////////////////////////////////////////


Expand All @@ -24,8 +27,6 @@ void setup()
Serial.begin(115200);
Wire.begin(0);

functionPtr callbackArr[] = { hi };

///////////////////////////////////////////////////////////////// Config Parameters
configST myConfig;
myConfig.debug = true;
Expand Down
5 changes: 3 additions & 2 deletions examples/uart_rx_with_callbacks/uart_rx_with_callbacks.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ void hi()
{
Serial.println("hi");
}

// supplied as a reference - persistent allocation required
const functionPtr callbackArr[] = { hi };
///////////////////////////////////////////////////////////////////


Expand All @@ -17,8 +20,6 @@ void setup()
Serial.begin(115200);
Serial1.begin(115200);

functionPtr callbackArr[] = { hi };

///////////////////////////////////////////////////////////////// Config Parameters
configST myConfig;
myConfig.debug = true;
Expand Down
12 changes: 6 additions & 6 deletions src/Packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ const uint8_t NUM_OVERHEAD = 6; // Delete

struct configST
{
Stream* debugPort = &Serial;
bool debug = true;
functionPtr* callbacks = NULL;
uint8_t callbacksLen = 0;
Stream* debugPort = &Serial;
bool debug = true;
const functionPtr* callbacks = NULL;
uint8_t callbacksLen = 0;
};


Expand Down Expand Up @@ -160,8 +160,8 @@ class Packet
};
fsm state = find_start_byte;

functionPtr* callbacks = NULL;
uint8_t callbacksLen = 0;
const functionPtr* callbacks = NULL;
uint8_t callbacksLen = 0;

Stream* debugPort;
bool debug = false;
Expand Down

0 comments on commit d2112da

Please sign in to comment.