First of all this is my first post and i haven’t done html so it’s not gonna be pretty but that’s not the point.
Having said that here i present you with a very simple python script that allows the osr2 to work with xtoys.
!!(Big disclaimer: this was only tested on the esp32 version of osr2)!!
import serial
import time
import asyncio
import websockets
import json
ser = serial.Serial()
ser.port = ‘COM4’
ser.baudrate = 115200
ser.open()
header = ‘\r\n’
max = 75
min = 20
async def write(websocket):
async for message in websocket:
parsed = json.loads(message)
pos = parsed[“position”]
if pos > max:
pos = max
if pos < min:
pos = min
pos = str(pos)
if len(pos) == 1:
mess = str(“L000” + pos + header)
ser.write(mess.encode())
elif len(pos) == 2:
mess = “L0” + pos + “0” + header
ser.write(mess.encode())
else:
mess == “L999” + header
ser.write(mess.encode())
print(mess)
async def main():
async with websockets.serve(write, “localhost”, 8765):
await asyncio.Future() # run forever
asyncio.run(main())
When it comes to setting this up, in xtoys you have to go to the custom toys section and create a speed + position stroker new toy with websockets, then in its setting name it whatever you want and change the websocket info to ws://localhost:8765 or whatever you set the port in the script.
I wrote this for virtual succubus and in this configuration it works quite well.
Also i wrote this script which follows your mouse movement when you right click and stops when you right click again, this one i wrote for slave matrix but any game with similar mechanics should work.
import win32api
import time
import serial
import pyautogui
state_right = win32api.GetKeyState(0x02)
header = ‘\r\n’
ser = serial.Serial()
ser.port = ‘COM4’
ser.baudrate = 115200
ser.open()
max = 750
min = 60
while True:
b = win32api.GetKeyState(0x02)
if b != state_right:
state_right = b
if b < 0:
print('Right Button Pressed')
while True:
b = win32api.GetKeyState(0x02)
if b != state_right:
state_right = b
if b > 0:
print('Right Button Released')
break
x, y = pyautogui.position()
if y > max:
y = max
if y < min:
y = min
y=str(y)
print(y)
if len(y) == 1:
mess = str("L000" + y + header)
ser.write(mess.encode())
elif len(y) == 2:
mess = str("L00" + y + header)
ser.write(mess.encode())
elif len(y) == 3:
mess = str("L0" + y + header)
ser.write(mess.encode())
time.sleep(0.001)
Also for both toys you have to set the appropriate serial port in script. And remember for this to work you have to have installed python3 and the appropriate libraries which are serial, websockets and pyautogui. And also if your esp32 is not showing up then you need to install these drivers: CP210x USB to UART Bridge VCP Drivers - Silicon Labs.
Here is a link for google drive with these files so that you don’t have to copy and paste to a file since the formatting may be a bit screwed up: OSR2 - Google Drive