mirror of
https://github.com/m5stack/M5Stack_MicroPython.git
synced 2026-05-20 10:14:44 -07:00
Refactored 'machine.UART' module
changes in buffering mode and callbacks Updated (again) 'utimeq' module fix handling if time values More events handling in 'network' module not enabled by default
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -166,8 +166,34 @@ static bool wifi_sta_connected = false;
|
||||
static uint8_t _isConnected = 0;
|
||||
|
||||
static mp_obj_t event_callback = NULL;
|
||||
static mp_obj_t probereq_callback = NULL;
|
||||
static QueueHandle_t wifi_mutex = NULL;
|
||||
|
||||
#ifdef INCLUDE_PROBEREQRECVED
|
||||
|
||||
static QueueHandle_t probereq_mutex = NULL;
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
static void processPROBEREQRECVED(const uint8_t *frame, int len, int rssi)
|
||||
{
|
||||
if (probereq_callback != NULL) {
|
||||
if (probereq_mutex) xSemaphoreTake(probereq_mutex, 1000);
|
||||
//mp_obj_t tuple[3];
|
||||
mp_obj_dict_t *dct = mp_obj_new_dict(0);
|
||||
mp_obj_dict_store(dct, mp_obj_new_str("rssi", 4, false), mp_obj_new_int(rssi));
|
||||
mp_obj_dict_store(dct, mp_obj_new_str("len", 3, false), mp_obj_new_int(len));
|
||||
mp_obj_dict_store(dct, mp_obj_new_str("frame", 5, false), mp_obj_new_str((const char*)frame, len, false));
|
||||
|
||||
//tuple[0] = mp_obj_new_int(SYSTEM_EVENT_AP_PROBEREQRECVED);
|
||||
//tuple[1] = mp_obj_new_str("Receive probe request packet", 28, false);
|
||||
//tuple[2] = dct;
|
||||
|
||||
mp_sched_schedule(probereq_callback, dct); //mp_obj_new_tuple(3, tuple));
|
||||
if (probereq_mutex) xSemaphoreGive(probereq_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------
|
||||
static void processEvent_callback(system_event_t *event)
|
||||
@@ -343,6 +369,7 @@ STATIC mp_obj_t get_wlan(size_t n_args, const mp_obj_t *args) {
|
||||
ESP_EXCEPTIONS( esp_wifi_set_mode(0) );
|
||||
ESP_EXCEPTIONS( esp_wifi_start() );
|
||||
ESP_LOGD("modnetwork", "Started");
|
||||
|
||||
initialized = 1;
|
||||
}
|
||||
|
||||
@@ -368,6 +395,10 @@ STATIC mp_obj_t esp_initialize() {
|
||||
|
||||
if (wifi_mutex == NULL) wifi_mutex = xSemaphoreCreateMutex();
|
||||
|
||||
#ifdef INCLUDE_PROBEREQRECVED
|
||||
if (probereq_mutex == NULL) probereq_mutex = xSemaphoreCreateMutex();
|
||||
esp_wifi_set_sta_rx_probe_req(processPROBEREQRECVED);
|
||||
#endif
|
||||
initialized = 1;
|
||||
}
|
||||
return mp_const_none;
|
||||
@@ -683,6 +714,27 @@ STATIC mp_obj_t esp_callback(size_t n_args, const mp_obj_t *args)
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_callback_obj, 1, 2, esp_callback);
|
||||
|
||||
#ifdef INCLUDE_PROBEREQRECVED
|
||||
//------------------------------------------------------------------------
|
||||
STATIC mp_obj_t esp_probereq_callback(size_t n_args, const mp_obj_t *args)
|
||||
{
|
||||
if (n_args == 1) {
|
||||
if (probereq_callback == NULL) return mp_const_false;
|
||||
return mp_const_true;
|
||||
}
|
||||
|
||||
if (probereq_mutex) xSemaphoreTake(probereq_mutex, 1000);
|
||||
if ((MP_OBJ_IS_FUN(args[1])) || (MP_OBJ_IS_METH(args[1]))) {
|
||||
probereq_callback = args[1];
|
||||
}
|
||||
else probereq_callback = NULL;
|
||||
if (probereq_mutex) xSemaphoreGive(probereq_mutex);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_probereq_callback_obj, 1, 2, esp_probereq_callback);
|
||||
#endif
|
||||
|
||||
STATIC const mp_map_elem_t wlan_if_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_active), (mp_obj_t)&esp_active_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_connect), (mp_obj_t)&esp_connect_obj },
|
||||
@@ -693,6 +745,9 @@ STATIC const mp_map_elem_t wlan_if_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_config), (mp_obj_t)&esp_config_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_ifconfig), (mp_obj_t)&esp_ifconfig_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_eventCB), (mp_obj_t)&esp_callback_obj },
|
||||
#ifdef INCLUDE_PROBEREQRECVED
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_probereqCB), (mp_obj_t)&esp_probereq_callback_obj },
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table);
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#ifndef MICROPY_INCLUDED_ESP32_MODNETWORK_H
|
||||
#define MICROPY_INCLUDED_ESP32_MODNETWORK_H
|
||||
|
||||
//#define INCLUDE_PROBEREQRECVED
|
||||
|
||||
enum { PHY_LAN8720, PHY_TLK110 };
|
||||
|
||||
typedef struct _wlan_if_obj_t {
|
||||
@@ -33,6 +35,11 @@ typedef struct _wlan_if_obj_t {
|
||||
int if_id;
|
||||
} wlan_if_obj_t;
|
||||
|
||||
#ifdef INCLUDE_PROBEREQRECVED
|
||||
typedef void (*wifi_sta_rx_probe_req_t)(const uint8_t *frame, int len, int rssi);
|
||||
extern esp_err_t esp_wifi_set_sta_rx_probe_req(wifi_sta_rx_probe_req_t cb);
|
||||
#endif
|
||||
|
||||
extern const mp_obj_type_t wlan_if_type;
|
||||
|
||||
#ifdef CONFIG_MICROPY_USE_ETHERNET
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// MicroPython version info
|
||||
#define MICROPY_GIT_TAG "ESP32_LoBo_v3.1.15"
|
||||
#define MICROPY_GIT_TAG "ESP32_LoBo_v3.1.16"
|
||||
#define MICROPY_GIT_HASH "gdaa8cfa8"
|
||||
#define MICROPY_BUILD_DATE "2017-02-03"
|
||||
#define MICROPY_BUILD_DATE "2017-02-04"
|
||||
#define MICROPY_VERSION_MAJOR (3)
|
||||
#define MICROPY_VERSION_MINOR (1)
|
||||
#define MICROPY_VERSION_MICRO (15)
|
||||
#define MICROPY_VERSION_STRING "3.1.15"
|
||||
#define MICROPY_VERSION_MICRO (16)
|
||||
#define MICROPY_VERSION_STRING "3.1.16"
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
#define DEBUG 0
|
||||
|
||||
// the algorithm here is modelled on CPython's heapq.py
|
||||
// the algorithm here is modeled on CPython's heapq.py
|
||||
|
||||
struct qentry {
|
||||
mp_uint_t time;
|
||||
@@ -121,6 +121,7 @@ STATIC void heap_siftup(mp_obj_utimeq_t *heap, mp_uint_t pos) {
|
||||
heap_siftdown(heap, start_pos, pos);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
STATIC mp_obj_t mod_utimeq_heappush(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
mp_obj_t heap_in = args[0];
|
||||
@@ -134,7 +135,8 @@ STATIC mp_obj_t mod_utimeq_heappush(size_t n_args, const mp_obj_t *args) {
|
||||
mp_float_t time = mp_obj_float_get(args[1]);
|
||||
itime = (uint32_t)time;
|
||||
}
|
||||
else itime = MP_OBJ_SMALL_INT_VALUE(args[1]);
|
||||
else itime = mp_obj_get_int(args[1]);
|
||||
|
||||
heap->items[l].time = itime;
|
||||
heap->items[l].id = utimeq_id++;
|
||||
heap->items[l].callback = args[2];
|
||||
@@ -145,6 +147,7 @@ STATIC mp_obj_t mod_utimeq_heappush(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_utimeq_heappush_obj, 4, 4, mod_utimeq_heappush);
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
STATIC mp_obj_t mod_utimeq_heappop(mp_obj_t heap_in, mp_obj_t list_ref) {
|
||||
mp_obj_utimeq_t *heap = get_heap(heap_in);
|
||||
if (heap->len == 0) {
|
||||
@@ -156,7 +159,7 @@ STATIC mp_obj_t mod_utimeq_heappop(mp_obj_t heap_in, mp_obj_t list_ref) {
|
||||
}
|
||||
|
||||
struct qentry *item = &heap->items[0];
|
||||
ret->items[0] = MP_OBJ_NEW_SMALL_INT(item->time);
|
||||
ret->items[0] = mp_obj_new_int(item->time);
|
||||
ret->items[1] = item->callback;
|
||||
ret->items[2] = item->args;
|
||||
heap->len -= 1;
|
||||
@@ -170,6 +173,7 @@ STATIC mp_obj_t mod_utimeq_heappop(mp_obj_t heap_in, mp_obj_t list_ref) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_utimeq_heappop_obj, mod_utimeq_heappop);
|
||||
|
||||
//-----------------------------------------------------
|
||||
STATIC mp_obj_t mod_utimeq_peektime(mp_obj_t heap_in) {
|
||||
mp_obj_utimeq_t *heap = get_heap(heap_in);
|
||||
if (heap->len == 0) {
|
||||
@@ -177,7 +181,7 @@ STATIC mp_obj_t mod_utimeq_peektime(mp_obj_t heap_in) {
|
||||
}
|
||||
|
||||
struct qentry *item = &heap->items[0];
|
||||
return MP_OBJ_NEW_SMALL_INT(item->time);
|
||||
return mp_obj_new_int(item->time);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_utimeq_peektime_obj, mod_utimeq_peektime);
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user