Compare commits

..

No commits in common. "5ae054f3140390dd89ce501adb9341a4a7aa7e02" and "a2aa30212139636afc4ef4716b9bbdb5bbf9a629" have entirely different histories.

4 changed files with 25 additions and 41 deletions

View File

@ -90,7 +90,7 @@ const configData_t ConfigData_defaults = {
0 // checksum 0 // checksum
}; };
boolean InitEEPROM(); void InitEEPROM();
void EEPROM_Process(); void EEPROM_Process();
void StoreConfig_EEPROM(); void StoreConfig_EEPROM();
void GetConfig_EEPROM(); void GetConfig_EEPROM();

View File

@ -35,13 +35,12 @@ boolean checkEEPROMavailable();
* *
* This function initializes the EEPROM using the I2C_eeprom instance and checks if it's available. * This function initializes the EEPROM using the I2C_eeprom instance and checks if it's available.
*/ */
boolean InitEEPROM() void InitEEPROM()
{ {
Wire.begin();
ConfigData = ConfigData_defaults; ConfigData = ConfigData_defaults;
PersistenceData = {0}; PersistenceData = {0};
ee.begin(); ee.begin();
return checkEEPROMavailable(); checkEEPROMavailable();
} }
/** /**

View File

@ -79,7 +79,7 @@ void LoRa_Process()
if (e220ttl.available() > 1) if (e220ttl.available() > 1)
{ {
ResponseContainer rc = e220ttl.receiveMessageRSSI(); ResponseContainer rc = e220ttl.receiveMessageRSSI();
// If something goes wrong, print error // Is something goes wrong print error
if (rc.status.code != 1) if (rc.status.code != 1)
{ {
Serial.println(rc.status.getResponseDescription()); Serial.println(rc.status.getResponseDescription());
@ -96,45 +96,34 @@ void LoRa_Process()
#elif defined(FEATURE_ENABLE_UARTLORA) #elif defined(FEATURE_ENABLE_UARTLORA)
static char packageInput[32]; static char packageInput[32];
static bool packageReceived = false; static bool packageRecieved = false;
static unsigned int bufferPtr = 0; static unsigned int bufferPtr = 0;
int receivedSize = 0; int recievedSize = 0;
while (SerialLoRa.available() && !packageReceived) while (SerialLoRa.available() && packageRecieved == false)
{ {
if (bufferPtr < sizeof(packageInput) - 1) if (bufferPtr < sizeof(packageInput) - 1)
{ {
char c = SerialLoRa.read(); packageInput[bufferPtr] = SerialLoRa.read();
packageInput[bufferPtr] = c; packageInput[bufferPtr + 1] = 0; // always terminate String
packageInput[bufferPtr + 1] = '\0'; // always terminate string
if (c == '\n') if (packageInput[bufferPtr] == '\n')
{ {
packageReceived = true; packageRecieved = true;
receivedSize = bufferPtr; recievedSize = bufferPtr;
bufferPtr = 0; bufferPtr = 0;
Debug_pushMessage("Got LoRa UART: %s\n", packageInput); Debug_pushMessage("Got LoRa UART: %s\n", packageInput);
} }
else if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c == ' ' || c == ',' || c == '.')) // Accept numbers, uppercase letters, and some special chars else if ((packageInput[bufferPtr] >= 0x30) || (packageInput[bufferPtr] <= 0x5A)) // only accept Numbers, UpperCase-Letters and some special chars
{ {
bufferPtr++; bufferPtr++;
} }
else
{
Debug_pushMessage("Invalid character received: %c\n", c);
}
}
else
{
Debug_pushMessage("Buffer overflow. Resetting buffer.\n");
bufferPtr = 0;
} }
} }
if (packageReceived) if (packageRecieved) {
{ Parse_LoRa_UartCommand(packageInput, recievedSize);
Parse_LoRa_UartCommand(packageInput, receivedSize); packageRecieved = false;
packageReceived = false;
} }
#endif #endif
@ -262,14 +251,14 @@ void Parse_LoRa_UartCommand(char input[], int size)
while (ptr != NULL) while (ptr != NULL)
{ {
strncpy(command, ptr, sizeof(command) - 1); // Platz für Nullterminator lassen strncpy(command, ptr, sizeof(command) - 1); // Platz für Nullterminator lassen
command[sizeof(command) - 1] = '\0'; // Nullterminator setzen command[sizeof(command) - 1] = '\0'; // Nullterminator setzen
ptr = strtok(NULL, delimiter); ptr = strtok(NULL, delimiter);
if (ptr != NULL) if (ptr != NULL)
{ {
strncpy(value, ptr, sizeof(value) - 1); // Platz für Nullterminator lassen strncpy(value, ptr, sizeof(value) - 1); // Platz für Nullterminator lassen
value[sizeof(value) - 1] = '\0'; // Nullterminator setzen value[sizeof(value) - 1] = '\0'; // Nullterminator setzen
} }
else else
{ {

View File

@ -110,19 +110,13 @@ void setup()
Serial.print("\n\n-------------------START-------------------\n"); Serial.print("\n\n-------------------START-------------------\n");
Serial.print(globals.DeviceNameId); Serial.print(globals.DeviceNameId);
Serial.print("\nby Hiabuto Defense\n\n"); Serial.print("\nby Hiabuto Defense\n");
// Initialize EEPROM, load configuration, and persistence data from EEPROM // Initialize EEPROM, load configuration, and persistence data from EEPROM
if (InitEEPROM()) InitEEPROM();
{ GetConfig_EEPROM();
GetConfig_EEPROM(); GetPersistence_EEPROM();
GetPersistence_EEPROM(); Serial.print("\nEE-Init done");
Serial.printf("Initialized EEPROM at Address 0x%02X\n", I2C_EE_ADDRESS);
}
else
{
Serial.print("EEPROM not Initialized\n");
}
if (i2c_io.begin()) if (i2c_io.begin())
{ {
@ -215,6 +209,7 @@ void setup()
// Start cyclic EEPROM updates for Persistence Data Structure (PDS) // Start cyclic EEPROM updates for Persistence Data Structure (PDS)
tmrEEPROMCyclicPDS.start(); tmrEEPROMCyclicPDS.start();
Serial.print("\nSetup Done\n");
disp_FAC_1.init(); disp_FAC_1.init();
disp_FAC_1.setBrightness(5); disp_FAC_1.setBrightness(5);
@ -223,6 +218,7 @@ void setup()
disp_FAC_3.init(); disp_FAC_3.init();
disp_FAC_3.setBrightness(5); disp_FAC_3.setBrightness(5);
tmrEEPROMCyclicPDS.start();
tmrFactionTicker.start(); tmrFactionTicker.start();
tmrInputGetter.start(); tmrInputGetter.start();