Skip to content

Commit

Permalink
[CONTROLLER][BLENDER] Control panel / control script update (#585)
Browse files Browse the repository at this point in the history
* Control panel / control script update

* Update controller server README
  • Loading branch information
Chalkman071 authored Mar 18, 2024
1 parent ef18fb4 commit aa40a17
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 10 deletions.
10 changes: 10 additions & 0 deletions controller-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

The configuation for pinMapTable and dancerTable is in `configs/`.

## Playing music

For Linux, use `play` command, it can be installed by running:
```
sudo apt-get install sox libsox-fmt-all
```
For macOS, use `afplay` command.

These commands must be modified in `scripts/schedule_play.sh` and `scripts/schedule_stop.sh` depending on the device that the controller server runs on.

## Message Format

* Example Message from RPi
Expand Down
7 changes: 4 additions & 3 deletions controller-server/scripts/schedule_play.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#! /usr/bin/env bash

TIME=$1
STARTTIME=$2

pgrep 'afplay' | xargs kill
pgrep 'play' | xargs kill # Linux: play (from sox) / macOS: afplay
cd "$(dirname "$0")" || exit

while true; do
# break if the current time is greater than TIME
if [[ $(gdate +%s%N | cut -b1-13) -gt $TIME ]]; then
if [[ $(date +%s%N | cut -b1-13) -gt $TIME ]]; then # Linux: date / macOS: gdate
break
fi
done

afplay '../../files/music/2023.mp3' &
play '../../files/music/2024.mp3' trim $STARTTIME &
echo "start playing"
2 changes: 1 addition & 1 deletion controller-server/scripts/schedule_stop.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#! /usr/bin/env bash
pgrep 'afplay' | xargs kill
pgrep 'play' | xargs kill
4 changes: 3 additions & 1 deletion controller-server/websocket/controlPanel/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function handlePlay(msg: FromControlPanelPlay) {

sendToRPi(dancers, toRPiMsg);

exec(`./scripts/schedule_play.sh ${timestampString}`);
exec(`./scripts/schedule_play.sh ${timestampString} ${start/1000}`);
}

export function handlePause(msg: FromControlPanelPause) {
Expand All @@ -123,6 +123,8 @@ export function handlePause(msg: FromControlPanelPause) {
};

sendToRPi(dancers, toRPiMsg);

exec("./scripts/schedule_stop.sh");
}

export function handleStop(msg: FromControlPanelStop) {
Expand Down
1 change: 1 addition & 0 deletions editor-blender/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ async def close_command(self):

async def restart_command(self):
await self.close_command()
await asyncio.sleep(1)
await self.open_command()


Expand Down
2 changes: 0 additions & 2 deletions editor-blender/core/actions/property/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ async def countdown(delay: int):
print(countdown)
if seconds > 0:
await asyncio.sleep(1)
else:
bpy.ops.screen.animation_play()

if countdown_task.task:
countdown_task.task.cancel()
Expand Down
1 change: 1 addition & 0 deletions editor-blender/core/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ class State:

rpi_status: RPiStatus
shell_history: ShellHistory
last_play_timestamp_ms: int

color_map_updates: ColorMapUpdates
color_map_pending: ColorMapPending
Expand Down
1 change: 1 addition & 0 deletions editor-blender/core/states/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
color_map={},
rpi_status={},
shell_history={},
last_play_timestamp_ms=0,
color_map_updates=ColorMapUpdates(added=[], updated=[], deleted=[]),
color_map_pending=ColorMapPending(add_or_delete=False, update=False),
led_map_updates=LEDMapUpdates(added=[], updated=[], deleted=[]),
Expand Down
14 changes: 11 additions & 3 deletions editor-blender/operators/command_center/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,21 @@ async def async_execute(self, context: bpy.types.Context):
bpy.context.window_manager, "ld_ui_command_center"
)
set_countdown(command_status.delay)
start_timestamp_ms = int(time.time() * 1000) + command_status.delay * 1000
try:
play_payload = ToControllerServerPlayPartial.from_dict(
{
"topic": "play",
"payload": {
"dancers": get_selected_dancer(),
"start": bpy.context.scene.frame_current,
"timestamp": int(time.time()) + command_status.delay,
"timestamp": start_timestamp_ms,
},
}
)
# set_requesting(True)
await command_agent.send_to_controller_server(play_payload)
state.last_play_timestamp_ms = start_timestamp_ms

except Exception as e:
# set_requesting(False)
Expand All @@ -156,13 +158,18 @@ def poll(cls, context: bpy.types.Context):
return True

async def async_execute(self, context: bpy.types.Context):
bpy.ops.screen.animation_cancel(restore_frame=False)
# bpy.ops.screen.animation_cancel(restore_frame=False)
try:
pause_payload = ToControllerServerPausePartial.from_dict(
{"topic": "pause", "payload": {"dancers": get_selected_dancer()}}
)
# set_requesting(True)
await command_agent.send_to_controller_server(pause_payload)
time_since_last_play_ms = (
int(time.time() * 1000) - state.last_play_timestamp_ms
)
if time_since_last_play_ms < 600000:
bpy.context.scene.frame_current += time_since_last_play_ms

except Exception as e:
# set_requesting(False)
Expand All @@ -179,7 +186,7 @@ def poll(cls, context: bpy.types.Context):
return True

async def async_execute(self, context: bpy.types.Context):
bpy.ops.screen.animation_cancel(restore_frame=True)
# bpy.ops.screen.animation_cancel(restore_frame=True)
if countdown_task.task:
countdown_task.task.cancel()
countdown_task.task = None
Expand All @@ -193,6 +200,7 @@ async def async_execute(self, context: bpy.types.Context):
)
# set_requesting(True)
await command_agent.send_to_controller_server(stop_payload)
bpy.context.scene.frame_current = 0

except Exception as e:
# set_requesting(False)
Expand Down

0 comments on commit aa40a17

Please sign in to comment.