#!/usr/bin/lua5.1 -- Created by jiaqiang.ye@lnxall.com -- Simple script invoked when system is going down for XL9555/DO local invoker = require "invoker" local g_setfunc = nil local g_delmsec = 150 local g_runtime = nil local function dummy_setdodown() io.stderr:write("Warning, dummy setdodown function called.\n") io.stderr:flush() return false end local function xl9555_setdodown() invoker.invoke(0, "i2cset", "-y", "0", "0x23", "0x6", "0xffff", "w") invoker.invoke(0, "i2cset", "-y", "0", "0x23", "0x4", "0x0", "w") invoker.invoke(0, "i2cset", "-y", "0", "0x23", "0x2", "0x0", "w") local now = invoker.uptime() if (now - g_runtime) >= 10 then return false end return true end local function downinit() invoker.setname("SETDODOWN") g_runtime = invoker.uptime() g_setfunc = dummy_setdodown local okay, uname = invoker.invoke(invoker.OUTPUT, "uname", "-a") if okay ~= 0 or type(uname) ~= "string" then io.stderr:write("Error, command `uname -a` has failed.\n") io.stderr:flush() return false end local model = invoker.readfile("/proc/device-tree/model") if type(model) ~= "string" then model = "" end if string.find(uname, "aarch64", 1, true) and string.find(uname, "4.19.232", 1, true) and string.find(model, "3568", 1, true) then g_delmsec = 5 g_setfunc = xl9555_setdodown io.stdout:write("Found RK3568/EMS1000 board!\n") io.stdout:flush() return true end local cpuinfo = invoker.readfile("/proc/cpuinfo") if not cpuinfo then cpuinfo = "" end if string.find(uname, "armv7l", 1, true) and string.find(uname, "5.4.70", 1, true) and string.find(cpuinfo, "i.MX6 Ultralite", 1, true) and invoker.statfile("/dev/i2c-0") == "character" then g_setfunc = xl9555_setdodown io.stdout:write("Found imx6ul/new board!\n") io.stdout:flush() return true end return false end local function mainfunc() okay = true while okay do okay = g_setfunc() invoker.msleep(g_delmsec) end return true end downinit() mainfunc()