Browse Source

Added NRF24L01 functions...

master
Englebert 4 years ago
parent
commit
ab09271289
  1. 681
      LoRa_E32.cpp
  2. 298
      LoRa_E32.h
  3. 22
      OpenFlightTX.h
  4. 614
      OpenFlightTX.ino
  5. 1567
      RF24.cpp
  6. 2072
      RF24.h
  7. 187
      RF24_config.h
  8. 128
      nRF24L01.h
  9. 42
      printf.h
  10. 452
      statesNaming.h

681
LoRa_E32.cpp

@ -1,681 +0,0 @@
#include "LoRa_E32.h"
LoRa_E32::LoRa_E32(HardwareSerial hs) {
/**** For RX ****
this->auxPin = 4;
this->m0Pin = 18;
this->m1Pin = 5;
*/
this->auxPin = 4;
this->m0Pin = 2;
this->m1Pin = 5;
this->hs = &Serial2;
this->bpsRate = UART_BPS_RATE_9600;
// this->bpsRate = UART_BPS_RATE_115200;
}
bool LoRa_E32::begin(){
pinMode(this->auxPin, INPUT);
pinMode(this->m0Pin, OUTPUT);
pinMode(this->m1Pin, OUTPUT);
digitalWrite(this->m0Pin, HIGH);
digitalWrite(this->m1Pin, HIGH);
if (this->hs){
this->serialDef.begin(*this->hs, this->bpsRate, this->serialConfig);
while (!this->hs) {
}
}
this->serialDef.stream->setTimeout(1000);
Status status = setMode(MODE_0_NORMAL);
return status==SUCCESS;
}
/*
* Utility method to wait until module is doen tranmitting
* a timeout is provided to avoid an infinite loop
*/
Status LoRa_E32::waitCompleteResponse(unsigned long timeout, unsigned int waitNoAux) {
Status result = SUCCESS;
unsigned long t = millis();
// make darn sure millis() is not about to reach max data type limit and start over
if (((unsigned long) (t + timeout)) == 0){
t = 0;
}
// if AUX pin was supplied and look for HIGH state
// note you can omit using AUX if no pins are available, but you will have to use delay() to let module finish
if (this->auxPin != -1) {
while (digitalRead(this->auxPin) == LOW) {
if ((millis() - t) > timeout){
result = ERR_TIMEOUT;
// DEBUG_PRINTLN(F("LORA: Timeout error!"));
return result;
}
}
// DEBUG_PRINTLN("AUX HIGH!");
} else {
// if you can't use aux pin, use 4K7 pullup with Arduino
// you may need to adjust this value if transmissions fail
this->managedDelay(waitNoAux);
// DEBUG_PRINTLN(F("Wait no AUX pin!"));
}
// per data sheet control after aux goes high is 2ms so delay for at least that long)
// this->managedDelay(20);
this->managedDelay(3);
// DEBUG_PRINTLN(F("Complete!"));
return result;
}
/*
* delay() in a library is not a good idea as it can stop interrupts
* just poll internal time until timeout is reached
*/
void LoRa_E32::managedDelay(unsigned long timeout) {
unsigned long t = millis();
// make darn sure millis() is not about to reach max data type limit and start over
if(((unsigned long) (t + timeout)) == 0) {
t = 0;
}
while((millis() - t) < timeout) {
}
}
/*
* Method to indicate availability
*/
int LoRa_E32::available(unsigned long timeout) {
// unsigned long t = millis();
//
// // make darn sure millis() is not about to reach max data type limit and start over
// if (((unsigned long) (t + timeout)) == 0){
// t = 0;
// }
//
// if (this->auxPin != 0) {
// if (digitalRead(this->auxPin) == HIGH){
// return 0;
// }else{
// while (digitalRead(this->auxPin) == LOW) {
// if ((millis() - t) > timeout){
// DEBUG_PRINTLN("Timeout error!");
// return 0;
// }
// }
// DEBUG_PRINTLN("AUX HIGH!");
// return 2;
// }
// }else{
return this->serialDef.stream->available();
// }
}
/*
* Method to indicate availability
*/
void LoRa_E32::flush() {
this->serialDef.stream->flush();
}
void LoRa_E32::cleanUARTBuffer() {
// bool IsNull = true;
while (this->available()) {
// IsNull = false;
this->serialDef.stream->read();
}
}
/*
* Method to send a chunk of data provided data is in a struct--my personal favorite as you
* need not parse or worry about sprintf() inability to handle floats
*
* TTP: put your structure definition into a .h file and include in both the sender and reciever
* sketches
*
* NOTE: of your sender and receiver MCU's are different (Teensy and Arduino) caution on the data
* types each handle ints floats differently
*
*/
Status LoRa_E32::sendStruct(void *structureManaged, uint16_t size_) {
if(size_ > MAX_SIZE_TX_PACKET){
return ERR_PACKET_TOO_BIG;
}
Status result = SUCCESS;
uint8_t len = this->serialDef.stream->write((uint8_t *) structureManaged, size_);
if(len!=size_){
/*
DEBUG_PRINT(F("Send... len:"))
DEBUG_PRINT(len);
DEBUG_PRINT(F(" size:"))
DEBUG_PRINT(size_);
*/
if(len==0){
result = ERR_NO_RESPONSE_FROM_DEVICE;
} else {
result = ERR_DATA_SIZE_NOT_MATCH;
}
}
if(result != SUCCESS) return result;
result = this->waitCompleteResponse(1000);
if(result != SUCCESS) return result;
// DEBUG_PRINT(F("Clear buffer..."))
this->cleanUARTBuffer();
// DEBUG_PRINTLN(F("ok!"))
return result;
}
/*
*
* Method to get a chunk of data provided data is in a struct--my personal favorite as you
* need not parse or worry about sprintf() inability to handle floats
*
* TTP: put your structure definition into a .h file and include in both the sender and reciever
* sketches
*
* NOTE: of your sender and receiver MCU's are different (Teensy and Arduino) caution on the data
* types each handle ints floats differently
*
*/
Status LoRa_E32::receiveStruct(void *structureManaged, uint16_t size_) {
Status result = SUCCESS;
uint8_t len = this->serialDef.stream->readBytes((uint8_t *) structureManaged, size_);
DEBUG_PRINT("Available buffer: ");
DEBUG_PRINT(len);
DEBUG_PRINT(" structure size: ");
DEBUG_PRINTLN(size_);
if(len!=size_){
if(len==0){
result = ERR_NO_RESPONSE_FROM_DEVICE;
} else {
result = ERR_DATA_SIZE_NOT_MATCH;
}
}
if(result != SUCCESS)
return result;
result = this->waitCompleteResponse(1000);
if(result != SUCCESS)
return result;
return result;
}
/*
* method to set the mode (program, normal, etc.)
*/
Status LoRa_E32::setMode(MODE_TYPE mode) {
// data sheet claims module needs some extra time after mode setting (2ms)
// most of my projects uses 10 ms, but 40ms is safer
this->managedDelay(40);
if (this->m0Pin == -1 && this->m1Pin == -1) {
DEBUG_PRINTLN(F("The M0 and M1 pins is not set, this mean that you are connect directly the pins as you need!"))
}else{
switch (mode)
{
case MODE_0_NORMAL:
// Mode 0 | normal operation
digitalWrite(this->m0Pin, LOW);
digitalWrite(this->m1Pin, LOW);
DEBUG_PRINTLN(F("MODE NORMAL!"));
break;
case MODE_1_WAKE_UP:
digitalWrite(this->m0Pin, HIGH);
digitalWrite(this->m1Pin, LOW);
DEBUG_PRINTLN(F("MODE WAKE UP!"));
break;
case MODE_2_POWER_SAVING:
digitalWrite(this->m0Pin, LOW);
digitalWrite(this->m1Pin, HIGH);
DEBUG_PRINTLN(F("MODE POWER SAVING!"));
break;
case MODE_3_SLEEP:
// Mode 3 | Setting operation
digitalWrite(this->m0Pin, HIGH);
digitalWrite(this->m1Pin, HIGH);
DEBUG_PRINTLN(F("MODE PROGRAM/SLEEP!"));
break;
default:
return ERR_INVALID_PARAM;
}
}
// data sheet says 2ms later control is returned, let's give just a bit more time
// these modules can take time to activate pins
this->managedDelay(40);
// wait until aux pin goes back low
Status res = this->waitCompleteResponse(1000);
if(res == SUCCESS){
this->mode = mode;
}
return res;
}
MODE_TYPE LoRa_E32::getMode(){
return this->mode;
}
void LoRa_E32::writeProgramCommand(PROGRAM_COMMAND cmd){
uint8_t CMD[3] = {cmd, cmd, cmd};
uint8_t size = this->serialDef.stream->write(CMD, 3);
DEBUG_PRINTLN(size);
this->managedDelay(50); //need ti check
}
ResponseStructContainer LoRa_E32::getConfiguration(){
ResponseStructContainer rc;
rc.status.code = checkUARTConfiguration(MODE_3_PROGRAM);
if (rc.status.code!=SUCCESS) return rc;
MODE_TYPE prevMode = this->mode;
rc.status.code = this->setMode(MODE_3_PROGRAM);
if (rc.status.code!=SUCCESS) return rc;
this->writeProgramCommand(READ_CONFIGURATION);
rc.data = malloc(sizeof(Configuration));
rc.status.code = this->receiveStruct((uint8_t *)rc.data, sizeof(Configuration));
#ifdef LoRa_E32_DEBUG
this->printParameters((Configuration *)rc.data);
#endif
if (rc.status.code!=SUCCESS) {
this->setMode(prevMode);
return rc;
}
DEBUG_PRINTLN("----------------------------------------");
DEBUG_PRINT(F("HEAD BIN INSIDE: ")); DEBUG_PRINT(((Configuration *)rc.data)->HEAD, BIN);DEBUG_PRINT(" ");DEBUG_PRINT(((Configuration *)rc.data)->HEAD, DEC);DEBUG_PRINT(" ");DEBUG_PRINTLN(((Configuration *)rc.data)->HEAD, HEX);
DEBUG_PRINTLN("----------------------------------------");
rc.status.code = this->setMode(prevMode);
if (rc.status.code!=SUCCESS) return rc;
// this->printParameters(*configuration);
if (0xC0 != ((Configuration *)rc.data)->HEAD && 0xC2 != ((Configuration *)rc.data)->HEAD){
rc.status.code = ERR_HEAD_NOT_RECOGNIZED;
}
// rc.data = configuration;
return rc;
}
RESPONSE_STATUS LoRa_E32::checkUARTConfiguration(MODE_TYPE mode){
if (mode==MODE_3_PROGRAM && this->bpsRate!=UART_BPS_RATE_9600){
return ERR_WRONG_UART_CONFIG;
}
return SUCCESS;
}
ResponseStatus LoRa_E32::setConfiguration(Configuration configuration, PROGRAM_COMMAND saveType){
ResponseStatus rc;
rc.code = checkUARTConfiguration(MODE_3_PROGRAM);
if (rc.code!=SUCCESS) return rc;
MODE_TYPE prevMode = this->mode;
rc.code = this->setMode(MODE_3_PROGRAM);
if (rc.code!=SUCCESS) return rc;
this->writeProgramCommand(READ_CONFIGURATION);
configuration.HEAD = saveType;
rc.code = this->sendStruct((uint8_t *)&configuration, sizeof(Configuration));
if (rc.code!=SUCCESS) {
this->setMode(prevMode);
return rc;
}
DEBUG_PRINTLN("----------------------------------------");
DEBUG_PRINT(F("HEAD BIN INSIDE: ")); DEBUG_PRINT(configuration.HEAD, BIN);DEBUG_PRINT(" ");DEBUG_PRINT(configuration.HEAD, DEC);DEBUG_PRINT(" ");DEBUG_PRINTLN(configuration.HEAD, HEX);
DEBUG_PRINTLN("----------------------------------------");
rc.code = this->setMode(prevMode);
if (rc.code!=SUCCESS) return rc;
// this->printParameters(*configuration);
if (0xC0 != configuration.HEAD && 0xC2 != configuration.HEAD){
rc.code = ERR_HEAD_NOT_RECOGNIZED;
}
return rc;
}
ResponseStructContainer LoRa_E32::getModuleInformation(){
ResponseStructContainer rc;
rc.status.code = checkUARTConfiguration(MODE_3_PROGRAM);
if (rc.status.code!=SUCCESS) return rc;
MODE_TYPE prevMode = this->mode;
rc.status.code = this->setMode(MODE_3_PROGRAM);
if (rc.status.code!=SUCCESS) return rc;
this->writeProgramCommand(READ_MODULE_VERSION);
struct ModuleInformation *moduleInformation = (ModuleInformation *)malloc(sizeof(ModuleInformation));
rc.status.code = this->receiveStruct((uint8_t *)moduleInformation, sizeof(ModuleInformation));
if (rc.status.code!=SUCCESS) {
this->setMode(prevMode);
return rc;
}
rc.status.code = this->setMode(prevMode);
if (rc.status.code!=SUCCESS) return rc;
// this->printParameters(*configuration);
if (0xC3 != moduleInformation->HEAD){
rc.status.code = ERR_HEAD_NOT_RECOGNIZED;
}
DEBUG_PRINTLN("----------------------------------------");
DEBUG_PRINT(F("HEAD BIN INSIDE: ")); DEBUG_PRINT(moduleInformation->HEAD, BIN);DEBUG_PRINT(" ");DEBUG_PRINT(moduleInformation->HEAD, DEC);DEBUG_PRINT(" ");DEBUG_PRINTLN(moduleInformation->HEAD, HEX);
DEBUG_PRINT(F("Freq.: ")); DEBUG_PRINTLN(moduleInformation->frequency, HEX);
DEBUG_PRINT(F("Version : ")); DEBUG_PRINTLN(moduleInformation->version, HEX);
DEBUG_PRINT(F("Features : ")); DEBUG_PRINTLN(moduleInformation->features, HEX);
DEBUG_PRINTLN("----------------------------------------");
rc.data = moduleInformation; // malloc(sizeof (moduleInformation));
return rc;
}
ResponseStatus LoRa_E32::resetModule(){
ResponseStatus status;
status.code = checkUARTConfiguration(MODE_3_PROGRAM);
if (status.code!=SUCCESS) return status;
MODE_TYPE prevMode = this->mode;
status.code = this->setMode(MODE_3_PROGRAM);
if (status.code!=SUCCESS) return status;
this->writeProgramCommand(WRITE_RESET_MODULE);
status.code = this->waitCompleteResponse(1000);
if (status.code!=SUCCESS) {
this->setMode(prevMode);
return status;
}
status.code = this->setMode(prevMode);
if (status.code!=SUCCESS) return status;
return status;
}
ResponseContainer LoRa_E32::receiveMessage(){
ResponseContainer rc;
rc.status.code = SUCCESS;
rc.data = this->serialDef.stream->readString();
this->cleanUARTBuffer();
if (rc.status.code!=SUCCESS) {
return rc;
}
// rc.data = message; // malloc(sizeof (moduleInformation));
return rc;
}
ResponseContainer LoRa_E32::receiveMessageUntil(char delimiter){
ResponseContainer rc;
rc.status.code = SUCCESS;
rc.data = this->serialDef.stream->readStringUntil(delimiter);
// this->cleanUARTBuffer();
if (rc.status.code!=SUCCESS) {
return rc;
}
// rc.data = message; // malloc(sizeof (moduleInformation));
return rc;
}
ResponseStructContainer LoRa_E32::receiveMessage(const uint8_t size){
ResponseStructContainer rc;
rc.data = malloc(size);
rc.status.code = this->receiveStruct((uint8_t *)rc.data, size);
this->cleanUARTBuffer();
if (rc.status.code!=SUCCESS) {
return rc;
}
return rc;
}
ResponseStatus LoRa_E32::sendMessage(const void *message, const uint8_t size){
ResponseStatus status;
status.code = this->sendStruct((uint8_t *)message, size);
if (status.code!=SUCCESS) return status;
return status;
}
ResponseStatus LoRa_E32::sendMessage(const String message){
DEBUG_PRINT(F("Send message: "));
DEBUG_PRINT(message);
byte size = message.length(); // sizeof(message.c_str())+1;
DEBUG_PRINT(F(" size: "));
DEBUG_PRINTLN(size);
char messageFixed[size];
memcpy(messageFixed,message.c_str(),size);
ResponseStatus status;
status.code = this->sendStruct((uint8_t *)&messageFixed, size);
if (status.code!=SUCCESS) return status;
return status;
}
ResponseStatus LoRa_E32::sendFixedMessage(byte ADDH, byte ADDL, byte CHAN, const String message){
// DEBUG_PRINT("String/size: ");
// DEBUG_PRINT(message);
// DEBUG_PRINT("/");
byte size = message.length(); // sizeof(message.c_str())+1;
// DEBUG_PRINTLN(size);
//
// #pragma pack(push, 1)
// struct FixedStransmissionString {
// byte ADDH = 0;
// byte ADDL = 0;
// byte CHAN = 0;
// char message[];
// } fixedStransmission;
// #pragma pack(pop)
//
// fixedStransmission.ADDH = ADDH;
// fixedStransmission.ADDL = ADDL;
// fixedStransmission.CHAN = CHAN;
// char* msg = (char*)message.c_str();
// memcpy(fixedStransmission.message, (char*)msg, size);
//// fixedStransmission.message = message;
//
// DEBUG_PRINT("Message: ");
// DEBUG_PRINTLN(fixedStransmission.message);
//
// ResponseStatus status;
// status.code = this->sendStruct((uint8_t *)&fixedStransmission, sizeof(fixedStransmission));
// if (status.code!=SUCCESS) return status;
//
// return status;
char messageFixed[size];
memcpy(messageFixed,message.c_str(),size);
return this->sendFixedMessage(ADDH, ADDL, CHAN, (uint8_t *)messageFixed, size);
}
ResponseStatus LoRa_E32::sendBroadcastFixedMessage(byte CHAN, const String message){
return this->sendFixedMessage(0xFF, 0xFF, CHAN, message);
}
typedef struct fixedStransmission
{
byte ADDH = 0;
byte ADDL = 0;
byte CHAN = 0;
unsigned char message[];
}FixedStransmission;
FixedStransmission *init_stack(int m){
FixedStransmission *st = (FixedStransmission *)malloc(sizeof(FixedStransmission)+m*sizeof(int));
return st;
}
ResponseStatus LoRa_E32::sendFixedMessage( byte ADDH,byte ADDL, byte CHAN, const void *message, const uint8_t size){
// #pragma pack(push, 1)
// struct FixedStransmission {
// byte ADDH = 0;
// byte ADDL = 0;
// byte CHAN = 0;
// unsigned char message[];
// } fixedStransmission;
// #pragma pack(pop)
FixedStransmission *fixedStransmission = init_stack(size);
// STACK *resize_stack(STACK *st, int m){
// if (m<=st->max){
// return st; /* Take sure do not kill old values */
// }
// STACK *st = (STACK *)realloc(sizeof(STACK)+m*sizeof(int));
// st->max = m;
// return st;
// }
fixedStransmission->ADDH = ADDH;
fixedStransmission->ADDL = ADDL;
fixedStransmission->CHAN = CHAN;
// fixedStransmission.message = &message;
memcpy(fixedStransmission->message,(unsigned char*)message,size);
ResponseStatus status;
status.code = this->sendStruct((uint8_t *)fixedStransmission, size+3);
free(fixedStransmission);
// if (status.code!=SUCCESS) return status;
return status;
}
ResponseStatus LoRa_E32::sendBroadcastFixedMessage(byte CHAN, const void *message, const uint8_t size){
return this->sendFixedMessage(0xFF, 0xFF, CHAN, message, size);
}
ResponseContainer LoRa_E32::receiveInitialMessage(uint8_t size){
ResponseContainer rc;
rc.status.code = SUCCESS;
char buff[size];
uint8_t len = this->serialDef.stream->readBytes(buff, size);
if (len!=size) {
if (len==0){
rc.status.code = ERR_NO_RESPONSE_FROM_DEVICE;
}else{
rc.status.code = ERR_DATA_SIZE_NOT_MATCH;
}
return rc;
}
rc.data = buff;
return rc;
}
#define KeeLoq_NLF 0x3A5C742E
unsigned long LoRa_E32::encrypt(unsigned long data)
{
unsigned long x = data;
unsigned long r;
int keyBitNo, index;
unsigned long keyBitVal,bitVal;
for (r = 0; r < 528; r++)
{
keyBitNo = r & 63;
if(keyBitNo < 32)
keyBitVal = bitRead(this->halfKeyloqKey,keyBitNo); // key low
else
keyBitVal = bitRead(this->halfKeyloqKey, keyBitNo - 32);// key hight
index = 1 * bitRead(x,1) + 2 * bitRead(x,9) + 4 * bitRead(x,20) + 8 * bitRead(x,26) + 16 * bitRead(x,31);
bitVal = bitRead(x,0) ^ bitRead(x, 16) ^ bitRead(KeeLoq_NLF,index) ^ keyBitVal;
x = (x>>1) ^ bitVal<<31;
}
return x;
}
unsigned long LoRa_E32::decrypt(unsigned long data)
{
unsigned long x = data;
unsigned long r;
int keyBitNo, index;
unsigned long keyBitVal,bitVal;
for (r = 0; r < 528; r++)
{
keyBitNo = (15-r) & 63;
if(keyBitNo < 32)
keyBitVal = bitRead(this->halfKeyloqKey,keyBitNo); // key low
else
keyBitVal = bitRead(this->halfKeyloqKey, keyBitNo - 32); // key hight
index = 1 * bitRead(x,0) + 2 * bitRead(x,8) + 4 * bitRead(x,19) + 8 * bitRead(x,25) + 16 * bitRead(x,30);
bitVal = bitRead(x,31) ^ bitRead(x, 15) ^ bitRead(KeeLoq_NLF,index) ^ keyBitVal;
x = (x<<1) ^ bitVal;
}
return x;
}
#ifdef LoRa_E32_DEBUG
void LoRa_E32::printParameters(struct Configuration *configuration) {
DEBUG_PRINTLN("----------------------------------------");
DEBUG_PRINT(F("HEAD : ")); DEBUG_PRINT(configuration->HEAD, BIN);DEBUG_PRINT(" ");DEBUG_PRINT(configuration->HEAD, DEC);DEBUG_PRINT(" ");DEBUG_PRINTLN(configuration->HEAD, HEX);
DEBUG_PRINTLN(F(" "));
DEBUG_PRINT(F("AddH : ")); DEBUG_PRINTLN(configuration->ADDH, DEC);
DEBUG_PRINT(F("AddL : ")); DEBUG_PRINTLN(configuration->ADDL, DEC);
DEBUG_PRINT(F("Chan : ")); DEBUG_PRINT(configuration->CHAN, DEC); DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration->getChannelDescription());
DEBUG_PRINTLN(F(" "));
DEBUG_PRINT(F("SpeedParityBit : ")); DEBUG_PRINT(configuration->SPED.uartParity, BIN);DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration->SPED.getUARTParityDescription());
DEBUG_PRINT(F("SpeedUARTDatte : ")); DEBUG_PRINT(configuration->SPED.uartBaudRate, BIN);DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration->SPED.getUARTBaudRate());
DEBUG_PRINT(F("SpeedAirDataRate : ")); DEBUG_PRINT(configuration->SPED.airDataRate, BIN);DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration->SPED.getAirDataRate());
DEBUG_PRINT(F("OptionTrans : ")); DEBUG_PRINT(configuration->OPTION.fixedTransmission, BIN);DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration->OPTION.getFixedTransmissionDescription());
DEBUG_PRINT(F("OptionPullup : ")); DEBUG_PRINT(configuration->OPTION.ioDriveMode, BIN);DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration->OPTION.getIODroveModeDescription());
DEBUG_PRINT(F("OptionWakeup : ")); DEBUG_PRINT(configuration->OPTION.wirelessWakeupTime, BIN);DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration->OPTION.getWirelessWakeUPTimeDescription());
DEBUG_PRINT(F("OptionFEC : ")); DEBUG_PRINT(configuration->OPTION.fec, BIN);DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration->OPTION.getFECDescription());
DEBUG_PRINT(F("OptionPower : ")); DEBUG_PRINT(configuration->OPTION.transmissionPower, BIN);DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration->OPTION.getTransmissionPowerDescription());
DEBUG_PRINTLN("----------------------------------------");
}
#endif

