updated api
This commit is contained in:
parent
6b26acf538
commit
d7d2ff4248
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "SimpleSerialProtocol",
|
||||
"version": "1.4.0",
|
||||
"version": "1.5.0",
|
||||
"description": "Easy-to-use serial protocol system for arduino type devices.",
|
||||
"keywords": "Serial, Connectivity, USB, Simple",
|
||||
"repository":
|
||||
|
@ -41,7 +41,7 @@ class SerialConnection
|
||||
Stream *serialRefrence;
|
||||
|
||||
public:
|
||||
void init(int serialIndex, unsigned long serialBaud);
|
||||
void init(HardwareSerial &serialObject, unsigned long serialBaud);
|
||||
void send(char * data);
|
||||
char* handle();
|
||||
char* getPacketMarker(int type);
|
||||
@ -49,32 +49,9 @@ class SerialConnection
|
||||
|
||||
};
|
||||
|
||||
void SerialConnection::init(int serialIndex, unsigned long serialBaud) {
|
||||
if (serialIndex == 0) {
|
||||
Serial.begin(serialBaud);
|
||||
serialRefrence = &Serial;
|
||||
}
|
||||
|
||||
#ifdef Serial1
|
||||
else if (serialIndex == 1) {
|
||||
Serial1.begin(serialBaud);
|
||||
serialRefrence = &Serial1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef Serial2
|
||||
else if (serialIndex == 2) {
|
||||
Serial2.begin(serialBaud);
|
||||
serialRefrence = &Serial2;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef Serial3
|
||||
else if (serialIndex == 3) {
|
||||
Serial3.begin(serialBaud);
|
||||
serialRefrence = &Serial3;
|
||||
}
|
||||
#endif
|
||||
void SerialConnection::init(HardwareSerial &serialObject, unsigned long serialBaud) {
|
||||
serialObject.begin(serialBaud);
|
||||
serialRefrence = &serialObject;
|
||||
};
|
||||
|
||||
char* SerialConnection::handle() {
|
||||
|
@ -26,19 +26,15 @@ class SimpleSerialProtocol
|
||||
private:
|
||||
SerialConnection serialConnection;
|
||||
public:
|
||||
bool init(int deviceIndex, unsigned long baud);
|
||||
bool init(HardwareSerial &serialObject, unsigned long baud);
|
||||
bool receivePackets(void (*callback)(Packet));
|
||||
bool sendPacket(char* ID, char* command, char* data);
|
||||
};
|
||||
|
||||
bool SimpleSerialProtocol::init(int deviceIndex, unsigned long baud) {
|
||||
// Check if device index is in range
|
||||
if (deviceIndex < 0 || deviceIndex > 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SimpleSerialProtocol::init(HardwareSerial &serialObject, unsigned long baud) {
|
||||
// Init serial connection
|
||||
serialConnection.init(deviceIndex, baud);
|
||||
serialConnection.init(serialObject, baud);
|
||||
|
||||
// Serial Connection Delay
|
||||
delay(5);
|
||||
|
Loading…
x
Reference in New Issue
Block a user