Skip to content

Commit 5fac283

Browse files
committed
Reduce codesize of setOutputPower
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.
1 parent 5b767a3 commit 5fac283

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -369,17 +369,18 @@ WiFiPhyMode_t ESP8266WiFiGenericClass::getPhyMode() {
369369
*/
370370
void ESP8266WiFiGenericClass::setOutputPower(float dBm) {
371371

372-
if(dBm > 20.5f) {
373-
dBm = 20.5f;
374-
} else if(dBm < 0.0f) {
375-
dBm = 0.0f;
372+
int i_dBm = int(dBm * 4.0f);
373+
374+
// i_dBm 82 == 20.5 dBm
375+
if(i_dBm > 82) {
376+
i_dBm = 82;
377+
} else if(i_dBm < 0) {
378+
i_dBm = 0;
376379
}
377380

378-
uint8_t val = (dBm*4.0f);
379-
system_phy_set_max_tpw(val);
381+
system_phy_set_max_tpw((uint8_t) i_dBm);
380382
}
381383

382-
383384
/**
384385
* store WiFi config in SDK flash area
385386
* @param persistent

0 commit comments

Comments
 (0)