2025-08-31 20:23:11 +08:00
|
|
|
-- 程序顶部名称栏
|
|
|
|
|
local term = require("term")
|
|
|
|
|
local colors = require("colors")
|
|
|
|
|
|
|
|
|
|
-- 保存当前颜色设置
|
|
|
|
|
local old_fg = term.getTextColor()
|
|
|
|
|
local old_bg = term.getBackgroundColor()
|
|
|
|
|
|
|
|
|
|
-- 设置名称栏颜色并显示
|
|
|
|
|
term.setTextColor(colors.white)
|
|
|
|
|
term.setBackgroundColor(colors.cyan)
|
|
|
|
|
term.at(1, 1).clearLine()
|
|
|
|
|
term.at(1, 1).write("=== 红石控制 ===")
|
|
|
|
|
|
|
|
|
|
-- 恢复颜色设置
|
|
|
|
|
term.setTextColor(old_fg)
|
|
|
|
|
term.setBackgroundColor(old_bg)
|
|
|
|
|
term.at(1, 2)
|
|
|
|
|
|
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 和命令补全系统
- 多标签终端支持
- 设置管理系统
2025-08-31 16:54:18 +08:00
|
|
|
local rc = require("rc")
|
|
|
|
|
local rs = require("redstone")
|
|
|
|
|
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
|