Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*.lua]
indent_style = tab
indent_size = tab
tab_width = 4

4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"json.schemas": [],
"terminal.integrated.defaultProfile.linux": "bash",
"[lua]": {
"editor.tabSize": 4
"editor.tabSize": 4,
"editor.insertSpaces": false,
"editor.detectIndentation": false
},
"Lua.diagnostics.workspaceDelay": -1,
"Lua.diagnostics.enable": true,
Expand Down
17 changes: 13 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ VENDOR_DIR := vendor
BUILD_DIR := build
TEST_DIR := tests
LINTER := luacheck
LUA_INDENT_DIRS := $(SRC_DIR) $(TEST_DIR) examples tools
UI_REPO ?= https://github.com/jangala-dev/local-ui.git
UI_DIR ?= local-ui
UI_WWW_DIR := $(SRC_DIR)/services/ui/www
Expand Down Expand Up @@ -115,11 +116,18 @@ test-all:
@rm -f $(VENDOR_DIR)/lua-bus/src/trie.lua
@echo "All tests complete."

# Lint: Static analysis on source and test directories
# Check-Indent: Enforce tab-based indentation in first-party Lua files
.PHONY: check-indent
check-indent:
@echo "Checking Lua indentation..."
@luajit tools/check_lua_indentation.lua $(LUA_INDENT_DIRS)
@echo "Lua indentation check complete."

# Lint: Indentation and static analysis on source and test directories
.PHONY: lint
lint:
lint: check-indent
@echo "Running linter..."
@$(LINTER) $(SRC_DIR) $(TEST_DIR)
@$(LINTER) $(SRC_DIR) $(TEST_DIR) tools
@echo "Linting complete."

# Clean: Remove the build directory
Expand All @@ -143,6 +151,7 @@ help:
@echo " env Pin vendor submodules to revisions in .env"
@echo " test Run the devicecode test suite"
@echo " test-all Run devicecode and all vendor test suites"
@echo " lint Run luacheck on $(SRC_DIR)/ and $(TEST_DIR)/"
@echo " check-indent Enforce tab-based indentation in first-party Lua files"
@echo " lint Run indentation checks and luacheck"
@echo " clean Remove $(BUILD_DIR)/"
@echo " help Show this message"
68 changes: 34 additions & 34 deletions examples/gpio_control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,48 @@ local fiber = require 'fibers.fiber'
local gpio = require 'gpio'

local map = {
{
{["1"] = false, ["7"] = false, ["8"] = true},
{["1"] = false, ["7"] = true, ["8"] = true},
{["1"] = true, ["7"] = false, ["8"] = false},
{["1"] = false, ["7"] = true, ["8"] = false},
{["1"] = true, ["7"] = true, ["8"] = true},
{["1"] = true, ["7"] = false, ["8"] = true}
},
{
{["24"] = false, ["23"] = false, ["18"] = true},
{["24"] = false, ["23"] = true, ["18"] = true},
{["24"] = true, ["23"] = false, ["18"] = false},
{["24"] = false, ["23"] = true, ["18"] = false},
{["24"] = true, ["23"] = true, ["18"] = true},
{["24"] = true, ["23"] = false, ["18"] = true}
}
{
{["1"] = false, ["7"] = false, ["8"] = true},
{["1"] = false, ["7"] = true, ["8"] = true},
{["1"] = true, ["7"] = false, ["8"] = false},
{["1"] = false, ["7"] = true, ["8"] = false},
{["1"] = true, ["7"] = true, ["8"] = true},
{["1"] = true, ["7"] = false, ["8"] = true}
},
{
{["24"] = false, ["23"] = false, ["18"] = true},
{["24"] = false, ["23"] = true, ["18"] = true},
{["24"] = true, ["23"] = false, ["18"] = false},
{["24"] = false, ["23"] = true, ["18"] = false},
{["24"] = true, ["23"] = true, ["18"] = true},
{["24"] = true, ["23"] = false, ["18"] = true}
}
}

local function map_modem_to_sim(modem_index, sim_index)
local pin_states = map[modem_index][sim_index]
for pin_no, value in pairs(pin_states) do
local pin = gpio.new_pin(pin_no)
assert(pin:export())
assert(pin:set_out())
if value then assert(pin:write_high()) else assert(pin:write_low()) end
end
local pin_states = map[modem_index][sim_index]
for pin_no, value in pairs(pin_states) do
local pin = gpio.new_pin(pin_no)
assert(pin:export())
assert(pin:set_out())
if value then assert(pin:write_high()) else assert(pin:write_low()) end
end
end

