text stringlengths 1 93.6k |
|---|
def print_queue(qval):
|
while qval.qsize() > 0:
|
timestamp = '{:%H:%M:%S.%f}'.format(datetime.datetime.now())
|
message = qval.get()
|
print(timestamp + ' -> ' + message)
|
socketio.emit('my_response',
|
{'data': message, 'type': 'event', 'time': timestamp})
|
def background_thread(qval):
|
while True:
|
if not qval.empty():
|
print_queue(qval)
|
socketio.sleep(.1)
|
@socketio.on('connect')
|
def test_connect():
|
global thread
|
if thread is None:
|
thread = socketio.start_background_task(background_thread, q)
|
emit('my_response', {'data': 'SERVER: websocket connection established. Displaying events, like Cozmo seeing a cube or tapping a cube.'})
|
@app.route('/')
|
def index():
|
return render_template('index.html', randomID=rndID, animations=lists[0], triggers=lists[1], behaviors=lists[2], hasSocketIO=flask_socketio_installed, hasPillow=active_viewer)
|
def start_server():
|
if flask_socketio_installed:
|
flask_socket_helpers.run_flask(socketio, app)
|
else:
|
flask_socket_helpers.run_flask(None, app)
|
def cozmo_program(_robot: cozmo.robot.Robot):
|
global robot
|
global lists
|
global active_viewer
|
robot = _robot
|
try:
|
lists = init_animate(robot)
|
event_monitor.monitor(robot, q)
|
active_viewer = activate_viewer_if_enabled(robot)
|
activate_controls(robot)
|
start_server()
|
except KeyboardInterrupt:
|
print("\nExit requested by user")
|
try:
|
cozmo.robot.Robot.drive_off_charger_on_connect = False
|
cozmo.run_program(cozmo_program)
|
except SystemExit as e:
|
cozmoEnabled = False
|
try:
|
start_server()
|
except KeyboardInterrupt:
|
print("\nExit requested by user")
|
# <FILESEP>
|
# The only clever thing that we do, is strip out "pad" and "last" records
|
# To make editing less tedious
|
def split(mpwobj):
|
"""Split the binary object into a list of "chunks"
|
"""
|
biglist = []
|
ofs = 0
|
while ofs < len(mpwobj):
|
rectype = mpwobj[ofs]
|
if not (rectype <= 20 or rectype == 25):
|
raise ValueError(f'bad record type {rectype} at {hex(offset)}')
|
if rectype == 1: # First
|
reclen = 4
|
elif rectype == 2: # Last
|
reclen = 2
|
elif rectype == 5: # Module
|
reclen = 6
|
elif rectype == 6: # EntryPoint
|
reclen = 8
|
elif rectype == 7: # Size
|
reclen = 6
|
elif rectype == 11: # Filename
|
reclen = 8
|
elif rectype == 14: # ModuleEnd
|
reclen = 8
|
elif rectype == 16: # BlockEnd
|
reclen = 12
|
elif rectype == 25: # XData
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.