298
LoRa_E32.h

@ -1,298 +0,0 @@
/*
* EBYTE LoRa E32 Series
*/
#ifndef LoRa_E32_h
#define LoRa_E32_h
#ifdef ESP32
#define HARDWARE_SERIAL_SELECTABLE_PIN
#endif
#ifdef ACTIVATE_SOFTWARE_SERIAL
#include <SoftwareSerial.h>
#endif
#include "statesNaming.h"
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#define MAX_SIZE_TX_PACKET 58
// Uncomment to enable printing out nice debug messages.
// #define LoRa_E32_DEBUG
// Operating Freq
#define FREQUENCY_915
// Define where debug output will be printed.
#define DEBUG_PRINTER Serial
// Setup debug printing macros.
#ifdef LoRa_E32_DEBUG
#define DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); }
#define DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); }
#else
#define DEBUG_PRINT(...) {}
#define DEBUG_PRINTLN(...) {}
#endif
enum MODE_TYPE
{
MODE_0_NORMAL = 0,
MODE_1_WAKE_UP = 1,
MODE_2_POWER_SAVING = 2,
MODE_3_SLEEP = 3,
MODE_3_PROGRAM =3,
MODE_INIT = 0xFF
};
enum PROGRAM_COMMAND
{
WRITE_CFG_PWR_DWN_SAVE = 0xC0,
READ_CONFIGURATION = 0xC1,
WRITE_CFG_PWR_DWN_LOSE = 0xC2,
READ_MODULE_VERSION = 0xC3,
WRITE_RESET_MODULE = 0xC4
};
#pragma pack(push, 1)
struct Speed {
uint8_t airDataRate : 3; //bit 0-2
String getAirDataRate() {
return getAirDataRateDescriptionByParams(this->airDataRate);
}
uint8_t uartBaudRate: 3; //bit 3-5
String getUARTBaudRate() {
return getUARTBaudRateDescriptionByParams(this->uartBaudRate);
}
uint8_t uartParity: 2; //bit 6-7
String getUARTParityDescription() {
return getUARTParityDescriptionByParams(this->uartParity);
}
};
struct Option {
byte transmissionPower : 2; //bit 0-1
String getTransmissionPowerDescription() {
return getTransmissionPowerDescriptionByParams(this->transmissionPower);
}
byte fec : 1; //bit 2
String getFECDescription() {
return getFECDescriptionByParams(this->fec);
}
byte wirelessWakeupTime : 3; //bit 3-5
String getWirelessWakeUPTimeDescription() {
return getWirelessWakeUPTimeDescriptionByParams(this->wirelessWakeupTime);
}
byte ioDriveMode : 1; //bit 6
String getIODroveModeDescription() {
return getIODriveModeDescriptionDescriptionByParams(this->ioDriveMode);
}
byte fixedTransmission : 1; //bit 7
String getFixedTransmissionDescription() {
return getFixedTransmissionDescriptionByParams(this->fixedTransmission);
}
};
struct Configuration {
byte HEAD = 0;
byte ADDH = 0;
byte ADDL = 0;
struct Speed SPED;
byte CHAN = 0;
String getChannelDescription() {
return String(this->CHAN + OPERATING_FREQUENCY) + F("MHz") ;
}
struct Option OPTION;
};
struct ModuleInformation {
byte HEAD = 0;
byte frequency = 0;
byte version = 0;
byte features = 0;
};
struct ResponseStatus {
Status code;
String getResponseDescription() {
return getResponseDescriptionByParams(this->code);
}
};
struct ResponseStructContainer {
void *data;
ResponseStatus status;
void close() {
free(this->data);
}
};
struct ResponseContainer {
String data;
ResponseStatus status;
};
//struct FixedStransmission {
// byte ADDL = 0;
// byte ADDH = 0;
// byte CHAN = 0;
// void *message;
//};
#pragma pack(pop)
class LoRa_E32 {
public:
LoRa_E32(HardwareSerial hs);
/*
#ifdef ACTIVATE_SOFTWARE_SERIAL
LoRa_E32(byte txE32pin, byte rxE32pin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
LoRa_E32(byte txE32pin, byte rxE32pin, byte auxPin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
LoRa_E32(byte txE32pin, byte rxE32pin, byte auxPin, byte m0Pin, byte m1Pin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
#endif
LoRa_E32(HardwareSerial* serial, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
LoRa_E32(HardwareSerial* serial, byte auxPin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
LoRa_E32(HardwareSerial* serial, byte auxPin, byte m0Pin, byte m1Pin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
#ifdef HARDWARE_SERIAL_SELECTABLE_PIN
LoRa_E32(byte txE32pin, byte rxE32pin, HardwareSerial* serial, UART_BPS_RATE bpsRate, uint32_t serialConfig = SERIAL_8N1);
LoRa_E32(byte txE32pin, byte rxE32pin, HardwareSerial* serial, byte auxPin, UART_BPS_RATE bpsRate, uint32_t serialConfig = SERIAL_8N1);
LoRa_E32(byte txE32pin, byte rxE32pin, HardwareSerial* serial, byte auxPin, byte m0Pin, byte m1Pin, UART_BPS_RATE bpsRate, uint32_t serialConfig = SERIAL_8N1);
#endif
#ifdef ACTIVATE_SOFTWARE_SERIAL
LoRa_E32(SoftwareSerial* serial, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
LoRa_E32(SoftwareSerial* serial, byte auxPin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
LoRa_E32(SoftwareSerial* serial, byte auxPin, byte m0Pin, byte m1Pin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
#endif
// LoRa_E32(byte txE32pin, byte rxE32pin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600, MODE_TYPE mode = MODE_0_NORMAL);
// LoRa_E32(HardwareSerial* serial = &Serial, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600, MODE_TYPE mode = MODE_0_NORMAL);
// LoRa_E32(SoftwareSerial* serial, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600, MODE_TYPE mode = MODE_0_NORMAL);
*/
bool begin();
Status setMode(MODE_TYPE mode);
MODE_TYPE getMode();
ResponseStructContainer getConfiguration();
ResponseStatus setConfiguration(Configuration configuration, PROGRAM_COMMAND saveType = WRITE_CFG_PWR_DWN_LOSE);
ResponseStructContainer getModuleInformation();
ResponseStatus resetModule();
ResponseStatus sendMessage(const void *message, const uint8_t size);
ResponseStructContainer receiveMessage(const uint8_t size);
ResponseStatus sendMessage(const String message);
ResponseContainer receiveMessage();
ResponseStatus sendFixedMessage(byte ADDH,byte ADDL, byte CHAN, const String message);
ResponseStatus sendBroadcastFixedMessage(byte CHAN, const String message);
ResponseStatus sendFixedMessage(byte ADDH,byte ADDL, byte CHAN, const void *message, const uint8_t size);
ResponseStatus sendBroadcastFixedMessage(byte CHAN, const void *message, const uint8_t size );
ResponseContainer receiveInitialMessage(const uint8_t size);
ResponseContainer receiveMessageUntil(char delimiter = '\0');
int available(unsigned long timeout = 1000);
private:
HardwareSerial* hs;
#ifdef ACTIVATE_SOFTWARE_SERIAL
SoftwareSerial* ss;
#endif
bool isSoftwareSerial = true;
int8_t txE32pin = -1;
int8_t rxE32pin = -1;
int8_t auxPin = -1;
#ifdef HARDWARE_SERIAL_SELECTABLE_PIN
uint32_t serialConfig = SERIAL_8N1;
#endif
int8_t m0Pin = -1;
int8_t m1Pin = -1;
unsigned long halfKeyloqKey = 0x06660708;
unsigned long encrypt(unsigned long data);
unsigned long decrypt(unsigned long data);
UART_BPS_RATE bpsRate = UART_BPS_RATE_9600;
struct NeedsStream{
template< typename T >
void begin( T &t, int baud){
DEBUG_PRINTLN("Begin ");
t.setTimeout(500);
t.begin(baud);
stream = &t;
}
#ifdef HARDWARE_SERIAL_SELECTABLE_PIN
// template< typename T >
// void begin( T &t, int baud, SerialConfig config ){
// DEBUG_PRINTLN("Begin ");
// t.setTimeout(500);
// t.begin(baud, config);
// stream = &t;
// }
//
template< typename T >
void begin( T &t, int baud, uint32_t config ){
DEBUG_PRINTLN("Begin ");
t.setTimeout(500);
t.begin(baud, config);
stream = &t;
}
template< typename T >
void begin( T &t, int baud, uint32_t config, int8_t txE32pin, int8_t rxE32pin ){
DEBUG_PRINTLN("Begin ");
t.setTimeout(500);
t.begin(baud, config, txE32pin, rxE32pin);
stream = &t;
}
#endif
void listen(){
}
Stream *stream;
};
NeedsStream serialDef;
MODE_TYPE mode = MODE_0_NORMAL;
void managedDelay(unsigned long timeout);
Status waitCompleteResponse(unsigned long timeout = 1000, unsigned int waitNoAux = 100);
void flush();
void cleanUARTBuffer();
Status sendStruct(void *structureManaged, uint16_t size_);
Status receiveStruct(void *structureManaged, uint16_t size_);
void writeProgramCommand(PROGRAM_COMMAND cmd);
RESPONSE_STATUS checkUARTConfiguration(MODE_TYPE mode);
#ifdef LoRa_E32_DEBUG
void printParameters(struct Configuration *configuration);
#endif
};
#endif

