99#include " esp32-hal.h"
1010#include " esp_wifi.h"
1111
12- static void (*new_cb)(const esp_now_recv_info_t *info, const uint8_t *data, int len, void *arg) = NULL ;
13- static void *new_arg = NULL ; // * tx_arg = NULL , * rx_arg = NULL ,
12+ static void (*new_cb)(const esp_now_recv_info_t *info, const uint8_t *data, int len, void *arg) = nullptr ;
13+ static void *new_arg = nullptr ; // * tx_arg = nullptr , * rx_arg = nullptr ,
1414static bool _esp_now_has_begun = false ;
1515static ESP_NOW_Peer *_esp_now_peers[ESP_NOW_MAX_TOTAL_PEER_NUM];
1616
17- static esp_err_t _esp_now_add_peer (const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, const uint8_t *lmk, ESP_NOW_Peer *_peer = NULL ) {
17+ static esp_err_t _esp_now_add_peer (const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, const uint8_t *lmk, ESP_NOW_Peer *_peer = nullptr ) {
1818 log_v (MACSTR, MAC2STR (mac_addr));
1919 if (esp_now_is_peer_exist (mac_addr)) {
2020 log_e (" Peer Already Exists" );
@@ -26,16 +26,16 @@ static esp_err_t _esp_now_add_peer(const uint8_t *mac_addr, uint8_t channel, wif
2626 memcpy (peer.peer_addr , mac_addr, ESP_NOW_ETH_ALEN);
2727 peer.channel = channel;
2828 peer.ifidx = iface;
29- peer.encrypt = lmk != NULL ;
29+ peer.encrypt = lmk != nullptr ;
3030 if (lmk) {
3131 memcpy (peer.lmk , lmk, ESP_NOW_KEY_LEN);
3232 }
3333
3434 esp_err_t result = esp_now_add_peer (&peer);
3535 if (result == ESP_OK) {
36- if (_peer != NULL ) {
36+ if (_peer != nullptr ) {
3737 for (uint8_t i = 0 ; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) {
38- if (_esp_now_peers[i] == NULL ) {
38+ if (_esp_now_peers[i] == nullptr ) {
3939 _esp_now_peers[i] = _peer;
4040 return ESP_OK;
4141 }
@@ -67,8 +67,8 @@ static esp_err_t _esp_now_del_peer(const uint8_t *mac_addr) {
6767 }
6868
6969 for (uint8_t i = 0 ; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) {
70- if (_esp_now_peers[i] != NULL && memcmp (mac_addr, _esp_now_peers[i]->addr (), ESP_NOW_ETH_ALEN) == 0 ) {
71- _esp_now_peers[i] = NULL ;
70+ if (_esp_now_peers[i] != nullptr && memcmp (mac_addr, _esp_now_peers[i]->addr (), ESP_NOW_ETH_ALEN) == 0 ) {
71+ _esp_now_peers[i] = nullptr ;
7272 break ;
7373 }
7474 }
@@ -87,7 +87,7 @@ static esp_err_t _esp_now_modify_peer(const uint8_t *mac_addr, uint8_t channel,
8787 memcpy (peer.peer_addr , mac_addr, ESP_NOW_ETH_ALEN);
8888 peer.channel = channel;
8989 peer.ifidx = iface;
90- peer.encrypt = lmk != NULL ;
90+ peer.encrypt = lmk != nullptr ;
9191 if (lmk) {
9292 memcpy (peer.lmk , lmk, ESP_NOW_KEY_LEN);
9393 }
@@ -111,17 +111,17 @@ static void _esp_now_rx_cb(const esp_now_recv_info_t *info, const uint8_t *data,
111111 bool broadcast = memcmp (info->des_addr , ESP_NOW.BROADCAST_ADDR , ESP_NOW_ETH_ALEN) == 0 ;
112112 log_v (" %s from " MACSTR " , data length : %u" , broadcast ? " Broadcast" : " Unicast" , MAC2STR (info->src_addr ), len);
113113 log_buf_v (data, len);
114- if (!esp_now_is_peer_exist (info->src_addr ) && new_cb != NULL ) {
114+ if (!esp_now_is_peer_exist (info->src_addr ) && new_cb != nullptr ) {
115115 log_v (" Calling new_cb, peer not found." );
116116 new_cb (info, data, len, new_arg);
117117 return ;
118118 }
119119 // find the peer and call it's callback
120120 for (uint8_t i = 0 ; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) {
121- if (_esp_now_peers[i] != NULL ) {
121+ if (_esp_now_peers[i] != nullptr ) {
122122 log_v (" Checking peer " MACSTR, MAC2STR (_esp_now_peers[i]->addr ()));
123123 }
124- if (_esp_now_peers[i] != NULL && memcmp (info->src_addr , _esp_now_peers[i]->addr (), ESP_NOW_ETH_ALEN) == 0 ) {
124+ if (_esp_now_peers[i] != nullptr && memcmp (info->src_addr , _esp_now_peers[i]->addr (), ESP_NOW_ETH_ALEN) == 0 ) {
125125 log_v (" Calling onReceive" );
126126 _esp_now_peers[i]->onReceive (data, len, broadcast);
127127 return ;
@@ -133,7 +133,7 @@ static void _esp_now_tx_cb(const uint8_t *mac_addr, esp_now_send_status_t status
133133 log_v (MACSTR " : %s" , MAC2STR (mac_addr), (status == ESP_NOW_SEND_SUCCESS) ? " SUCCESS" : " FAILED" );
134134 // find the peer and call it's callback
135135 for (uint8_t i = 0 ; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) {
136- if (_esp_now_peers[i] != NULL && memcmp (mac_addr, _esp_now_peers[i]->addr (), ESP_NOW_ETH_ALEN) == 0 ) {
136+ if (_esp_now_peers[i] != nullptr && memcmp (mac_addr, _esp_now_peers[i]->addr (), ESP_NOW_ETH_ALEN) == 0 ) {
137137 _esp_now_peers[i]->onSent (status == ESP_NOW_SEND_SUCCESS);
138138 return ;
139139 }
@@ -197,7 +197,7 @@ bool ESP_NOW_Class::end() {
197197 }
198198 // remove all peers
199199 for (uint8_t i = 0 ; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) {
200- if (_esp_now_peers[i] != NULL ) {
200+ if (_esp_now_peers[i] != nullptr ) {
201201 removePeer (*_esp_now_peers[i]);
202202 }
203203 }
@@ -249,7 +249,7 @@ size_t ESP_NOW_Class::write(const uint8_t *data, size_t len) {
249249 if (len > ESP_NOW_MAX_DATA_LEN) {
250250 len = ESP_NOW_MAX_DATA_LEN;
251251 }
252- esp_err_t result = esp_now_send (NULL , data, len);
252+ esp_err_t result = esp_now_send (nullptr , data, len);
253253 if (result == ESP_OK) {
254254 return len;
255255 } else if (result == ESP_ERR_ESPNOW_NOT_INIT) {
@@ -292,7 +292,7 @@ ESP_NOW_Peer::ESP_NOW_Peer(const uint8_t *mac_addr, uint8_t channel, wifi_interf
292292 }
293293 chan = channel;
294294 ifc = iface;
295- encrypt = lmk != NULL ;
295+ encrypt = lmk != nullptr ;
296296 if (encrypt) {
297297 memcpy (key, lmk, 16 );
298298 }
@@ -305,7 +305,7 @@ bool ESP_NOW_Peer::add() {
305305 if (added) {
306306 return true ;
307307 }
308- if (_esp_now_add_peer (mac, chan, ifc, encrypt ? key : NULL , this ) != ESP_OK) {
308+ if (_esp_now_add_peer (mac, chan, ifc, encrypt ? key : nullptr , this ) != ESP_OK) {
309309 return false ;
310310 }
311311 log_v (" Peer added - " MACSTR, MAC2STR (mac));
@@ -350,7 +350,7 @@ bool ESP_NOW_Peer::setChannel(uint8_t channel) {
350350 if (!_esp_now_has_begun || !added) {
351351 return true ;
352352 }
353- return _esp_now_modify_peer (mac, chan, ifc, encrypt ? key : NULL ) == ESP_OK;
353+ return _esp_now_modify_peer (mac, chan, ifc, encrypt ? key : nullptr ) == ESP_OK;
354354}
355355
356356wifi_interface_t ESP_NOW_Peer::getInterface () const {
@@ -362,22 +362,22 @@ bool ESP_NOW_Peer::setInterface(wifi_interface_t iface) {
362362 if (!_esp_now_has_begun || !added) {
363363 return true ;
364364 }
365- return _esp_now_modify_peer (mac, chan, ifc, encrypt ? key : NULL ) == ESP_OK;
365+ return _esp_now_modify_peer (mac, chan, ifc, encrypt ? key : nullptr ) == ESP_OK;
366366}
367367
368368bool ESP_NOW_Peer::isEncrypted () const {
369369 return encrypt;
370370}
371371
372372bool ESP_NOW_Peer::setKey (const uint8_t *lmk) {
373- encrypt = lmk != NULL ;
373+ encrypt = lmk != nullptr ;
374374 if (encrypt) {
375375 memcpy (key, lmk, 16 );
376376 }
377377 if (!_esp_now_has_begun || !added) {
378378 return true ;
379379 }
380- return _esp_now_modify_peer (mac, chan, ifc, encrypt ? key : NULL ) == ESP_OK;
380+ return _esp_now_modify_peer (mac, chan, ifc, encrypt ? key : nullptr ) == ESP_OK;
381381}
382382
383383size_t ESP_NOW_Peer::send (const uint8_t *data, int len) {
0 commit comments