]> hydra-www.ietfng.org Git - acmetensortoys-esp-lua_lamp/commitdiff
Rework for LFS changes in core
authorNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sun, 12 Aug 2018 14:43:35 +0000 (15:43 +0100)
committerNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sun, 12 Aug 2018 14:43:35 +0000 (15:43 +0100)
Most of the changes are to use the OVL mechanism

init-early.lua
init2.lua
lamp-lfs-strings.lua [new file with mode: 0644]
lamp-touch.lua
mklfs.sh [new file with mode: 0755]
pushall.sh
telnetd-cap.lua

index ea8e2f8cb9c3d7517d1ad0b5ef5d3bb16cff9a1a..3232176a162ef698fffdbd9ffb07d986e1a42e73 100644 (file)
@@ -7,3 +7,12 @@ fb:fill(0,0,0)
 gpio.write(3,gpio.HIGH)
 ws2812.write(fb)
 gpio.write(3,gpio.LOW)
+
+-- Do we have a new LFS blob?  If so, install it.
+file.remove("luac.out.stage")
+if file.exists("luac.out") then
+  print("Updating LFS image.  Will reboot if things go well.")
+  file.rename("luac.out", "luac.out.stage")
+  node.flashreload("luac.out.stage")
+  error("Failed to update LFS!")
+end
index 9fb386a2731b61b6f933d59ff3c116bb5ca6ef96..44a6ffb91b930acb73cddb71122f9cf9676fe46e 100644 (file)
--- a/init2.lua
+++ b/init2.lua
@@ -3,9 +3,9 @@ local mqttUser
 -- some exported modules for overlay and REPL use
 remotetmr = tmr.create()
 touchtmr = tmr.create()
-tq = (dofile "tq.lc")(tmr.create())
+tq = OVL.tq()(tmr.create())
 nwfnet = require "nwfnet"
-mqc, mqttUser = dofile("nwfmqtt.lc").mkclient("nwfmqtt.conf")
+mqc, mqttUser = OVL.nwfmqtt().mkclient("nwfmqtt.conf")
 local mqttBcastPfx = string.format("lamp/%s/out",mqttUser)
 local mqttHeartTopic = string.format("lamp/%s/boot",mqttUser)
 cap = require "cap1188"
@@ -15,7 +15,7 @@ pendRemoteMsg = nil
 
 local function drawfailsafe(t,fb,p) fb:fill(p[1]:byte(1),p[1]:byte(2),p[1]:byte(3)) end
 function loaddrawfn(name)
-  local f = loadfile (string.format("draw-%s.lc",name))
+  local f = OVL[string.format("draw-%s",name)]
   local fn = f and f()
   if fn then return fn else return drawfailsafe end
 end
@@ -23,7 +23,7 @@ end
 -- telnetd overlay
 tcpserv = net.createServer(net.TCP, 120)
 tcpserv:listen(23,function(k)
-  local telnetd = dofile "telnetd.lc"
+  local telnetd = OVL.telnetd()
   telnetd.on["conn"] = function(k) k(string.format("%s [NODE-%06X]",mqttUser,node.chipid())) end
   telnetd.server(k)
 end)
@@ -74,7 +74,7 @@ local function remotemsg(m)
     touchtmr:unregister()
     ledfb = remotefb
     removeremote()
-    dofile("lamp-remote.lc")(m)
+    OVL["lamp-remote"](m)
   end
 end
 
@@ -112,7 +112,7 @@ end
 -- mqtt setup
 local mqtt_reconn_timer
 local function mqtt_reconn(_t)
-  mqc:close(); dofile("nwfmqtt.lc").connect(mqc,"nwfmqtt.conf")
+  mqc:close(); OVL.nwfmqtt().connect(mqc,"nwfmqtt.conf")
 end
 local function mqtt_conn()
   mqtt_reconn_timer = tmr.create()
@@ -123,7 +123,7 @@ end
 local mqtt_beat_cron
 
 local wifitmr = tmr.create()
-wifitmr:register(10000, tmr.ALARM_SEMI, function() dofile("nwfnet-go.lc") end)
+wifitmr:register(10000, tmr.ALARM_SEMI, function() OVL["nwfnet-go"]() end)
 
 -- network callbacks
 nwfnet.onnet["init"] = function(e,c)
@@ -140,7 +140,7 @@ nwfnet.onnet["init"] = function(e,c)
     mqtt_beat_cron = cron.schedule("*/5 * * * *",function(e) mqc:publish(mqttHeartTopic,"beat",1,1) end)
     mqc:publish(mqttHeartTopic,"alive",1,1)
     mqc:subscribe(string.format("lamp/+/out/%s",mqttUser),1)
-    dofile("nwfmqtt.lc").suball(mqc,"nwfmqtt.subs")
+    OVL.nwfmqtt().suball(mqc,"nwfmqtt.subs")
        remotemsg("draw xx 4 0 4 ;")
   elseif e == "wstagoip"              then
     if not mqtt_reconn_poller then mqtt_reconn() end
@@ -157,13 +157,13 @@ end
 remotemsg("draw xx 4 0 0;")
 
 -- touch overlay loader
