From 63128fd1f0863fc516232ce2f35bb7fdf391fe6c Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Sun, 12 Aug 2018 15:43:35 +0100 Subject: [PATCH] Rework for LFS changes in core Most of the changes are to use the OVL mechanism --- init-early.lua | 9 +++++++++ init2.lua | 24 ++++++++++++------------ lamp-lfs-strings.lua | 27 +++++++++++++++++++++++++++ lamp-touch.lua | 2 +- mklfs.sh | 27 +++++++++++++++++++++++++++ pushall.sh | 13 ++++++++++--- telnetd-cap.lua | 2 +- 7 files changed, 87 insertions(+), 17 deletions(-) create mode 100644 lamp-lfs-strings.lua create mode 100755 mklfs.sh diff --git a/init-early.lua b/init-early.lua index ea8e2f8..3232176 100644 --- a/init-early.lua +++ b/init-early.lua @@ -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 diff --git a/init2.lua b/init2.lua index 9fb386a..44a6ffb 100644 --- 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 index 0000000..451df8e --- /dev/null +++ b/lamp-lfs-strings.lua @@ -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" + diff --git a/lamp-touch.lua b/lamp-touch.lua index f2b3050..4348848 100644 --- a/lamp-touch.lua +++ b/lamp-touch.lua @@ -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 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) diff --git a/pushall.sh b/pushall.sh index 6ce18c3..57d3933 100755 --- a/pushall.sh +++ b/pushall.sh @@ -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 diff --git a/telnetd-cap.lua b/telnetd-cap.lua index 4b508e7..445e1b6 100644 --- a/telnetd-cap.lua +++ b/telnetd-cap.lua @@ -1,3 +1,3 @@ return { - ["calibrate"] = function(_,s) dofile("cap1188-init.lc").calibrate() end + ["calibrate"] = function(_,s) OVL["cap1188-init"]().calibrate() end } -- 2.50.1