In my RA02.h below, the preprocessor does not find MCU_TYPE defined in the original sketch. I have tried both #define MCU_TYPE 68
and #define MCU_TYPE DUE_R3
My goals here are two:
(1) Make hardware changes only in OriginalSketch.ino
(2) Instantiate those changes in various Hardware.h and Hardware.cpp files, but require no manual changes each time.
How I know I have a problem:
(1) My #if MCU_TYPE == MKR_WiFi_1010
guard below always evaluates #else
(2) The IDE editor does not identify MCU_TYPE in RA02.h as a macro when I hover over it.
It occurs to me that this may be a matter of the order in which the translation units are compiled. Other similar comparisons work, for example #if MCU_MODE == RX_MODE
. At execution time though, MCU_TYPE reliably evaluates as 68. What path to follow?
/*
* RA02.h
* Based on RadioLib Example PhysicalLayer_interface
*
* Communication is via SPI, the only documented method.
*/
#include <RadioLib.h>
#include "RR_LoRa.h"
#define RADIO_TYPE SX1278
#define MKR_WiFi_1010 77
#define Portenta_H7 80
#define DUE_R3 68
#define Heltec_ESP32 72
#define RX_MODE 82
#define TX_MODE 84
// set the pinout depending on the wiring and module type
// SPI NSS pin: 10
// interrupt pin: 2
// reset pin: 9 (unused on some modules)
// extra GPIO/interrupt pin: 3 (unused on some modules)
#if MCU_TYPE == MKR_WiFi_1010
#define S_NSS 6
#define S_INT 2
#define S_RST 7
#define S_GPI 3
#elif MCU_TYPE == DUE_R3
#define S_NSS 10
#define S_INT 2
#define S_RST 9
#define S_GPI 3
#else // the indeterminate condition
#define S_NSS 60
#define S_INT 61
#define S_RST 62
#define S_GPI 63
#endif // RADIO_TYPE radio = new Module(S_NSS, S_INT, S_RST, S_GPI);
//Function Prototypes
void RA02_setup(void); // Function that includes LoRa configuration
void RA02_tx_loop(void); // Function that includes LoRa tx operation
void RA02_rx_loop(void); // Function that includes LoRa rx operation
//void getCommand(void); // Function to receive the command and parse it
//void execCommand(char, int); // Function to execute relevant functions depending on the command
#ifndef DPACKET
#define DPACKET
struct DataPacket {
char station[5]; // 4 bytes plus NUL
uint32_t time; // 4 bytes
int16_t lat; // 2 bytes
int16_t lon; // 2 bytes
uint16_t temp; // 2 bytes
int16_t alti; // 2 bytes
int16_t pres; // 2 bytes
};
extern DataPacket txpacket;
#endif //DPACKET