Skip to content

Commit

Permalink
chore: script and readme improvements
Browse files Browse the repository at this point in the history
- Add Caution and Uninstall sections to readme
-  Add uninstall scripts
  • Loading branch information
bahaaador committed Nov 10, 2024
1 parent 9879122 commit b33f1cc
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 34 deletions.
43 changes: 39 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,37 @@ Before building and running the project, ensure you have the following installed
```
> Note: You may need to add $(go env GOPATH)/bin to your PATH environment variable with the second command.

## ⚠️ Caution

**Please read before proceeding:**

This project is currently in an experimental state and has only been tested on a limited number of devices. While it works well for my use case, please be aware that:

- The scripts modify system-level configurations and USB settings
- Incorrect USB gadget configuration could potentially require a fresh OS installation to recover
- The project has only been tested on a small number of devices and configurations
- This is a personal project, not production-ready software

**Before running this project, you should:**
- Only use it on devices where you can easily reinstall the OS if needed
- Carefully review all scripts and code before execution
- Have a backup plan in case something goes wrong
- Be comfortable with Linux system administration and USB configurations

I cannot guarantee this will work on all devices or configurations. Proceed at your own risk.

## Setup

1. Log in to your Raspberry Pi Zero.
2. Clone this repository to your board.
3. Run the setup scripts in the following order:

```bash
sudo ./scripts/setup_usb_host.sh
sudo ./scripts/setup_usb_host.sh # enable the USB host and load the necessary modules
sudo reboot
sudo ./scripts/setup_bluetooth.sh
sudo ./scripts/setup_gadgets.sh
sudo ./scripts/setup_bluetooth.sh # enable and start the bluetooth service
sudo ./scripts/setup_gadgets.sh # create the gadget and configure the USB strings
```

5. Pair your Bluetooth devices manually or using the script:
Expand Down Expand Up @@ -113,7 +133,7 @@ This project uses Task runner for common operations:

## Diagnostic Tools

### IO Diagnostic
### I/O Doctor

This tool will check for connected Bluetooth devices and display all incoming events from your Bluetooth keyboard and mouse, helping you debug connection and input issues.

Expand All @@ -133,6 +153,21 @@ This interactive tool allows you to:
2. Type a test message
These simulations help verify that the USB HID device is working correctly on the host computer.

### Uninstall and remove gadget

To uninstall the service:
```bash
task service:uninstall
```

To remove the gadget and restore the USB host configuration:
```bash
./scripts/uninstall/undo_setup_gadgets.sh
./scripts/uninstall/undo_setup_usb_host.sh
```



## Development

This project can be used as is or as basis for other types of USB gadgets. It can also serve as a learning opportunity for:
Expand Down
30 changes: 0 additions & 30 deletions scripts/setup_service.sh

This file was deleted.

39 changes: 39 additions & 0 deletions scripts/uninstall/undo_setup_gadgets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash


# Clean up gadget directory if it exists

cleanup_gadget() {
echo "Cleaning up existing USB configurations..."

# Only unload modules if they exist
if [ $MODULES_LOADED -eq 1 ]; then
echo "Unloading existing USB modules..."
modprobe -r g_ether usb_f_rndis usb_f_ecm u_ether || true
fi

# Clean up gadget directory if it exists
if [ $GADGET_EXISTS -eq 1 ]; then
echo "Removing existing HID gadget configuration..."
cd /sys/kernel/config/usb_gadget/hid_gadget
if [ -f UDC ]; then
echo "" > UDC
fi

# Remove symbolic links
rm -f configs/c.1/hid.usb0
rm -f configs/c.1/hid.usb1

# Remove directories
rm -rf functions/hid.usb0
rm -rf functions/hid.usb1
rm -rf configs/c.1/strings/0x409
rm -rf configs/c.1
rm -rf strings/0x409

cd ..
rmdir hid_gadget 2>/dev/null || true
fi
}

cleanup_gadget
7 changes: 7 additions & 0 deletions scripts/uninstall/undo_setup_usb_host.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Restore config.txt
sudo cp /boot/config.txt.bak /boot/config.txt

# Remove dwc2 driver
sudo sed -i '/dtoverlay=dwc2/d' /boot/config.txt

0 comments on commit b33f1cc

Please sign in to comment.