sys - sys Library#
Adapted Air780E
Note
This page document is automatically generated by this file. If there is any error, please submit issue or help modify pr, thank you!
Tip
There are also video tutorials in this library, click this link to view
sys.wait(timeout)#
Task Concoroutation waiting for specified duration
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
The waiting time, in milliseconds, must be greater than 0, otherwise it is invalid. |
Return Value
return value type |
explanation |
---|---|
any |
usually nil unless actively awakened (usually not) |
Examples
sys.taskInit(function()
while 1 do
sys.wait(500)
end
end)
sys.waitUntil(topic, timeout)#
Task The concord waits for a specified length or a specific topic
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
Event topic |
int |
The waiting time, in milliseconds, must be greater than 0, otherwise it is invalid. |
Return Value
return value type |
explanation |
---|---|
boolean |
If it is a timeout, return false, otherwise return true |
any |
content corresponding to the topic |
Examples
sys.taskInit(function()
// do something
local result, data = sys.waitUntil("NET_READY", 30000)
// do something else
end)
sys.taskInit(func, arg1, arg2, argN)#
Create a Task Concord
Parameters
Incoming Value Type |
Explanation |
---|---|
function |
The function to be executed, which can be an anonymous function or a local or global function. |
any |
Parameter 1 to be passed, optional |
any |
Parameter 2 to be passed, optional |
any |
Parameter N to be passed, optional |
Return Value
return value type |
explanation |
---|---|
task |
Concoroutation Object |
Examples
sys.taskInit(function(a, b, c)
log.info("task", a, b, c) -- Print task A B C
end, "A", "B", "N")
sys.timerStart(func, timeout, arg1, arg2, argN)#
Create a timer. Non-Task, function cannot be directly sys.waitXXX
Parameters
Incoming Value Type |
Explanation |
---|---|
function |
The function to be executed, which can be an anonymous function or a local or global function. |
int |
Delay duration, in milliseconds |
any |
Parameter 1 to be passed, optional |
any |
Parameter 2 to be passed, optional |
any |
Parameter N to be passed, optional |
Return Value
return value type |
explanation |
---|---|
int |
Timer id |
Examples
sys.timerStart(function(a, b, c)
log.info("task", a, b, c) -- 1000 It will be executed after milliseconds. Print task A B C
end, 1000, "A", "B", "N")
sys.timerLoopStart(func, timeout, arg1, arg2, argN)#
Create a loop timer. Non-Task, function cannot be directly sys.waitXXX
Parameters
Incoming Value Type |
Explanation |
---|---|
function |
The function to be executed, which can be an anonymous function or a local or global function. |
int |
Delay duration, in milliseconds |
any |
Parameter 1 to be passed, optional |
any |
Parameter 2 to be passed, optional |
any |
Parameter N to be passed, optional |
Return Value
return value type |
explanation |
---|---|
int |
Timer id |
Examples
sys.timerLoopStart(function(a, b, c)
log.info("task", a, b, c) -- 1000 It will be executed after milliseconds. Print task A B C
end, 1000, "A", "B", "N")
sys.timerStop(id)#
Turn off a timer.
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
Timer id |
Return Value
return value type |
explanation |
---|---|
nil |
No return value |
Examples
local tcount = 0
local tid
tid = sys.timerLoopStart(function(a, b, c)
log.info("task", a, b, c) -- 1000 It will be executed after milliseconds. Print task A B C
if tcount > 10 then
sys.timerStop(tid)
end
tcount = tcount + 1
end, 1000, "A", "B", "N")
sys.timerStopAll(fnc)#
Turn off all timers for the same callback function.
Parameters
Incoming Value Type |
Explanation |
---|---|
function |
fnc callback function |
Return Value
return value type |
explanation |
---|---|
nil |
No return value |
Examples
-- Turn off the callback function for all timers publicTimerCbFnc
local function publicTimerCbFnc(tag)
log.info("publicTimerCbFnc",tag)
end
sys.timerStart(publicTimerCbFnc,8000,"first")
sys.timerStart(publicTimerCbFnc,8000,"second")
sys.timerStart(publicTimerCbFnc,8000,"third")
sys.timerStopAll(publicTimerCbFnc)
sys.publish(topic, arg1, agr2, argN)#
publish a message to a specific topic channel
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
topic The value |
any |
incidental parameters 1 |
any |
incidental parameters 2 |
any |
incidental parameters N |
Return Value
return value type |
explanation |
---|---|
nil |
No return value |
Examples
sys.publish("BT_READY", false)
sys.subscribe(topic, func)#
subscribe to a topic channel
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
topic The value |
function |
Callback function, note, cannot be used directly sys.waitXXX |
Return Value
return value type |
explanation |
---|---|
nil |
No return value |
Examples
local function bt_cb(state)
log.info("bt", state)
end
sys.subscribe("BT_READY", bt_cb)
sys.subscribe("BT_READY", function(state)
log.info("sys", "Got BT_READY", state)
end)
sys.unsubscribe(topic, func)#
unsubscribe from topic channel
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
topic The value |
function |
Callback function, note, cannot be used directly sys.waitXXX |
Return Value
return value type |
explanation |
---|---|
nil |
No return value |
Examples
local function bt_cb(state)
log.info("bt", state)
end
sys.unsubscribe("BT_READY", bt_cb)
sys.run()#
sys Library main loop method, allowed to be called only at the end of main.lua
Parameters
None
Return Value
return value type |
explanation |
---|---|
nil |
No return value. It is almost impossible for this method to return. |
Examples
-- Always the end of main.lua, which may be simplified in the future.
sys.run()
-- After the code is not executed