Skip to content

Commit 8814ee0

Browse files
authored
Merge pull request micropython#6542 from todbot/wifi-tx-power
Add wifi.radio.tx_power
2 parents 2ae791a + 2d7793e commit 8814ee0

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

ports/espressif/common-hal/wifi/Radio.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ void common_hal_wifi_radio_set_mac_address(wifi_radio_obj_t *self, const uint8_t
139139
esp_wifi_set_mac(ESP_IF_WIFI_STA, mac);
140140
}
141141

142+
uint8_t common_hal_wifi_radio_get_tx_power(wifi_radio_obj_t *self) {
143+
int8_t tx_power;
144+
esp_wifi_get_max_tx_power(&tx_power);
145+
return tx_power / 4;
146+
}
147+
148+
void common_hal_wifi_radio_set_tx_power(wifi_radio_obj_t *self, const uint8_t tx_power) {
149+
esp_wifi_set_max_tx_power(tx_power * 4);
150+
}
151+
142152
mp_obj_t common_hal_wifi_radio_get_mac_address_ap(wifi_radio_obj_t *self) {
143153
uint8_t mac[MAC_ADDRESS_LENGTH];
144154
esp_wifi_get_mac(ESP_IF_WIFI_AP, mac);

shared-bindings/wifi/Radio.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,27 @@ MP_PROPERTY_GETSET(wifi_radio_mac_address_obj,
138138
(mp_obj_t)&wifi_radio_get_mac_address_obj,
139139
(mp_obj_t)&wifi_radio_set_mac_address_obj);
140140

141+
//| tx_power: int
142+
//| """Wifi transmission power, in dBm."""
143+
//|
144+
STATIC mp_obj_t wifi_radio_get_tx_power(mp_obj_t self_in) {
145+
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in);
146+
return mp_obj_new_int(common_hal_wifi_radio_get_tx_power(self));
147+
}
148+
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_tx_power_obj, wifi_radio_get_tx_power);
149+
150+
STATIC mp_obj_t wifi_radio_set_tx_power(mp_obj_t self_in, mp_obj_t tx_power_in) {
151+
mp_int_t tx_power = mp_obj_get_int(tx_power_in);
152+
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in);
153+
common_hal_wifi_radio_set_tx_power(self, tx_power);
154+
return mp_const_none;
155+
}
156+
MP_DEFINE_CONST_FUN_OBJ_2(wifi_radio_set_tx_power_obj, wifi_radio_set_tx_power);
157+
158+
MP_PROPERTY_GETSET(wifi_radio_tx_power_obj,
159+
(mp_obj_t)&wifi_radio_get_tx_power_obj,
160+
(mp_obj_t)&wifi_radio_set_tx_power_obj);
161+
141162
//| mac_address_ap: ReadableBuffer
142163
//| """MAC address for the AP. When the address is altered after interface is started
143164
//| the changes would only be reflected once the interface restarts."""
@@ -549,6 +570,7 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = {
549570
{ MP_ROM_QSTR(MP_QSTR_mac_address), MP_ROM_PTR(&wifi_radio_mac_address_obj) },
550571
{ MP_ROM_QSTR(MP_QSTR_mac_address_ap), MP_ROM_PTR(&wifi_radio_mac_address_ap_obj) },
551572

573+
{ MP_ROM_QSTR(MP_QSTR_tx_power), MP_ROM_PTR(&wifi_radio_tx_power_obj) },
552574
{ MP_ROM_QSTR(MP_QSTR_start_scanning_networks), MP_ROM_PTR(&wifi_radio_start_scanning_networks_obj) },
553575
{ MP_ROM_QSTR(MP_QSTR_stop_scanning_networks), MP_ROM_PTR(&wifi_radio_stop_scanning_networks_obj) },
554576

shared-bindings/wifi/Radio.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ extern void common_hal_wifi_radio_set_mac_address(wifi_radio_obj_t *self, const
8282
extern mp_obj_t common_hal_wifi_radio_get_mac_address_ap(wifi_radio_obj_t *self);
8383
extern void common_hal_wifi_radio_set_mac_address_ap(wifi_radio_obj_t *self, const uint8_t *mac);
8484

85+
extern uint8_t common_hal_wifi_radio_get_tx_power(wifi_radio_obj_t *self);
86+
extern void common_hal_wifi_radio_set_tx_power(wifi_radio_obj_t *self, const uint8_t power);
87+
8588
extern mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self);
8689
extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self);
8790

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy