mirror of
https://github.com/CCLeonOS/LeonOS.git
synced 2026-03-03 06:47:00 +00:00
feat: 初始提交 LeonOS 实现
添加 LeonOS 的基本实现,包括: - 核心 API 模块(colors, disk, gps, keys, multishell, parallel, rednet, redstone, settings, vector) - 命令行程序(about, alias, bg, clear, copy, delete, edit, fg, help, list, lua, mkdir, move, paint, peripherals, programs, reboot, set, shutdown, threads) - 系统启动脚本和包管理 - 文档(README.md, LICENSE) - 开发工具(devbin)和更新程序 实现功能: - 完整的线程管理系统 - 兼容 ComputerCraft 的 API 设计 - 改进的 shell 和命令补全系统 - 多标签终端支持 - 设置管理系统
This commit is contained in:
88
data/computercraft/lua/rom/programs/redstone.lua
Normal file
88
data/computercraft/lua/rom/programs/redstone.lua
Normal file
@@ -0,0 +1,88 @@
|
||||
local rc = require("rc")
|
||||
local rs = require("redstone")
|
||||
local colors = require("colors")
|
||||
local textutils = require("textutils")
|
||||
|
||||
local args = {...}
|
||||
|
||||
local commands = {}
|
||||
|
||||
local sides = {"top", "bottom", "left", "right", "front", "back"}
|
||||
|
||||
function commands.probe()
|
||||
textutils.coloredPrint(colors.yellow, "redstone inputs", colors.white)
|
||||
local inputs = {}
|
||||
for i=1, #sides, 1 do
|
||||
if rs.getInput(sides[i]) then
|
||||
inputs[#inputs+1] = sides[i]
|
||||
end
|
||||
end
|
||||
if #inputs == 0 then inputs[1] = "None" end
|
||||
print(table.concat(inputs, ", "))
|
||||
return true
|
||||
end
|
||||
|
||||
local function coerce(value)
|
||||
if value == "true" then return true end
|
||||
if value == "false" then return false end
|
||||
return tonumber(value) or value
|
||||
end
|
||||
|
||||
function commands.set(side, color, value)
|
||||
if not side then
|
||||
io.stderr:write("side expected\n")
|
||||
return true
|
||||
end
|
||||
|
||||
if not value then
|
||||
value = color
|
||||
color = nil
|
||||
end
|
||||
|
||||
value = coerce(value)
|
||||
if type(value) == "string" then
|
||||
io.stderr:write("value must be boolean or 0-15\n")
|
||||
end
|
||||
|
||||
if color then
|
||||
color = coerce(color)
|
||||
if type(value) == "number" then
|
||||
io.stderr:write("value must be boolean\n")
|
||||
end
|
||||
|
||||
if not colors[color] then
|
||||
io.stderr:write("color not defined\n")
|
||||
end
|
||||
|
||||
rs.setBundledOutput(side, colors[color], value)
|
||||
|
||||
elseif type(value) == "boolean" then
|
||||
rs.setOutput(side, value)
|
||||
|
||||
else
|
||||
rs.setAnalogOutput(side, value)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function commands.pulse(side, count, period)
|
||||
count = tonumber(count) or 1
|
||||
period = tonumber(period) or 0.5
|
||||
|
||||
for _=1, count, 1 do
|
||||
rs.setOutput(side, true)
|
||||
rc.sleep(period / 2)
|
||||
rs.setOutput(side, false)
|
||||
rc.sleep(period / 2)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
if not (args[1] and commands[args[1]] and
|
||||
commands[args[1]](table.unpack(args, 2))) then
|
||||
io.stderr:write("Usages:\nredstone probe\n"..
|
||||
"redstone set <side> <value>\nredstone set <side> <color> <value>\n"..
|
||||
"redstone pulse <side> <count> <period>\n")
|
||||
end
|
||||
Reference in New Issue
Block a user