22
OpenFlightTX.h

@ -1,7 +1,7 @@
#ifndef OPENFLIGHTTX_H_
#define OPENFLIGHTTX_H_
void battery_management(void);
void draw_menu(struct menu_state *state);
void to_right(struct menu_state *state);
void to_left(struct menu_state *state);
@ -16,7 +16,6 @@ uint16_t roll_insert(uint16_t val);
uint16_t pool_insert(uint8_t pool_type, uint16_t val);
void intro(void);
void read_all_voltage(void);
void battery_management(void);
void bluetooth_gamepad(void);
void stick_calibration(void);
void draw_gimbalbox(uint8_t x, uint8_t y);
@ -36,7 +35,20 @@ void setup_webserver(void);
void stick_trims(void);
void wifi_enabler(void);
void unload_webserver(void);
void printParameters(struct Configuration configuration);
void printModuleInformation(struct ModuleInformation moduleInformation);
void setup_lora(void);
void debug_me(void);
void rf_scanners(void);
void setup_nrf_scanner(void);
void setRegister(byte r, byte v);
byte getRegister(byte r);
void SignalHandler(void *pvParameters);
void setup_nrf_tx(void);
/*
void disableRX(void);
void powerUp(void);
void powerDown(void);
void enableRX(void);
void setRX(void);
*/
#endif

