Skip to content

Commit

Permalink
Modify for Due support per #4
Browse files Browse the repository at this point in the history
- modified header toString function to use sprintf_P
- updated RF24Network_config.h to match RF24_config.h
  • Loading branch information
TMRh20 committed May 24, 2014
1 parent 37406db commit fe1fe3b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 29 deletions.
3 changes: 2 additions & 1 deletion RF24Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ bool RF24Network::write_to_pipe( uint16_t node, uint8_t pipe )
const char* RF24NetworkHeader::toString(void) const
{
static char buffer[45];
snprintf_P(buffer,sizeof(buffer),PSTR("id %04x from 0%o to 0%o type %c"),id,from_node,to_node,type);
//snprintf_P(buffer,sizeof(buffer),PSTR("id %04x from 0%o to 0%o type %c"),id,from_node,to_node,type);
sprintf_P(buffer,PSTR("id %04x from 0%o to 0%o type %c"),id,from_node,to_node,type);
return buffer;
}

Expand Down
86 changes: 58 additions & 28 deletions RF24Network_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,77 @@

/*************************************/

// Stuff that is normally provided by Arduino
#ifndef ARDUINO
#include <stdint.h>
#include <stdio.h>
#include <string.h>
extern HardwareSPI SPI;
#define _BV(x) (1<<(x))
#endif

#undef SERIAL_DEBUG
#ifdef SERIAL_DEBUG
#define IF_SERIAL_DEBUG(x) ({x;})
// Define _BV for non-Arduino platforms and for Arduino DUE
#if defined (ARDUINO) && !defined (__arm__)
#include <SPI.h>
#else
#define IF_SERIAL_DEBUG(x)
#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny85__)
#define printf_P(...)
#endif

#include <stdint.h>
#include <stdio.h>
#include <string.h>


#if defined(__arm__) || defined (CORE_TEENSY)
#include <SPI.h>
#endif

#if !defined(CORE_TEENSY)
#define _BV(x) (1<<(x))
#if !defined(__arm__)
extern HardwareSPI SPI;
#endif
#endif


#endif


#undef SERIAL_DEBUG
#ifdef SERIAL_DEBUG
#define IF_SERIAL_DEBUG(x) ({x;})
#else
#define IF_SERIAL_DEBUG(x)
#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny85__)
#define printf_P(...)
#endif
#endif

// Avoid spurious warnings
#if ! defined( NATIVE ) && defined( ARDUINO )
// Arduino DUE is arm and uses traditional PROGMEM constructs
#if 1
#if ! defined( NATIVE ) && defined( ARDUINO ) && ! defined(__arm__) && ! defined( CORE_TEENSY3 )
#undef PROGMEM
#define PROGMEM __attribute__(( section(".progmem.data") ))
#undef PSTR
#define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}))
#endif
#endif

// Progmem is Arduino-specific
#ifdef ARDUINO

#include <avr/pgmspace.h>
#define PRIPSTR "%S"
// Arduino DUE is arm and does not include avr/pgmspace
#if defined(ARDUINO) && ! defined(__arm__)
#include <avr/pgmspace.h>
#define PRIPSTR "%S"
#else
typedef char const prog_char;
typedef uint16_t prog_uint16_t;
#define PSTR(x) (x)
#define printf_P printf
#define strlen_P strlen
#define PROGMEM
#define pgm_read_word(p) (*(p))
#define PRIPSTR "%s"
#if ! defined(ARDUINO) // This doesn't work on Arduino DUE
typedef char const char;
#else // Fill in pgm_read_byte that is used, but missing from DUE
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
#endif


#if !defined (CORE_TEENSY)
typedef uint16_t prog_uint16_t;
#define PSTR(x) (x)
#define printf_P printf
#define strlen_P strlen
#define PROGMEM
#define pgm_read_word(p) (*(p))
#endif

#define PRIPSTR "%s"

#endif

#endif // __RF24_CONFIG_H__
Expand Down

0 comments on commit fe1fe3b

Please sign in to comment.