mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Allow SPP to work in Arduino 0.2.3 and below
This commit is contained in:
parent
843eec8ba6
commit
4533e3cd44
3 changed files with 30 additions and 1 deletions
14
SPP.cpp
14
SPP.cpp
|
@ -756,17 +756,29 @@ bool SPP::checkFcs(uint8_t *data, uint8_t fcs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Serial commands */
|
/* Serial commands */
|
||||||
|
#if defined(ARDUINO) && ARDUINO >=100
|
||||||
size_t SPP::write(uint8_t data) {
|
size_t SPP::write(uint8_t data) {
|
||||||
return write(&data,1);
|
return write(&data, 1);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
void SPP::write(uint8_t data) {
|
||||||
|
write(&data, 1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ARDUINO) && ARDUINO >=100
|
||||||
size_t SPP::write(const uint8_t *data, size_t size) {
|
size_t SPP::write(const uint8_t *data, size_t size) {
|
||||||
|
#else
|
||||||
|
void SPP::write(const uint8_t *data, size_t size) {
|
||||||
|
#endif
|
||||||
for(uint8_t i = 0; i < size; i++) {
|
for(uint8_t i = 0; i < size; i++) {
|
||||||
if(sppIndex >= sizeof(sppOutputBuffer)/sizeof(sppOutputBuffer[0]))
|
if(sppIndex >= sizeof(sppOutputBuffer)/sizeof(sppOutputBuffer[0]))
|
||||||
send(); // Send the current data in the buffer
|
send(); // Send the current data in the buffer
|
||||||
sppOutputBuffer[sppIndex++] = data[i]; // All the bytes are put into a buffer and then send using the send() function
|
sppOutputBuffer[sppIndex++] = data[i]; // All the bytes are put into a buffer and then send using the send() function
|
||||||
}
|
}
|
||||||
|
#if defined(ARDUINO) && ARDUINO >=100
|
||||||
return size;
|
return size;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SPP::send() {
|
void SPP::send() {
|
||||||
|
|
16
SPP.h
16
SPP.h
|
@ -147,6 +147,8 @@ public:
|
||||||
* @return Return the byte. Will return -1 if no bytes are available.
|
* @return Return the byte. Will return -1 if no bytes are available.
|
||||||
*/
|
*/
|
||||||
virtual int read(void);
|
virtual int read(void);
|
||||||
|
|
||||||
|
#if defined(ARDUINO) && ARDUINO >=100
|
||||||
/**
|
/**
|
||||||
* Writes the byte to send to a buffer. The message is send when either send() or after Usb.Task() is called.
|
* Writes the byte to send to a buffer. The message is send when either send() or after Usb.Task() is called.
|
||||||
* @param data The byte to write.
|
* @param data The byte to write.
|
||||||
|
@ -162,6 +164,20 @@ public:
|
||||||
virtual size_t write(const uint8_t* data, size_t size);
|
virtual size_t write(const uint8_t* data, size_t size);
|
||||||
/** Pull in write(const char *str) from Print */
|
/** Pull in write(const char *str) from Print */
|
||||||
using Print::write;
|
using Print::write;
|
||||||
|
#else
|
||||||
|
/**
|
||||||
|
* Writes the byte to send to a buffer. The message is send when either send() or after Usb.Task() is called.
|
||||||
|
* @param data The byte to write.
|
||||||
|
*/
|
||||||
|
virtual void write(uint8_t data);
|
||||||
|
/**
|
||||||
|
* Writes the bytes to send to a buffer. The message is send when either send() or after Usb.Task() is called.
|
||||||
|
* @param data The data array to send.
|
||||||
|
* @param size Size of the data.
|
||||||
|
*/
|
||||||
|
virtual void write(const uint8_t* data, size_t size);
|
||||||
|
#endif
|
||||||
|
|
||||||
/** Discard all the bytes in the buffer. */
|
/** Discard all the bytes in the buffer. */
|
||||||
void discard(void);
|
void discard(void);
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -75,6 +75,7 @@
|
||||||
#include <pins_arduino.h>
|
#include <pins_arduino.h>
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
#define F(str) (str)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if USE_XMEM_SPI_LOCK | defined(USE_MULTIPLE_APP_API)
|
#if USE_XMEM_SPI_LOCK | defined(USE_MULTIPLE_APP_API)
|
||||||
|
|
Loading…
Reference in a new issue