fiber.spawn(function ()
gpio.initialize_gpio()
gpio.initialize_gpio()

--set both en's to low
local ens = {25, 12}
for _, v in ipairs(ens) do
local pin = gpio.new_pin(v)
assert(pin:export())
assert(pin:set_out())
assert(pin:write_low())
end
map_modem_to_sim(2, 2)
--set both en's to low
local ens = {25, 12}
for _, v in ipairs(ens) do
local pin = gpio.new_pin(v)
assert(pin:export())
assert(pin:set_out())
assert(pin:write_low())
end
map_modem_to_sim(2, 2)

fiber.stop()
fiber.stop()
end)

fiber.main()
108 changes: 54 additions & 54 deletions examples/gpio_detect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@ local fiber = require 'fibers.fiber'
local gpio = require 'gpio'

local function setup(pin)
assert(pin:export())
assert(pin:pull_up())
assert(pin:set_in())
assert(pin:edge_both())
return pin
assert(pin:export())
assert(pin:pull_up())
assert(pin:set_in())
assert(pin:edge_both())
return pin
end

fiber.spawn(function ()
gpio.initialize_gpio()
gpio.initialize_gpio()

local p1 = setup(gpio.new_pin(5))
local p2 = setup(gpio.new_pin(6))
local p3 = setup(gpio.new_pin(13))
local p4 = setup(gpio.new_pin(19))
local p1 = setup(gpio.new_pin(5))
local p2 = setup(gpio.new_pin(6))
local p3 = setup(gpio.new_pin(13))
local p4 = setup(gpio.new_pin(19))

while true do
local status = op.choice(
p1:watch_op():wrap(function (status)
return status=="0" and "1: inserted" or "1: removed"
end),
p2:watch_op():wrap(function (status)
return status=="0" and "2: inserted" or "2: removed"
end),
p3:watch_op():wrap(function (status)
return status=="0" and "3: inserted" or "3: removed"
end),
p4:watch_op():wrap(function (status)
return status=="0" and "4: inserted" or "4: removed"
end)
):perform()
print(status)
end
while true do
local status = op.choice(
p1:watch_op():wrap(function (status)
return status=="0" and "1: inserted" or "1: removed"
end),
p2:watch_op():wrap(function (status)
return status=="0" and "2: inserted" or "2: removed"
end),
p3:watch_op():wrap(function (status)
return status=="0" and "3: inserted" or "3: removed"
end),
p4:watch_op():wrap(function (status)
return status=="0" and "4: inserted" or "4: removed"
end)
):perform()
print(status)
end
end)

fiber.main()
Expand All @@ -49,38 +49,38 @@ local fiber = require 'fibers.fiber'
local gpio = require 'gpio'

local function setup(pin)
assert(pin:export())
assert(pin:pull_up())
assert(pin:set_in())
assert(pin:edge_both())
return pin
assert(pin:export())
assert(pin:pull_up())
assert(pin:set_in())
assert(pin:edge_both())
return pin
end

fiber.spawn(function ()
gpio.initialize_gpio()
gpio.initialize_gpio()

local p1 = setup(gpio.new_pin(5))
local p2 = setup(gpio.new_pin(6))
local p3 = setup(gpio.new_pin(13))
local p4 = setup(gpio.new_pin(19))
local p1 = setup(gpio.new_pin(5))
local p2 = setup(gpio.new_pin(6))
local p3 = setup(gpio.new_pin(13))
local p4 = setup(gpio.new_pin(19))

while true do
local status = op.choice(
p1:watch_op():wrap(function (status)
return status=="0" and "1: inserted" or "1: removed"
end),
p2:watch_op():wrap(function (status)
return status=="0" and "2: inserted" or "2: removed"
end),
p3:watch_op():wrap(function (status)
return status=="0" and "3: inserted" or "3: removed"
end),
p4:watch_op():wrap(function (status)
return status=="0" and "4: inserted" or "4: removed"
end)
):perform()
print(status)
end
while true do
local status = op.choice(
p1:watch_op():wrap(function (status)
return status=="0" and "1: inserted" or "1: removed"
end),
p2:watch_op():wrap(function (status)
return status=="0" and "2: inserted" or "2: removed"
end),
p3:watch_op():wrap(function (status)
return status=="0" and "3: inserted" or "3: removed"
end),
p4:watch_op():wrap(function (status)
return status=="0" and "4: inserted" or "4: removed"
end)
):perform()
print(status)
end
end)

fiber.main()
Loading