Pārlūkot izejas kodu

add init.lua examples

funshine 9 gadi atpakaļ
vecāks
revīzija
52ca40b8ea
3 mainītis faili ar 21 papildinājumiem un 2 dzēšanām
  1. 2 2
      app/platform/flash_api.c
  2. 18 0
      examples/init.lua
  3. 1 0
      examples/user.lua

+ 2 - 2
app/platform/flash_api.c

@@ -369,8 +369,8 @@ bool flash_init_data_blank(void)
     // It will init system config to blank!
     bool result = false;
 #if defined(FLASH_SAFE_API)
-    if ((SPI_FLASH_RESULT_OK == flash_safe_erase_sector((flash_rom_get_sec_num() - 2))) &&
-            (SPI_FLASH_RESULT_OK == flash_safe_erase_sector((flash_rom_get_sec_num() - 1))))
+    if ((SPI_FLASH_RESULT_OK == flash_safe_erase_sector((flash_safe_get_sec_num() - 2))) &&
+            (SPI_FLASH_RESULT_OK == flash_safe_erase_sector((flash_safe_get_sec_num() - 1))))
 #else
     if ((SPI_FLASH_RESULT_OK == spi_flash_erase_sector((flash_rom_get_sec_num() - 2))) &&
             (SPI_FLASH_RESULT_OK == spi_flash_erase_sector((flash_rom_get_sec_num() - 1))))

+ 18 - 0
examples/init.lua

@@ -0,0 +1,18 @@
+--init.lua, something like this
+countdown = 3
+tmr.alarm(0,1000,1,function()
+    print(countdown)
+    countdown = countdown-1
+    if countdown<1 then
+        tmr.stop(0)
+        countdown = nil
+        local s,err
+        if file.open("user.lc") then
+            file.close()
+            s,err = pcall(function() dofile("user.lc") end)
+        else
+            s,err = pcall(function() dofile("user.lua") end)
+        end
+        if not s then print(err) end
+    end
+end)

+ 1 - 0
examples/user.lua

@@ -0,0 +1 @@
+print("hello NodeMCU")