40
40
//| def __init__(
41
41
//| self,
42
42
//| mac: bytes,
43
+ //| *,
43
44
//| lmk: Optional[bytes],
44
45
//| channel: int = 0,
45
46
//| interface: int = 0,
46
- //| encrypt : bool = False,
47
+ //| encrypted : bool = False,
47
48
//| ) -> None:
48
49
//| """Construct a new peer object.
49
50
//|
50
51
//| :param bytes mac: The mac address of the peer.
51
52
//| :param bytes lmk: The Local Master Key (lmk) of the peer.
52
53
//| :param int channel: The peer's channel. Default: 0 ie. use the current channel.
53
54
//| :param int interface: The WiFi interface to use. Default: 0 ie. STA.
54
- //| :param bool encrypt : Whether or not to use encryption.
55
+ //| :param bool encrypted : Whether or not to use encryption.
55
56
//| """
56
57
//| ...
57
58
STATIC mp_obj_t espnow_peer_make_new (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * all_args ) {
58
- enum { ARG_mac , ARG_lmk , ARG_channel , ARG_interface , ARG_encrypt };
59
+ enum { ARG_mac , ARG_lmk , ARG_channel , ARG_interface , ARG_encrypted };
59
60
static const mp_arg_t allowed_args [] = {
60
61
{ MP_QSTR_mac , MP_ARG_OBJ | MP_ARG_REQUIRED },
61
- { MP_QSTR_lmk , MP_ARG_OBJ , { .u_obj = mp_const_none } },
62
- { MP_QSTR_channel , MP_ARG_INT , { .u_obj = mp_const_none } },
63
- { MP_QSTR_interface ,MP_ARG_INT , { .u_obj = mp_const_none } },
64
- { MP_QSTR_encrypt , MP_ARG_BOOL , { .u_obj = mp_const_none } },
62
+ { MP_QSTR_lmk , MP_ARG_OBJ | MP_ARG_KW_ONLY , { .u_obj = mp_const_none } },
63
+ { MP_QSTR_channel , MP_ARG_INT | MP_ARG_KW_ONLY , { .u_int = 0 } },
64
+ { MP_QSTR_interface ,MP_ARG_INT | MP_ARG_KW_ONLY , { .u_int = 0 } },
65
+ { MP_QSTR_encrypted , MP_ARG_BOOL | MP_ARG_KW_ONLY , { .u_bool = false } },
65
66
};
66
67
67
68
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
@@ -77,20 +78,11 @@ STATIC mp_obj_t espnow_peer_make_new(const mp_obj_type_t *type, size_t n_args, s
77
78
78
79
memcpy (self -> peer_info .peer_addr , common_hal_espnow_get_bytes_len (args [ARG_mac ].u_obj , ESP_NOW_ETH_ALEN ), ESP_NOW_ETH_ALEN );
79
80
80
- const mp_obj_t channel = args [ARG_channel ].u_obj ;
81
- if (channel != mp_const_none ) {
82
- self -> peer_info .channel = mp_arg_validate_int_range (mp_obj_get_int (channel ), 0 , 14 , MP_QSTR_channel );
83
- }
81
+ self -> peer_info .channel = mp_arg_validate_int_range (args [ARG_channel ].u_int , 0 , 14 , MP_QSTR_channel );
84
82
85
- const mp_obj_t interface = args [ARG_interface ].u_obj ;
86
- if (interface != mp_const_none ) {
87
- self -> peer_info .ifidx = (wifi_interface_t )mp_arg_validate_int_range (mp_obj_get_int (interface ), 0 , 1 , MP_QSTR_interface );
88
- }
83
+ self -> peer_info .ifidx = (wifi_interface_t )mp_arg_validate_int_range (args [ARG_interface ].u_int , 0 , 1 , MP_QSTR_interface );
89
84
90
- const mp_obj_t encrypt = args [ARG_encrypt ].u_obj ;
91
- if (encrypt != mp_const_none ) {
92
- self -> peer_info .encrypt = mp_obj_is_true (encrypt );
93
- }
85
+ self -> peer_info .encrypt = args [ARG_encrypted ].u_bool ;
94
86
95
87
const mp_obj_t lmk = args [ARG_lmk ].u_obj ;
96
88
if (lmk != mp_const_none ) {
0 commit comments