Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installer script #22

Merged
merged 8 commits into from
Oct 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ Below are the currently supported cores:
|PSX|


If you find bugs, please report them as an issue if you run into any.
Please report any bugs as an issue if you run into any.


# Table of Contents

- [TL;DR Instructions](#tldr)
- [Quick Start Guide](#quick-start)
- [Hardware Needed](#hardware-needed)
- [Arduino Hardware Setup](#arduino-hardware-setup)
- [Write Card Setup](#write-card-setup)
Expand Down Expand Up @@ -71,7 +71,7 @@ _This version allows you to assign games to cards without needing to edit the `r

- Download Arduino software
- Connect Arduino Nano
- Open misterrfid.ino
- Open arduino/misterrfid.ino
- Go to Tools -> Manage Libraries and search for MFRC522
- Install Easy MFRC522
- Verify Installation and Upload
Expand All @@ -80,7 +80,7 @@ On your computer, attach the serial monitor to your Arduino and you should see i

:warning: Skipping steps below will cause your code to not function! :warning:

If you find out that that you would like to extend the distance the card is picked up, You can adjust the receiver gain by editing line `21` of the `misterrfid.ino` and upload the code.
If you find out that that you would like to extend the distance the card is picked up, You can adjust the receiver gain by editing line `21` of the `arduino/misterrfid.ino` and upload the code.

```
rfid.PCD_SetRegisterBitMask(rfid.RFCfgReg, (0x03<<4)); // RFID Gain
Expand All @@ -102,17 +102,17 @@ On your computer, attach the serial monitor to your Arduino and you should see i

### Write Card Setup

As you are gathering numbers from your cards or RFID tags, choose an RFID device that you'd like to use as a `write card` This card acts as a trigger to put your Arduino code into a loop that will run the `rfid_write.sh` file. The number of this RFID device needs to be replace `12346789` in `misterrfid.ino` at line `4`. After you have done this, overwrite your Arduino with the new code. Set that card aside for later.
As you are gathering numbers from your cards or RFID tags, choose an RFID device that you'd like to use as a `write card` This card acts as a trigger to put your Arduino code into a loop that will run the `rfid_write.sh` file. The number of this RFID device needs to be replace `12346789` in `arduino/misterrfid.ino` at line `4`. After you have done this, overwrite your Arduino with the new code. Set that card aside for later.

```
#define WRITE_TAG 1234567890
```

## MiSTer Setup

Copy the files to your MiSTer SD card based on the structure of this repo from the `fat/media` folder. ATTENTION: Make sure you don't overwrite user-startup.sh if you have other services running like Favorites, Super Attract Mode or TTY2OLED. If you use TTY2OLED, make sure you assign the right ttydev to the right device.
Copy `rfid_updater.sh` to `/media/fat/Scripts`. Boot your mister, and run `rfid_updater.sh` from the Scripts folder. Continue to [Use](#use) when this is done.

Edit MiSTer.ini and change `log_file_entry=0` to `log_file_entry=1`. This step allows `rfid_write.sh` to read the currently-playing game/core.
Note: If you use TTY2OLED, make sure you assign the right ttydev to the right device.

#### Manually Adding Cores _(Optional)_

Expand Down Expand Up @@ -157,7 +157,7 @@ Relative to the games folder for the PSX core is: `Crash Bandicoot/Crash Bandico

## Use

- After making any changes or uploading files to your MiSTer, power it down.
- After running `rfid_updater.sh`, making any changes, or uploading files to your MiSTer, power it down.
- Plug your Arduino into an available USB port on your USB board module and turn on your MiSTer. Depending on how many scripts you have running, it can take up to 30 seconds from first turning on the power to the RFID reader becoming available.
- Once the RFID is available, you can start lunching games (if you added games to the `game_list.conf` file), or begin [Assigning Games to Cards](#Assigning-Games-to-Cards)

Expand All @@ -179,19 +179,21 @@ NeoGeo games must use the `.neo` extension. You cannot use a darksoft roll-up wi

## Troubleshooting

- Check that your MiSTer.ini file(s) has `log_file_entry=1`
- If your cards don't seem to be scanning in MiSTer, make sure that `serial_listen.sh` actually started. I have had issues with that not booting in the past. Re-imaging my SD card takes care of this if nothing else.
- If games aren't being added to the right spot, or being injected in odd places in `game_list.conf` make sure you respected the format into `game_list.conf`. Read [MiSTer Setup](#MiSTer-Setup).
- If your write card doesn't function. Make sure you added the card number to the Arduino code **and** re-uploaded after making that change.

## TL;DR

## Quick Start

- Set up your Arduino and MFRC522 using: [Arduino Hardware Setup](#Arduino-Hardware-Setup)
- Write the code to the Arduino
- Pick a card to be the `write card` and jot down the number
- Replace the value for `const uint32_t wCard` in `misterrfid.ino` with your card number
- Pick a card to be the `write card`, scan it with the serial listener open, and jot down the number
- Replace the value for `WRITE_TAG` in `arduino/misterrfid.ino` with your card number
- Re-write to the arduino
- Add Scripts files to the `Scripts` folder on the MiSTer, as well as the linux file
- Edit MiSTer.ini and change `log_file_entry=0` to `log_file_entry=1`.
- Add rfid_updater.sh to Scripts folder and run it.
- Follow the [Use](#use) section

### THANK YOU

Expand Down
File renamed without changes.
124 changes: 124 additions & 0 deletions rfid_updater.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/bin/bash
{
CURL_RETRY="--connect-timeout 15 --max-time 600 --retry 3 --retry-delay 5"
ALLOW_INSECURE_SSL="true"
SCRIPT_PATH=/media/fat/Scripts/rfid_updater.sh
SCRIPTS_FOLDER=/media/fat/Scripts
SSL_SECURITY_OPTION=""
UPDATER_DOWNLOAD=("rfid_updater.sh")
ROOT_DOWNLOADS=("rfid_process.sh" "rfid_write.sh" "serial_listen.sh")
UTIL_DOWNLOADS=("game_list.conf" "neoGeo_games.sh" "rfid_write.mp3" "rfid_process.mp3" "write_tag.mp3")
USER_STARTUP=/media/fat/linux/user-startup.sh
LOGFILE=/media/fat/Scripts/rfid_util/rfid_log.txt

mister_rfid() {
if [ -e "/media/fat/Scripts/rfid_util" ]; then
UTIL_DOWNLOADS=("${UTIL_DOWNLOADS[@]:1}")
echo -e "Updating MiSTerRFID!\n"
mv "$SCRIPTS_FOLDER"/rfid_write.sh "$SCRIPTS_FOLDER"/rfid_util/rfid_write.bak
echo -e "A backup of rfid_write.sh has been created in\n${SCRIPTS_FOLDER}/rfid_util/rfid_write.bak\n"
echo -e "############################################################\n"
sleep 2
else
mkdir ""$SCRIPTS_FOLDER"/rfid_util"
echo -e "Installing MiSTerRFID!\n"
echo -e "############################################################\n"
sleep 2
fi

curl ${CURL_RETRY} --silent --show-error "https://github.com" >/dev/null 2>&1
case $? in
0) ;;

60)
if [[ "${ALLOW_INSECURE_SSL}" == "true" ]]; then
SSL_SECURITY_OPTION="--insecure"
else
echo "CA certificates need"
echo "to be fixed for"
echo "using SSL certificate"
echo "verification."
echo "Please fix them"
exit 2
fi
;;
*)
echo "No Internet connection"
exit 1
;;
esac

REPOSITORY_URL="https://raw.githubusercontent.com/ElRojo/MiSTerRFID"
echo "Starting download..."
echo -e "${REPOSITORY_URL}\n"
for i in "${ROOT_DOWNLOADS[@]}"; do
curler ""${SCRIPTS_FOLDER}"/"${i}"" "${REPOSITORY_URL}/main/fat/media/Scripts/${i}"
done
for i in "${UTIL_DOWNLOADS[@]}"; do
curler ""${SCRIPTS_FOLDER}/rfid_util"/"${i}"" "${REPOSITORY_URL}/main/fat/media/Scripts/rfid_util/${i}"
done
}

curler() {
echo "Downloading ${i}"
curl \
${CURL_RETRY} --silent --show-error \
${SSL_SECURITY_OPTION} \
--fail \
--location \
-o "$1" \
"$2"
}
mister_log_enabler() {
echo -e "\n############################################################"
echo "Enabling log_file_entry in MiSTer.ini"
echo -e "############################################################\n"
sed -i "s/log_file_entry=0/log_file_entry=1/g" "/media/fat/MiSTer.ini"
if [ -e "/media/fat/MiSTer_alt_1.ini" ]; then
echo -e "\n############################################################"
echo "Enabling log_file_entry in alt ini files."
echo -e "############################################################\n"
for ((i = 1; i < 4; i++)); do
sed -i "s/log_file_entry=0/log_file_entry=1/g" "/media/fat/MiSTer_alt_$i.ini"
done
fi
}

user_startup() {
if [ ! -e ${USER_STARTUP} ]; then
echo -e "user-startup.sh not found.\n"
create_user_startup
else
userStartupLine=$(grep -n "screen -d -m -t rfid sh /media/fat/Scripts/serial_listen.sh" ${USER_STARTUP})
if [[ $userStartupLine != *"screen -d -m -t rfid"* ]]; then
echo -e "user-startup.sh exists, adding rfid line..."
echo "screen -d -m -t rfid sh /media/fat/Scripts/serial_listen.sh" >>${USER_STARTUP}
fi
fi

}

create_user_startup() {
echo "############################################################"
echo "Creating user-startup.sh"
echo "############################################################"
touch ${USER_STARTUP}
{
echo '#!/bin/sh'
echo '"***" $1 "***"'
echo 'screen -d -m -t rfid sh /media/fat/Scripts/serial_listen.sh'
} >>${USER_STARTUP}
}
echo -e "############################################################\n\nThanks for using MiSTer RFID!\nPlease report any bugs here:\nhttps://github.com/ElRojo/MiSTerRFID/issues\n\n############################################################\n"
sleep 2
mister_rfid
mister_log_enabler
user_startup
for i in "${UPDATER_DOWNLOAD}"; do
curler "${SCRIPT_PATH}" "${REPOSITORY_URL}/main/${SCRIPT_PATH}"
done
echo -e "\nComplete!\n"
echo -e "Power off your MiSTER, plug in your RFID reader,\nand power the MiSTER back on to begin using it!\n"
sleep 2
exit 0
}