Skip to content

Commit

Permalink
Merge pull request #139 from doudar/Double_Power
Browse files Browse the repository at this point in the history
Added Double Power
  • Loading branch information
fireyeti authored Mar 17, 2021
2 parents a54ef2e + dffc68a commit 2389e8d
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/BLE_Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ void BLECommunications(void *pvParameters)
if (sensorData->hasPower())
{
int power = sensorData->getPower();
userConfig.setSimulatedWatts(power);
if (userConfig.getDoublePower())
{
userConfig.setSimulatedWatts(power * 2);
}
else
{
userConfig.setSimulatedWatts(power);
}
spinBLEClient.connectedPM |= true;
logBufP += sprintf(logBufP, " PW(%d)", power % 10000);
}
Expand All @@ -93,12 +100,12 @@ void BLECommunications(void *pvParameters)
}
else if (!pClient->isConnected()) //This shouldn't ever be called really..........
{
if(pClient->disconnect()==0) //0 is a suscessful disconnect :?
{
BLEDevice::deleteClient(pClient);
vTaskDelay(100/portTICK_PERIOD_MS);
debugDirector("Workaround connect");
myAdvertisedDevice.doConnect = true;
if (pClient->disconnect() == 0) //0 is a suscessful disconnect :?
{
BLEDevice::deleteClient(pClient);
vTaskDelay(100 / portTICK_PERIOD_MS);
debugDirector("Workaround connect");
myAdvertisedDevice.doConnect = true;
}
}
}
Expand All @@ -112,9 +119,9 @@ void BLECommunications(void *pvParameters)
{
calculateInstPwrFromHR();
}
#ifdef DEBUG_HR_TO_PWR
calculateInstPwrFromHR();
#endif
#ifdef DEBUG_HR_TO_PWR
calculateInstPwrFromHR();
#endif

if (!spinBLEClient.connectedPM && !userPWC.hr2Pwr)
{
Expand All @@ -126,7 +133,7 @@ void BLECommunications(void *pvParameters)
userConfig.setSimulatedHr(0);
}

if (connectedClientCount()>0)
if (connectedClientCount() > 0)
{
//update the BLE information on the server
computeCSC();
Expand All @@ -144,15 +151,14 @@ void BLECommunications(void *pvParameters)
}
else
{

}
if (connectedClientCount()==0)
if (connectedClientCount() == 0)
{
digitalWrite(LED_PIN, LOW); //blink if no client connected
}
if(BLEDevice::getAdvertising())
if (BLEDevice::getAdvertising())
{
if(!(BLEDevice::getAdvertising()->isAdvertising())&& (BLEDevice::getServer()->getConnectedCount()<CONFIG_BT_NIMBLE_MAX_CONNECTIONS-NUM_BLE_DEVICES))
if (!(BLEDevice::getAdvertising()->isAdvertising()) && (BLEDevice::getServer()->getConnectedCount() < CONFIG_BT_NIMBLE_MAX_CONNECTIONS - NUM_BLE_DEVICES))
{
debugDirector("Starting Advertising From Communication Loop");
BLEDevice::startAdvertising();
Expand All @@ -167,4 +173,3 @@ void BLECommunications(void *pvParameters)
#endif
}
}

0 comments on commit 2389e8d

Please sign in to comment.