Skip to content

Commit

Permalink
Reduce codesize of setOutputPower (#7572)
Browse files Browse the repository at this point in the history
The logic can be simplified by using integer logic without a functional
change. Reduces code size by 40% (78 bytes -> 46 bytes) and silences
a Warith-conversion warning.
  • Loading branch information
dirkmueller committed Sep 2, 2020
1 parent ca149a2 commit df01d19
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,17 +369,18 @@ WiFiPhyMode_t ESP8266WiFiGenericClass::getPhyMode() {
*/
void ESP8266WiFiGenericClass::setOutputPower(float dBm) {

if(dBm > 20.5f) {
dBm = 20.5f;
} else if(dBm < 0.0f) {
dBm = 0.0f;
int i_dBm = int(dBm * 4.0f);

// i_dBm 82 == 20.5 dBm
if(i_dBm > 82) {
i_dBm = 82;
} else if(i_dBm < 0) {
i_dBm = 0;
}

uint8_t val = (dBm*4.0f);
system_phy_set_max_tpw(val);
system_phy_set_max_tpw((uint8_t) i_dBm);
}


/**
* store WiFi config in SDK flash area
* @param persistent
Expand Down

0 comments on commit df01d19

Please sign in to comment.