Merge from old Gitea
This commit is contained in:
27
examples/NFC.py
Normal file
27
examples/NFC.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import asyncio
|
||||
import time
|
||||
from esasdk import Machine
|
||||
|
||||
async def main():
|
||||
# Connect to a machine
|
||||
machine = Machine("ws://localhost:5424")
|
||||
await machine.connect()
|
||||
|
||||
# send NFC UID
|
||||
login = await machine.login_NFC("048CB772AC6D81")
|
||||
loginInfo = login.split(" ")
|
||||
userID = loginInfo[-1]
|
||||
# start a game as jon
|
||||
gameCode = "MAES"
|
||||
countdown = 5
|
||||
duration = 15
|
||||
await machine.game_start(gameCode, userID, countdown, duration)
|
||||
print(f"INFO: running {gameCode}")
|
||||
# wait a stop event
|
||||
await machine._await_message("STOPPED")
|
||||
print("INFO: game stopped")
|
||||
# Close connection
|
||||
await machine.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
62
examples/example-multiple-devices.py
Normal file
62
examples/example-multiple-devices.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import asyncio
|
||||
from esasdk import Machine
|
||||
|
||||
######## Custom command broadcast to multiple machines ########
|
||||
async def broadcast_command(machines, command):
|
||||
return await asyncio.gather(
|
||||
*[m._send_command(command) for m in machines]
|
||||
)
|
||||
|
||||
######## Different commands to different machines ########
|
||||
async def mixed_operations():
|
||||
m1 = Machine("ws://worker1")
|
||||
m2 = Machine("ws://supervisor")
|
||||
|
||||
await asyncio.gather(
|
||||
m1.connect(),
|
||||
m2.connect()
|
||||
)
|
||||
|
||||
results = await asyncio.gather(
|
||||
m1.poweroff(),
|
||||
m2.info()
|
||||
)
|
||||
|
||||
await asyncio.gather(
|
||||
m1.close(),
|
||||
m2.close()
|
||||
)
|
||||
|
||||
################### MAIN EXAMPLE ################
|
||||
async def manage_machine(machine: Machine):
|
||||
"""Handle connection and commands for a single machine"""
|
||||
try:
|
||||
await machine.connect()
|
||||
print(f"Connected to {machine.uri}")
|
||||
|
||||
# Get machine info
|
||||
info = await machine.info()
|
||||
print(f"{machine.uri} info: {info}")
|
||||
|
||||
# Power off the machine
|
||||
result = await machine.poweroff()
|
||||
print(f"{machine.uri} poweroff result: {result}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error with {machine.uri}: {str(e)}")
|
||||
finally:
|
||||
await machine.close()
|
||||
|
||||
async def main():
|
||||
# Create multiple machine connections
|
||||
machines = [
|
||||
Machine("ws://machine1.example.com:8765"),
|
||||
Machine("ws://machine2.example.com:8765"),
|
||||
Machine("ws://machine3.example.com:8765")
|
||||
]
|
||||
|
||||
# Run all machine operations concurrently
|
||||
await asyncio.gather(*[manage_machine(m) for m in machines])
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
47
examples/example.py
Normal file
47
examples/example.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import asyncio
|
||||
import time
|
||||
from esasdk import Machine
|
||||
|
||||
async def main():
|
||||
# Connect to a machine
|
||||
machine = Machine("ws://localhost:5424")
|
||||
await machine.connect()
|
||||
|
||||
# Get machine info
|
||||
name = await machine.name()
|
||||
print(f"Machine Name: {name}")
|
||||
|
||||
# Get machine info
|
||||
info = await machine.info()
|
||||
print(f"Machine Info: {info}")
|
||||
|
||||
# Get machine size
|
||||
size = await machine.size()
|
||||
print(f"Machine Size: {size}")
|
||||
|
||||
# get versions
|
||||
sw = await machine.software_version()
|
||||
print(f"SW: {sw}")
|
||||
sw1 = await machine.software_version(1)
|
||||
print(f"SW1: {sw1}")
|
||||
|
||||
# Get machine volume
|
||||
volume = await machine.volume()
|
||||
print(f"Machine Volume: {volume}")
|
||||
# Set machine volume
|
||||
volume = await machine.volume(50)
|
||||
print(f"Machine Volume: {volume}")
|
||||
|
||||
# Get machine brightness
|
||||
brightness = await machine.brightness()
|
||||
print(f"Machine Brightness: {brightness}")
|
||||
|
||||
# Get machine power
|
||||
power = await machine.power()
|
||||
print(f"Machine Power (Volts): {power}")
|
||||
|
||||
# Close connection
|
||||
await machine.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
36
examples/game.py
Normal file
36
examples/game.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import asyncio
|
||||
import time
|
||||
from esasdk import Machine
|
||||
|
||||
async def main():
|
||||
# Connect to a machine
|
||||
machine = Machine("ws://localhost:5424")
|
||||
await machine.connect()
|
||||
|
||||
# start a game
|
||||
gameCode = "MAES"
|
||||
await machine.game_start(gameCode)
|
||||
print(f"running {gameCode}")
|
||||
|
||||
# wait a bit and stop the game
|
||||
time.sleep(15)
|
||||
await machine.game_stop()
|
||||
print("game stopped forcefully")
|
||||
|
||||
# start a game as jon
|
||||
gameCode = "MAES"
|
||||
user = "16566"
|
||||
countdown = 15
|
||||
duration = 15
|
||||
await machine.game_start(gameCode, user, countdown, duration)
|
||||
print(f"running {gameCode}")
|
||||
|
||||
# wait for game stopped signal to know the game has stopped.
|
||||
await machine.game_stop_signal()
|
||||
print("game stopped naturally")
|
||||
|
||||
# Close connection
|
||||
await machine.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
33
examples/game_events.py
Normal file
33
examples/game_events.py
Normal file
@@ -0,0 +1,33 @@
|
||||
#TODO: This needs IMP to be implemented as a websocket message not just a control panel message
|
||||
|
||||
import asyncio
|
||||
import time
|
||||
from esasdk import Machine
|
||||
|
||||
async def main():
|
||||
# Connect to a machine
|
||||
machine = Machine("ws://localhost:5424")
|
||||
await machine.connect()
|
||||
|
||||
# start a game
|
||||
gameCode = "MAES"
|
||||
countdown = 5
|
||||
duration = 15
|
||||
await machine.game_start(gameCode, 0, countdown, duration)
|
||||
print(f"running {gameCode}")
|
||||
|
||||
# wait for impact event - TODO: use 3491 socket or improve websocket?
|
||||
await machine._await_message("IMP")
|
||||
print("Impact!")
|
||||
|
||||
# program in game events like seconds remaining and hits/misses.
|
||||
|
||||
# wait for game stopped signal to know the game has stopped.
|
||||
#await machine.game_stop()
|
||||
await machine.game_stop_signal()
|
||||
|
||||
# Close connection
|
||||
await machine.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
26
examples/logs.py
Normal file
26
examples/logs.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import asyncio
|
||||
import time
|
||||
from esasdk import Machine
|
||||
|
||||
async def main():
|
||||
# Connect to a machine
|
||||
machine = Machine("ws://localhost:5424")
|
||||
await machine.connect()
|
||||
|
||||
# Get machine logs
|
||||
logs = await machine.log()
|
||||
print(f"Machine logs: {logs}")
|
||||
|
||||
# Get machine log state - not implemented in cpp yet.
|
||||
#log = await machine.log('GameBase')
|
||||
#print(f"Machine logs: {log}")
|
||||
|
||||
# Set machine log state - TODO: reply message is not implemented in cpp yet.
|
||||
log = await machine.log_enabled('GameBase', True)
|
||||
#print(f"Machine logs: {log}")
|
||||
|
||||
# Close connection
|
||||
await machine.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
26
examples/power.py
Normal file
26
examples/power.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import asyncio
|
||||
import time
|
||||
from esasdk import Machine
|
||||
|
||||
async def main():
|
||||
# Connect to a machine
|
||||
machine = Machine("ws://localhost:5424")
|
||||
await machine.connect()
|
||||
|
||||
# Get machine power
|
||||
power = await machine.power()
|
||||
print(f"Machine Power (Volts): {power}")
|
||||
|
||||
# Get machine power source
|
||||
powerSource = await machine.power_source()
|
||||
print(f"Machine Power Source: {powerSource}")
|
||||
|
||||
# Set machine power timer - TODO: cpp response for this call.
|
||||
powerTimer = await machine.poweroff_timer_enable(False)
|
||||
print(f"Machine Power Timer: {powerTimer}")
|
||||
|
||||
# Close connection
|
||||
await machine.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
16
examples/test.py
Normal file
16
examples/test.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import asyncio
|
||||
import time
|
||||
from esasdk import Machine
|
||||
|
||||
async def main():
|
||||
# Connect to a machine
|
||||
machine = Machine("ws://localhost:5424")
|
||||
await machine.connect()
|
||||
|
||||
await machine.forceUserlistDownload()
|
||||
|
||||
# Close connection
|
||||
await machine.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user