-function ontouch_load() dofile("lamp-touch.lc") end
+function ontouch_load() OVL["lamp-touch"]() end
 
 -- pin 6 (GPIO12) is cap sensor IRQ (active low)
 -- pin 5 (GPIO14) is cap sensor reset (active low)
-dofile("cap1188-init.lc").init(6,5,ontouch_load)
+OVL["cap1188-init"]().init(6,5,ontouch_load)
 
 -- initialize network
-dofile("nwfnet-diag.lc")(true)
-dofile("nwfnet-go.lc")
+OVL["nwfnet-diag"]()(true)
+OVL["nwfnet-go"]()
 wifitmr:start()
diff --git a/lamp-lfs-strings.lua b/lamp-lfs-strings.lua
new file mode 100644 (file)
index 0000000..451df8e
--- /dev/null
@@ -0,0 +1,27 @@
+local modload =
+  "ALARM_AUTO", "unregister",
+  "cron", "cron.entry", "schedule", "unschedule",
+  "error",
+  "mqtt.socket", "publish", "subscribe",
+  "ws2812", "ws2812.buffer", "fill"
+
+local lampload =
+  "%s [NODE-%06X]",
+  "*/5 * * * *",
+  "^lamp/[^/]+/out",
+  "lamp/+/out/%s",
+  "alive", "beat",
+  "color %x %x %x %x; ",
+  "draw %s %x %x %x;",
+  "draw xx 0 0 4 ;",
+  "draw xx 0 4 0 ;",
+  "draw xx 4 0 0 ;",
+  "draw xx 4 0 4 ;",
+  "draw-%s",
+  "dimfactor", "dodraw", "isDim", "isTouch", "isblackout",
+  "lamp", "lamp-remote", "lamp-touch", "lamp_announce", "ledfb", "loaddrawfn",
+  "mix", "mqc", "mqtt_reconn_poller",
+  "nwfmqtt.conf", "nwfmqtt.subs",
+  "ontouch_load", "pendRemoteMsg", "remotefb", "remoteqtmrs", "remotetmr",
+  "removeremote", "tcpserv", "touchtmr", "transformcolors"
index f2b30500813ff281fc273a1027b92fdaecfacaf9..434884830a65d7549524ee50f00bfe26dab69956 100644 (file)
@@ -113,7 +113,7 @@ local function ontouchdone()
   if pendRemoteMsg ~= nil then
     touchtmr:unregister()
     ledfb = remotefb
-    dofile("lamp-remote.lc")(pendRemoteMsg)
+    OVL["lamp-remote"]()(pendRemoteMsg)
     pendRemoteMsg = nil
   end
 end
diff --git a/mklfs.sh b/mklfs.sh
new file mode 100755 (executable)
index 0000000..40f43f3
--- /dev/null
+++ b/mklfs.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+set -e -u
+
+SOURCES=(
+  lamp-lfs-strings.lua
+  core/cap1188/cap1188.lua
+  core/cap1188/cap1188-init.lua
+  core/fifo/fifo.lua
+  core/net/{fifosock,nwfmqtt,nwfnet*}.lua
+  core/telnetd/telnetd{,-{diag,file}}.lua
+  core/tq/tq.lua
+  core/util/compileall.lua
+  core/util/diag.lua
+  core/util/lfs-strings.lua
+)
+
+rm -rf _lfs_build
+mkdir _lfs_build
+
+# for i in ${SOURCES[@]}; do
+#   lua5.1 -e "package.path=package.path..';core/_external/luasrcdiet/?.lua'" \
+#     core/_external/luasrcdiet/bin/luasrcdiet $i -o _lfs_build/`basename $i` --quiet
+# done
+cp ${SOURCES[@]} _lfs_build/
+
+(cd _lfs_build; $LUACROSS -f *.lua)
index 6ce18c38209abc20d0a1b5d24fe50fd4aa3487b7..57d393379b812af79e370d66ac61ddc24fe59f6a 100755 (executable)
@@ -4,9 +4,16 @@ set -e -u
 
 . ./core/host/pushcommon.sh
 
-dopushcompile core/net/nwfmqtt.lua
-dopushcompile core/cap1188/cap1188.lua
-dopushcompile core/cap1188/cap1188-init.lua
+if [ -z ${LUACROSS:-} ] ; then
+  . ./core/host/pushinit.sh
+  dopushcompile core/net/nwfmqtt.lua
+  dopushcompile core/cap1188/cap1188.lua
+  dopushcompile core/cap1188/cap1188-init.lua
+else
+  ./mklfs.sh
+  dopushtext _lfs_build/luac.out
+fi
+
 dopushcompile lamp-touch.lua
 dopushcompile lamp-remote.lua
 dopushcompile telnetd-cap.lua
index 4b508e780dcc2ca5c73770a71954af77eca7adde..445e1b6c1ddd1edc419cb96d5b3219e7d24d20c4 100644 (file)
@@ -1,3 +1,3 @@
 return {
-  ["calibrate"] = function(_,s) dofile("cap1188-init.lc").calibrate() end
+  ["calibrate"] = function(_,s) OVL["cap1188-init"]().calibrate() end
 }