Extend BLEDevice::setPower() to include powerType parameter. It's optional and set to ESP_BLE_PWR_TYPE_DEFAULT for compatibility. (#3623)

Extend BLEDevice::setPower() to include powerType parameter. It's optional and set to ESP_BLE_PWR_TYPE_DEFAULT for compatibility.
This commit is contained in:
Robert Alfaro 2020-01-20 06:09:02 -08:00 committed by Me No Dev
parent 89351e3ade
commit cb005fc8b5
2 changed files with 19 additions and 4 deletions

View File

@ -441,11 +441,26 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
* * ESP_PWR_LVL_P1
* * ESP_PWR_LVL_P4
* * ESP_PWR_LVL_P7
*
* The power types can be one of:
* * ESP_BLE_PWR_TYPE_CONN_HDL0
* * ESP_BLE_PWR_TYPE_CONN_HDL1
* * ESP_BLE_PWR_TYPE_CONN_HDL2
* * ESP_BLE_PWR_TYPE_CONN_HDL3
* * ESP_BLE_PWR_TYPE_CONN_HDL4
* * ESP_BLE_PWR_TYPE_CONN_HDL5
* * ESP_BLE_PWR_TYPE_CONN_HDL6
* * ESP_BLE_PWR_TYPE_CONN_HDL7
* * ESP_BLE_PWR_TYPE_CONN_HDL8
* * ESP_BLE_PWR_TYPE_ADV
* * ESP_BLE_PWR_TYPE_SCAN
* * ESP_BLE_PWR_TYPE_DEFAULT
* @param [in] powerType.
* @param [in] powerLevel.
*/
/* STATIC */ void BLEDevice::setPower(esp_power_level_t powerLevel) {
log_v(">> setPower: %d", powerLevel);
esp_err_t errRc = ::esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, powerLevel);
/* STATIC */ void BLEDevice::setPower(esp_power_level_t powerLevel, esp_ble_power_type_t powerType) {
log_v(">> setPower: %d (type: %d)", powerLevel, powerType);
esp_err_t errRc = ::esp_ble_tx_power_set(powerType, powerLevel);
if (errRc != ESP_OK) {
log_e("esp_ble_tx_power_set: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
};

View File

@ -37,7 +37,7 @@ public:
static BLEScan* getScan(); // Get the scan object
static std::string getValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID); // Get the value of a characteristic of a service on a server.
static void init(std::string deviceName); // Initialize the local BLE environment.
static void setPower(esp_power_level_t powerLevel); // Set our power level.
static void setPower(esp_power_level_t powerLevel, esp_ble_power_type_t powerType=ESP_BLE_PWR_TYPE_DEFAULT); // Set our power level.
static void setValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID, std::string value); // Set the value of a characteristic on a service on a server.
static std::string toString(); // Return a string representation of our device.
static void whiteListAdd(BLEAddress address); // Add an entry to the BLE white list.