Skip to content

Commit

Permalink
added automatic pairing for receiver dongle if devlist empty
Browse files Browse the repository at this point in the history
  • Loading branch information
f1andrew committed Jul 19, 2023
1 parent 8cf8fdb commit 4edce19
Showing 1 changed file with 50 additions and 44 deletions.
94 changes: 50 additions & 44 deletions arduino/arduino_nRF52840/arduino_nRF52840.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1207,65 +1207,71 @@ void bleConnectCallback(uint16_t conn_handle)
}
else
{
i = 0;

for (i = 0; i < maxBleDevListSize; i++)
{
if (!strcmp((char *)central_name, (char *)bleDeviceNameList[i]))
if(bleDeviceNameListIndex == 0 && !strcmp((char *)central_name, "AceRK receiver")) {
// Adding receiver dongle automatically since dev list is empty
strcpy(bleDeviceNameList[bleDeviceNameListIndex++], central_name);
flag_saveListToFile = true;
} else{
i = 0;

for (i = 0; i < maxBleDevListSize; i++)
{
#ifdef DEBUG
Serial.println("Device found in list - " + String(central_name));
#endif

if (flag_addDevProsStarted)
if (!strcmp((char *)central_name, (char *)bleDeviceNameList[i]))
{
connection->disconnect();

#ifdef DEBUG
Serial.print("Disconnected - Device already present in list");
Serial.println(central_name);
Serial.println("Device found in list - " + String(central_name));
#endif

if (flag_addDevProsStarted)
{
connection->disconnect();

#ifdef DEBUG
Serial.print("Disconnected - Device already present in list");
Serial.println(central_name);
#endif
}
else
{
}
break;
}
else
{
}
break;
}
}

if (i >= maxBleDevListSize)
{
if (flag_addDevProsStarted)

if (i >= maxBleDevListSize)
{
flag_addDevProsStarted = 0;
updateStatusLED();
if (bleDeviceNameListIndex > maxBleDevListSize)
if (flag_addDevProsStarted)
{
connection->disconnect();

#ifdef DEBUG
Serial.println("ERROR: Device list is full");
#endif
flag_addDevProsStarted = 0;
updateStatusLED();
if (bleDeviceNameListIndex > maxBleDevListSize)
{
connection->disconnect();

#ifdef DEBUG
Serial.println("ERROR: Device list is full");
#endif
}
else
{
#ifdef DEBUG
Serial.println("SUCCESS");
Serial.println(String(central_name) + " Connected and Name added into list");
#endif

strcpy(bleDeviceNameList[bleDeviceNameListIndex++], central_name);
flag_saveListToFile = true;
}
}
else
{
connection->disconnect();

#ifdef DEBUG
Serial.println("SUCCESS");
Serial.println(String(central_name) + " Connected and Name added into list");
Serial.println(String(central_name) + " Disconnected - Not present in the list");
#endif

strcpy(bleDeviceNameList[bleDeviceNameListIndex++], central_name);
flag_saveListToFile = true;
}
}
else
{
connection->disconnect();

#ifdef DEBUG
Serial.println(String(central_name) + " Disconnected - Not present in the list");
#endif
}
}
}

Expand Down

0 comments on commit 4edce19

Please sign in to comment.