/
Sangak
/
ardupilot
Обзор
Документация
Войти
/
Sangak
/
ardupilot
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
libraries/AP_Scripting/examples/i2c_scan.lua
30 строк
673 B
Iampete1
AP_Scripting: ignore lua-language-server-errors
21 май 2024, 02:42
21 май 2024, 02:42
5bb5f44
Код
Авторство
О чём код?
-- This script scans for devices on the i2c bus ---@diagnostic disable: need-check-nil local address = 0 local found = 0 local i2c_bus = i2c:get_device(0,0) i2c_bus:set_retries(10) function update() -- this is the loop which periodically runs i2c_bus:set_address(address) if i2c_bus:read_registers(0) then gcs:send_text(0, "Found I2C at " .. tostring(address)) found = found + 1 end address = address + 1 if address == 127 then address = 0 gcs:send_text(0, "Found " .. tostring(found) .. " devices") found = 0 end return update, 100 -- reschedules the loop end return update() -- run immediately before starting to reschedule