Skip to content

Polishing the library #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 38 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9a8686b
enums and contrexpr
Jul 23, 2020
8e7ccf1
Started restructuring of the Packet class
Jul 23, 2020
24d3b04
Finished restructuring the core Packet functionality
Jul 24, 2020
df6dc81
Added magic value constant
Jul 24, 2020
145191c
Added missing getPacketSize() function
Jul 24, 2020
ddbe472
Implemented SerialTransfer
Jul 24, 2020
c85b095
Added StreamTransfer alias
Jul 24, 2020
cbe6e00
Moved stream implementation to StreamTransfer
Jul 24, 2020
997897a
Preprocessor cleanup
Jul 24, 2020
4e4a14c
Added helper class that implements serial debugging
Jul 24, 2020
0694e89
Fixed PacketCRC
Jul 24, 2020
e8c3eb0
gcc doesn't like __FUNCTION__
Jul 24, 2020
fb30cfb
Consistent naming
Jul 24, 2020
e91b848
Implemented the majority of SPITransfer
Jul 24, 2020
3d3074b
Properly implement SPI
Jul 24, 2020
283261f
Moved fields around a bit
Jul 24, 2020
89e4232
Minor SPI optimization
Jul 24, 2020
d1b0fd3
Added back callbacks
Jul 24, 2020
21ae959
Don't forget the destructor
Jul 24, 2020
f488f85
Don't allocate dynamic memory in PacketCRC
Jul 24, 2020
2e9251d
Fixed compilation and CRC table generation
Jul 24, 2020
8941076
Formatting
Jul 24, 2020
a76352b
Generate CRC table at compile time
Jul 27, 2020
1b598b4
Use the begin pattern
Jul 27, 2020
a232ec5
Reordered parameters for tx and rx functions
Jul 27, 2020
4a58170
Properly handle out of bounds values in rxObj
Jul 27, 2020
b1e6770
Updated uart examples
Jul 27, 2020
c5cbcde
Made value gating a bit better
Jul 27, 2020
756413c
Added const where possible
Jul 27, 2020
17cf48f
Pass the packet instance as parameter in callback
Jul 27, 2020
400327c
Added debugging Serial port
Jul 27, 2020
1041145
Updated I2C examples
Jul 27, 2020
b1a8ce5
Updated SPI examples
Jul 27, 2020
988f190
Added debug notice to all begin calls
Jul 27, 2020
4442648
Fixe compilation issue with SPI library
BrainStone Jul 27, 2020
447c666
Handled the ESP8266 not having SPI support
Jul 28, 2020
67068df
Use single transmission buffer for preamble, data and postamble
Jul 29, 2020
85264a9
Force struct to be packed for consitent results
Jul 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ See the [example sketches](https://github.com/PowerBroker2/SerialTransfer/tree/m

# ***NOTE:***

SPITransfer.h and it's associated features are not supported for the Arduino Nano 33 BLE or DUE.
SPITransfer.h and it's associated features are not supported for the ESP8266, Arduino Nano 33 BLE or DUE.

Should the automatic detection of SPI support fail you can define the macro `SPI_TRANSFER` to `1` to forcefully enable SPI or to `0` to forcefully disable it.
46 changes: 18 additions & 28 deletions examples/i2c_rx_data/i2c_rx_data.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,41 @@

I2CTransfer myTransfer;

struct STRUCT {
char z;
float y;
struct STRUCT
{
char z;
float y;
} testStruct;

char arr[6];


/////////////////////////////////////////////////////////////////// Callbacks
void hi()
void handlePacket(Packet& packet)
{
// use this variable to keep track of how many
// bytes we've processed from the receive buffer
uint16_t recSize = 0;

recSize = myTransfer.rxObj(testStruct, recSize);
Serial.print(testStruct.z);
Serial.print(testStruct.y);
Serial.print(" | ");
packet.rxObj(testStruct);
Serial.print(testStruct.z);
Serial.print(testStruct.y);
Serial.print(" | ");

recSize = myTransfer.rxObj(arr, recSize);
Serial.println(arr);
packet.rxObj(arr);
Serial.println(arr);
}
///////////////////////////////////////////////////////////////////


void setup()
{
Serial.begin(115200);
Wire.begin(0);

functionPtr callbackArr[] = { hi };

///////////////////////////////////////////////////////////////// Config Parameters
configST myConfig;
myConfig.debug = true;
myConfig.callbacks = callbackArr;
myConfig.callbacksLen = sizeof(callbackArr) / sizeof(functionPtr);
/////////////////////////////////////////////////////////////////

myTransfer.begin(Wire, myConfig);
Serial.begin(115200);
Wire.begin(0);

// Serial is the debug serial port. If you don't want to enable debugging, you can remove it
myTransfer.begin(Wire, Serial);
myTransfer.addCallback(handlePacket);
}


void loop()
{
// Do nothing
myTransfer.tick();
}
38 changes: 17 additions & 21 deletions examples/i2c_rx_datum/i2c_rx_datum.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,37 @@

I2CTransfer myTransfer;

struct STRUCT {
char z;
float y;
struct STRUCT
{
char z;
float y;
} testStruct;


/////////////////////////////////////////////////////////////////// Callbacks
void hi()
void handlePacket(Packet& packet)
{
myTransfer.rxObj(testStruct);
Serial.print(testStruct.z);
Serial.println(testStruct.y);
packet.rxObj(testStruct);
Serial.print(testStruct.z);
Serial.print(testStruct.y);
}
///////////////////////////////////////////////////////////////////


void setup()
{
Serial.begin(115200);
Wire.begin(0);

functionPtr callbackArr[] = { hi };

///////////////////////////////////////////////////////////////// Config Parameters
configST myConfig;
myConfig.debug = true;
myConfig.callbacks = callbackArr;
myConfig.callbacksLen = sizeof(callbackArr) / sizeof(functionPtr);
/////////////////////////////////////////////////////////////////

myTransfer.begin(Wire, myConfig);
Serial.begin(115200);
Wire.begin(0);

Wire.begin(0);

// Serial is the debug serial port. If you don't want to enable debugging, you can remove it
myTransfer.begin(Wire, Serial);
myTransfer.addCallback(handlePacket);
}


void loop()
{
// Do nothing
myTransfer.tick();
}
36 changes: 17 additions & 19 deletions examples/i2c_tx_data/i2c_tx_data.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,37 @@

I2CTransfer myTransfer;

struct STRUCT {
char z;
float y;
struct STRUCT
{
char z;
float y;
} testStruct;

char arr[] = "hello";


void setup()
{
Serial.begin(115200);
Wire.begin();
Serial.begin(115200);
Wire.begin();

myTransfer.begin(Wire);
// Serial is the debug serial port. If you don't want to enable debugging, you can remove it
myTransfer.begin(Wire, Serial);

testStruct.z = '$';
testStruct.y = 4.5;
testStruct.z = '$';
testStruct.y = 4.5;
}


void loop()
{
// use this variable to keep track of how many
// bytes we're stuffing in the transmit buffer
uint16_t sendSize = 0;

///////////////////////////////////////// Stuff buffer with struct
sendSize = myTransfer.txObj(testStruct, sendSize);
///////////////////////////////////////// Stuff buffer with struct
myTransfer.txObj(testStruct);

///////////////////////////////////////// Stuff buffer with array
sendSize = myTransfer.txObj(arr, sendSize);
///////////////////////////////////////// Stuff buffer with array
myTransfer.txObj(arr);

///////////////////////////////////////// Send buffer
myTransfer.sendData(sendSize);
delay(500);
///////////////////////////////////////// Send buffer
myTransfer.sendPacket();
delay(500);
}
22 changes: 12 additions & 10 deletions examples/i2c_tx_datum/i2c_tx_datum.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@

I2CTransfer myTransfer;

struct STRUCT {
char z;
float y;
struct STRUCT
{
char z;
float y;
} testStruct;


void setup()
{
Serial.begin(115200);
Wire.begin();
Serial.begin(115200);
Wire.begin();

myTransfer.begin(Wire);
// Serial is the debug serial port. If you don't want to enable debugging, you can remove it
myTransfer.begin(Wire, Serial);

testStruct.z = '$';
testStruct.y = 4.5;
testStruct.z = '$';
testStruct.y = 4.5;
}


void loop()
{
myTransfer.sendDatum(testStruct);
delay(500);
myTransfer.sendObj(testStruct);
delay(500);
}
50 changes: 16 additions & 34 deletions examples/spi_rx_data/spi_rx_data.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,33 @@

SPITransfer myTransfer;

struct STRUCT {
char z;
float y;
struct STRUCT
{
char z;
float y;
} testStruct;

char arr[6];

volatile bool procNewPacket = false;


void setup()
{
Serial.begin(115200);

SPCR |= bit (SPE);
pinMode(MISO, OUTPUT);
SPI.attachInterrupt();

myTransfer.begin(SPI);
}
Serial.begin(115200);

pinMode(MISO, OUTPUT);

void loop()
{
if(procNewPacket)
{
procNewPacket = false;

// use this variable to keep track of how many
// bytes we've processed from the receive buffer
uint16_t recSize = 0;

recSize = myTransfer.rxObj(testStruct, recSize);
Serial.print(testStruct.z);
Serial.print(testStruct.y);
Serial.print(" | ");

recSize = myTransfer.rxObj(arr, recSize);
Serial.println(arr);
}
// Serial is the debug serial port. If you don't want to enable debugging, you can remove it
myTransfer.begin(SPI, Serial);
}


ISR (SPI_STC_vect)
void loop()
{
if(myTransfer.available())
procNewPacket = true;
myTransfer.rxObj(testStruct);
Serial.print(testStruct.z);
Serial.print(testStruct.y);
Serial.print(" | ");

myTransfer.rxObj(arr);
Serial.println(arr);
}
38 changes: 12 additions & 26 deletions examples/spi_rx_datum/spi_rx_datum.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,27 @@

SPITransfer myTransfer;

struct STRUCT {
char z;
float y;
struct STRUCT
{
char z;
float y;
} testStruct;

volatile bool procNewPacket = false;


void setup()
{
Serial.begin(115200);

SPCR |= bit (SPE);
pinMode(MISO, OUTPUT);
SPI.attachInterrupt();

myTransfer.begin(SPI);
}
Serial.begin(115200);

pinMode(MISO, OUTPUT);

void loop()
{
if(procNewPacket)
{
procNewPacket = false;

myTransfer.rxObj(testStruct);
Serial.print(testStruct.z);
Serial.println(testStruct.y);
}
// Serial is the debug serial port. If you don't want to enable debugging, you can remove it
myTransfer.begin(SPI, Serial);
}


ISR (SPI_STC_vect)
void loop()
{
if(myTransfer.available())
procNewPacket = true;
myTransfer.rxObj(testStruct);
Serial.print(testStruct.z);
Serial.print(testStruct.y);
}
Loading