Skip to content

Commit df95c3f

Browse files
committed
updated
1 parent abadd20 commit df95c3f

2 files changed

Lines changed: 22 additions & 24 deletions

File tree

File renamed without changes.

12.network/wifi.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import network
21

3-
from button import Button
2+
import network
43

54
wlan = network.WLAN(network.STA_IF)
65

76
if wlan.active() is False:
87
wlan.active(True)
9-
8+
109
def disconnect():
1110
global wlan
1211
wlan.disconnect()
@@ -23,37 +22,35 @@ def isconnected():
2322
def smartconfig():
2423
close()
2524
print(network.smartconfig())
26-
25+
2726
def try_connect():
2827
import wifi_cfg
2928
wlan.disconnect()
3029
wlan.connect(wifi_cfg.WIFI_SSID, wifi_cfg.WIFI_PSWD)
3130

32-
__button__, __last_button__ = False, False
31+
is_smartconfig = False
3332

34-
def __check_button(button):
35-
global __button__, __last_button__
36-
if __last_button__ != button.is_pressed():
37-
__button__ = True
33+
def __irq_sc(p):
34+
p.irq().trigger(0)
35+
global is_smartconfig
36+
if is_smartconfig is False:
37+
is_smartconfig = True
38+
print("Started wifi in smartconfig mode")
3839

39-
def start(led_delay=150, button=Button(35)):
4040

41+
42+
def start(led_delay=150, pin_id=35):
4143
if isconnected():
4244
print('Wifi connected.')
4345
return
4446

45-
global wlan, __button__, __last_button__
46-
__button__, __last_button__ = False, button.is_pressed()
47-
48-
if wlan.active() is False:
49-
wlan.active(True)
47+
from machine import Pin
48+
pin = Pin(pin_id, Pin.IN).irq(trigger=Pin.IRQ_RISING, handler=__irq_sc)
5049

51-
from machine import Timer
52-
from display import Display, Purple, Yellow, Green, Blue
53-
print('Press "A" to enter the smartconfig mode while the led is rolling')
5450
try:
55-
timer = Timer(-100)
56-
timer.init(period = 250, mode = Timer.PERIODIC, callback = lambda t : (__check_button(button)))
51+
52+
from display import Display, Purple, Yellow, Green, Blue
53+
print('Press "A" to enter the smartconfig mode while the led is rolling')
5754
mac = wlan.config('mac')
5855
view = ('%X%X' % (mac[4], mac[5]))
5956
try:
@@ -66,11 +63,10 @@ def start(led_delay=150, button=Button(35)):
6663
import wifi_cfg
6764
if hasattr(wifi_cfg, 'HOST_NAME'):
6865
wlan.config(dhcp_hostname=wifi_cfg.HOST_NAME)
69-
66+
7067
Display().scroll(view, [Purple, Yellow, Green, Blue], led_delay)
7168

72-
if __button__:
73-
print("Started wifi in smartconfig mode")
69+
if is_smartconfig:
7470
smartconfig()
7571
else:
7672
print("Started wifi in normal mode")
@@ -80,5 +76,7 @@ def start(led_delay=150, button=Button(35)):
8076
print(e)
8177
finally:
8278
Display().clear()
83-
timer.deinit()
79+
pin.trigger(0)
8480

81+
if __name__ == '__main__':
82+
start()

0 commit comments

Comments
 (0)