-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadapters.py
55 lines (40 loc) · 1.2 KB
/
adapters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
try:
import gc
import ujson as json
import utime as time
from micropython import const
from utime import sleep_ms
class DummyLogger:
def __init__(self):
pass
def __getattr__(self, name):
return self.dummy()
def dummy(self, *args, **kwargs):
return None
DUMMY_LOGGER = DummyLogger()
MAIN_LOGGER = DUMMY_LOGGER
def getLogger(name):
return MAIN_LOGGER
def updateLogger(logger):
global MAIN_LOGGER
MAIN_LOGGER = logger
def mem_stats():
gc.collect()
return gc.mem_alloc(), gc.mem_free()
except ImportError:
import json # type: ignore # noqa: F401
import logging
import time
import psutil
def const(val):
"""const() replacement for non-micropython environment"""
return val
def sleep_ms(val):
return time.sleep(val / 1000.0)
def getLogger(name):
return logging.getLogger(name)
def updateLogger(logger):
return None # does nothing, not supported outside ESP32
def mem_stats():
mem_info = psutil.virtual_memory() # mem_info.total, mem_info.available,
return mem_info.used, mem_info.free