Skip to content

Commit fe0e0a8

Browse files
author
andrew.rapp
committed
Release 0.3. Includes support for Arduino 1.0. Added setSerial method to use alternate serial ports (e.g. Mega). Some bug fixes
git-svn-id: https://xbee-arduino.googlecode.com/svn/trunk@41 42c8444e-1c8e-11de-a108-cd2f117ce590
1 parent 19603d9 commit fe0e0a8

File tree

56 files changed

+656
-655
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+656
-655
lines changed

XBee.cpp

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818
*/
1919

2020
#include "XBee.h"
21-
#include "WProgram.h"
21+
22+
#if defined(ARDUINO) && ARDUINO >= 100
23+
#include "Arduino.h"
24+
#else
25+
#include "WProgram.h"
26+
#endif
27+
2228
#include "HardwareSerial.h"
23-
#include "NewSoftSerial.h"
2429

2530
XBeeResponse::XBeeResponse() {
2631

@@ -760,10 +765,8 @@ XBee::XBee(): _response(XBeeResponse()) {
760765

761766
_response.init();
762767
_response.setFrameData(_responseFrameData);
763-
764-
_useNss = false;
765-
_serial = NULL;
766-
_nssSerial = NULL;
768+
// default
769+
_serial = &Serial;
767770
}
768771

769772
uint8_t XBee::getNextFrameId() {
@@ -779,53 +782,27 @@ uint8_t XBee::getNextFrameId() {
779782
}
780783

781784
void XBee::begin(long baud) {
782-
if (_useNss) {
783-
_nssSerial->begin(baud);
784-
} else {
785-
_serial->begin(baud);
786-
}
785+
_serial->begin(baud);
786+
}
787+
788+
void XBee::setSerial(HardwareSerial &serial) {
789+
_serial = &serial;
787790
}
788791

789792
bool XBee::available() {
790-
if (_useNss) {
791-
return _nssSerial->available();
792-
} else {
793-
return _serial->available();
794-
}
793+
return _serial->available();
795794
}
796795

797796
uint8_t XBee::read() {
798-
if (_useNss) {
799-
return _nssSerial->read();
800-
} else {
801-
return _serial->read();
802-
}
797+
return _serial->read();
803798
}
804799

805800
void XBee::flush() {
806-
if (_useNss) {
807-
_nssSerial->flush();
808-
} else {
809-
_serial->flush();
810-
}
801+
_serial->flush();
811802
}
812803

813-
void XBee::print(uint8_t val) {
814-
if (_useNss) {
815-
_nssSerial->print(val, BYTE);
816-
} else {
817-
_serial->print(val, BYTE);
818-
}
819-
}
820-
821-
void XBee::setSerial(HardwareSerial &serial) {
822-
_serial = &serial;
823-
_useNss = false;
824-
}
825-
826-
void XBee::setNss(NewSoftSerial &nssSerial) {
827-
_nssSerial = &nssSerial;
828-
_useNss = true;
804+
void XBee::write(uint8_t val) {
805+
_serial->write(val);
829806
}
830807

831808
XBeeResponse& XBee::getResponse() {
@@ -1473,18 +1450,18 @@ void XBee::send(XBeeRequest &request) {
14731450
// send checksum
14741451
sendByte(checksum, true);
14751452

1476-
// send packet
1477-
// flush does not flush the output buffer, but instead input buffer, which would be awful!
1478-
//flush();
1453+
// send packet (Note: prior to Arduino 1.0 this flushed the incoming buffer, which of course was not so great)
1454+
flush();
14791455
}
14801456

14811457
void XBee::sendByte(uint8_t b, bool escape) {
14821458

14831459
if (escape && (b == START_BYTE || b == ESCAPE || b == XON || b == XOFF)) {
14841460
// std::cout << "escaping byte [" << toHexString(b) << "] " << std::endl;
1485-
print(ESCAPE);
1486-
print(b ^ 0x20);
1461+
write(ESCAPE);
1462+
write(b ^ 0x20);
14871463
} else {
1488-
print(b);
1464+
write(b);
14891465
}
1490-
}
1466+
}
1467+

XBee.h

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
#ifndef XBee_h
2121
#define XBee_h
2222

23-
#include <WProgram.h>
24-
#include <inttypes.h>
25-
26-
#include <NewSoftSerial.h>
27-
#include <HardwareSerial.h>
23+
#if defined(ARDUINO) && ARDUINO >= 100
24+
#include "Arduino.h"
25+
#else
26+
#include "WProgram.h"
27+
#endif
2828

29-
// TODO
30-
#define USE_NSS 0
29+
#include <inttypes.h>
3130

3231
#define SERIES_1
3332
#define SERIES_2
@@ -718,21 +717,15 @@ class XBee {
718717
* Returns a sequential frame id between 1 and 255
719718
*/
720719
uint8_t getNextFrameId();
721-
722720
/**
723-
* Sets the Serial port for communication.
721+
* Specify the serial port. Only relevant for Arduinos that support multiple serial ports (e.g. Mega)
724722
*/
725723
void setSerial(HardwareSerial &serial);
726-
/**
727-
* Tells the library to use NSS for communication, with the specified TX and RX pins
728-
*/
729-
//void setNss(uint8_t tx, uint8_t rx);
730-
void setNss(NewSoftSerial &nssSerial);
731724
private:
732725
bool available();
733726
uint8_t read();
734727
void flush();
735-
void print(uint8_t val);
728+
void write(uint8_t val);
736729
void sendByte(uint8_t b, bool escape);
737730
void resetResponse();
738731
XBeeResponse _response;
@@ -746,10 +739,6 @@ class XBee {
746739
// buffer for incoming RX packets. holds only the api specific frame data, starting after the api id byte and prior to checksum
747740
uint8_t _responseFrameData[MAX_FRAME_DATA_SIZE];
748741
HardwareSerial* _serial;
749-
NewSoftSerial* _nssSerial;
750-
bool _useNss;
751-
//uint8_t nssTx;
752-
//uint8_t nssRx;
753742
};
754743

755744
/**

docs/api/_x_bee_8h-source.html

Lines changed: 539 additions & 530 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/annotated.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/class_at_command_request-members.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/class_at_command_request.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/class_at_command_response-members.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/class_at_command_response.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/class_frame_id_response-members.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/class_frame_id_response.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)