设置任意按钮配置的工具
项目描述
AITPI
终端或 Pi 或 Aitpi 的任意输入(发音为“8 pi”)
目标
该项目的目标是提供一种简单但任意的输入机制,用于树莓派或终端键盘(将来可能会有更多 SBC?!)。
这个程序可以配置两个简单的 json 文件。
支持的
该项目支持:
- 简单的“按钮”
- '1 to 1' gpio 到树莓派上的按钮设置
- 非基于中断的键输入
- 基于中断的键输入(使用 pynput)
- 编码器
- '2 to 1' gpio 到树莓派上的编码器设置
- 基于非中断的 2 对 1 键输入
- 基于中断的 2 对 1 键输入(使用 pynput)
例子
要配置您的设置,您最多可以创建三种类型的 json 文件:
命令注册表:
将直接与您的用户程序交互的命令注册表
[
{
"type": "normal",
"input_type": "button",
"id": "1",
"name": "command0"
},
{
"id": "1",
"input_type": "button",
"path": "../temp/",
"type": "presets",
"name": "howdy"
},
{
"id": "1",
"input_type": "button",
"path": "../temp/",
"type": "presets",
"name": "test"
},
{
"id": "1",
"input_type": "button",
"path": "../temp/",
"type": "presets",
"name": "another.txt"
}
]
- 名称:呈现的唯一标识符。
- id:每个命令发送的消息id
- input_type:抽象功能表示,即(目前)按钮或编码器
- 类型:每个命令的类别。必须定义,但仅用于对命令进行有效排序
- 路径:仅用于文件夹命令。告诉表示文件的文件路径。
输入列表
您的系统使用的所有“输入单元”的列表
[
{
"name": "Button0",
"type": "button",
"mechanism": "rpi_gpio",
"trigger": "5",
"reg_link": "commandName0"
},
{
"name": "Encoder0",
"type": "encoder",
"mechanism": "rpi_gpio",
"left_trigger": "17",
"right_trigger": "24",
"reg_link": "commandName2"
}
]
- 这是一个深度为 1 的数组,所有“输入单元”都列为字典
- “name”:指定输入单元的名称
- 有效名称:任何字符串,在所有输入单元中必须是唯一的
- “type”:指定这个单元是什么类型的输入
- 有效类型:“按钮”、“编码器”
- “机制”:这告诉 Aitpi 通过什么机制来监视输入
- 有效机制:'key_interrupt'、'key_input'、'rpi_gpio'
- key_interrupt:使用pynput设置键盘本身的中断
- key_input:通过函数'aitpi.takeInput'手动输入代码
- rpi_gpio:树莓派GPIO输入,所有输入单元都假定为低电平有效
- 有效机制:'key_interrupt'、'key_input'、'rpi_gpio'
- “触发器”:将触发按钮输入的键字符串或 gpio 编号
- 注意:仅当 'type' 等于 'button' 时才需要
- 有效触发器:任何字符串,或树莓派上任何有效的未使用的 gpio 编号
- 注意超过一个字符的字符串不适用于 key_interrupt (pynput)
- “left_trigger”和“right_trigger”:作为编码器左或右的键字符串或gpio数字
- 注意:仅当 'type' 等于 'encoder' 时才需要这些
- 有效的 left_triggers 和 right_triggers:任何字符串,或树莓派上任何有效的未使用的 gpio 编号
- 注意超过一个字符的字符串不适用于 key_interrupt (pynput)
- “reg_link”:这对应于命令注册表中的命令,并将确定将什么消息发送到您的用户程序
- “name”:指定输入单元的名称
文件夹命令
文件夹命令允许您将文件夹中的所有文件视为注册表中的“命令”。这使用watchdog python 包来监视文件夹并动态更新。添加的所有命令将在程序启动时删除并重新加载。
[
{
"name": "Folder0",
"path": "/path/to/your/folder",
"type": "<registry_type>",
"id": "3",
"input_type": "button"
},
{
"name": "Folder1",
"path": "/another/path",
"type": "<registry_type>",
"id": "4",
"input_type": "encoder"
}
]
- 这是一个深度为 1 的数组,列出了您要添加的所有文件夹
- “name”:给出一个名称,您可以使用该名称使用“getFolderedCommands”访问 json
- 有效名称:任何字符串
- “path”:指定将被监视的文件夹
- 有效路径:系统上的任何有效文件夹
- “type”:这将告诉 Aitpi 将文件夹中的命令插入到命令注册表的位置
- 有效类型:任何字符串
- “id”:从文件夹添加命令时,此 id 将是命令注册表 'id' 值
- 有效 id:任何正整数、负整数都保留给 Aitpi,可能会产生不良的副作用
- “input_type”:当从文件夹添加命令时,这直接对应于命令注册表的“input_type”
- “name”:给出一个名称,您可以使用该名称使用“getFolderedCommands”访问 json
示例用法:
# import the base aitpi
import aitpi
# The postal service allows us to receive messages
from aitpi import router
# In order to receive messages can either make an object with a consume(message) function
# or just provide a function `def consume(message)`
class Watcher():
def consume(self, message):
print("Got command: %s" % message.name)
print("On event: %s" % message.event)
print("All attributes: %s" % message.attributes)
watcher = Watcher()
# Here we add a consumer that will receive commands with ids 0,1,2,3,4, these ids are the sameconsume
# as defined in your registry json file.consume
router.addConsumer([0,1,2,3,4], watcher)
# We must first initialize our command registry before we can start getting input
aitpi.addRegistry("<path_to_json>/command_reg.json", "<path_to_json>/foldered_commands.json")
# We can add multiple registries, and do not need the foldered commands
aitpi.addRegistry("<path_to_json>/another_reg.json")
# Once we initialize our system, all interrupt based commands can be sent imediately.
# Therefore, make sure you are ready to handle any input in your functions before calling this.
aitpi.initInput("<path_to_json>/example_input.json")
# For synchronous input (not interrupt based) using the 'key_input' input mechanism is desireable
# You can setup a custom progromatic form of input using this (If it is good enough, add it to AITPI!)
while (True):
aitpi.takeInput(input())
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
aitpi-0.3.1.tar.gz
(16.4 kB
查看哈希)
内置分布
aitpi-0.3.1-py3-none-any.whl
(17.8 kB
查看哈希)