@johnnycubides/micropython-esp32-plugin-catalejo-editor 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/micropython-esp32/README.md +3 -0
- package/micropython-esp32/commands.d.ts +3 -3
- package/micropython-esp32/esp32-libs/esp32-c3-mini/boot.py +14 -0
- package/micropython-esp32/esp32-libs/esp32-c3-mini/webrepl_cfg.py +1 -0
- package/micropython-esp32/esp32-libs/esp32-c3-mini/wifi.py +135 -0
- package/micropython-esp32/esp32-libs/esp32-c3-mini/wifi_config.py +11 -0
- package/micropython-esp32/esp32-libs/esp32-c3-oled-mini/boot.py +14 -0
- package/micropython-esp32/esp32-libs/esp32-c3-oled-mini/display.py +67 -0
- package/micropython-esp32/esp32-libs/esp32-c3-oled-mini/ssd1306.py +164 -0
- package/micropython-esp32/esp32-libs/esp32-c3-oled-mini/webrepl_cfg.py +1 -0
- package/micropython-esp32/esp32-libs/esp32-c3-oled-mini/wifi.py +135 -0
- package/micropython-esp32/esp32-libs/esp32-c3-oled-mini/wifi_config.py +11 -0
- package/micropython-esp32/esp32-libs/esp32-s3-zero/boot.py +14 -0
- package/micropython-esp32/esp32-libs/esp32-s3-zero/webrepl_cfg.py +1 -0
- package/micropython-esp32/esp32-libs/esp32-s3-zero/wifi.py +135 -0
- package/micropython-esp32/esp32-libs/esp32-s3-zero/wifi_config.py +11 -0
- package/micropython-esp32/esp32-libs/esp32-wroom-devkit/boot.py +14 -0
- package/micropython-esp32/esp32-libs/esp32-wroom-devkit/webrepl_cfg.py +1 -0
- package/micropython-esp32/esp32-libs/esp32-wroom-devkit/wifi.py +135 -0
- package/micropython-esp32/esp32-libs/esp32-wroom-devkit/wifi_config.py +11 -0
- package/micropython-esp32/lang.d.ts +60 -1
- package/micropython-esp32/micropython.es.js +330 -178
- package/micropython-esp32/micropython.umd.js +14 -14
- package/micropython-esp32/plugin.json +1 -1
- package/micropython-esp32/upy-websockect.d.ts +30 -2
- package/package.json +1 -1
- package/micropython-esp32/esp32-libs/boot.py +0 -13
- package/micropython-esp32/esp32-libs/wifi.py +0 -77
- package/micropython-esp32/esp32-libs/wifi_config_esp32c3mini.py +0 -14
package/README.md
CHANGED
|
@@ -8,3 +8,6 @@ import * as micropython_esp32 from "./micropython-esp32/micropython.es.js";
|
|
|
8
8
|
plugins.push(micropython_esp32)
|
|
9
9
|
defaultPaths.push("app/ui-app/plugins/micropython-esp32/esp32-libs")
|
|
10
10
|
```
|
|
11
|
+
|
|
12
|
+
Los scripts de arranque de cada placa quedan en `esp32-libs/<placa>/` (por ejemplo
|
|
13
|
+
`esp32-libs/esp32-c3-mini/`) y salen de la carpeta del firmware al empaquetar. Ver [DEV.md](DEV.md).
|
|
@@ -8,3 +8,6 @@ import * as micropython_esp32 from "./micropython-esp32/micropython.es.js";
|
|
|
8
8
|
plugins.push(micropython_esp32)
|
|
9
9
|
defaultPaths.push("app/ui-app/plugins/micropython-esp32/esp32-libs")
|
|
10
10
|
```
|
|
11
|
+
|
|
12
|
+
Los scripts de arranque de cada placa quedan en `esp32-libs/<placa>/` (por ejemplo
|
|
13
|
+
`esp32-libs/esp32-c3-mini/`) y salen de la carpeta del firmware al empaquetar. Ver [DEV.md](DEV.md).
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Project, PluginResult } from './types';
|
|
2
2
|
import { LANG } from './consts';
|
|
3
3
|
/** Envío de código de tarjeta de desarrollo en función del método [wifi, serial] */
|
|
4
|
-
declare function micropythonSend(project: Project, generateCode: Function): Promise<PluginResult>;
|
|
4
|
+
declare function micropythonSend(project: Project, generateCode: Function, lang: LANG): Promise<PluginResult>;
|
|
5
5
|
/** Reset de software */
|
|
6
|
-
declare function micropythonSoftReset(project: Project): Promise<PluginResult>;
|
|
6
|
+
declare function micropythonSoftReset(project: Project, lang: LANG): Promise<PluginResult>;
|
|
7
7
|
/** Correr un programa en micropython */
|
|
8
|
-
declare function micropythonRunMain(project: Project): Promise<PluginResult>;
|
|
8
|
+
declare function micropythonRunMain(project: Project, lang: LANG): Promise<PluginResult>;
|
|
9
9
|
/** Conectarse por terminal "prompt" a micropython **/
|
|
10
10
|
declare function micropythonTerm(project: Project): Promise<PluginResult>;
|
|
11
11
|
/** Enviar archivo a través del puerto serial **/
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# This file is executed on every boot (including wake-boot from deepsleep)
|
|
2
|
+
# import esp
|
|
3
|
+
# esp.osdebug(None)
|
|
4
|
+
# import webrepl
|
|
5
|
+
# webrepl.start()
|
|
6
|
+
|
|
7
|
+
import webrepl
|
|
8
|
+
from wifi import do_ap, do_sta_connect, removeMain
|
|
9
|
+
|
|
10
|
+
removeMain()
|
|
11
|
+
webrepl.start()
|
|
12
|
+
do_ap()
|
|
13
|
+
do_sta_connect()
|
|
14
|
+
gc.collect()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PASS = '0000'
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
try:
|
|
2
|
+
import display
|
|
3
|
+
except ImportError:
|
|
4
|
+
display = None
|
|
5
|
+
|
|
6
|
+
AP_PASS = '87654321'
|
|
7
|
+
|
|
8
|
+
def scr(*lines, inv=None):
|
|
9
|
+
# Complemento OLED: muestra en pantalla lo mismo que se imprime por serial
|
|
10
|
+
if display:
|
|
11
|
+
display.show(*lines, inv=inv)
|
|
12
|
+
|
|
13
|
+
def ip_lines(ip):
|
|
14
|
+
return display.ip_lines(ip) if display else [ip]
|
|
15
|
+
|
|
16
|
+
def status_txt(network, st):
|
|
17
|
+
# Máximo 7 caracteres: se muestra como 'X <motivo>' en una fila de 9
|
|
18
|
+
names = {
|
|
19
|
+
getattr(network, 'STAT_NO_AP_FOUND', -1): 'sin red',
|
|
20
|
+
getattr(network, 'STAT_WRONG_PASSWORD', -2): 'clave?', # también CONNECTION_FAIL
|
|
21
|
+
getattr(network, 'STAT_HANDSHAKE_TIMEOUT', -3): 'enlace',
|
|
22
|
+
getattr(network, 'STAT_BEACON_TIMEOUT', -4): 'enlace',
|
|
23
|
+
getattr(network, 'STAT_CONNECTING', -5): 'timeout',
|
|
24
|
+
}
|
|
25
|
+
return names.get(st, 'st:' + str(st))
|
|
26
|
+
|
|
27
|
+
def do_ap():
|
|
28
|
+
import network
|
|
29
|
+
ap_if = network.WLAN(network.AP_IF)
|
|
30
|
+
mac = ''.join('%02x' % b for b in ap_if.config('mac'))[-5:]
|
|
31
|
+
if not network.WLAN(network.AP_IF).active() and not network.WLAN(network.STA_IF).isconnected():
|
|
32
|
+
print("Config...")
|
|
33
|
+
ap_if.config(essid='Catalejo-'+mac, authmode=3, password=AP_PASS)
|
|
34
|
+
ap_if.active(True)
|
|
35
|
+
print('WiFi name: ' + 'Catalejo-' + mac)
|
|
36
|
+
print('PASS: ' + AP_PASS)
|
|
37
|
+
scr('AP:', 'Catalejo-' + mac, AP_PASS)
|
|
38
|
+
|
|
39
|
+
def led_ctr(led, state):
|
|
40
|
+
if led:
|
|
41
|
+
if state != None:
|
|
42
|
+
led.value(state)
|
|
43
|
+
else:
|
|
44
|
+
led.value(not led.value())
|
|
45
|
+
|
|
46
|
+
def but_ctr(but, logic):
|
|
47
|
+
if but:
|
|
48
|
+
return but.value() == logic
|
|
49
|
+
else:
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
def removeMain():
|
|
53
|
+
try:
|
|
54
|
+
from machine import Pin
|
|
55
|
+
import wifi_config
|
|
56
|
+
import time
|
|
57
|
+
scr('Catalejo', 'arrancando')
|
|
58
|
+
if wifi_config.BUT != None and wifi_config.LBUT != None:
|
|
59
|
+
led = Pin(wifi_config.LED, Pin.OUT)
|
|
60
|
+
but = Pin(wifi_config.BUT, Pin.IN)
|
|
61
|
+
time.sleep(1.5)
|
|
62
|
+
ret_but = but_ctr(but, wifi_config.LBUT)
|
|
63
|
+
if ret_but:
|
|
64
|
+
import os
|
|
65
|
+
os.remove("main.py")
|
|
66
|
+
led_ctr(led, not wifi_config.LLED)
|
|
67
|
+
print("main.py removed")
|
|
68
|
+
scr('Catalejo', 'main.py', 'borrado')
|
|
69
|
+
except OSError as e:
|
|
70
|
+
print(e)
|
|
71
|
+
|
|
72
|
+
def do_sta_connect():
|
|
73
|
+
import network
|
|
74
|
+
import wifi_config
|
|
75
|
+
if not wifi_config.SSID or not wifi_config.PASS or not wifi_config.ATTE:
|
|
76
|
+
return
|
|
77
|
+
wlan = network.WLAN(network.STA_IF)
|
|
78
|
+
mac = ''.join('%02x' % b for b in network.WLAN(network.AP_IF).config('mac'))[-5:]
|
|
79
|
+
wlan.active(True)
|
|
80
|
+
# Placas ESP32-C3 con antena chip (0.42" OLED, Super Mini) no conectan a potencia máxima
|
|
81
|
+
txp = getattr(wifi_config, 'TXP', None)
|
|
82
|
+
if txp != None:
|
|
83
|
+
try:
|
|
84
|
+
# Rango válido 2 - 21 dBm; el chip usa escalones 2, 5, 7, 8.5, 11, 13, 14, 15, 16.5, 18, 20
|
|
85
|
+
wlan.config(txpower=txp)
|
|
86
|
+
except (OSError, ValueError) as e:
|
|
87
|
+
print('TXP invalido (2-21 dBm):', txp, e)
|
|
88
|
+
from machine import Pin
|
|
89
|
+
import time
|
|
90
|
+
led = None
|
|
91
|
+
but = None
|
|
92
|
+
ret_but = None
|
|
93
|
+
if wifi_config.LED != None and wifi_config.LLED != None:
|
|
94
|
+
led = Pin(wifi_config.LED, Pin.OUT)
|
|
95
|
+
if wifi_config.BUT != None and wifi_config.LBUT != None:
|
|
96
|
+
but = Pin(wifi_config.BUT, Pin.IN)
|
|
97
|
+
led_ctr(led, wifi_config.LLED)
|
|
98
|
+
time.sleep(0.5)
|
|
99
|
+
ret_but = but_ctr(but, wifi_config.LBUT)
|
|
100
|
+
if not wlan.isconnected():
|
|
101
|
+
print('Connecting to network...')
|
|
102
|
+
wlan.connect(wifi_config.SSID, wifi_config.PASS)
|
|
103
|
+
attemps = 0
|
|
104
|
+
while not wlan.isconnected() and attemps < wifi_config.ATTE:
|
|
105
|
+
scr('STA...', wifi_config.SSID[:9], '%d/%d' % (attemps + 1, wifi_config.ATTE))
|
|
106
|
+
led_ctr(led, wifi_config.LLED)
|
|
107
|
+
time.sleep(0.1)
|
|
108
|
+
led_ctr(led, not wifi_config.LLED)
|
|
109
|
+
time.sleep(0.9)
|
|
110
|
+
attemps += 1
|
|
111
|
+
if wlan.isconnected():
|
|
112
|
+
led_ctr(led, wifi_config.LLED)
|
|
113
|
+
ip = wlan.ifconfig()[0]
|
|
114
|
+
print("IP STA: ", ip)
|
|
115
|
+
print("Dev: catalejo-" + mac)
|
|
116
|
+
scr('STA OK', ip_lines(ip), 'Dev:' + mac)
|
|
117
|
+
if ret_but :
|
|
118
|
+
scr('IP STA:', ip_lines(ip), 'Dev:' + mac, 'Btn:salir')
|
|
119
|
+
time.sleep(3)
|
|
120
|
+
while not but_ctr(but, wifi_config.LBUT):
|
|
121
|
+
led_ctr(led, None)
|
|
122
|
+
print("IP STA: ", ip)
|
|
123
|
+
print("Dev: catalejo-" + mac)
|
|
124
|
+
time.sleep(1)
|
|
125
|
+
scr('STA OK', ip_lines(ip), 'Dev:' + mac)
|
|
126
|
+
if not wifi_config.AP:
|
|
127
|
+
network.WLAN(network.AP_IF).active(False)
|
|
128
|
+
print("AP_IF off")
|
|
129
|
+
scr('STA OK', ip_lines(ip), 'Dev:' + mac, 'AP off')
|
|
130
|
+
else:
|
|
131
|
+
st = wlan.status()
|
|
132
|
+
wlan.active(False)
|
|
133
|
+
led_ctr(led, not wifi_config.LLED)
|
|
134
|
+
print("Don't connect how a STA, status:", st)
|
|
135
|
+
scr('X ' + status_txt(network, st), 'AP:', 'Catalejo-' + mac, AP_PASS, inv=0)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
SSID = None # vacío en el paquete: la red se configura en cada placa
|
|
2
|
+
PASS = None # vacío en el paquete: la red se configura en cada placa
|
|
3
|
+
ATTE = 15
|
|
4
|
+
TXP = 8.5 # LOLIN C3 Mini v2.1 / C3 Super Mini: antena chip, no conectan a 20 dBm
|
|
5
|
+
AP = False
|
|
6
|
+
LED = 8
|
|
7
|
+
LLED = 0
|
|
8
|
+
BUT = 9
|
|
9
|
+
LBUT = 0
|
|
10
|
+
OLED_SDA = None # sin pantalla OLED
|
|
11
|
+
OLED_SCL = None
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# This file is executed on every boot (including wake-boot from deepsleep)
|
|
2
|
+
# import esp
|
|
3
|
+
# esp.osdebug(None)
|
|
4
|
+
# import webrepl
|
|
5
|
+
# webrepl.start()
|
|
6
|
+
|
|
7
|
+
import webrepl
|
|
8
|
+
from wifi import do_ap, do_sta_connect, removeMain
|
|
9
|
+
|
|
10
|
+
removeMain()
|
|
11
|
+
webrepl.start()
|
|
12
|
+
do_ap()
|
|
13
|
+
do_sta_connect()
|
|
14
|
+
gc.collect()
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Pantalla OLED 0.42" (SSD1306 72x40) para complementar el LED en wifi.py.
|
|
2
|
+
# Fuente 8x8 -> 9 columnas x 5 filas. Si no hay pantalla, driver o pines
|
|
3
|
+
# configurados, todas las funciones son no-op: el arranque nunca falla por la OLED.
|
|
4
|
+
COLS = 9
|
|
5
|
+
ROWS = 5
|
|
6
|
+
_oled = None
|
|
7
|
+
_tried = False
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def init():
|
|
11
|
+
global _oled, _tried
|
|
12
|
+
_tried = True
|
|
13
|
+
try:
|
|
14
|
+
import wifi_config
|
|
15
|
+
sda = getattr(wifi_config, 'OLED_SDA', None)
|
|
16
|
+
scl = getattr(wifi_config, 'OLED_SCL', None)
|
|
17
|
+
if sda is None or scl is None:
|
|
18
|
+
return None
|
|
19
|
+
from machine import Pin, SoftI2C
|
|
20
|
+
import ssd1306
|
|
21
|
+
i2c = SoftI2C(sda=Pin(sda), scl=Pin(scl))
|
|
22
|
+
_oled = ssd1306.SSD1306_I2C(72, 40, i2c, addr=getattr(wifi_config, 'OLED_ADDR', 0x3C))
|
|
23
|
+
except Exception as e:
|
|
24
|
+
print('OLED:', e)
|
|
25
|
+
_oled = None
|
|
26
|
+
return _oled
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def get():
|
|
30
|
+
# Para usar la pantalla desde main.py: oled = display.get()
|
|
31
|
+
if not _tried:
|
|
32
|
+
init()
|
|
33
|
+
return _oled
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def ip_lines(ip):
|
|
37
|
+
# '192.168.100.200' -> ['192.168.', '100.200'] (cada mitad cabe en 9 columnas)
|
|
38
|
+
p = ip.split('.')
|
|
39
|
+
return [p[0] + '.' + p[1] + '.', p[2] + '.' + p[3]] if len(p) == 4 else [ip]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def show(*lines, inv=None):
|
|
43
|
+
# inv: índice de la fila que se dibuja en video inverso (p. ej. 0 = encabezado)
|
|
44
|
+
oled = get()
|
|
45
|
+
if not oled:
|
|
46
|
+
return
|
|
47
|
+
rows = []
|
|
48
|
+
for l in lines:
|
|
49
|
+
if isinstance(l, (list, tuple)):
|
|
50
|
+
rows.extend(l)
|
|
51
|
+
continue
|
|
52
|
+
l = str(l)
|
|
53
|
+
while len(l) > COLS:
|
|
54
|
+
rows.append(l[:COLS])
|
|
55
|
+
l = l[COLS:]
|
|
56
|
+
rows.append(l)
|
|
57
|
+
try:
|
|
58
|
+
oled.fill(0)
|
|
59
|
+
for i, l in enumerate(rows[:ROWS]):
|
|
60
|
+
if i == inv:
|
|
61
|
+
oled.fill_rect(0, i * 8, 72, 8, 1)
|
|
62
|
+
oled.text(l, 0, i * 8, 0)
|
|
63
|
+
else:
|
|
64
|
+
oled.text(l, 0, i * 8)
|
|
65
|
+
oled.show()
|
|
66
|
+
except Exception as e:
|
|
67
|
+
print('OLED:', e)
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# MicroPython SSD1306 OLED driver, I2C and SPI interfaces
|
|
2
|
+
|
|
3
|
+
from micropython import const
|
|
4
|
+
import framebuf
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# register definitions
|
|
8
|
+
SET_CONTRAST = const(0x81)
|
|
9
|
+
SET_ENTIRE_ON = const(0xA4)
|
|
10
|
+
SET_NORM_INV = const(0xA6)
|
|
11
|
+
SET_DISP = const(0xAE)
|
|
12
|
+
SET_MEM_ADDR = const(0x20)
|
|
13
|
+
SET_COL_ADDR = const(0x21)
|
|
14
|
+
SET_PAGE_ADDR = const(0x22)
|
|
15
|
+
SET_DISP_START_LINE = const(0x40)
|
|
16
|
+
SET_SEG_REMAP = const(0xA0)
|
|
17
|
+
SET_MUX_RATIO = const(0xA8)
|
|
18
|
+
SET_IREF_SELECT = const(0xAD)
|
|
19
|
+
SET_COM_OUT_DIR = const(0xC0)
|
|
20
|
+
SET_DISP_OFFSET = const(0xD3)
|
|
21
|
+
SET_COM_PIN_CFG = const(0xDA)
|
|
22
|
+
SET_DISP_CLK_DIV = const(0xD5)
|
|
23
|
+
SET_PRECHARGE = const(0xD9)
|
|
24
|
+
SET_VCOM_DESEL = const(0xDB)
|
|
25
|
+
SET_CHARGE_PUMP = const(0x8D)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# Subclassing FrameBuffer provides support for graphics primitives
|
|
29
|
+
# http://docs.micropython.org/en/latest/pyboard/library/framebuf.html
|
|
30
|
+
class SSD1306(framebuf.FrameBuffer):
|
|
31
|
+
def __init__(self, width, height, external_vcc):
|
|
32
|
+
self.width = width
|
|
33
|
+
self.height = height
|
|
34
|
+
self.external_vcc = external_vcc
|
|
35
|
+
self.pages = self.height // 8
|
|
36
|
+
self.buffer = bytearray(self.pages * self.width)
|
|
37
|
+
super().__init__(self.buffer, self.width, self.height, framebuf.MONO_VLSB)
|
|
38
|
+
self.init_display()
|
|
39
|
+
|
|
40
|
+
def init_display(self):
|
|
41
|
+
for cmd in (
|
|
42
|
+
SET_DISP, # display off
|
|
43
|
+
# address setting
|
|
44
|
+
SET_MEM_ADDR,
|
|
45
|
+
0x00, # horizontal
|
|
46
|
+
# resolution and layout
|
|
47
|
+
SET_DISP_START_LINE, # start at line 0
|
|
48
|
+
SET_SEG_REMAP | 0x01, # column addr 127 mapped to SEG0
|
|
49
|
+
SET_MUX_RATIO,
|
|
50
|
+
self.height - 1,
|
|
51
|
+
SET_COM_OUT_DIR | 0x08, # scan from COM[N] to COM0
|
|
52
|
+
SET_DISP_OFFSET,
|
|
53
|
+
0x00,
|
|
54
|
+
SET_COM_PIN_CFG,
|
|
55
|
+
0x02 if self.width > 2 * self.height else 0x12,
|
|
56
|
+
# timing and driving scheme
|
|
57
|
+
SET_DISP_CLK_DIV,
|
|
58
|
+
0x80,
|
|
59
|
+
SET_PRECHARGE,
|
|
60
|
+
0x22 if self.external_vcc else 0xF1,
|
|
61
|
+
SET_VCOM_DESEL,
|
|
62
|
+
0x30, # 0.83*Vcc
|
|
63
|
+
# display
|
|
64
|
+
SET_CONTRAST,
|
|
65
|
+
0xFF, # maximum
|
|
66
|
+
SET_ENTIRE_ON, # output follows RAM contents
|
|
67
|
+
SET_NORM_INV, # not inverted
|
|
68
|
+
SET_IREF_SELECT,
|
|
69
|
+
0x30, # enable internal IREF during display on
|
|
70
|
+
# charge pump
|
|
71
|
+
SET_CHARGE_PUMP,
|
|
72
|
+
0x10 if self.external_vcc else 0x14,
|
|
73
|
+
SET_DISP | 0x01, # display on
|
|
74
|
+
): # on
|
|
75
|
+
self.write_cmd(cmd)
|
|
76
|
+
self.fill(0)
|
|
77
|
+
self.show()
|
|
78
|
+
|
|
79
|
+
def poweroff(self):
|
|
80
|
+
self.write_cmd(SET_DISP)
|
|
81
|
+
|
|
82
|
+
def poweron(self):
|
|
83
|
+
self.write_cmd(SET_DISP | 0x01)
|
|
84
|
+
|
|
85
|
+
def contrast(self, contrast):
|
|
86
|
+
self.write_cmd(SET_CONTRAST)
|
|
87
|
+
self.write_cmd(contrast)
|
|
88
|
+
|
|
89
|
+
def invert(self, invert):
|
|
90
|
+
self.write_cmd(SET_NORM_INV | (invert & 1))
|
|
91
|
+
|
|
92
|
+
def rotate(self, rotate):
|
|
93
|
+
self.write_cmd(SET_COM_OUT_DIR | ((rotate & 1) << 3))
|
|
94
|
+
self.write_cmd(SET_SEG_REMAP | (rotate & 1))
|
|
95
|
+
|
|
96
|
+
def show(self):
|
|
97
|
+
x0 = 0
|
|
98
|
+
x1 = self.width - 1
|
|
99
|
+
if self.width != 128:
|
|
100
|
+
# narrow displays use centred columns
|
|
101
|
+
col_offset = (128 - self.width) // 2
|
|
102
|
+
x0 += col_offset
|
|
103
|
+
x1 += col_offset
|
|
104
|
+
self.write_cmd(SET_COL_ADDR)
|
|
105
|
+
self.write_cmd(x0)
|
|
106
|
+
self.write_cmd(x1)
|
|
107
|
+
self.write_cmd(SET_PAGE_ADDR)
|
|
108
|
+
self.write_cmd(0)
|
|
109
|
+
self.write_cmd(self.pages - 1)
|
|
110
|
+
self.write_data(self.buffer)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class SSD1306_I2C(SSD1306):
|
|
114
|
+
def __init__(self, width, height, i2c, addr=0x3C, external_vcc=False):
|
|
115
|
+
self.i2c = i2c
|
|
116
|
+
self.addr = addr
|
|
117
|
+
self.temp = bytearray(2)
|
|
118
|
+
self.write_list = [b"\x40", None] # Co=0, D/C#=1
|
|
119
|
+
super().__init__(width, height, external_vcc)
|
|
120
|
+
|
|
121
|
+
def write_cmd(self, cmd):
|
|
122
|
+
self.temp[0] = 0x80 # Co=1, D/C#=0
|
|
123
|
+
self.temp[1] = cmd
|
|
124
|
+
self.i2c.writeto(self.addr, self.temp)
|
|
125
|
+
|
|
126
|
+
def write_data(self, buf):
|
|
127
|
+
self.write_list[1] = buf
|
|
128
|
+
self.i2c.writevto(self.addr, self.write_list)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class SSD1306_SPI(SSD1306):
|
|
132
|
+
def __init__(self, width, height, spi, dc, res, cs, external_vcc=False):
|
|
133
|
+
self.rate = 10 * 1024 * 1024
|
|
134
|
+
dc.init(dc.OUT, value=0)
|
|
135
|
+
res.init(res.OUT, value=0)
|
|
136
|
+
cs.init(cs.OUT, value=1)
|
|
137
|
+
self.spi = spi
|
|
138
|
+
self.dc = dc
|
|
139
|
+
self.res = res
|
|
140
|
+
self.cs = cs
|
|
141
|
+
import time
|
|
142
|
+
|
|
143
|
+
self.res(1)
|
|
144
|
+
time.sleep_ms(1)
|
|
145
|
+
self.res(0)
|
|
146
|
+
time.sleep_ms(10)
|
|
147
|
+
self.res(1)
|
|
148
|
+
super().__init__(width, height, external_vcc)
|
|
149
|
+
|
|
150
|
+
def write_cmd(self, cmd):
|
|
151
|
+
self.spi.init(baudrate=self.rate, polarity=0, phase=0)
|
|
152
|
+
self.cs(1)
|
|
153
|
+
self.dc(0)
|
|
154
|
+
self.cs(0)
|
|
155
|
+
self.spi.write(bytearray([cmd]))
|
|
156
|
+
self.cs(1)
|
|
157
|
+
|
|
158
|
+
def write_data(self, buf):
|
|
159
|
+
self.spi.init(baudrate=self.rate, polarity=0, phase=0)
|
|
160
|
+
self.cs(1)
|
|
161
|
+
self.dc(1)
|
|
162
|
+
self.cs(0)
|
|
163
|
+
self.spi.write(buf)
|
|
164
|
+
self.cs(1)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PASS = '0000'
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
try:
|
|
2
|
+
import display
|
|
3
|
+
except ImportError:
|
|
4
|
+
display = None
|
|
5
|
+
|
|
6
|
+
AP_PASS = '87654321'
|
|
7
|
+
|
|
8
|
+
def scr(*lines, inv=None):
|
|
9
|
+
# Complemento OLED: muestra en pantalla lo mismo que se imprime por serial
|
|
10
|
+
if display:
|
|
11
|
+
display.show(*lines, inv=inv)
|
|
12
|
+
|
|
13
|
+
def ip_lines(ip):
|
|
14
|
+
return display.ip_lines(ip) if display else [ip]
|
|
15
|
+
|
|
16
|
+
def status_txt(network, st):
|
|
17
|
+
# Máximo 7 caracteres: se muestra como 'X <motivo>' en una fila de 9
|
|
18
|
+
names = {
|
|
19
|
+
getattr(network, 'STAT_NO_AP_FOUND', -1): 'sin red',
|
|
20
|
+
getattr(network, 'STAT_WRONG_PASSWORD', -2): 'clave?', # también CONNECTION_FAIL
|
|
21
|
+
getattr(network, 'STAT_HANDSHAKE_TIMEOUT', -3): 'enlace',
|
|
22
|
+
getattr(network, 'STAT_BEACON_TIMEOUT', -4): 'enlace',
|
|
23
|
+
getattr(network, 'STAT_CONNECTING', -5): 'timeout',
|
|
24
|
+
}
|
|
25
|
+
return names.get(st, 'st:' + str(st))
|
|
26
|
+
|
|
27
|
+
def do_ap():
|
|
28
|
+
import network
|
|
29
|
+
ap_if = network.WLAN(network.AP_IF)
|
|
30
|
+
mac = ''.join('%02x' % b for b in ap_if.config('mac'))[-5:]
|
|
31
|
+
if not network.WLAN(network.AP_IF).active() and not network.WLAN(network.STA_IF).isconnected():
|
|
32
|
+
print("Config...")
|
|
33
|
+
ap_if.config(essid='Catalejo-'+mac, authmode=3, password=AP_PASS)
|
|
34
|
+
ap_if.active(True)
|
|
35
|
+
print('WiFi name: ' + 'Catalejo-' + mac)
|
|
36
|
+
print('PASS: ' + AP_PASS)
|
|
37
|
+
scr('AP:', 'Catalejo-' + mac, AP_PASS)
|
|
38
|
+
|
|
39
|
+
def led_ctr(led, state):
|
|
40
|
+
if led:
|
|
41
|
+
if state != None:
|
|
42
|
+
led.value(state)
|
|
43
|
+
else:
|
|
44
|
+
led.value(not led.value())
|
|
45
|
+
|
|
46
|
+
def but_ctr(but, logic):
|
|
47
|
+
if but:
|
|
48
|
+
return but.value() == logic
|
|
49
|
+
else:
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
def removeMain():
|
|
53
|
+
try:
|
|
54
|
+
from machine import Pin
|
|
55
|
+
import wifi_config
|
|
56
|
+
import time
|
|
57
|
+
scr('Catalejo', 'arrancando')
|
|
58
|
+
if wifi_config.BUT != None and wifi_config.LBUT != None:
|
|
59
|
+
led = Pin(wifi_config.LED, Pin.OUT)
|
|
60
|
+
but = Pin(wifi_config.BUT, Pin.IN)
|
|
61
|
+
time.sleep(1.5)
|
|
62
|
+
ret_but = but_ctr(but, wifi_config.LBUT)
|
|
63
|
+
if ret_but:
|
|
64
|
+
import os
|
|
65
|
+
os.remove("main.py")
|
|
66
|
+
led_ctr(led, not wifi_config.LLED)
|
|
67
|
+
print("main.py removed")
|
|
68
|
+
scr('Catalejo', 'main.py', 'borrado')
|
|
69
|
+
except OSError as e:
|
|
70
|
+
print(e)
|
|
71
|
+
|
|
72
|
+
def do_sta_connect():
|
|
73
|
+
import network
|
|
74
|
+
import wifi_config
|
|
75
|
+
if not wifi_config.SSID or not wifi_config.PASS or not wifi_config.ATTE:
|
|
76
|
+
return
|
|
77
|
+
wlan = network.WLAN(network.STA_IF)
|
|
78
|
+
mac = ''.join('%02x' % b for b in network.WLAN(network.AP_IF).config('mac'))[-5:]
|
|
79
|
+
wlan.active(True)
|
|
80
|
+
# Placas ESP32-C3 con antena chip (0.42" OLED, Super Mini) no conectan a potencia máxima
|
|
81
|
+
txp = getattr(wifi_config, 'TXP', None)
|
|
82
|
+
if txp != None:
|
|
83
|
+
try:
|
|
84
|
+
# Rango válido 2 - 21 dBm; el chip usa escalones 2, 5, 7, 8.5, 11, 13, 14, 15, 16.5, 18, 20
|
|
85
|
+
wlan.config(txpower=txp)
|
|
86
|
+
except (OSError, ValueError) as e:
|
|
87
|
+
print('TXP invalido (2-21 dBm):', txp, e)
|
|
88
|
+
from machine import Pin
|
|
89
|
+
import time
|
|
90
|
+
led = None
|
|
91
|
+
but = None
|
|
92
|
+
ret_but = None
|
|
93
|
+
if wifi_config.LED != None and wifi_config.LLED != None:
|
|
94
|
+
led = Pin(wifi_config.LED, Pin.OUT)
|
|
95
|
+
if wifi_config.BUT != None and wifi_config.LBUT != None:
|
|
96
|
+
but = Pin(wifi_config.BUT, Pin.IN)
|
|
97
|
+
led_ctr(led, wifi_config.LLED)
|
|
98
|
+
time.sleep(0.5)
|
|
99
|
+
ret_but = but_ctr(but, wifi_config.LBUT)
|
|
100
|
+
if not wlan.isconnected():
|
|
101
|
+
print('Connecting to network...')
|
|
102
|
+
wlan.connect(wifi_config.SSID, wifi_config.PASS)
|
|
103
|
+
attemps = 0
|
|
104
|
+
while not wlan.isconnected() and attemps < wifi_config.ATTE:
|
|
105
|
+
scr('STA...', wifi_config.SSID[:9], '%d/%d' % (attemps + 1, wifi_config.ATTE))
|
|
106
|
+
led_ctr(led, wifi_config.LLED)
|
|
107
|
+
time.sleep(0.1)
|
|
108
|
+
led_ctr(led, not wifi_config.LLED)
|
|
109
|
+
time.sleep(0.9)
|
|
110
|
+
attemps += 1
|
|
111
|
+
if wlan.isconnected():
|
|
112
|
+
led_ctr(led, wifi_config.LLED)
|
|
113
|
+
ip = wlan.ifconfig()[0]
|
|
114
|
+
print("IP STA: ", ip)
|
|
115
|
+
print("Dev: catalejo-" + mac)
|
|
116
|
+
scr('STA OK', ip_lines(ip), 'Dev:' + mac)
|
|
117
|
+
if ret_but :
|
|
118
|
+
scr('IP STA:', ip_lines(ip), 'Dev:' + mac, 'Btn:salir')
|
|
119
|
+
time.sleep(3)
|
|
120
|
+
while not but_ctr(but, wifi_config.LBUT):
|
|
121
|
+
led_ctr(led, None)
|
|
122
|
+
print("IP STA: ", ip)
|
|
123
|
+
print("Dev: catalejo-" + mac)
|
|
124
|
+
time.sleep(1)
|
|
125
|
+
scr('STA OK', ip_lines(ip), 'Dev:' + mac)
|
|
126
|
+
if not wifi_config.AP:
|
|
127
|
+
network.WLAN(network.AP_IF).active(False)
|
|
128
|
+
print("AP_IF off")
|
|
129
|
+
scr('STA OK', ip_lines(ip), 'Dev:' + mac, 'AP off')
|
|
130
|
+
else:
|
|
131
|
+
st = wlan.status()
|
|
132
|
+
wlan.active(False)
|
|
133
|
+
led_ctr(led, not wifi_config.LLED)
|
|
134
|
+
print("Don't connect how a STA, status:", st)
|
|
135
|
+
scr('X ' + status_txt(network, st), 'AP:', 'Catalejo-' + mac, AP_PASS, inv=0)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
SSID = None # vacío en el paquete: la red se configura en cada placa
|
|
2
|
+
PASS = None # vacío en el paquete: la red se configura en cada placa
|
|
3
|
+
ATTE = 15
|
|
4
|
+
TXP = 8.5 # ESP32-C3 0.42" OLED: antena chip, no conecta a 20 dBm
|
|
5
|
+
AP = False
|
|
6
|
+
LED = 8
|
|
7
|
+
LLED = 0
|
|
8
|
+
BUT = 9
|
|
9
|
+
LBUT = 0
|
|
10
|
+
OLED_SDA = 5
|
|
11
|
+
OLED_SCL = 6
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# This file is executed on every boot (including wake-boot from deepsleep)
|
|
2
|
+
# import esp
|
|
3
|
+
# esp.osdebug(None)
|
|
4
|
+
# import webrepl
|
|
5
|
+
# webrepl.start()
|
|
6
|
+
|
|
7
|
+
import webrepl
|
|
8
|
+
from wifi import do_ap, do_sta_connect, removeMain
|
|
9
|
+
|
|
10
|
+
removeMain()
|
|
11
|
+
webrepl.start()
|
|
12
|
+
do_ap()
|
|
13
|
+
do_sta_connect()
|
|
14
|
+
gc.collect()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PASS = '0000'
|