Rangé toutes mes refactorisations des modules de base
This commit is contained in:
31
Boot init.lua/mid/boot.lua
Normal file
31
Boot init.lua/mid/boot.lua
Normal file
@@ -0,0 +1,31 @@
|
||||
-- Scripts à charger après le boot pour démarrer son appli
|
||||
|
||||
print("\n boot.lua zf190310.1537 \n")
|
||||
|
||||
function heartbeat()
|
||||
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
|
||||
flash_led_xfois()
|
||||
boottimer1=tmr.create()
|
||||
tmr.alarm(boottimer1, 1*1000, tmr.ALARM_AUTO, function()
|
||||
xfois =2
|
||||
blink_LED ()
|
||||
end)
|
||||
end
|
||||
|
||||
f= "led_rgb.lua" if file.exists(f) then dofile(f) end
|
||||
f= "wifi_ap_start.lua" if file.exists(f) then dofile(f) end
|
||||
f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end
|
||||
f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "web_ide2.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "web_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "set_time.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "dsleep.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
f=nil
|
||||
heartbeat=nil
|
||||
--heartbeat()
|
||||
|
||||
|
||||
|
||||
|
||||
37
Boot init.lua/mid/flash_led_xfois.lua
Normal file
37
Boot init.lua/mid/flash_led_xfois.lua
Normal file
@@ -0,0 +1,37 @@
|
||||
-- programme pour faire clignoter x fois une LED avec un rapport on/off
|
||||
|
||||
function flash_led_xfois()
|
||||
print("\n flash_led_xfois.lua zf190310.1533 \n")
|
||||
|
||||
--zLED=0 --NodeMCU
|
||||
zLED=4 --EPS-M3
|
||||
zTm_On_LED = 50 --> en ms
|
||||
zTm_Off_LED = 100 --> en ms
|
||||
nbfois = 0
|
||||
gpio.write(zLED, gpio.HIGH)
|
||||
gpio.mode(zLED, gpio.OUTPUT)
|
||||
ztmr_Flash_LED = tmr.create()
|
||||
|
||||
function blink_LED ()
|
||||
if nbfois >= xfois then
|
||||
-- print(nbfois)
|
||||
nbfois = 0
|
||||
else
|
||||
if gpio.read(zLED)==gpio.HIGH then
|
||||
gpio.write(zLED, gpio.LOW)
|
||||
tmr.alarm(ztmr_Flash_LED, zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED)
|
||||
else
|
||||
gpio.write(zLED, gpio.HIGH)
|
||||
nbfois = nbfois+1
|
||||
tmr.alarm(ztmr_Flash_LED, zTm_On_LED, tmr.ALARM_SINGLE, blink_LED)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- xfois =2
|
||||
-- blink_LED ()
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
52
Boot init.lua/mid/initz.lua
Normal file
52
Boot init.lua/mid/initz.lua
Normal file
@@ -0,0 +1,52 @@
|
||||
--Script de bootstrap, test au moment du boot qui a été la cause de boot.
|
||||
-- Si la cause est un power on ou une connexion depuis l'IDE, alors
|
||||
-- le script repair.lua pendant xx secondes avant de continuer
|
||||
--Source: https://nodemcu.readthedocs.io/en/master/en/modules/node/#nodebootreason
|
||||
|
||||
print("\n init.lua zf190310.1549 \n")
|
||||
|
||||
zswitch=3 --switch flash
|
||||
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
|
||||
|
||||
function hvbouton()
|
||||
-- gpio.trig(zswitch, "none")
|
||||
tmr.unregister(initalarme)
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
end
|
||||
|
||||
gpio.trig(zswitch, "both", hvbouton)
|
||||
|
||||
function second_chance()
|
||||
print("seconde chance...")
|
||||
f= "repair.lua" if file.exists(f) then dofile(f) end
|
||||
initalarme=tmr.create()
|
||||
tmr.alarm(initalarme, 4*1000, tmr.ALARM_SINGLE, function()
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
end)
|
||||
end
|
||||
|
||||
_, reset_reason = node.bootreason()
|
||||
print("reset_reason:",reset_reason)
|
||||
if reset_reason == 0 then
|
||||
print("power on")
|
||||
second_chance()
|
||||
elseif reset_reason == 4 then
|
||||
print("node.restart")
|
||||
gpio.trig(zswitch)
|
||||
hvbouton=nil
|
||||
second_chance=nil
|
||||
zswitch=nil
|
||||
reset_reason=nil
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
elseif reset_reason == 5 then
|
||||
print("dsleep wake up")
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
elseif reset_reason == 6 then
|
||||
print("external reset")
|
||||
second_chance()
|
||||
-- f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
else
|
||||
print("autre raison")
|
||||
second_chance()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user