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