-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from SkyoKen/rascon1.0
Ver.1.0
- Loading branch information
Showing
9 changed files
with
547 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import inspect | ||
import logging | ||
import asyncio | ||
|
||
from aioconsole import ainput | ||
|
||
from joycontrol.controller_state import button_push, ControllerState | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ControllerCLI: | ||
def __init__(self, controller_state: ControllerState): | ||
self.controller_state = controller_state | ||
self.available_buttons = self.controller_state.button_state.get_available_buttons() | ||
self.available_sticks = {'ls','rs'} | ||
self.script = False | ||
|
||
async def write(self,msg): | ||
with open('file/message.txt','a') as f: | ||
f.write(msg+'\n') | ||
|
||
async def get(self,file): | ||
with open('file/'+file,'r') as f: | ||
result = list() | ||
for line in f.readlines(): #依次读取每行 | ||
line = line.strip() #去掉每行头尾空白 | ||
if not len(line) or line.startswith('#'): #判断是否是空行或注释行 | ||
continue #是的话,跳过不处理 | ||
result.append(line.lower()) #保存小写文字 | ||
return result | ||
async def clear(self,file): | ||
with open('file/'+file,'w+') as f: | ||
return f.truncate() | ||
|
||
async def runCommand(self): | ||
user_input = await self.get('command.txt') | ||
if not user_input: | ||
return | ||
await self.clear('command.txt') | ||
|
||
for command in user_input: | ||
cmd, *args = command.split() | ||
|
||
if cmd == 'run': | ||
self.script = True | ||
elif cmd == 'stop': | ||
self.script = False | ||
elif cmd == 'off' or cmd =='on': | ||
print('开/关 未完成') | ||
else: | ||
await self.pressButton(command) | ||
return ' ' | ||
async def pressButton(self,*commands): | ||
for command in commands: | ||
cmd,*args=command.split() | ||
if cmd in self.available_sticks: | ||
print('side = ',cmd,'direction = ',args[0]) | ||
elif cmd in self.available_buttons: #按钮 | ||
await button_push(self.controller_state,cmd) | ||
elif cmd.isdecimal(): #等待(ms) | ||
await asyncio.sleep(float(cmd)/1000) | ||
elif cmd == 'print': | ||
print(args[0]) | ||
else: #错误代码 | ||
print('command',cmd,'not found') | ||
async def readCommand(self,file): | ||
user_input = await self.get(file) | ||
if not user_input: | ||
return | ||
await self.clear(file) | ||
def isCommand(self,cmd): | ||
return cmd in self.available_sticks or cmd in self.available_buttons or cmd.isdecimal() or cmd =='print' | ||
|
||
def forCheck(self,n,user_input): | ||
commands = [] | ||
until = -1 | ||
for i in range(len(user_input)): | ||
if i <= n or i<= until: | ||
continue | ||
|
||
cmd,*args = user_input[i].split() | ||
if cmd == 'for': | ||
for _ in range(int(args[0])): | ||
until,forcmd = self.forCheck(i,user_input) | ||
for get in forcmd: | ||
commands.append(get) | ||
elif cmd == 'next': | ||
return i,commands | ||
elif self.isCommand(cmd): | ||
commands.append(user_input[i]) | ||
else: | ||
print('command',cmd,'not found') | ||
|
||
async def runScript(self): | ||
user_input = await self.get('script.txt') | ||
if not user_input: | ||
return | ||
await self.clear('script.txt') | ||
|
||
commands=[] | ||
until=-1 | ||
for i in range(len(user_input)): | ||
#检测按键 | ||
await self.runCommand() | ||
#确认脚本是否要停止 | ||
if self.script == False: | ||
return | ||
|
||
if i <= until: | ||
continue | ||
|
||
cmd, *args =user_input[i].split() | ||
if cmd == 'for': | ||
for _ in range(int(args[0])): | ||
until,forcmd = self.forCheck(i,user_input) | ||
for get in forcmd: | ||
commands.append(get) | ||
elif self.isCommand(cmd): | ||
commands.append(user_input[i]) | ||
else: | ||
print('commands',cmd,'not found') | ||
|
||
for command in commands: | ||
await self.runCommand() | ||
if self.script == False: | ||
return | ||
|
||
await self.pressButton(command) | ||
|
||
self.script = False | ||
|
||
async def run(self): | ||
|
||
while True: | ||
#等待输入 | ||
cmd = await self.runCommand() | ||
if cmd == 'exit': | ||
return | ||
if self.script == True: | ||
await self.runScript() | ||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
该功能暂时无法使用 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
使用方法 | ||
|
||
所有代码不区分大小写,支持前置后置空格,支持行内注释。 | ||
|
||
【注释】 | ||
语法:# 注释内容 | ||
|
||
【输出】 | ||
语法:PRINT 输出内容 | ||
暂不显示 | ||
|
||
【按键】 | ||
语法:键位 [持续时间(ms)|DOWN|UP] | ||
(键位可以取A、B、X、Y、L、R、ZL、ZR、MINUS(-)、PLUS(+)、LCLICK(按左摇杆)、RCLICK(按右摇杆)、HOME(返回系统)、CAPTURE(截屏)、LEFT、RIGHT、UP、DOWN;持续时间省略则为默认50ms) | ||
示例:A(按下A键50毫秒) | ||
|
||
【摇杆】 | ||
暂时无法使用 | ||
|
||
【等待】 | ||
语法:等待时间(ms) | ||
示例:2000 | ||
|
||
【循环】 | ||
语法: | ||
FOR 循环次数 | ||
... | ||
NEXT | ||
|
||
|
||
脚本参考铃落大佬的伊机控写的 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#<<剑盾自动放生>> | ||
#———————准备工作——————— | ||
# 语速——快; | ||
# 对战动画——不看; | ||
# 比赛规则——连战; | ||
# 自动记录——关闭; | ||
# 小轻松模式——关闭; | ||
# 跳过动画——开启; | ||
#———————使用方法——————— | ||
#1.打开游戏菜单进入宝可梦队伍 | ||
#2.按R进入箱子选到需要放生的那个箱子上(请保证有一整箱要放生的精灵) | ||
#3.光标对准要放生的第一箱的第一个精灵,点击RUN即可 | ||
#———————注意事项——————— | ||
#想放生的箱子都是满的并且是可以放生的精灵 | ||
#运行前需要修改下面的是放生箱数 | ||
#—————这数字是放生箱数————— | ||
for 1 | ||
#—————————————— | ||
for 3 | ||
a | ||
800 | ||
up | ||
100 | ||
up | ||
100 | ||
a | ||
1000 | ||
up | ||
100 | ||
a | ||
1000 | ||
a | ||
500 | ||
for 4 | ||
down | ||
100 | ||
a | ||
800 | ||
up | ||
100 | ||
up | ||
100 | ||
a | ||
1000 | ||
up | ||
100 | ||
a | ||
1000 | ||
a | ||
500 | ||
next | ||
right | ||
100 | ||
a | ||
800 | ||
up | ||
100 | ||
up | ||
100 | ||
a | ||
1000 | ||
up | ||
100 | ||
a | ||
1000 | ||
a | ||
500 | ||
for 4 | ||
up | ||
100 | ||
a | ||
800 | ||
up | ||
100 | ||
up | ||
100 | ||
a | ||
1000 | ||
up | ||
100 | ||
a | ||
1000 | ||
a | ||
500 | ||
next | ||
right | ||
100 | ||
next | ||
left | ||
100 | ||
l | ||
100 | ||
for 5 | ||
left | ||
100 | ||
next | ||
next |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import argparse | ||
import asyncio | ||
import logging | ||
import os | ||
from contextlib import contextmanager | ||
|
||
from joycontrol import logging_default as log | ||
from joycontrol.command_line_interface import ControllerCLI | ||
from joycontrol.controller import Controller | ||
from joycontrol.memory import FlashMemory | ||
from joycontrol.protocol import controller_protocol_factory | ||
from joycontrol.server import create_hid_server | ||
import command | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
async def _main(controller, capture_file=None, spi_flash=None): | ||
factory = controller_protocol_factory(controller, spi_flash=spi_flash) | ||
transport, protocol = await create_hid_server(factory, 17, 19, capture_file=capture_file) | ||
|
||
controller_state = protocol.get_controller_state() | ||
|
||
cli = command.ControllerCLI(controller_state) | ||
await controller_state.connect() | ||
await cli.run() | ||
|
||
logger.info('Stopping communication...') | ||
await transport.close() | ||
|
||
|
||
if __name__ == '__main__': | ||
# check if root | ||
if not os.geteuid() == 0: | ||
raise PermissionError('Script must be run as root!') | ||
|
||
# setup logging | ||
log.configure() | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-l', '--log') | ||
parser.add_argument('--spi_flash') | ||
args = parser.parse_args() | ||
|
||
controller = Controller.PRO_CONTROLLER | ||
|
||
spi_flash = None | ||
if args.spi_flash: | ||
with open(args.spi_flash, 'rb') as spi_flash_file: | ||
spi_flash = spi_flash_file.read() | ||
|
||
# creates file if arg is given | ||
@contextmanager | ||
def get_output(path=None): | ||
""" | ||
Opens file if path is given | ||
""" | ||
if path is not None: | ||
file = open(path, 'wb') | ||
yield file | ||
file.close() | ||
else: | ||
yield None | ||
|
||
with get_output(args.log) as capture_file: | ||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(_main(controller, capture_file=capture_file, spi_flash=spi_flash)) |
Oops, something went wrong.