Add command to install PDX on device

I'd like to have have an option to install a PDX via command line.

I can compile a project and run it in the Simulator via the command line via:

pdc src game.pdx
PlaydateSimulator game.pdx

But then I must use Device > Install Game To device for the final step. The most frustrating bit is that the folder selection window doesn't always remember my last folder.

This isn't terrible, but it does make on-device iteration longer :confused:

1 Like

If a game is running in the Simulator you can press Cmd+U to upload the game to the device. The device needs to be unlocked, of course. This is how I install most things.

https://sdk.play.date/inside-playdate/#_running_your_game_on_playdate_hardware

A command line option that can be integrated in the build process world be useful.

1 Like

Oh nice! That shortcut is certainly handy. Would be nice to have this documented, or show up in the menu item like other shortcuts.

EDIT: hmm...this doesn't seem to work on Windows. I tried both CTRL+U and ALT+U :frowning:

When you plug in an unlocked device the Simulator (at least on Mac) get a new toolbar icon. I believe I learned the keyboard shortcut from the menu on that button.

I will add a hot key to the Windows Sim for the next release, thanks for pointing that out.

2 Likes

Awesome thank you! That will definitely help a ton🀘

A CLI option would still be preferable - is that something that will be added too?

@SHiLLySiT Adding it directly to pdc would be unlikely due to all platform specific USB code that would have to be added to pdc. However, I could look at adding a flag to the Sim so if you passed the game path using the CLI with this flag it would upload it to the device.

4 Likes

Oh yeah that works! Definitely doesnt need to be in the pdc command. Thanks!

Hi @willco
Was that flag implemented? It would be really useful to have a quick way to test things on the device without moving out of the IDE :smiley:

Thanks!

I totally forgot about this, I'd still like to do it. I've targeted it to the next major release, hopefully I can get to it.

2 Likes

Wait are people not using pdutil? When I make a device build I auto install and run it on device.

pdutil.exe install ../Game.pdx & timeout.exe /t 1 & pdutil.exe run Games/Game.pdx

edit: I mean also being able to auto deploy from sim would be cool too.

3 Likes

Whaaaa?... I've been developing for playdate for a while now and it is my first time learning about pdutil. My bad for only referring to the "Inside Playdate" docs, and nothing else. :smiley:

pdutil doesn't support the install command on Linux or Mac. However, adding it shouldn't be too hard...hum. Ya'll are making more work for me, not less. :wink:

2 Likes

Having no work to do is soul destroying. We're looking out for you Will.

In the meantime, this is the script I use to install and run a pdx to device from Mac.

It uses
Pdutil to reboot device to data disk mode
RSync to copy the pdx (efficiently; only changed files)
Diskutil to stop data disk mode and reboot the device to launcher as a side effect
Pdutil to start the game

If you want to use this, you'll have to remove some unrelated lines and adjust it a bit to your file structure

3 Likes

Just dropping in to say yes please! Thanks in advance for the Linux version :heart:

In the mean time if someone knows of a reliable way in user space to put the device back out of disk mode on Linux that'd be rad. udisksctl unmount/power-off don't seem to do it. (eject requires sudo :frowning: )

depending on your distro you might be able to add your user to a group that allows you to use eject without sudo

Yeah... I went one step better and made a script that creates a script that's locked out for non-sudoers, only ejects playdate and is runnable without sudo.

#!/bin/bash
# Workaround for the fact eject on Linux needs sudo
# Create a script that is locked down and can be run safely

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

PLAYDATE_DEVICE="/dev/sdb1"
EJECT_SCRIPT="$SCRIPT_DIR/eject-playdate.sh"
EJECT_SCRIPT_CONTENT="#!/bin/bash
eject $PLAYDATE_DEVICE"

# Write the eject script out and ensure only sudo can edit it
echo "Creating eject script"
echo "$EJECT_SCRIPT_CONTENT" >>"$EJECT_SCRIPT"
echo "Setting script permissions"
sudo chmod 744 "$EJECT_SCRIPT"
sudo chown root:root "$EJECT_SCRIPT"

SUDOERS_LINE="$USER ALL=(ALL:ALL) NOPASSWD: $EJECT_SCRIPT"
SUDOERS_PATH="/etc/sudoers.d/eject-playdate"

# Add the rights to the sudoers file
echo "Allowing sudo $EJECT_SCRIPT for $USER"
echo "$SUDOERS_LINE" | sudo tee "$SUDOERS_PATH"

echo "Done."

I then have another script that does the actual install using the generated eject script, based on Nino's above for Mac.

#!/bin/bash
# Workaround for the missing "pdutil install" on linux
# Should be implemented soon https://devforum.play.date/t/add-command-to-install-pdx-on-device/5645/16

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

# These seem like the defaults
PLAYDATE_DEVICE="/dev/ttyACM0"
PLAYDATE_MOUNT="/media/$USER/PLAYDATE"
GAMES_PATH="$PLAYDATE_MOUNT/Games"

# Mount the device in data mode
echo "Mounting to datadisk..."
pdutil "$PLAYDATE_DEVICE" datadisk

# Wait for the device to be mounted
until [ -d "$PLAYDATE_MOUNT" ]; do
    sleep 1
done

# Sync over the game, updating only new files and cleaning up
echo "Syncing files..."
rsync -zavrti --update --modify-window=1 --prune-empty-dirs --delete "$SCRIPT_DIR/../zig/$GAME/zig-out/$GAME.pdx" $GAMES_PATH

# Unmount and power-off
# TODO: This doesn't actually reboot the PD?
# udisksctl unmount --block-device /dev/sdb1
# udisksctl power-off --block-device /dev/sdb1
# Use the sudoers script we made
echo "Ejecting playdate..."
sudo "$SCRIPT_DIR/eject-playdate.sh"

# Wait until playdate is back
until ls $PLAYDATE_DEVICE; do
    sleep 1
done

echo "Running on playdate..."
pdutil "$PLAYDATE_DEVICE" run "/Games/$GAME.pdx"

echo "Done."

Hope that helps people in the meantime!

1 Like