614
OpenFlightTX.ino

@ -32,35 +32,47 @@
#include <WebServer.h>
#include <Update.h>
// For E32 Lora Module (915MHz)
#include "LoRa_E32.h";
// For NRF24L01 (E01) - EByte
// #include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
// Temporary hardcode LoRA Settings...
#define ADDR_H 0x00
#define ADDR_L 0x00
#define CHANNEL 0x13 // 900MHz + 19 = 919MHz (Channel 19)
#define AIR_RATE AIR_DATA_RATE_101_192 // Default to 2.4kbps (AirRate)
#define TX_POWER POWER_17 // Temporary at 17dBm
// Declaration for NRF24L01
#define NRF24_CE 5 // GPIO5 (CE)
#define NRF24_CSN 4 // GPIO4 (CSN)
LoRa_E32 e32ttl100(Serial2);
// NRF24L01 registers we need - For 2.4G Scanning
#define _NRF24_CONFIG 0x00
#define _NRF24_EN_AA 0x01
#define _NRF24_RF_CH 0x05
#define _NRF24_RF_SETUP 0x06
#define _NRF24_RPD 0x09
bool lora_enable = false;
uint32_t lora_lastsent = 0;
uint32_t lora_sent_profiling_raw = 0;
uint32_t lora_sent_profiling = 0;
// For channel scanner
#define MAX_CHANNELS 125
#define MAX_SAMPLES 100
// LoRa related all on Core 0
TaskHandle_t LoraTask;
int channel_loads[MAX_CHANNELS]; // Channel 0 ~ Channel 124
const uint64_t pipeIn = 0xE8E8F0F0E1LL; // TODO: set it to EEPROM
RF24 radio(NRF24_CE, NRF24_CSN); // Starting up the module on GPIO5 (CE), GPIO4 (CSN)
bool nrf_enable = false;
bool nrf_scanner = false;
bool channel_used[MAX_CHANNELS];
uint8_t graph_type = 0;
TaskHandle_t SignalTask;
// TTTT TTTT TTTT ---- YYYY YYYY YYYY ---- PPPP PPPP PPPP ---- RRRR RRRR RRRR ---- SSSS SSSS = 72-bits ( 9 bytes )
// Data Structure
struct LoraMessage {
struct TxMessage {
uint16_t throttle;
uint16_t yaw;
uint16_t pitch;
uint16_t roll;
uint8_t switches;
} lora_message;
};
TxMessage txmessage;
bool wifi_enable = false;
bool webserver_setup = false;
@ -596,7 +608,10 @@ bool require_unlock = false;
bool ble_begin = false;
uint32_t ble_profiling = 0;
uint32_t ble_profiling_raw = 0;
uint32_t nrf_profiling = 0;
uint32_t nrf_profiling_raw = 0;
uint32_t last_seconds = 0;
uint32_t last_nrf_scanned = 0;
//define the pins used by the transceiver module
#define SS 5
@ -653,6 +668,8 @@ bool sw4 = 0;
bool sw5 = 0;
bool sw6 = 0;
uint8_t switches_value = 0;
bool invert_throttle = false;
bool invert_yaw = false;
bool invert_pitch = false;
@ -667,13 +684,7 @@ uint32_t frequency = 919999000;
uint8_t syncword = 0xA0;
uint16_t packet_sent = 0;
uint16_t packet_sent_count = 0;
uint16_t lora_packets = 0;
uint16_t lora_packets_per_second = 0;
uint32_t uptime = 0;
bool lora_started = false;
bool lora_rx_displayed = false;
String LoRaData;
#define MEDIAN_TOTAL 11
#define MEDIAN_POS MEDIAN_TOTAL/2
@ -686,7 +697,6 @@ String LoRaData;
#define VBAT 4
uint64_t last_update = 0;
uint64_t last_lora_update = 0;
uint64_t last_menu_stick_read = 0;
uint64_t last_menu_item_moved = 0;
@ -917,6 +927,18 @@ void read_all_voltage() {
sw5 = !digitalRead(SW5_PIN);
sw6 = !digitalRead(SW6_PIN);
// Combine values to one byte...
// NNssssss
// IIwwwwww
// switches_value = LL654321
switches_value = 0;
switches_value |= (sw6) ? 1 << 5 : 0;
switches_value |= (sw5) ? 1 << 4 : 0;
switches_value |= (sw4) ? 1 << 3 : 0;
switches_value |= (sw3) ? 1 << 2 : 0;
switches_value |= (sw2) ? 1 << 1 : 0;
switches_value |= (sw1) ? 1 << 0 : 0;
throttle_value = pool_insert(THROTTLE, throttle_raw);
if(!invert_throttle)
throttle_value = throttle_value + (trim_throttle << 3);
@ -940,6 +962,49 @@ void read_all_voltage() {
vbat_value = pool_insert(VBAT, vbat_raw);
}
void battery_management() {
/*
u8g2_left.clearBuffer();
u8g2_left.firstPage();
u8g2_left.setFont(menu_entry_alpha_huge_list[destination_alpha_state.position].font);
u8g2_left.drawGlyph(40, ICONX_Y, menu_entry_alpha_huge_list[destination_alpha_state.position].icon);
u8g2_left.nextPage();
*/
u8g2_left.clearBuffer();
u8g2_left.firstPage();
u8g2_left.setFontMode(1);
u8g2_left.setFont(u8g2_font_VCR_OSD_tr);
static char buf[6];
u8g2_left.setFont(u8g2_font_ImpactBits_tr);
u8g2_left.setCursor(0,12);
u8g2_left.print(F("Battery LEVEL"));
// u8g2_left.drawStr(45, 15, buf);
// strcpy(buf, ltoa(vbat_value, buf, 10));
// u8g2_left.drawStr(0, 30, buf);
float vbat_real_value = vbat_value * .0012142857;
//strcpy(buf, ltoa(vbat_real_value, buf, 10));
dtostrf(vbat_real_value, 2, 1, buf);
u8g2_left.setFont(u8g2_font_maniac_tf);
u8g2_left.drawStr(0, 64, buf);
u8g2_left.setCursor(44, 64);
u8g2_left.print(F("V"));
// The battery frame
u8g2_left.drawFrame(96, 0, 32, 64);
// Bars Calculations
uint8_t bars = map(vbat_value, 2650, 3460, 0, 31);
for(int i = 0; i < bars; i++) {
u8g2_left.drawHLine(98, 61 - (i*2), 28);
}
u8g2_left.nextPage();
}
void setup() {
Serial.begin(115200);
@ -1028,6 +1093,82 @@ void setup() {
// u8g2_right.print(F("READY"));
// u8g2_right.nextPage();
// setup_lora();
/* Starting up 2nd core... */
// Creating Lora Task on Core 0. This will keep sending over and over again...
xTaskCreatePinnedToCore(
SignalHandler, /* Task function. */
"SignalHandler", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
0, /* priority of the task */
&SignalTask, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
}
// Sending / Receive signals at Core 0
void SignalHandler(void *pvParameters) {
// Forever loop in this loop :P
for(;;) {
if(nrf_scanner == true) {
if(millis() > last_nrf_scanned) {
Serial.println("Inside nrf_scanner loop...");
// Collecting X number of samples on each channel
for(int i = 0; i < MAX_CHANNELS; i++) {
channel_loads[i] = 0x00;
for(int j = 0; j < MAX_SAMPLES; j++) {
// Select a new channel...
radio.setChannel(i);
// Listening for a while
radio.startListening();
// Delay for a while...
delayMicroseconds(128);
// Stop Listening
radio.stopListening();
// Read out RPD flag... set to 1 if received power > -64dBm
// return ( read_register(RPD) & 1 ) ;
if(radio.testCarrier()) {
channel_loads[i]++;
}
}
// Debug
Serial.print("Channel: ");
Serial.println(i);
}
// Wait for next second...
last_nrf_scanned = millis() + 100;
}
} else if(nrf_enable) {
// Disable it first...
if(nrf_scanner)
nrf_scanner = false;
// Assign values...
txmessage.throttle = throttle_value;
txmessage.yaw = yaw_value;
txmessage.pitch = pitch_value;
txmessage.roll = roll_value;
txmessage.switches = switches_value;
// Sending Data ove NRF
radio.write(&txmessage, sizeof(txmessage));
// Profiling..
nrf_profiling_raw++;
} else {
delay(10);
} // End of if(nrf_scanner)
} // End of for(;;)
}
void loop() {
@ -1037,13 +1178,13 @@ void loop() {
ble_profiling = ble_profiling_raw;
ble_profiling_raw = 0;
lora_sent_profiling = lora_sent_profiling_raw;
lora_sent_profiling_raw = 0;
nrf_profiling = nrf_profiling_raw;
nrf_profiling_raw = 0;
Serial.print(F("BLE:"));
Serial.println(ble_profiling);
Serial.print(F("LORA:"));
Serial.println(lora_sent_profiling);
/*
Serial.print(F("NRF:"));
Serial.println(nrf_profiling);
*/
last_seconds = millis() + 1000;
@ -1114,6 +1255,11 @@ void loop() {
stick_navigation_position = MENU_NONE;
}
/*** DEBUG START **/
// rf_scanners();
// return;
/*** DEBUG END **/
if(
!menu_entry_alpha_selected
) {
@ -1204,6 +1350,12 @@ void loop() {
} else if(menu_entry_alpha_list[destination_alpha_state.position].name == "Frequency") {
require_unlock = false;
frequency_settings();
} else if(menu_entry_alpha_list[destination_alpha_state.position].name == "Debug") {
require_unlock = false;
debug_me();
} else if(menu_entry_alpha_list[destination_alpha_state.position].name == "RF Scanners") {
require_unlock = true;
rf_scanners();
}
//// u8g2_right.clearBuffer();
@ -1248,51 +1400,16 @@ void loop() {
}
void rx_checker(void) {
/*
if(!lora_started) {
while(!LoRa.begin(frequency)) {
delay(500);
}
LoRa.setSyncWord(syncword);
LoRa.setPreambleLength(8);
lora_started = true;
}
int packetSize = LoRa.parsePacket();
if(packetSize) {
while(LoRa.available()) {
LoRaData = LoRa.readString();
}
lora_packets++;
lora_rx_displayed = false;
}
}
void rc_controller(void) {
static char buf[16];
if(!lora_rx_displayed) {
u8g2_left.clearBuffer();
u8g2_left.firstPage();
u8g2_left.setFont(u8g2_font_sirclivethebold_tr);
u8g2_left.setCursor(16, 8);
u8g2_left.print(F("RX Checker"));
u8g2_left.setCursor(0, 16);
u8g2_left.print(F("RSSI:"));
strcpy(buf, ltoa(LoRa.packetRssi(), buf, 10));
u8g2_left.drawStr(40, 16, buf);
u8g2_left.nextPage();
u8g2_right.clearBuffer();
u8g2_right.firstPage();
u8g2_right.nextPage();
lora_rx_displayed = true;
if(!nrf_enable) {
setup_nrf_tx();
}
*/
}
void rc_controller(void) {
static char buf[6];
/*
// Trying to send in this loop
if(!lora_enable) {
setup_lora();
@ -1301,6 +1418,7 @@ void rc_controller(void) {
//sendFixedMessage( byte ADDH,byte ADDL, byte CHAN, const void *message, const uint8_t size){
// ResponseStatus rs = e32ttl100.sendFixedMessage(ADDR_H, ADDR_L, CHANNEL, "Welcome1");
}
*/
u8g2_left.clearBuffer();
u8g2_left.firstPage();
@ -1361,58 +1479,9 @@ void rc_controller(void) {
u8g2_left.setCursor(0, 25);
u8g2_left.setFont(u8g2_font_5x7_tf);
u8g2_left.print(F("Rate:"));
strcpy(buf, ltoa(lora_sent_profiling, buf, 10));
sprintf(buf, "%d", nrf_profiling);
u8g2_left.drawStr(25, 25, buf);
// u8g2_right.clearBuffer();
// u8g2_right.firstPage();
/*
draw_gimbalbox(0, 0);
draw_gimbalbox(64, 0);
// Mapping based on the live values
uint16_t gimbal_y_raw = throttle_value;
uint16_t gimbal_x_raw = yaw_value;
if(gimbal_y_raw < throttle_min) gimbal_y_raw = throttle_min;
if(gimbal_y_raw > throttle_max) gimbal_y_raw = throttle_max;
if(gimbal_x_raw < yaw_min) gimbal_x_raw = yaw_min;
if(gimbal_x_raw > yaw_max) gimbal_x_raw = yaw_max;
uint8_t gimbal_y;
if(!invert_throttle)
gimbal_y = map(gimbal_y_raw, throttle_min, throttle_max, 0, 63); // Throttle
else
gimbal_y = map(gimbal_y_raw, throttle_max, throttle_min, 0, 63); // Throttle
uint8_t gimbal_x;
if(!invert_yaw)
gimbal_x = map(gimbal_x_raw, yaw_min, yaw_max, 0, 63); // Yaw
else
gimbal_x = map(gimbal_x_raw, yaw_max, yaw_min, 0, 63); // Yaw
// u8g2_right.drawFilledEllipse(gimbal_x, gimbal_y, 3, 3, U8G2_DRAW_ALL);
// Mapping based on the live values
gimbal_y_raw = pitch_value;
gimbal_x_raw = roll_value;
if(gimbal_y_raw < pitch_min) gimbal_y_raw = pitch_min;
if(gimbal_y_raw > pitch_max) gimbal_y_raw = pitch_max;
if(gimbal_x_raw < roll_min) gimbal_x_raw = roll_min;
if(gimbal_x_raw > roll_max) gimbal_x_raw = roll_max;
if(!invert_pitch)
gimbal_y = map(gimbal_y_raw, pitch_min, pitch_max, 0, 63); // Pitch
else
gimbal_y = map(gimbal_y_raw, pitch_max, pitch_min, 0, 63); // Pitch
if(!invert_roll)
gimbal_x = map(gimbal_x_raw, roll_min, roll_max, 0, 63); // Roll
else
gimbal_x = map(gimbal_x_raw, roll_max, roll_min, 0, 63); // Roll
// u8g2_right.drawFilledEllipse(64 + gimbal_x, gimbal_y, 3, 3, U8G2_DRAW_ALL);
// u8g2_right.nextPage();
*/
u8g2_left.nextPage();
}
@ -2363,7 +2432,7 @@ void wifi_enabler(void) {
}
void battery_management() {
void debug_me(void){
/*
u8g2_left.clearBuffer();
u8g2_left.firstPage();
@ -2371,186 +2440,221 @@ void battery_management() {
u8g2_left.drawGlyph(40, ICONX_Y, menu_entry_alpha_huge_list[destination_alpha_state.position].icon);
u8g2_left.nextPage();
*/
u8g2_left.clearBuffer();
u8g2_left.firstPage();
u8g2_left.setFontMode(1);
u8g2_left.setFont(u8g2_font_VCR_OSD_tr);
static char buf[6];
static char buf[10];
u8g2_left.setFont(u8g2_font_ImpactBits_tr);
u8g2_left.setCursor(0,12);
u8g2_left.print(F("Battery LEVEL"));
u8g2_left.print(F("DEBUG ME"));
// u8g2_left.drawStr(45, 15, buf);
// strcpy(buf, ltoa(vbat_value, buf, 10));
// u8g2_left.drawStr(0, 30, buf);
float vbat_real_value = vbat_value * .0012142857;
//strcpy(buf, ltoa(vbat_real_value, buf, 10));
dtostrf(vbat_real_value, 2, 1, buf);
//sprintf(buf, "RATE:%i", lora_receive_profiling);
u8g2_left.setFont(u8g2_font_maniac_tf);
u8g2_left.drawStr(0, 64, buf);
u8g2_left.setCursor(44, 64);
u8g2_left.print(F("V"));
// The battery frame
u8g2_left.drawFrame(96, 0, 32, 64);
// Bars Calculations
uint8_t bars = map(vbat_value, 2650, 3460, 0, 31);
for(int i = 0; i < bars; i++) {
u8g2_left.drawHLine(98, 61 - (i*2), 28);
}
//u8g2_left.setFont(u8g2_font_5x7_tf);
//u8g2_left.drawStr(0, 32, buf);
u8g2_left.nextPage();
}
/****** E32 Lora Functions *******/
void setup_lora() {
// Startup all pins and UART
e32ttl100.begin();
void setup_nrf_scanner() {
// Setting NRF24L01
printf_begin();
radio.begin();
radio.setAutoAck(false);
// Get into standby mode
radio.startListening();
radio.stopListening();
radio.printDetails();
ResponseStructContainer c;
c = e32ttl100.getConfiguration();
// Initialize variables...
for(int i = 0; i < MAX_CHANNELS; i++) {
channel_loads[i] = 0;
}
Serial.println("SET nrf_scanner = TRUE");
nrf_scanner = true;
}
// It's important get configuration pointer before all other operation
Configuration configuration = *(Configuration*) c.data;
Serial.println(c.status.getResponseDescription());
Serial.println(c.status.code);
void setup_nrf_tx(void) {
// Setting NRF24L01
printf_begin();
radio.begin();
printParameters(configuration);
// radio.setAutoAck(true);
radio.setAutoAck(false); // Seems like i am doing this on the last version...
radio.setPayloadSize(sizeof(TxMessage));
radio.setChannel(99); // This will need to set from EEPROM settings
radio.setDataRate(RF24_250KBPS); // Lowest.. at 250kbps
radio.setPALevel(RF24_PA_MAX); // Set the transmit power to Maximum... Later make it configurable.
/****** Setting up E32 Parameters *****/
// Communication address
configuration.ADDL = ADDR_L;
configuration.ADDH = ADDR_H;
// Communication channel
configuration.CHAN = CHANNEL;
const uint64_t pipe = 0xE8E8F0F0E1LL;
radio.openWritingPipe(pipe);
// Communication rate
configuration.SPED.airDataRate = AIR_RATE;
configuration.SPED.uartBaudRate = UART_BPS_9600;
// configuration.SPED.uartBaudRate = UART_BPS_115200;
configuration.SPED.uartParity = MODE_00_8N1;
Serial.println("SET nrf_scanner = TRUE");
nrf_enable = true;
}
// Transmission Power
configuration.OPTION.transmissionPower = TX_POWER;
configuration.OPTION.wirelessWakeupTime = WAKE_UP_1250;
void rf_scanners(void) {
int y = 0;
static char buf[10];
static int result_x = 0;
// Other configurations
configuration.OPTION.fec = FEC_0_OFF;
// configuration.OPTION.fec = FEC_1_ON;
configuration.OPTION.fixedTransmission = FT_FIXED_TRANSMISSION;
configuration.OPTION.ioDriveMode = IO_D_MODE_PUSH_PULLS_PULL_UPS;
if(!nrf_scanner) {
setup_nrf_scanner();
// Set not to hold configuration to save the life time of the device ;)
ResponseStatus rs = e32ttl100.setConfiguration(configuration, WRITE_CFG_PWR_DWN_LOSE);
//ResponseStatus rs = e32ttl100.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
Serial.println(rs.getResponseDescription());
Serial.println(rs.code);
printParameters(configuration);
for(int i = 0; i < MAX_CHANNELS; i++) {
channel_used[i] = false;
}
}
// Storing...
int channel_unused = 0;
for(int i = 0; i < MAX_CHANNELS; i++) {
if(channel_loads[i] > 0) {
channel_used[i] = true;
}
if(!channel_used[i]) channel_unused++;
}
ResponseStructContainer cMi;
cMi = e32ttl100.getModuleInformation();
// It's important get information pointer before all other operation
ModuleInformation mi = *(ModuleInformation*)cMi.data;
// Data processing
if(stick_navigation_position == MENU_LEFT) {
graph_type = 0;
} else if(stick_navigation_position == MENU_RIGHT) {
graph_type = 1;
} else if(stick_navigation_position == MENU_EXTEND_LEFT) {
result_x += 10;
} else if(stick_navigation_position == MENU_EXTEND_RIGHT) {
result_x -= 10;
}
Serial.println(cMi.status.getResponseDescription());
Serial.println(cMi.status.code);
u8g2_left.clearBuffer();
u8g2_left.firstPage();
u8g2_left.setFontMode(1);
u8g2_left.setFont(u8g2_font_VCR_OSD_tr);
u8g2_left.setFont(u8g2_font_ImpactBits_tr);
u8g2_left.setCursor(0,12);
u8g2_left.print(F("RF SCANNER"));
printModuleInformation(mi);
u8g2_left.setFont(u8g2_font_5x7_tf);
if(!sw6) {
u8g2_left.setCursor(85, 15);
u8g2_left.print(F("LOCKED"));
}
c.close();
cMi.close();
// List all free channels..
bool continuemore = true;
int c = 0;
int col = 0;
int frequency_mhz = 0;
for(int i = 0; i < MAX_CHANNELS; i++) {
if(channel_used[i]) {
continue;
}
frequency_mhz = 2400 + i;
sprintf(buf, "%d ", frequency_mhz);
col = c / 4;
int y = c % 4;
u8g2_left.drawStr(0 + (col * 22) - result_x, 40 + (y * 8), buf);
c++;
// Creating Lora Task on Core 0. This will keep sending over and over again...
xTaskCreatePinnedToCore(
SendLoRaSignals, /* Task function. */
"SendLoRaSignals", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
0, /* priority of the task */
&LoraTask, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
}
if(c >= 28) break;
}
// u8g2_left.drawStr(45, 15, buf);
// strcpy(buf, ltoa(vbat_value, buf, 10));
// u8g2_left.drawStr(0, 30, buf);
// Sending Lora Signals on Core 0
void SendLoRaSignals(void *pvParameters) {
// Forever loop in this loop :P
for(;;) {
/***** LORA ***/
if(lora_enable) {
// uint32_t timestart = millis();
struct LoraMessage {
byte throttle[2];
byte yaw[2];
byte pitch[2];
byte roll[2];
byte switches[1]; // <---------- TEMPORARY 0.... TODO: Change to the current switches value....
} lora_message;
*(uint16_t*) (lora_message.throttle) = throttle_value;
*(uint16_t*) (lora_message.yaw) = yaw_value;
*(uint16_t*) (lora_message.pitch) = pitch_value;
*(uint16_t*) (lora_message.roll) = roll_value;
*(uint8_t*) (lora_message.switches) = 0x00;
e32ttl100.sendFixedMessage(ADDR_H, ADDR_L, CHANNEL, &lora_message, sizeof(LoraMessage));
lora_sent_profiling_raw++;
last_lora_update = millis();
// Debugging....
// int a = last_lora_update - timestart;
// Serial.println(a);
//strcpy(buf, ltoa(vbat_real_value, buf, 10));
//sprintf(buf, "RATE:%i", lora_receive_profiling);
//u8g2_left.setFont(u8g2_font_5x7_tf);
//u8g2_left.drawStr(0, 32, buf);
// Drawing from the memory...
if(graph_type == 0) {
for(int x = 0; x < MAX_CHANNELS; x++) {
if(channel_loads[x] == 0) continue;
// y = 63 - (channel_loads[x] * 32 / MAX_SAMPLES);
y = 32 - rf24_min(0xF, channel_loads[x]);
u8g2_left.drawLine(x, 32, x, y);
}
/*
// Script way for delay....
unsigned long t = millis();
while((millis() - t) < 100) {
}
*/
} else {
for(int x = 0; x < MAX_CHANNELS; x++) {
if(!channel_used[x]) continue;
} // End of forever loop - for(;;)
}
// Meaning ... already use..... then draw a line
u8g2_left.drawLine(x, 16, x, 32);
}
}
// Stats
// u8g2_left.setFont(u8g2_font_5x7_tf);
u8g2_left.setCursor(85, 7);
u8g2_left.print(F("FREE:"));
itoa(channel_unused, buf, 10);
u8g2_left.drawStr(110, 7, buf);
void printParameters(struct Configuration configuration) {
Serial.println("----------------------------------------");
u8g2_left.nextPage();
}
Serial.print(F("HEAD BIN: ")); Serial.print(configuration.HEAD, BIN);Serial.print(" ");Serial.print(configuration.HEAD, DEC);Serial.print(" ");Serial.println(configuration.HEAD, HEX);
Serial.println(F(" "));
Serial.print(F("AddH BIN: ")); Serial.println(configuration.ADDH, BIN);
Serial.print(F("AddL BIN: ")); Serial.println(configuration.ADDL, BIN);
Serial.print(F("Chan BIN: ")); Serial.print(configuration.CHAN, DEC); Serial.print(" -> "); Serial.println(configuration.getChannelDescription());
Serial.println(F(" "));
Serial.print(F("SpeedParityBit BIN : ")); Serial.print(configuration.SPED.uartParity, BIN);Serial.print(" -> "); Serial.println(configuration.SPED.getUARTParityDescription());
Serial.print(F("SpeedUARTDataRate BIN : ")); Serial.print(configuration.SPED.uartBaudRate, BIN);Serial.print(" -> "); Serial.println(configuration.SPED.getUARTBaudRate());
Serial.print(F("SpeedAirDataRate BIN : ")); Serial.print(configuration.SPED.airDataRate, BIN);Serial.print(" -> "); Serial.println(configuration.SPED.getAirDataRate());
/*
// set the value of a nRF24L01 register
void setRegister(byte r, byte v) {
digitalWrite(NRF24_CE, 0);
SPI.transfer((r&0x1F)|0x20);
SPI.transfer(v);
digitalWrite(NRF24_CE, 1);
}
Serial.print(F("OptionTrans BIN : ")); Serial.print(configuration.OPTION.fixedTransmission, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getFixedTransmissionDescription());
Serial.print(F("OptionPullup BIN : ")); Serial.print(configuration.OPTION.ioDriveMode, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getIODroveModeDescription());
Serial.print(F("OptionWakeup BIN : ")); Serial.print(configuration.OPTION.wirelessWakeupTime, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getWirelessWakeUPTimeDescription());
Serial.print(F("OptionFEC BIN : ")); Serial.print(configuration.OPTION.fec, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getFECDescription());
Serial.print(F("OptionPower BIN : ")); Serial.print(configuration.OPTION.transmissionPower, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getTransmissionPowerDescription());
// Get the value of a nRF24L01 register
byte getRegister(byte r) {
byte c;
digitalWrite(NRF24_CE, 0);
c = SPI.transfer(r&0x1F);
c = SPI.transfer(0);
digitalWrite(NRF24_CE, 1);
return(c);
}
Serial.println("----------------------------------------");
void disableRX(void) {
digitalWrite(NRF24_CE, LOW);
}
// power up the nRF24L01p chip
void powerUp(void) {
setRegister(_NRF24_CONFIG,getRegister(_NRF24_CONFIG)|0x02);
delayMicroseconds(130);
}
void printModuleInformation(struct ModuleInformation moduleInformation) {
Serial.println("----------------------------------------");
Serial.print(F("HEAD BIN: ")); Serial.print(moduleInformation.HEAD, BIN);Serial.print(" ");Serial.print(moduleInformation.HEAD, DEC);Serial.print(" ");Serial.println(moduleInformation.HEAD, HEX);
// switch nRF24L01p off
void powerDown(void) {
setRegister(_NRF24_CONFIG,getRegister(_NRF24_CONFIG)&~0x02);
}
Serial.print(F("Freq.: ")); Serial.println(moduleInformation.frequency, HEX);
Serial.print(F("Version : ")); Serial.println(moduleInformation.version, HEX);
Serial.print(F("Features : ")); Serial.println(moduleInformation.features, HEX);
Serial.println("----------------------------------------");
// enable RX
void enableRX(void) {
digitalWrite(NRF24_CE, HIGH);
}
// setup RX-Mode of nRF24L01p
void setRX(void) {
setRegister(_NRF24_CONFIG,getRegister(_NRF24_CONFIG)|0x01);
enableRX();
// this is slightly shorter than
// the recommended delay of 130 usec
// - but it works for me and speeds things up a little...
delayMicroseconds(100);
}
*/

1567
RF24.cpp
File diff suppressed because it is too large
View File

2072
RF24.h
File diff suppressed because it is too large
View File

187
RF24_config.h

@ -0,0 +1,187 @@
/*
Copyright (C)
2011 J. Coliz <maniacbug@ymail.com>
2015-2019 TMRh20
2015 spaniakos <spaniakos@gmail.com>
2015 nerdralph
2015 zador-blood-stained
2016 akatran
2017-2019 Avamander <avamander@gmail.com>
2019 IkpeohaGodson
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
#ifndef __RF24_CONFIG_H__
#define __RF24_CONFIG_H__
/*** USER DEFINES: ***/
#define FAILURE_HANDLING
//#define SERIAL_DEBUG
//#define MINIMAL
//#define SPI_UART // Requires library from https://github.com/TMRh20/Sketches/tree/master/SPI_UART
//#define SOFTSPI // Requires library from https://github.com/greiman/DigitalIO
/**********************/
#define rf24_max(a,b) (a>b?a:b)
#define rf24_min(a,b) (a<b?a:b)
#define RF24_SPI_SPEED 10000000
//ATXMega
#if defined (__AVR_ATxmega64D3__) || defined (__AVR_ATxmega128D3__) || defined (__AVR_ATxmega192D3__) || defined (__AVR_ATxmega256D3__) || defined (__AVR_ATxmega384D3__) // In order to be available both in Windows and Linux this should take presence here.
#define XMEGA
#define XMEGA_D3
#include "utility/ATXMegaD3/RF24_arch_config.h"
#elif ( !defined (ARDUINO) ) // Any non-arduino device is handled via configure/Makefile
// The configure script detects device and copies the correct includes.h file to /utility/includes.h
// This behavior can be overridden by calling configure with respective parameters
// The includes.h file defines either RF24_RPi, MRAA, LITTLEWIRE or RF24_SPIDEV and includes the correct RF24_arch_config.h file
#include "utility/includes.h"
//ATTiny
#elif defined (__AVR_ATtiny25__) || defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) || defined (__AVR_ATtiny24__) || defined (__AVR_ATtiny44__) || defined (__AVR_ATtiny84__) || defined (__AVR_ATtiny2313__) || defined (__AVR_ATtiny4313__) || defined (__AVR_ATtiny861__)
#define RF24_TINY
#include "utility/ATTiny/RF24_arch_config.h"
#elif defined (LITTLEWIRE) //LittleWire
#include "utility/LittleWire/RF24_arch_config.h"
#elif defined (TEENSYDUINO) //Teensy
#include "utility/Teensy/RF24_arch_config.h"
#else //Everything else
#include <Arduino.h>
#if defined (ARDUINO) && !defined (__arm__) && !defined (__ARDUINO_X86__)
#if defined SPI_UART
#include <SPI_UART.h>
#define _SPI uspi
#elif defined (SOFTSPI)
// change these pins to your liking
//
#ifndef SOFT_SPI_MISO_PIN
#define SOFT_SPI_MISO_PIN 9
#endif // SOFT_SPI_MISO_PIN
#ifndef SOFT_SPI_MOSI_PIN
#define SOFT_SPI_MOSI_PIN 8
#endif // SOFT_SPI_MOSI_PIN
#ifndef SOFT_SPI_SCK_PIN
#define SOFT_SPI_SCK_PIN 7
#endif // SOFT_SPI_SCK_PIN
const uint8_t SPI_MODE = 0;
#define _SPI spi
#else // !defined (SPI_UART) && !defined (SOFTSPI)
#include <SPI.h>
#define _SPI SPI
#endif // !defined (SPI_UART) && !defined (SOFTSPI)
#else // defined (ARDUINO) && !defined (__arm__) && !defined (__ARDUINO_X86__)
// Define _BV for non-Arduino platforms and for Arduino DUE
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#if defined(__arm__) || defined (__ARDUINO_X86__)
#if defined (__arm__) && defined (SPI_UART)
#include <SPI_UART.h>
#define _SPI uspi
#else // !defined (__arm__) || !defined (SPI_UART)
#include <SPI.h>
#define _SPI SPI
#endif // !defined (__arm__) || !defined (SPI_UART)
#elif !defined(__arm__) && !defined (__ARDUINO_X86__)
extern HardwareSPI SPI;
#endif // !defined(__arm__) && !defined (__ARDUINO_X86__)
#ifndef _BV
#define _BV(x) (1<<(x))
#endif
#endif // defined (ARDUINO) && !defined (__arm__) && !defined (__ARDUINO_X86__)
#ifdef SERIAL_DEBUG
#define IF_SERIAL_DEBUG(x) ({x;})
#else
#define IF_SERIAL_DEBUG(x)
#if defined(RF24_TINY)
#define printf_P(...)
#endif // defined(RF24_TINY)
#endif // SERIAL_DEBUG
#if defined (__ARDUINO_X86__)
#define printf_P printf
#define _BV(bit) (1<<(bit))
#endif // defined (__ARDUINO_X86__)
// Progmem is Arduino-specific
// Arduino DUE is arm and does not include avr/pgmspace
#if defined (ARDUINO_ARCH_ESP8266) || defined (ESP32)
#include <pgmspace.h>
#define PRIPSTR "%s"
#ifndef pgm_read_ptr
#define pgm_read_ptr(p) (*(p))
#endif
#elif defined (ARDUINO) && !defined (ESP_PLATFORM) && ! defined (__arm__) && !defined (__ARDUINO_X86__) || defined (XMEGA)
#include <avr/pgmspace.h>
#define PRIPSTR "%S"
#else // !defined (ARDUINO) || defined (ESP_PLATFORM) || defined (__arm__) || defined (__ARDUINO_X86__) && !defined (XMEGA)
#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
#ifdef ARDUINO_ARCH_AVR
#include <avr/pgmspace.h>
#endif
#ifndef pgm_read_byte
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
#endif
#endif // !defined (ARDUINO)
#ifndef prog_uint16_t
typedef uint16_t prog_uint16_t;
#endif
#ifndef PSTR
#define PSTR(x) (x)
#endif
#ifndef printf_P
#define printf_P printf
#endif
#ifndef strlen_P
#define strlen_P strlen
#endif
#ifndef PROGMEM
#define PROGMEM
#endif
#ifndef pgm_read_word
#define pgm_read_word(p) (*(p))
#endif
#if !defined pgm_read_ptr || defined ARDUINO_ARCH_MBED
#define pgm_read_ptr(p) (*(p))
#endif
#ifndef PRIPSTR
#define PRIPSTR "%s"
#endif
#endif // !defined (ARDUINO) || defined (ESP_PLATFORM) || defined (__arm__) || defined (__ARDUINO_X86__) && !defined (XMEGA)
#endif //Everything else
#if defined (SPI_HAS_TRANSACTION) && !defined (SPI_UART) && !defined (SOFTSPI)
#define RF24_SPI_TRANSACTIONS
#endif // defined (SPI_HAS_TRANSACTION) && !defined (SPI_UART) && !defined (SOFTSPI)
#endif // __RF24_CONFIG_H__

128
nRF24L01.h

@ -0,0 +1,128 @@
/*
Copyright (c) 2007 Stefan Engelke <mbox@stefanengelke.de>
Portions Copyright (C) 2011 Greg Copeland
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/* Memory Map */
#define NRF_CONFIG 0x00
#define EN_AA 0x01
#define EN_RXADDR 0x02
#define SETUP_AW 0x03
#define SETUP_RETR 0x04
#define RF_CH 0x05
#define RF_SETUP 0x06
#define NRF_STATUS 0x07
#define OBSERVE_TX 0x08
#define CD 0x09
#define RX_ADDR_P0 0x0A
#define RX_ADDR_P1 0x0B
#define RX_ADDR_P2 0x0C
#define RX_ADDR_P3 0x0D
#define RX_ADDR_P4 0x0E
#define RX_ADDR_P5 0x0F
#define TX_ADDR 0x10
#define RX_PW_P0 0x11
#define RX_PW_P1 0x12
#define RX_PW_P2 0x13
#define RX_PW_P3 0x14
#define RX_PW_P4 0x15
#define RX_PW_P5 0x16
#define FIFO_STATUS 0x17
#define DYNPD 0x1C
#define FEATURE 0x1D
/* Bit Mnemonics */
#define MASK_RX_DR 6
#define MASK_TX_DS 5
#define MASK_MAX_RT 4
#define EN_CRC 3
#define CRCO 2
#define PWR_UP 1
#define PRIM_RX 0
#define ENAA_P5 5
#define ENAA_P4 4
#define ENAA_P3 3
#define ENAA_P2 2
#define ENAA_P1 1
#define ENAA_P0 0
#define ERX_P5 5
#define ERX_P4 4
#define ERX_P3 3
#define ERX_P2 2
#define ERX_P1 1
#define ERX_P0 0
#define AW 0
#define ARD 4
#define ARC 0
#define PLL_LOCK 4
#define CONT_WAVE 7
#define RF_DR 3
#define RF_PWR 6
#define RX_DR 6
#define TX_DS 5
#define MAX_RT 4
#define RX_P_NO 1
#define TX_FULL 0
#define PLOS_CNT 4
#define ARC_CNT 0
#define TX_REUSE 6
#define FIFO_FULL 5
#define TX_EMPTY 4
#define RX_FULL 1
#define RX_EMPTY 0
#define DPL_P5 5
#define DPL_P4 4
#define DPL_P3 3
#define DPL_P2 2
#define DPL_P1 1
#define DPL_P0 0
#define EN_DPL 2
#define EN_ACK_PAY 1
#define EN_DYN_ACK 0
/* Instruction Mnemonics */
#define R_REGISTER 0x00
#define W_REGISTER 0x20
#define REGISTER_MASK 0x1F
#define ACTIVATE 0x50
#define R_RX_PL_WID 0x60
#define R_RX_PAYLOAD 0x61
#define W_TX_PAYLOAD 0xA0
#define W_ACK_PAYLOAD 0xA8
#define FLUSH_TX 0xE1
#define FLUSH_RX 0xE2
#define REUSE_TX_PL 0xE3
#define RF24_NOP 0xFF
/* Non-P omissions */
#define LNA_HCURR 0
/* P model memory Map */
#define RPD 0x09
#define W_TX_PAYLOAD_NO_ACK 0xB0
/* P model bit Mnemonics */
#define RF_DR_LOW 5
#define RF_DR_HIGH 3
#define RF_PWR_LOW 1
#define RF_PWR_HIGH 2

42
printf.h

@ -0,0 +1,42 @@
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
/* Galileo support from spaniakos <spaniakos@gmail.com> */
/**
* @file printf.h
*
* Setup necessary to direct stdout to the Arduino Serial library, which
* enables 'printf'
*/
#ifndef __PRINTF_H__
#define __PRINTF_H__
#if defined(ARDUINO_ARCH_AVR) || defined(__ARDUINO_X86__)
int serial_putc(char c, FILE *)
{
Serial.write(c);
return c;
}
#endif
void printf_begin(void)
{
#if defined(ARDUINO_ARCH_AVR)
fdevopen(&serial_putc, 0);
#elif defined(__ARDUINO_X86__)
// JESUS - For reddirect stdout to /dev/ttyGS0 (Serial Monitor port)
stdout = freopen("/dev/ttyGS0", "w", stdout);
delay(500);
printf("Redirecting to Serial...");
#endif // defined(__ARDUINO_X86__)
}
#endif // __PRINTF_H__

452
statesNaming.h

@ -1,452 +0,0 @@
#include "Arduino.h"
#define FREQUENCY_915
#ifdef FREQUENCY_433
#define OPERATING_FREQUENCY 410
#elif defined(FREQUENCY_170)
#define OPERATING_FREQUENCY 130
#elif defined(FREQUENCY_470)
#define OPERATING_FREQUENCY 370
#elif defined(FREQUENCY_868)
#define OPERATING_FREQUENCY 862
#elif defined(FREQUENCY_915)
#define OPERATING_FREQUENCY 900
#else
#define OPERATING_FREQUENCY 410
#endif
#define BROADCAST_ADDRESS 0xFF
typedef enum RESPONSE_STATUS {
SUCCESS = 1,
ERR_UNKNOWN, /* something shouldn't happened */
ERR_NOT_SUPPORT,
ERR_NOT_IMPLEMENT,
ERR_NOT_INITIAL,
ERR_INVALID_PARAM,
ERR_DATA_SIZE_NOT_MATCH,
ERR_BUF_TOO_SMALL,
ERR_TIMEOUT,
ERR_HARDWARE,
ERR_HEAD_NOT_RECOGNIZED,
ERR_NO_RESPONSE_FROM_DEVICE,
ERR_WRONG_UART_CONFIG,
ERR_PACKET_TOO_BIG
} Status;
static String getResponseDescriptionByParams(byte status){
switch (status)
{
case SUCCESS:
return F("Success");
break;
case ERR_UNKNOWN:
return F("Unknown");
break;
case ERR_NOT_SUPPORT:
return F("Not support!");
break;
case ERR_NOT_IMPLEMENT:
return F("Not implement");
break;
case ERR_NOT_INITIAL:
return F("Not initial!");
break;
case ERR_INVALID_PARAM:
return F("Invalid param!");
break;
case ERR_DATA_SIZE_NOT_MATCH:
return F("Data size not match!");
break;
case ERR_BUF_TOO_SMALL:
return F("Buff too small!");
break;
case ERR_TIMEOUT:
return F("Timeout!!");
break;
case ERR_HARDWARE:
return F("Hardware error!");
break;
case ERR_HEAD_NOT_RECOGNIZED:
return F("Save mode returned not recognized!");
break;
case ERR_NO_RESPONSE_FROM_DEVICE:
return F("No response from device! (Check wiring)");
break;
case ERR_WRONG_UART_CONFIG:
return F("Wrong UART configuration! (BPS must be 9600 for configuration)");
break;
case ERR_PACKET_TOO_BIG:
return F("The device support only 58byte of data transmission!");
break;
default:
return F("Invalid status!");
}
}
enum UART_PARITY
{
MODE_00_8N1 = B00,
MODE_01_8O1 = B01,
MODE_10_8E1 = B10,
MODE_11_8N1 = B11
};
static String getUARTParityDescriptionByParams(byte uartParity){
switch (uartParity)
{
case MODE_00_8N1:
return F("8N1 (Default)");
break;
case MODE_01_8O1:
return F("8O1");
break;
case MODE_10_8E1:
return F("8E1");
break;
case MODE_11_8N1:
return F("8N1");
break;
default:
return F("Invalid UART Parity!");
}
}
enum UART_BPS_TYPE
{
UART_BPS_1200 = B000,
UART_BPS_2400 = B001,
UART_BPS_4800 = B010,
UART_BPS_9600 = B011,
UART_BPS_19200 = B100,
UART_BPS_38400 = B101,
UART_BPS_57600 = B110,
UART_BPS_115200 = B111
};
enum UART_BPS_RATE
{
UART_BPS_RATE_1200 = 1200,
UART_BPS_RATE_2400 = 2400,
UART_BPS_RATE_4800 = 4800,
UART_BPS_RATE_9600 = 9600,
UART_BPS_RATE_19200 = 19200,
UART_BPS_RATE_38400 = 38400,
UART_BPS_RATE_57600 = 57600,
UART_BPS_RATE_115200 = 115200
};
static String getUARTBaudRateDescriptionByParams(byte uartBaudRate)
{
switch (uartBaudRate)
{
case UART_BPS_1200:
return F("1200bps");
break;
case UART_BPS_2400:
return F("2400bps");
break;
case UART_BPS_4800:
return F("4800bps");
break;
case UART_BPS_9600:
return F("9600bps (default)");
break;
case UART_BPS_19200:
return F("19200bps");
break;
case UART_BPS_38400:
return F("38400bps");
break;
case UART_BPS_57600:
return F("57600bps");
break;
case UART_BPS_115200:
return F("115200bps");
break;
default:
return F("Invalid UART Baud Rate!");
}
}
enum AIR_DATA_RATE
{
AIR_DATA_RATE_000_03 = B000,
AIR_DATA_RATE_001_12 = B001,
AIR_DATA_RATE_010_24 = B010,
AIR_DATA_RATE_011_48 = B011,
AIR_DATA_RATE_100_96 = B100,
AIR_DATA_RATE_101_192 = B101,
AIR_DATA_RATE_110_192 = B110,
AIR_DATA_RATE_111_192 = B111
};
static String getAirDataRateDescriptionByParams(byte airDataRate)
{
switch (airDataRate)
{
case AIR_DATA_RATE_000_03:
return F("0.3kbps");
break;
case AIR_DATA_RATE_001_12:
return F("1.2kbps");
break;
case AIR_DATA_RATE_010_24:
return F("2.4kbps (default)");
break;
case AIR_DATA_RATE_011_48:
return F("4.8kbps");
break;
case AIR_DATA_RATE_100_96:
return F("9.6kbps");
break;
case AIR_DATA_RATE_101_192:
return F("19.2kbps");
break;
case AIR_DATA_RATE_110_192:
return F("19.2kbps");
break;
case AIR_DATA_RATE_111_192:
return F("19.2kbps");
break;
default:
return F("Invalid Air Data Rate!");
}
}
enum FIDEX_TRANSMISSION
{
FT_TRANSPARENT_TRANSMISSION = B0,
FT_FIXED_TRANSMISSION = B1
};
static String getFixedTransmissionDescriptionByParams(byte fixedTransmission)
{
switch (fixedTransmission)
{
case FT_TRANSPARENT_TRANSMISSION:
return F("Transparent transmission (default)");
break;
case FT_FIXED_TRANSMISSION:
return F("Fixed transmission (first three bytes can be used as high/low address and channel)");
break;
default:
return F("Invalid fixed transmission param!");
}
}
enum IO_DRIVE_MODE
{
IO_D_MODE_OPEN_COLLECTOR = B0,
IO_D_MODE_PUSH_PULLS_PULL_UPS = B1
};
static String getIODriveModeDescriptionDescriptionByParams(byte ioDriveMode)
{
switch (ioDriveMode)
{
case IO_D_MODE_OPEN_COLLECTOR:
return F("TXD, RXD, AUX are open-collectors");
break;
case IO_D_MODE_PUSH_PULLS_PULL_UPS:
return F("TXD, RXD, AUX are push-pulls/pull-ups");
break;
default:
return F("Invalid IO drive mode!");
}
}
enum WIRELESS_WAKE_UP_TIME
{
WAKE_UP_250 = B000,
WAKE_UP_500 = B001,
WAKE_UP_750 = B010,
WAKE_UP_1000 = B011,
WAKE_UP_1250 = B100,
WAKE_UP_1500 = B101,
WAKE_UP_1750 = B110,
WAKE_UP_2000 = B111
};
static String getWirelessWakeUPTimeDescriptionByParams(byte wirelessWakeUPTime)
{
switch (wirelessWakeUPTime)
{
case WAKE_UP_250:
return F("250ms (default)");
break;
case WAKE_UP_500:
return F("500ms");
break;
case WAKE_UP_750:
return F("750ms");
break;
case WAKE_UP_1000:
return F("1000ms");
break;
case WAKE_UP_1250:
return F("1250ms");
break;
case WAKE_UP_1500:
return F("1500ms");
break;
case WAKE_UP_1750:
return F("1750ms");
break;
case WAKE_UP_2000:
return F("2000ms");
break;
default:
return F("Invalid wireless wake-up mode!");
}
}
enum FORWARD_ERROR_CORRECTION_SWITCH
{
FEC_0_OFF = B0,
FEC_1_ON = B1
};
static String getFECDescriptionByParams(byte fec)
{
switch (fec)
{
case FEC_0_OFF:
return F("Turn off Forward Error Correction Switch");
break;
case FEC_1_ON:
return F("Turn on Forward Error Correction Switch (Default)");
break;
default:
return F("Invalid FEC param");
}
}
#ifdef E32_TTL_100
enum TRANSMISSION_POWER
{
POWER_20 = B00,
POWER_17 = B01,
POWER_14 = B10,
POWER_10 = B11
};
static String getTransmissionPowerDescriptionByParams(byte transmissionPower)
{
switch (transmissionPower)
{
case POWER_20:
return F("20dBm (Default)");
break;
case POWER_17:
return F("17dBm");
break;
case POWER_14:
return F("14dBm");
break;
case POWER_10:
return F("10dBm");
break;
default:
return F("Invalid transmission power param");
}
}
#elif defined(E32_TTL_500)
enum TRANSMISSION_POWER
{
POWER_27 = B00,
POWER_24 = B01,
POWER_21 = B10,
POWER_18 = B11
};
static String getTransmissionPowerDescriptionByParams(byte transmissionPower)
{
switch (transmissionPower)
{
case POWER_27:
return F("27dBm (Default)");
break;
case POWER_24:
return F("24dBm");
break;
case POWER_21:
return F("21dBm");
break;
case POWER_18:
return F("18dBm");
break;
default:
return F("Invalid transmission power param");
}
}
#elif defined(E32_TTL_1W)
enum TRANSMISSION_POWER
{
POWER_30 = B00,
POWER_27 = B01,
POWER_24 = B10,
POWER_21 = B11
};
static String getTransmissionPowerDescriptionByParams(byte transmissionPower)
{
switch (transmissionPower)
{
case POWER_30:
return F("30dBm (Default)");
break;
case POWER_27:
return F("27dBm");
break;
case POWER_24:
return F("24dBm");
break;
case POWER_21:
return F("21dBm");
break;
default:
return F("Invalid transmission power param");
}
}
#else
enum TRANSMISSION_POWER
{
POWER_20 = B00,
POWER_17 = B01,
POWER_14 = B10,
POWER_10 = B11
};
static String getTransmissionPowerDescriptionByParams(byte transmissionPower)
{
switch (transmissionPower)
{
case POWER_20:
return F("20dBm (Default)");
break;
case POWER_17:
return F("17dBm");
break;
case POWER_14:
return F("14dBm");
break;
case POWER_10:
return F("10dBm");
break;
default:
return F("Invalid transmission power param");
}
}
#endif
Loading…
Cancel
Save